diff --git a/components/cascader/__tests__/__snapshots__/index.test.js.snap b/components/cascader/__tests__/__snapshots__/index.test.js.snap index 358aacf65..986a456d9 100644 --- a/components/cascader/__tests__/__snapshots__/index.test.js.snap +++ b/components/cascader/__tests__/__snapshots__/index.test.js.snap @@ -69,7 +69,7 @@ exports[`Cascader can be selected 3`] = ` exports[`Cascader popup correctly when panel is open 1`] = `
-
+
-
+
- + `; diff --git a/components/date-picker/__tests__/__snapshots__/WeekPicker.test.js.snap b/components/date-picker/__tests__/__snapshots__/WeekPicker.test.js.snap index 09b809793..0f77cc217 100644 --- a/components/date-picker/__tests__/__snapshots__/WeekPicker.test.js.snap +++ b/components/date-picker/__tests__/__snapshots__/WeekPicker.test.js.snap @@ -1,3 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`WeekPicker should support style prop 1`] = ``; +exports[`WeekPicker should support style prop 1`] = ` + +
+
+ +
+
+`; diff --git a/components/date-picker/__tests__/__snapshots__/other.test.js.snap b/components/date-picker/__tests__/__snapshots__/other.test.js.snap index 109ca994d..a9f2d2b84 100644 --- a/components/date-picker/__tests__/__snapshots__/other.test.js.snap +++ b/components/date-picker/__tests__/__snapshots__/other.test.js.snap @@ -4,44 +4,65 @@ exports[`MonthPicker and WeekPicker render MonthPicker 1`] = `
-
-
-
-
-
- -
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
一月二月三月
四月五月六月
七月八月九月
十月十一月十二月
-
- -
-
+
+
+
+
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
Jan
+
+
Feb
+
+
Mar
+
+
Apr
+
+
May
+
+
Jun
+
+
Jul
+
+
Aug
+
+
Sep
+
+
Oct
+
+
Nov
+
+
Dec
+
@@ -56,185 +77,177 @@ exports[`MonthPicker and WeekPicker render WeekPicker 1`] = `
-
-
- -
- -
-
- - +
+
+
+
+
+
- -
- +
+
- - - - - - - - - + + + + + + + + + - - - - + + + - - - - - - - - - + + - - - - - - - - - + + - - - - - - - - - + + - - - - - - - - - + + - - - - - - - - - + + - - - - - -
x
SuMoTuWeThFrSa
52 -
27
+
1 +
26
-
28
+
+
27
-
29
+
+
28
-
30
+
+
29
-
31
+
+
30
-
-
1
-
+
+
31
-
-
2
-
+
+
1
1 -
3
+
2 +
2
-
4
+
+
3
-
5
+
+
4
-
6
+
+
5
-
7
+
+
6
-
8
+
+
7
-
9
+
+
8
2 -
10
+
3 +
9
-
11
+
+
10
-
12
+
+
11
-
13
+
+
12
-
14
+
+
13
-
15
+
+
14
-
16
+
+
15
3 -
17
+
4 +
16
-
18
+
+
17
-
19
+
+
18
-
20
+
+
19
-
21
+
+
20
-
22
+
+
21
-
23
+
+
22
4 -
24
+
5 +
23
-
25
+
+
24
-
26
+
+
25
-
27
+
+
26
-
28
+
+
27
-
29
+
+
28
-
30
+
+
29
5 -
31
+
6 +
30
-
1
+
+
31
-
2
+
+
1
-
3
+
+
2
-
4
+
+
3
-
5
+
+
4
-
6
+
+
5
-
+
@@ -242,10 +255,30 @@ exports[`MonthPicker and WeekPicker render WeekPicker 1`] = `
`; -exports[`Picker format by locale date 1`] = `
`; +exports[`Picker format by locale date 1`] = ` + +
+
+
+`; -exports[`Picker format by locale dateTime 1`] = `
`; +exports[`Picker format by locale dateTime 1`] = ` + +
+
+
+`; -exports[`Picker format by locale month 1`] = `
`; +exports[`Picker format by locale month 1`] = ` + +
+
+
+`; -exports[`Picker format by locale week 1`] = ``; +exports[`Picker format by locale week 1`] = ` + +
+
+
+`; diff --git a/components/date-picker/__tests__/other.test.js b/components/date-picker/__tests__/other.test.js index 0d8e5f6a3..178cc664f 100644 --- a/components/date-picker/__tests__/other.test.js +++ b/components/date-picker/__tests__/other.test.js @@ -1,6 +1,6 @@ import { mount } from '@vue/test-utils'; import { asyncExpect } from '@/tests/utils'; -import moment from 'moment'; +import dayjs from 'dayjs'; import DatePicker from '../'; import LocaleProvider from '../../locale-provider'; import locale from '../../locale-provider/zh_CN'; @@ -20,7 +20,7 @@ describe('Picker format by locale', () => { }, }; - const date = moment('2000-01-01', 'YYYY-MM-DD'); + const date = dayjs('2000-01-01', 'YYYY-MM-DD'); function matchPicker(name, Picker, props) { it(name, async () => { const wrapper = mount( @@ -52,7 +52,7 @@ describe('MonthPicker and WeekPicker', () => { document.body.innerHTML = ''; }); it('render MonthPicker', async () => { - const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn'); + const birthday = dayjs('2000-01-01', 'YYYY-MM-DD').locale('zh-cn'); const wrapper = mount(MonthPicker, { props: { open: true }, sync: false }); await asyncExpect(() => { wrapper.setProps({ value: birthday }); @@ -64,7 +64,7 @@ describe('MonthPicker and WeekPicker', () => { }); it('render WeekPicker', async () => { - const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn'); + const birthday = dayjs('2000-01-01', 'YYYY-MM-DD').locale('zh-cn'); const wrapper = mount(WeekPicker, { props: { open: false }, sync: false }); await asyncExpect(() => { wrapper.setProps({ value: birthday, open: true }); diff --git a/components/date-picker/__tests__/showTime.test.js b/components/date-picker/__tests__/showTime.test.js deleted file mode 100644 index d0e6de644..000000000 --- a/components/date-picker/__tests__/showTime.test.js +++ /dev/null @@ -1,178 +0,0 @@ -import { mount } from '@vue/test-utils'; -import { asyncExpect } from '@/tests/utils'; -import moment from 'moment'; -import DatePicker from '../'; -import { $$ } from './utils'; -import { sleep } from '../../../tests/utils'; - -const { RangePicker } = DatePicker; - -describe('DatePicker with showTime', () => { - beforeEach(() => { - document.body.outerHTML = ''; - }); - it('should trigger onChange when select value', async () => { - const onChangeFn = jest.fn(); - const onOpenChangeFn = jest.fn(); - mount( - { - render() { - return ; - }, - }, - { sync: false, attachTo: 'body' }, - ); - - await asyncExpect(() => { - $$('.ant-calendar-date')[0].click(); - }); - await asyncExpect(() => { - expect(onChangeFn).toHaveBeenCalled(); - expect(onOpenChangeFn).not.toHaveBeenCalled(); - }); - }); - - it('should trigger onOk when press ok button', async () => { - const onOkFn = jest.fn(); - const onOpenChangeFn = jest.fn(); - const onChangeFn = jest.fn(); - mount( - { - render() { - return ( - - ); - }, - }, - { sync: false, attachTo: 'body' }, - ); - - await asyncExpect(() => { - $$('.ant-calendar-ok-btn')[0].click(); - }); - await asyncExpect(() => { - expect(onOkFn).toHaveBeenCalled(); - expect(onOpenChangeFn).toHaveBeenCalledWith(false); - expect(onChangeFn).not.toHaveBeenCalled(); - }); - }); - - it('should trigger onChange when click Now link', async () => { - const onOpenChangeFn = jest.fn(); - const onChangeFn = jest.fn(); - mount( - { - render() { - return ; - }, - }, - { sync: false, attachTo: 'body' }, - ); - - await asyncExpect(() => { - $$('.ant-calendar-today-btn')[0].click(); - }); - await asyncExpect(() => { - expect(onOpenChangeFn).toHaveBeenCalledWith(false); - expect(onChangeFn).toHaveBeenCalled(); - }); - }); - - it('should have correct className when use12Hours is true', async () => { - mount( - { - render() { - return ; - }, - }, - { sync: false, attachTo: 'body' }, - ); - - await asyncExpect(() => { - expect($$('.ant-calendar-time-picker-column-4').length).toBe(0); - }); - $$('.ant-calendar-today')[0].click(); - await sleep(); - $$('.ant-calendar-time-picker-btn')[0].click(); - await asyncExpect(() => { - expect($$('.ant-calendar-time-picker-column-4').length).toBe(1); - }); - }); -}); - -describe('RangePicker with showTime', () => { - beforeEach(() => { - document.body.outerHTML = ''; - }); - it('should trigger onChange when select value', async () => { - const onChangeFn = jest.fn(); - const onOpenChangeFn = jest.fn(); - mount( - { - render() { - return ; - }, - }, - { sync: false }, - ); - - await asyncExpect(() => { - expect($$('.ant-calendar-time-picker-btn')[0].getAttribute('class').split(' ')).toContain( - 'ant-calendar-time-picker-btn-disabled', - ); - expect($$('.ant-calendar-ok-btn')[0].getAttribute('class').split(' ')).toContain( - 'ant-calendar-ok-btn-disabled', - ); - }); - $$('.ant-calendar-date')[10].click(); - $$('.ant-calendar-date')[11].click(); - await asyncExpect(() => { - expect($$('.ant-calendar-time-picker-btn')[0].getAttribute('class').split(' ')).not.toContain( - 'ant-calendar-time-picker-btn-disabled', - ); - expect($$('.ant-calendar-ok-btn')[0].getAttribute('class').split(' ')).not.toContain( - 'ant-calendar-ok-btn-disabled', - ); - }); - expect(onChangeFn).toHaveBeenCalled(); - expect(onOpenChangeFn).not.toHaveBeenCalled(); - }); - - it('hould trigger onOk when press ok button', async () => { - const onOkFn = jest.fn(); - const onChangeFn = jest.fn(); - const onOpenChangeFn = jest.fn(); - mount( - { - render() { - return ( - - ); - }, - }, - { sync: false, attachTo: 'body' }, - ); - await asyncExpect(() => { - $$('.ant-calendar-date')[10].click(); - $$('.ant-calendar-date')[11].click(); - }); - onChangeFn.mockClear(); - $$('.ant-calendar-ok-btn')[0].click(); - expect(onOkFn).toHaveBeenCalled(); - expect(onOpenChangeFn).toHaveBeenCalledWith(false); - expect(onChangeFn).not.toHaveBeenCalled(); - }); -}); diff --git a/components/date-picker/__tests__/utils.js b/components/date-picker/__tests__/utils.js index 6ad15af12..55c16655c 100644 --- a/components/date-picker/__tests__/utils.js +++ b/components/date-picker/__tests__/utils.js @@ -32,3 +32,29 @@ export function selectDateFromBody(date, index) { } calendar.querySelector(`[title="${date.format('LL')}"][role="gridcell"]`).click(); } + +export function openPicker(wrapper, index = 0) { + wrapper.findAll('input')[index].trigger('mousedown'); + wrapper.findAll('input')[index].trigger('focus'); +} +export function closePicker(wrapper, index = 0) { + wrapper.findAll('input')[index].trigger('blur'); +} + +export function selectCell(wrapper, text, index = 0) { + let matchCell; + $$('table') + [index].querySelectorAll('td') + .forEach(td => { + if (td.textContent === String(text) && td.className.includes('-in-view')) { + matchCell = td; + td.click('click'); + } + }); + + if (!matchCell) { + throw new Error('Cell not match in picker panel.'); + } + + return matchCell; +} diff --git a/components/locale-provider/__tests__/__snapshots__/index.test.js.snap b/components/locale-provider/__tests__/__snapshots__/index.test.js.snap index 73b88ca57..7244dcea1 100644 --- a/components/locale-provider/__tests__/__snapshots__/index.test.js.snap +++ b/components/locale-provider/__tests__/__snapshots__/index.test.js.snap @@ -599,522 +599,536 @@ exports[`Locale Provider should display the text as ar 1`] = ` -