Skip to content

Commit

Permalink
test: add plugins and partial mixins unit test (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phinome authored Nov 19, 2020
1 parent 37d5933 commit f26623d
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 9 deletions.
13 changes: 12 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,16 @@ module.exports = {
'vue/object-curly-spacing': ['error', 'always'],
'vue/space-infix-ops': 'error',
'vue/space-unary-ops': ['error', { words: true, nonwords: false }]
}
},
overrides: [
{
files: ['*.spec.js'],
env: {
mocha: true,
},
globals: {
expect: true
}
}
]
}
8 changes: 0 additions & 8 deletions packages/veui/test/unit/.eslintrc

This file was deleted.

55 changes: 55 additions & 0 deletions packages/veui/test/unit/specs/mixins/activatable.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Vue from 'vue'
import { createLocalVue, shallowMount } from '@vue/test-utils'
import activatable from '@/mixins/activatable'

const noop = function () {}

const localVue = createLocalVue()

const ActivatableComponent = {
template: '<div>Activatable Component</div>',
methods: {
activate: noop
},
mixins: [activatable]
}

const InActivatableComponent = {
template: '<div>InActivatable Component</div>',
methods: {
inactivate: noop
},
mixins: [activatable]
}

describe('mixins/activatable', () => {
let msg
beforeEach(() => {
Vue.config.warnHandler = message => {
msg = message
}
})

afterEach(() => {
Vue.config.warnHandler = undefined
msg = undefined
})

it('should has `activate` method', () => {
const { vm } = shallowMount(ActivatableComponent, {
localVue
})

expect(vm.activate).to.be.a('function')
expect(msg).to.equal(undefined)
})

it('should out warn that `activate` is not method', () => {
const { vm } = shallowMount(InActivatableComponent, {
localVue
})

expect(vm.activate).to.equal(undefined)
expect(msg).to.not.equal(undefined)
})
})
77 changes: 77 additions & 0 deletions packages/veui/test/unit/specs/mixins/dropdown.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { createLocalVue, shallowMount } from '@vue/test-utils'
import dropdown from '@/mixins/dropdown'

const localVue = createLocalVue()

const DropdownComponent = {
template: '<div><div ref="box">dropdown child</div></div>',
data () {
return {
realDisabled: false,
realReadonly: false
}
},
mixins: [dropdown]
}

describe('mixins/dropdown', () => {
it('should apply dropdown mixins', () => {
const { vm } = shallowMount(DropdownComponent, {
localVue,
propsData: {
expanded: false
}
})

expect(vm.dropdownId).to.include('veui-dropdown-')
})

it('should activate dropdown component', async () => {
const wrapper = shallowMount(DropdownComponent, {
localVue,
propsData: {
expanded: false
}
})

wrapper.vm.activate()

await wrapper.vm.$nextTick()

expect(wrapper.emitted().toggle.length).to.equal(1)
})

it('should inactivate dropdown component', async () => {
const wrapper = shallowMount(DropdownComponent, {
localVue,
propsData: {
expanded: true
}
})

wrapper.vm.close()

await wrapper.vm.$nextTick()

expect(wrapper.emitted().toggle.length).to.equal(1)
})

it('should not expand dropdown when being readonly or disabled', async () => {
const wrapper = shallowMount(DropdownComponent, {
localVue,
propsData: {
expanded: false
}
})

wrapper.setData({
realDisabled: true
})

wrapper.vm.activate()

await wrapper.vm.$nextTick()

expect(wrapper.emitted().toggle).to.be.equal(undefined)
})
})
16 changes: 16 additions & 0 deletions packages/veui/test/unit/specs/plugins/alert.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createLocalVue } from '@vue/test-utils'
import alertPlugin from '@/plugins/alert'

const localVue = createLocalVue()

localVue.use(alertPlugin)

describe('plugins/alert', () => {
it('should add `alert` methods to Vue prototype', () => {
expect(localVue.prototype.$alert).to.be.a('function')
expect(localVue.prototype.$alert.success).to.be.a('function')
expect(localVue.prototype.$alert.info).to.be.a('function')
expect(localVue.prototype.$alert.warn).to.be.a('function')
expect(localVue.prototype.$alert.error).to.be.a('function')
})
})
12 changes: 12 additions & 0 deletions packages/veui/test/unit/specs/plugins/confirm.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createLocalVue } from '@vue/test-utils'
import confirmPlugin from '@/plugins/confirm'

const localVue = createLocalVue()

localVue.use(confirmPlugin)

describe('plugins/confirm', () => {
it('should add `confirm` methods to Vue prototype', () => {
expect(localVue.prototype.$confirm).to.be.a('function')
})
})
12 changes: 12 additions & 0 deletions packages/veui/test/unit/specs/plugins/prompt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createLocalVue } from '@vue/test-utils'
import promptPlugin from '@/plugins/prompt'

const localVue = createLocalVue()

localVue.use(promptPlugin)

describe('plugins/prompt', () => {
it('should add `prompt` methods to Vue prototype', () => {
expect(localVue.prototype.$prompt).to.be.a('function')
})
})
16 changes: 16 additions & 0 deletions packages/veui/test/unit/specs/plugins/toast.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createLocalVue } from '@vue/test-utils'
import toastPlugin from '@/plugins/toast'

const localVue = createLocalVue()

localVue.use(toastPlugin)

describe('plugins/toast', () => {
it('should add `toast` methods to Vue prototype', () => {
expect(localVue.prototype.$toast).to.be.a('function')
expect(localVue.prototype.$toast.success).to.be.a('function')
expect(localVue.prototype.$toast.info).to.be.a('function')
expect(localVue.prototype.$toast.warn).to.be.a('function')
expect(localVue.prototype.$toast.error).to.be.a('function')
})
})

0 comments on commit f26623d

Please sign in to comment.