added unit tests to widgets

This commit is contained in:
woothu
2018-10-09 13:33:43 +02:00
parent b318110c7d
commit 4741d4231a
14 changed files with 233 additions and 71 deletions
+37
View File
@@ -0,0 +1,37 @@
import Vue from 'vue'
import { shallowMount } from '@vue/test-utils'
import BootstrapVue from 'bootstrap-vue'
import Component from '@/views/widgets/Widget01'
Vue.use(BootstrapVue)
const ComponentName = 'Widget01'
const wrapper = shallowMount(Component)
describe(ComponentName + '.vue', () => {
it('has a name', () => {
expect(Component.name).toMatch(ComponentName)
})
it('has a created hook', () => {
expect(typeof Component.data).toMatch('function')
})
it('is Vue instance', () => {
expect(wrapper.isVueInstance()).toBe(true)
})
it('correctly sets default props and data when created', () => {
const vm = new Vue(Component).$mount()
expect(vm.backgroundColor).toBe('')
expect(vm.styleClasses).toBe('')
expect(vm.header).toBe('header|string')
expect(vm.text).toBe('text|string')
expect(vm.variant).toBe('')
expect(vm.footer).toBe('footer|string')
expect(vm.value == 25).toBe(true)
})
it('correctly sets variant when background is not white', () => {
const Constructor = Vue.extend(Component)
const vm = new Constructor({ propsData: {variant : 'background-success'}}).$mount()
expect(vm.backgroundColor).toBe('success')
expect(vm.styleClasses).toBe('text-white bg-success')
})
})
+26
View File
@@ -0,0 +1,26 @@
import Vue from 'vue'
import { shallowMount } from '@vue/test-utils'
import BootstrapVue from 'bootstrap-vue'
import Component from '@/views/widgets/Widget02'
Vue.use(BootstrapVue)
const ComponentName = 'Widget02'
const wrapper = shallowMount(Component)
describe(ComponentName + '.vue', () => {
it('has a name', () => {
expect(Component.name).toMatch(ComponentName)
})
it('is Vue instance', () => {
expect(wrapper.isVueInstance()).toBe(true)
})
it('correctly sets default props when created', () => {
const vm = new Vue(Component).$mount()
expect(vm.header).toBe('header|string')
expect(vm.text).toBe('text|string')
expect(vm.link).toBe('#')
expect(vm.iconClasses).toBe('fa fa-cogs bg-primary')
expect(vm.showLink).toBe(false)
})
})
+24
View File
@@ -0,0 +1,24 @@
import Vue from 'vue'
import { shallowMount } from '@vue/test-utils'
import BootstrapVue from 'bootstrap-vue'
import Component from '@/views/widgets/Widget03'
Vue.use(BootstrapVue)
const ComponentName = 'Widget03'
const wrapper = shallowMount(Component)
describe(ComponentName + '.vue', () => {
it('has a name', () => {
expect(Component.name).toMatch(ComponentName)
})
it('is Vue instance', () => {
expect(wrapper.isVueInstance()).toBe(true)
})
it('correctly sets default props when created', () => {
const vm = new Vue(Component).$mount()
expect(vm.header).toBe('header|string')
expect(vm.text).toBe('text|string')
expect(vm.iconClasses).toBe('fa fa-cogs bg-primary')
})
})
+25
View File
@@ -0,0 +1,25 @@
import Vue from 'vue'
import { shallowMount } from '@vue/test-utils'
import BootstrapVue from 'bootstrap-vue'
import Component from '@/views/widgets/Widget04'
Vue.use(BootstrapVue)
const ComponentName = 'Widget04'
const wrapper = shallowMount(Component)
describe(ComponentName + '.vue', () => {
it('has a name', () => {
expect(Component.name).toMatch(ComponentName)
})
it('is Vue instance', () => {
expect(wrapper.isVueInstance()).toBe(true)
})
it('correctly sets default props and data when created', () => {
const vm = new Vue(Component).$mount()
expect(vm.rightHeader).toBe('rightHeader|string')
expect(vm.rightFooter).toBe('rightFooter|string')
expect(vm.leftHeader).toBe('leftHeader|string')
expect(vm.leftFooter).toBe('leftFooter|string')
})
})
+36
View File
@@ -0,0 +1,36 @@
import Vue from 'vue'
import { shallowMount } from '@vue/test-utils'
import BootstrapVue from 'bootstrap-vue'
import Component from '@/views/widgets/Widget05'
Vue.use(BootstrapVue)
const ComponentName = 'Widget05'
const wrapper = shallowMount(Component)
describe(ComponentName + '.vue', () => {
it('has a name', () => {
expect(Component.name).toMatch(ComponentName)
})
it('is Vue instance', () => {
expect(wrapper.isVueInstance()).toBe(true)
})
it('has a created hook', () => {
expect(typeof Component.data).toMatch('function')
})
it('correctly sets default props and data when created', () => {
const vm = new Vue(Component).$mount()
expect(vm.backgroundColor).toBe('')
expect(vm.styleClasses).toBe('')
expect(vm.header).toBe('header|string')
expect(vm.text).toBe('text|string')
expect(vm.variant).toBe('')
expect(vm.value == 25).toBe(true)
})
it('correctly sets variant when background is not white', () => {
const Constructor = Vue.extend(Component)
const vm = new Constructor({ propsData: {variant : 'background-success'}}).$mount()
expect(vm.backgroundColor).toBe('success')
expect(vm.styleClasses).toBe('text-white bg-success')
})
})
+18
View File
@@ -0,0 +1,18 @@
import Vue from 'vue'
import { shallowMount } from '@vue/test-utils'
import BootstrapVue from 'bootstrap-vue'
import Component from '@/views/Widgets'
Vue.use(BootstrapVue)
const ComponentName = 'Widgets'
const wrapper = shallowMount(Component)
describe(ComponentName + '.vue', () => {
it('has a name', () => {
expect(Component.name).toMatch(ComponentName)
})
it('is Vue instance', () => {
expect(wrapper.isVueInstance()).toBe(true)
})
})