Nothing Special   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
add unit test for theme/components
Browse files Browse the repository at this point in the history
  • Loading branch information
think-in-universe committed Oct 29, 2019
1 parent 9783f9e commit d0043af
Show file tree
Hide file tree
Showing 28 changed files with 1,338 additions and 0 deletions.
68 changes: 68 additions & 0 deletions docs/.vuepress/theme/components/__tests__/DropdownLink.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { shallowMount } from '@vue/test-utils'
import DropdownLink from "@/theme/components/DropdownLink"

describe('DropdownLink', () => {
test('render successfully for non-languages', () => {
const wrapper = shallowMount(DropdownLink, {
propsData: {
item: {
text: "choices",
items: [{
text: "currency",
link: "http://currency.com",
type: "links",
items: [{
text: "USD",
link: "http://currency.com/USD"
}, {
text: "BTC",
link: "http://currency.com/BTC"
}
]}, {
text: "planet",
link: "http://planets.com",
type: "images"
}, {
text: "color",
link: "http://colors.com",
type: "links",
items: [{
text: "red",
link: "http://color.com/red"
}, {
text: "blue",
link: "http://color.com/blue"
}, {
text: "green",
link: "http://color.com/blue"
}
]
}]
}
}
})
expect(wrapper.element).toMatchSnapshot()
})

test('render successfully for languages', () => {
const wrapper = shallowMount(DropdownLink, {
propsData: {
item: {
text: "Languages",
items: [{
text: "English",
link: "en"
}, {
text: "Deutsch",
link: "de",
}, {
text: "Italiano",
link: "it"
}]
}
}
})
expect(wrapper.element).toMatchSnapshot()
})

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { shallowMount } from '@vue/test-utils'
import DropdownTransition from "@/theme/components/DropdownTransition"

describe('DropdownTransition', () => {
test('render successfully', () => {
const wrapper = shallowMount(DropdownTransition)
expect(wrapper.element).toMatchSnapshot()
})
})
10 changes: 10 additions & 0 deletions docs/.vuepress/theme/components/__tests__/Footer.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { shallowMount } from '@vue/test-utils'
import Footer from "@/theme/components/Footer"

describe('Footer', () => {
test('render successfully', () => {
const wrapper = shallowMount(Footer)
expect(wrapper.element).toMatchSnapshot()
})
})

18 changes: 18 additions & 0 deletions docs/.vuepress/theme/components/__tests__/Header.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { shallowMount } from '@vue/test-utils'
import Header from "@/theme/components/Header"

describe('Header', () => {
test('render successfully', () => {
const wrapper = shallowMount(Header, {
mocks: {
$site: {
themeConfig: {
search: true
}
}
}
})
expect(wrapper.element).toMatchSnapshot()
})
})

23 changes: 23 additions & 0 deletions docs/.vuepress/theme/components/__tests__/Hero.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { shallowMount } from '@vue/test-utils'
import Hero from "@/theme/components/Hero"

describe('Hero', () => {
test('dark mode', () => {
const wrapper = shallowMount(Hero, {
propsData: {
dark: true
}
})
expect(wrapper.element).toMatchSnapshot()
})

test('light mode', () => {
const wrapper = shallowMount(Hero, {
propsData: {
dark: false
}
})
expect(wrapper.element).toMatchSnapshot()
})
})

68 changes: 68 additions & 0 deletions docs/.vuepress/theme/components/__tests__/LanguageDropdown.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { shallowMount } from '@vue/test-utils'
import LanguageDropdown from "@/theme/components/LanguageDropdown"

describe('LanguageDropdown', () => {
test('render with locales', () => {
const wrapper = shallowMount(LanguageDropdown, {
mocks: {
$site: {
locales: {
"en": {
label: "English",
lang: "en"
},
"de": {
label: "Deutsch",
lang: "de"
}
},
},
$lang: "ko",
$page: {
path: "/en"
},
$localeConfig: {
path: "en"
},
$router: {
options: {
routes: [{
path: "/en"
}, {
path: "/de"
}]
}
}
}
})
expect(wrapper.element).toMatchSnapshot()
})

test('render without locales', () => {
const wrapper = shallowMount(LanguageDropdown, {
mocks: {
$site: {
locales: {
},
},
$lang: "ko",
$page: {
path: "/en"
},
$localeConfig: {
path: "en"
},
$router: {
options: {
routes: [{
path: "/en"
}, {
path: "/de"
}]
}
}
}
})
expect(wrapper.element).toMatchSnapshot()
})
})
10 changes: 10 additions & 0 deletions docs/.vuepress/theme/components/__tests__/LanguageIcon.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { shallowMount } from '@vue/test-utils'
import LanguageIcon from "@/theme/components/LanguageIcon"

describe('LanguageIcon', () => {
test('render successfully', () => {
const wrapper = shallowMount(LanguageIcon)
expect(wrapper.element).toMatchSnapshot()
})
})

66 changes: 66 additions & 0 deletions docs/.vuepress/theme/components/__tests__/NavLink.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { shallowMount } from '@vue/test-utils'
import NavLink from "@/theme/components/NavLink"

describe('NavLink', () => {
test('render as external link', () => {
const wrapper = shallowMount(NavLink, {
propsData: {
item: {
text: "external link",
link: "https://google.com"
}
}
})
expect(wrapper.element).toMatchSnapshot()
})

test('render as email', () => {
const wrapper = shallowMount(NavLink, {
propsData: {
item: {
text: "email",
link: "mailto:abc@google.com"
}
}
})
expect(wrapper.element).toMatchSnapshot()
})

test('render as tel', () => {
const wrapper = shallowMount(NavLink, {
propsData: {
item: {
text: "tel",
link: "tel:1778901652"
}
}
})
expect(wrapper.element).toMatchSnapshot()
})

test('render as link with locales', () => {
const wrapper = shallowMount(NavLink, {
propsData: {
item: {
text: "English",
link: "en"
}
},
mocks: {
$site: {
locales: {
"en": {
label: "English",
lang: "en"
},
"de": {
label: "Deutsch",
lang: "de"
}
},
}
}
})
expect(wrapper.element).toMatchSnapshot()
})
})
84 changes: 84 additions & 0 deletions docs/.vuepress/theme/components/__tests__/NavLinks.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { shallowMount } from '@vue/test-utils'
import NavLinks from "@/theme/components/NavLinks"

describe('NavLinks', () => {
test('render as sidebar, with no navigation', () => {
const wrapper = shallowMount(NavLinks, {
propsData: {
isSidebar: true
},
mocks: {
$site: {
locales: {
"/": {}
},
},
$lang: "en-US"
}
})
expect(wrapper.element).toMatchSnapshot()
})

test('render as sidebar, with navigation', () => {
const wrapper = shallowMount(NavLinks, {
propsData: {
isSidebar: true
},
mocks: {
$site: {
locales: {
"/": {
nav: ["en"]
},
"/de/": {
nav: "de"
}
},
},
$lang: "en-US"
}
})
expect(wrapper.element).toMatchSnapshot()
})

test('render as sidebar, with navigation and sub-items', () => {
const wrapper = shallowMount(NavLinks, {
propsData: {
isSidebar: true
},
mocks: {
$site: {
locales: {
"/": {
nav: [{
items: ["en-US", "en-GB"]
}]
},
"/de/": {
nav: "de"
}
},
},
$lang: "en-US"
}
})
expect(wrapper.element).toMatchSnapshot()
})

test('render not as sidebar', () => {
const wrapper = shallowMount(NavLinks, {
propsData: {
isSidebar: false
},
mocks: {
$site: {
locales: {
"/": {}
},
},
$lang: "en-US"
}
})
expect(wrapper.element).toMatchSnapshot()
})
})
17 changes: 17 additions & 0 deletions docs/.vuepress/theme/components/__tests__/SearchBox.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { shallowMount } from '@vue/test-utils'
import SearchBox from "@/theme/components/SearchBox"

describe('SearchBox', () => {
test('render searchbox', () => {
const wrapper = shallowMount(SearchBox)
expect(wrapper.element).toMatchSnapshot()
})

test('searchbox suggest', () => {
const wrapper = shallowMount(SearchBox)
wrapper.find("input[aria-label]").setValue("eth")
wrapper.find("input[aria-label]").trigger("keyup.enter")
expect(wrapper.element).toMatchSnapshot()
})
})

Loading

0 comments on commit d0043af

Please sign in to comment.