From 221eafea3e325a2c856a8c177ded5fa4703efb60 Mon Sep 17 00:00:00 2001 From: feibinyang Date: Wed, 29 May 2019 18:00:16 +0800 Subject: [PATCH] test: add test cases for Alert (#444) --- .../test/unit/specs/components/Alert.spec.js | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 packages/veui/test/unit/specs/components/Alert.spec.js diff --git a/packages/veui/test/unit/specs/components/Alert.spec.js b/packages/veui/test/unit/specs/components/Alert.spec.js new file mode 100644 index 000000000..7cbb676ef --- /dev/null +++ b/packages/veui/test/unit/specs/components/Alert.spec.js @@ -0,0 +1,116 @@ +import { mount } from '@vue/test-utils' +import Alert from '@/components/Alert' +import { wait } from '../../../utils' + +describe('components/Alert', function () { + it('shoule render right type for Alert', () => { + let wrapper = mount({ + components: { + 'veui-alert': Alert + }, + template: '' + }) + expect(wrapper.contains('.veui-alert-success')).to.be.equal(true) + wrapper.destroy() + }) + + it('should render slot successfully for Alert', () => { + let wrapper = mount({ + components: { + 'veui-alert': Alert + }, + data () { + return { + message: 'default slot content' + } + }, + template: ` + +
{{ message }}
+
+ ` + }) + expect(wrapper.text()).to.be.equal('default slot content') + wrapper.destroy() + }) + + it('should close the message successfully for Alert', async () => { + let wrapper = mount({ + components: { + 'veui-alert': Alert + }, + data () { + return { + open: true, + closed: false + } + }, + methods: { + close () { + this.closed = true + } + }, + template: ` + + ` + }) + wrapper.find('.veui-alert-close-text').trigger('click') + await wait(500) + expect(wrapper.find('.veui-alert').exists()).to.be.equal(false) + expect(wrapper.vm.open).to.be.equal(false) + expect(wrapper.vm.closed).to.be.equal(true) + wrapper.destroy() + }) + + it('should render multiple message successfully for Alert', () => { + let wrapper = mount({ + components: { + 'veui-alert': Alert + }, + data () { + return { + message: ['message one', 'message two', 'message three'] + } + }, + template: '' + }) + expect(wrapper.find('.veui-alert-nav').exists()).to.be.equal(true) + wrapper.destroy() + }) + + it('should switch message correctly for Alert', () => { + let wrapper = mount({ + components: { + 'veui-alert': Alert + }, + data () { + return { + message: ['message one', 'message two', 'message three'] + } + }, + template: '' + }) + let nav = wrapper.find('.veui-alert-nav') + let prev = nav.findAll('.veui-button').at(0) + let next = nav.findAll('.veui-button').at(1) + prev.trigger('click') + expect(wrapper.text()).to.be.equal('message one 1/3') + prev.trigger('click') + expect(wrapper.text()).to.be.equal('message one 1/3') + next.trigger('click') + expect(wrapper.text()).to.be.equal('message two 2/3') + next.trigger('click') + expect(wrapper.text()).to.be.equal('message three 3/3') + next.trigger('click') + expect(wrapper.text()).to.be.equal('message three 3/3') + wrapper.destroy() + }) +})