From cb2c71bd2f210e706c552a38ff51be3591555bd7 Mon Sep 17 00:00:00 2001 From: tjz <415800467@qq.com> Date: Sun, 17 Jun 2018 15:57:09 +0800 Subject: [PATCH] =?UTF-8?q?test:=20add=20dropdown=20=E3=80=81popover?= =?UTF-8?q?=E3=80=81=20tag=E3=80=81=20time-picker=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/dropdown-button.test.js | 34 ++++++++++++++ .../__snapshots__/index.test.js.snap | 25 +++++++++++ components/popover/__tests__/index.test.js | 35 +++++++++++++++ components/tag/__tests__/index.test.js | 44 +++++++++++++++++++ .../__snapshots__/index.test.js.snap | 7 +++ .../time-picker/__tests__/index.test.js | 24 ++++++++++ 6 files changed, 169 insertions(+) create mode 100644 components/dropdown/__tests__/dropdown-button.test.js create mode 100644 components/popover/__tests__/__snapshots__/index.test.js.snap create mode 100644 components/popover/__tests__/index.test.js create mode 100644 components/tag/__tests__/index.test.js create mode 100644 components/time-picker/__tests__/__snapshots__/index.test.js.snap create mode 100644 components/time-picker/__tests__/index.test.js diff --git a/components/dropdown/__tests__/dropdown-button.test.js b/components/dropdown/__tests__/dropdown-button.test.js new file mode 100644 index 000000000..12cd3c37f --- /dev/null +++ b/components/dropdown/__tests__/dropdown-button.test.js @@ -0,0 +1,34 @@ +import { mount } from '@vue/test-utils' +import Dropdown from '..' + +describe('DropdownButton', () => { + it('pass appropriate props to Dropdown', () => { + const props = { + align: { + offset: [10, 20], + }, + disabled: false, + trigger: ['hover'], + visible: true, + } + + const wrapper = mount(Dropdown.Button, { + propsData: props, + listeners: { + visibleChange: () => {}, + }, + }) + const dropdownProps = wrapper.find({ name: 'ADropdown' }).props() + + Object.keys(props).forEach((key) => { + expect(dropdownProps[key]).toBe(props[key]) + }) + }) + + it('don\'t pass visible to Dropdown if it\'s not exits', () => { + const wrapper = mount(Dropdown.Button) + const dropdownProps = wrapper.find({ name: 'ADropdown' }).props() + + expect('visible' in dropdownProps).toBe(false) + }) +}) diff --git a/components/popover/__tests__/__snapshots__/index.test.js.snap b/components/popover/__tests__/__snapshots__/index.test.js.snap new file mode 100644 index 000000000..82aba59e8 --- /dev/null +++ b/components/popover/__tests__/__snapshots__/index.test.js.snap @@ -0,0 +1,25 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Popover should show overlay when trigger is clicked 1`] = ` +
+
+
+
+
code
+
console.log('hello world')
+
+
+
+`; + +exports[`Popover should show overlay when trigger is clicked 2`] = ` +
+
+
+
+
code
+
console.log('hello world')
+
+
+
+`; diff --git a/components/popover/__tests__/index.test.js b/components/popover/__tests__/index.test.js new file mode 100644 index 000000000..aa1d60115 --- /dev/null +++ b/components/popover/__tests__/index.test.js @@ -0,0 +1,35 @@ +import { mount } from '@vue/test-utils' +import { asyncExpect } from '@/tests/utils' +import Popover from '..' + +describe('Popover', () => { + it('should show overlay when trigger is clicked', async () => { + const popover = mount({ + render () { + return ( + + show me your code + + ) + }, + }, { sync: false }) + await asyncExpect(() => { + expect(popover.vm.$refs.popover.getPopupDomNode()).toBe(null) + + popover.find('span').trigger('click') + }, 0) + let popup = null + await asyncExpect(() => { + popup = popover.vm.$refs.popover.getPopupDomNode() + expect(popup).not.toBe(null) + expect(popup.className).toContain('ant-popover-placement-top') + }, 1000) + await asyncExpect(() => { + expect(popup.innerHTML).toMatchSnapshot() + expect(popup.innerHTML).toMatchSnapshot() + }) + await asyncExpect(() => { + + }) + }) +}) diff --git a/components/tag/__tests__/index.test.js b/components/tag/__tests__/index.test.js new file mode 100644 index 000000000..9420ddeb7 --- /dev/null +++ b/components/tag/__tests__/index.test.js @@ -0,0 +1,44 @@ +import { mount } from '@vue/test-utils' +import { asyncExpect } from '@/tests/utils' +import Tag from '..' + +describe('Tag', () => { + beforeAll(() => { + jest.useFakeTimers() + }) + + afterAll(() => { + jest.useRealTimers() + }) + + it('should be closable', () => { + const onClose = jest.fn() + const wrapper = mount({ + render () { + return + }, + }) + expect(wrapper.findAll('.anticon-cross').length).toBe(1) + expect(wrapper.findAll('.ant-tag').length).toBe(1) + wrapper.find('.anticon-cross').trigger('click') + expect(onClose).toBeCalled() + jest.runAllTimers() + expect(wrapper.findAll('.ant-tag').length).toBe(0) + }) + + it('should not be closed when prevent default', () => { + const onClose = (e) => { + e.preventDefault() + } + const wrapper = mount({ + render () { + return + }, + }) + expect(wrapper.findAll('.anticon-cross').length).toBe(1) + expect(wrapper.findAll('.ant-tag').length).toBe(1) + wrapper.find('.anticon-cross').trigger('click') + jest.runAllTimers() + expect(wrapper.findAll('.ant-tag').length).toBe(1) + }) +}) diff --git a/components/time-picker/__tests__/__snapshots__/index.test.js.snap b/components/time-picker/__tests__/__snapshots__/index.test.js.snap new file mode 100644 index 000000000..e2a73952a --- /dev/null +++ b/components/time-picker/__tests__/__snapshots__/index.test.js.snap @@ -0,0 +1,7 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TimePicker renders addon correctly 1`] = ` +
+ +
+`; diff --git a/components/time-picker/__tests__/index.test.js b/components/time-picker/__tests__/index.test.js new file mode 100644 index 000000000..dbadf3ca2 --- /dev/null +++ b/components/time-picker/__tests__/index.test.js @@ -0,0 +1,24 @@ +import { mount } from '@vue/test-utils' +import { asyncExpect } from '@/tests/utils' +import VcTimePicker from '../../vc-time-picker/TimePicker' +import TimePicker from '..' +import focusTest from '../../../tests/shared/focusTest' + +describe('TimePicker', () => { + focusTest(TimePicker) + + it('renders addon correctly', () => { + const wrapper = mount({ + render () { + return ()} /> + }, + }) + const vcTimePicker = wrapper.find({ name: VcTimePicker.name }) + const addonWrapper = mount({ + render () { + return vcTimePicker.vm.$slots.addon[0] + }, + }) + expect(addonWrapper.html()).toMatchSnapshot() + }) +})