-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add plugins and partial mixins unit test (#746)
- Loading branch information
Showing
8 changed files
with
200 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |