From ae8d4c71c961141296d46eb33e554a4d65da95d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <645381995@qq.com> Date: Wed, 17 Jul 2024 11:05:07 +0800 Subject: [PATCH 1/6] feat: test --- tests/disabledTime.spec.tsx | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/disabledTime.spec.tsx b/tests/disabledTime.spec.tsx index 43ba41dc3..4848a6125 100644 --- a/tests/disabledTime.spec.tsx +++ b/tests/disabledTime.spec.tsx @@ -1,4 +1,4 @@ -import { fireEvent, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; import type { Dayjs } from 'dayjs'; import { resetWarned } from 'rc-util/lib/warning'; import React from 'react'; @@ -218,4 +218,30 @@ describe('Picker.DisabledTime', () => { errSpy.mockRestore(); }); }); + it('limit', async () => { + const wrapper = render( + { + if (from) { + return Math.abs(current.diff(from, 'days')) >= 2; + } + return false; + }} + />, + ); + + openPicker(wrapper.container); + await act(async () => { + wrapper.getByTitle('2021-06-21').click(); + }); + await act(async () => { + wrapper.getByTitle('2021-06-26').click(); + }); + closePicker(wrapper.container); + expect(wrapper.getByPlaceholderText('Start date').getAttribute('value')).toBe('2021-06-01'); + // disabled 后不可选中 + expect(wrapper.getByPlaceholderText('End date').getAttribute('value')).toBe('2021-06-02'); + }); }); From 139e01127f504c6c905887e06bcb348719f515f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <645381995@qq.com> Date: Wed, 17 Jul 2024 11:10:47 +0800 Subject: [PATCH 2/6] feat: test --- tests/disabledTime.spec.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/disabledTime.spec.tsx b/tests/disabledTime.spec.tsx index 4848a6125..dc9d41496 100644 --- a/tests/disabledTime.spec.tsx +++ b/tests/disabledTime.spec.tsx @@ -234,14 +234,13 @@ describe('Picker.DisabledTime', () => { openPicker(wrapper.container); await act(async () => { - wrapper.getByTitle('2021-06-21').click(); + fireEvent.click(wrapper.getByTitle('2021-06-21')); }); await act(async () => { - wrapper.getByTitle('2021-06-26').click(); + fireEvent.click(wrapper.getByTitle('2021-06-26')); }); closePicker(wrapper.container); - expect(wrapper.getByPlaceholderText('Start date').getAttribute('value')).toBe('2021-06-01'); - // disabled 后不可选中 - expect(wrapper.getByPlaceholderText('End date').getAttribute('value')).toBe('2021-06-02'); + expect(wrapper.container.querySelectorAll('input')?.[0]?.value).toBe('2021-06-01'); + expect(wrapper.container.querySelectorAll('input')?.[1]?.value).toBe('2021-06-02'); }); }); From eebdd1e3323ff21f822bbf5622fa14b69d24fcf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <645381995@qq.com> Date: Thu, 18 Jul 2024 11:08:43 +0800 Subject: [PATCH 3/6] feat: test --- docs/examples/range.tsx | 14 ++++++++++++++ tests/disabledTime.spec.tsx | 15 +++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/docs/examples/range.tsx b/docs/examples/range.tsx index 1b137c8b0..1be4c576d 100644 --- a/docs/examples/range.tsx +++ b/docs/examples/range.tsx @@ -202,6 +202,20 @@ export default () => { disabledDate={disabledDate} /> +
+

DisabledDate

+ + generateConfig={momentGenerateConfig} + locale={zhCN} + defaultValue={[moment('2021-06-01'), moment('2021-06-02')]} + disabledDate={(current, { from }) => { + if (from) { + return Math.abs(current.diff(from, 'days')) >= 2; + } + return false; + }} + /> +
); diff --git a/tests/disabledTime.spec.tsx b/tests/disabledTime.spec.tsx index dc9d41496..0b4c24769 100644 --- a/tests/disabledTime.spec.tsx +++ b/tests/disabledTime.spec.tsx @@ -1,4 +1,4 @@ -import { act, fireEvent, render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import type { Dayjs } from 'dayjs'; import { resetWarned } from 'rc-util/lib/warning'; import React from 'react'; @@ -222,7 +222,6 @@ describe('Picker.DisabledTime', () => { const wrapper = render( { if (from) { return Math.abs(current.diff(from, 'days')) >= 2; @@ -233,14 +232,10 @@ describe('Picker.DisabledTime', () => { ); openPicker(wrapper.container); - await act(async () => { - fireEvent.click(wrapper.getByTitle('2021-06-21')); - }); - await act(async () => { - fireEvent.click(wrapper.getByTitle('2021-06-26')); - }); + fireEvent.click(wrapper.getByTitle('2021-06-21')); + fireEvent.click(wrapper.getByTitle('2021-06-26')); closePicker(wrapper.container); - expect(wrapper.container.querySelectorAll('input')?.[0]?.value).toBe('2021-06-01'); - expect(wrapper.container.querySelectorAll('input')?.[1]?.value).toBe('2021-06-02'); + expect(wrapper.container.querySelectorAll('input')?.[0]?.value).toBe('2021-06-21'); + expect(wrapper.container.querySelectorAll('input')?.[1]?.value).toBe('2021-06-21'); }); }); From 3fd12e32ae93ba0c7cc9eac2204a110bd0fbed8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <645381995@qq.com> Date: Thu, 18 Jul 2024 11:34:27 +0800 Subject: [PATCH 4/6] feat: test --- docs/examples/range.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/range.tsx b/docs/examples/range.tsx index 1be4c576d..85da79106 100644 --- a/docs/examples/range.tsx +++ b/docs/examples/range.tsx @@ -203,7 +203,7 @@ export default () => { />
-

DisabledDate

+

Limit Date

generateConfig={momentGenerateConfig} locale={zhCN} From 65ba9b57aacdb8adfa24338664e48d1183236c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <645381995@qq.com> Date: Thu, 18 Jul 2024 16:23:10 +0800 Subject: [PATCH 5/6] feat: test --- tests/demo.spec.tsx | 37 +++++++++++++++++++++++++++++++++++++ tests/disabledTime.spec.tsx | 20 -------------------- 2 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 tests/demo.spec.tsx diff --git a/tests/demo.spec.tsx b/tests/demo.spec.tsx new file mode 100644 index 000000000..8d1ac4334 --- /dev/null +++ b/tests/demo.spec.tsx @@ -0,0 +1,37 @@ +import { fireEvent, render } from '@testing-library/react'; +import React from 'react'; +import { closePicker, DayRangePicker, getDay, openPicker } from './util/commonUtil'; + +const fakeTime = getDay('1990-09-03 00:00:00').valueOf(); + +describe('Picker.DisabledTime', () => { + beforeEach(() => { + jest.useFakeTimers().setSystemTime(fakeTime); + }); + + afterEach(() => { + jest.clearAllTimers(); + jest.useRealTimers(); + }); + + it('limit', async () => { + const wrapper = render( + { + if (from) { + return Math.abs(current.diff(from, 'days')) >= 2; + } + return false; + }} + />, + ); + + openPicker(wrapper.container); + fireEvent.click(wrapper.getByTitle('2021-06-21')); + fireEvent.click(wrapper.getByTitle('2021-06-26')); + closePicker(wrapper.container); + expect(wrapper.container.querySelectorAll('input')?.[0]?.value).toBe('2021-06-21'); + expect(wrapper.container.querySelectorAll('input')?.[1]?.value).toBe('2021-06-21'); + }); +}); diff --git a/tests/disabledTime.spec.tsx b/tests/disabledTime.spec.tsx index 0b4c24769..43ba41dc3 100644 --- a/tests/disabledTime.spec.tsx +++ b/tests/disabledTime.spec.tsx @@ -218,24 +218,4 @@ describe('Picker.DisabledTime', () => { errSpy.mockRestore(); }); }); - it('limit', async () => { - const wrapper = render( - { - if (from) { - return Math.abs(current.diff(from, 'days')) >= 2; - } - return false; - }} - />, - ); - - openPicker(wrapper.container); - fireEvent.click(wrapper.getByTitle('2021-06-21')); - fireEvent.click(wrapper.getByTitle('2021-06-26')); - closePicker(wrapper.container); - expect(wrapper.container.querySelectorAll('input')?.[0]?.value).toBe('2021-06-21'); - expect(wrapper.container.querySelectorAll('input')?.[1]?.value).toBe('2021-06-21'); - }); }); From 80de2cf2d4811c8d963d49d0298b3d3d3de96ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <645381995@qq.com> Date: Thu, 18 Jul 2024 16:24:46 +0800 Subject: [PATCH 6/6] feat: test --- tests/demo.spec.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/demo.spec.tsx b/tests/demo.spec.tsx index 8d1ac4334..2b74ef6a9 100644 --- a/tests/demo.spec.tsx +++ b/tests/demo.spec.tsx @@ -31,7 +31,11 @@ describe('Picker.DisabledTime', () => { fireEvent.click(wrapper.getByTitle('2021-06-21')); fireEvent.click(wrapper.getByTitle('2021-06-26')); closePicker(wrapper.container); - expect(wrapper.container.querySelectorAll('input')?.[0]?.value).toBe('2021-06-21'); - expect(wrapper.container.querySelectorAll('input')?.[1]?.value).toBe('2021-06-21'); + expect( + [ + wrapper.container.querySelectorAll('input')?.[0]?.value, + wrapper.container.querySelectorAll('input')?.[0]?.value, + ].join(' '), + ).toBe(['2021-06-21', '2021-06-21'].join(' ')); }); });