From ece4c834d6b86ef2060f26c36b527b41e21d13f1 Mon Sep 17 00:00:00 2001 From: MrHeer Date: Wed, 15 May 2019 21:00:16 +0800 Subject: [PATCH] add milliseconds test --- tests/Header.spec.jsx | 3 + tests/Select.spec.jsx | 70 ++++++++++++++------ tests/TimePicker.spec.jsx | 34 +++++----- tests/__snapshots__/TimePicker.spec.jsx.snap | 4 +- 4 files changed, 74 insertions(+), 37 deletions(-) diff --git a/tests/Header.spec.jsx b/tests/Header.spec.jsx index 85659d01..d4ccf7a7 100644 --- a/tests/Header.spec.jsx +++ b/tests/Header.spec.jsx @@ -90,6 +90,9 @@ describe('Header', () => { disabledSeconds(h, m) { return [h + (m % 60)]; }, + disabledMilliseconds() { + return [15, 25, 35]; + }, }); expect(picker.state().open).toBeFalsy(); clickInput(picker); diff --git a/tests/Select.spec.jsx b/tests/Select.spec.jsx index cc0bf53f..c13f2539 100644 --- a/tests/Select.spec.jsx +++ b/tests/Select.spec.jsx @@ -9,15 +9,15 @@ describe('Select', () => { let container; function renderPicker(props) { - const showSecond = true; - const format = 'HH:mm:ss'; + const showMillisecond = true; + const format = 'HH:mm:ss:SS'; // eslint-disable-next-line return mount( , ); @@ -81,6 +81,7 @@ describe('Select', () => { hourStep: 5, minuteStep: 15, secondStep: 21, + millisecondStep: 30, }); clickInput(picker); @@ -89,6 +90,7 @@ describe('Select', () => { const hourSelector = selectors.at(0); const minuteSelector = selectors.at(1); const secondSelector = selectors.at(2); + const millisecondSelector = selectors.at(3); const hours = hourSelector.find('li').map(node => node.text()); expect(hours).toEqual(['00', '05', '10', '15', '20']); @@ -98,6 +100,9 @@ describe('Select', () => { const seconds = secondSelector.find('li').map(node => node.text()); expect(seconds).toEqual(['00', '21', '42']); + + const milliseconds = millisecondSelector.find('li').map(node => node.text()); + expect(milliseconds).toEqual(['00', '30', '60', '90']); }); }); @@ -109,7 +114,7 @@ describe('Select', () => { clickInput(picker); expect(picker.state().open).toBeTruthy(); - expect(picker.find('.rc-time-picker-panel-select').length).toBe(3); + expect(picker.find('.rc-time-picker-panel-select').length).toBe(4); }); }); @@ -124,13 +129,13 @@ describe('Select', () => { clickInput(picker); expect(picker.state().open).toBeTruthy(); - matchAll(picker, '01:02:04'); + matchAll(picker, '01:02:04:05'); clickSelectItem(picker, 0, 19); expect(onChange).toBeCalled(); expect(onChange.mock.calls[0][0].hour()).toBe(19); - matchAll(picker, '19:02:04'); + matchAll(picker, '19:02:04:05'); expect(picker.state().open).toBeTruthy(); }); @@ -144,13 +149,13 @@ describe('Select', () => { clickInput(picker); expect(picker.state().open).toBeTruthy(); - matchAll(picker, '01:02:04'); + matchAll(picker, '01:02:04:05'); clickSelectItem(picker, 1, 19); expect(onChange).toBeCalled(); expect(onChange.mock.calls[0][0].minute()).toBe(19); - matchAll(picker, '01:19:04'); + matchAll(picker, '01:19:04:05'); expect(picker.state().open).toBeTruthy(); }); @@ -164,13 +169,33 @@ describe('Select', () => { clickInput(picker); expect(picker.state().open).toBeTruthy(); - matchAll(picker, '01:02:04'); + matchAll(picker, '01:02:04:05'); clickSelectItem(picker, 2, 19); expect(onChange).toBeCalled(); expect(onChange.mock.calls[0][0].second()).toBe(19); - matchAll(picker, '01:02:19'); + matchAll(picker, '01:02:19:05'); + expect(picker.state().open).toBeTruthy(); + }); + + it('millisecond correctly', async () => { + const onChange = jest.fn(); + const picker = renderPicker({ + onChange, + }); + expect(picker.state().open).toBeFalsy(); + + clickInput(picker); + + expect(picker.state().open).toBeTruthy(); + matchAll(picker, '01:02:04:05'); + + clickSelectItem(picker, 3, 19); + + expect(onChange).toBeCalled(); + expect(onChange.mock.calls[0][0].millisecond()).toBe(190); + matchAll(picker, '01:02:04:19'); expect(picker.state().open).toBeTruthy(); }); @@ -184,6 +209,7 @@ describe('Select', () => { .second(0), format: undefined, showSecond: false, + showMillisecond: false, use12Hours: true, }); expect(picker.state().open).toBeFalsy(); @@ -216,25 +242,25 @@ describe('Select', () => { expect(picker.state().open).toBeTruthy(); - matchAll(picker, '01:02:04'); + matchAll(picker, '01:02:04:05'); clickSelectItem(picker, 1, 1); expect(onChange).not.toBeCalled(); - matchAll(picker, '01:02:04'); + matchAll(picker, '01:02:04:05'); expect(picker.state().open).toBeTruthy(); clickSelectItem(picker, 2, 3); expect(onChange).not.toBeCalled(); - matchAll(picker, '01:02:04'); + matchAll(picker, '01:02:04:05'); expect(picker.state().open).toBeTruthy(); clickSelectItem(picker, 1, 7); expect(onChange).toBeCalled(); expect(onChange.mock.calls[0][0].minute()).toBe(7); - matchAll(picker, '01:07:04'); + matchAll(picker, '01:07:04:05'); expect(picker.state().open).toBeTruthy(); }); @@ -251,13 +277,13 @@ describe('Select', () => { clickInput(picker); expect(picker.state().open).toBeTruthy(); - matchAll(picker, '01:02:04'); + matchAll(picker, '01:02:04:05'); clickSelectItem(picker, 0, 3); expect(onChange).toBeCalled(); expect(onChange.mock.calls[0][0].hour()).toBe(6); - matchAll(picker, '06:02:04'); + matchAll(picker, '06:02:04:05'); expect(picker.state().open).toBeTruthy(); onChange.mockReset(); @@ -265,7 +291,7 @@ describe('Select', () => { expect(onChange).toBeCalled(); expect(onChange.mock.calls[0][0].hour()).toBe(8); - matchAll(picker, '08:02:04'); + matchAll(picker, '08:02:04:05'); expect(picker.state().open).toBeTruthy(); }); }); @@ -279,6 +305,7 @@ describe('Select', () => { .minute(0) .second(0), showSecond: false, + showMillisecond: false, format: undefined, }); @@ -299,6 +326,7 @@ describe('Select', () => { .minute(0) .second(0), showSecond: false, + showMillisecond: false, format: undefined, }); expect(picker.state().open).toBeFalsy(); @@ -316,6 +344,7 @@ describe('Select', () => { .minute(0) .second(0), showSecond: false, + showMillisecond: false, format: undefined, }); expect(picker.state().open).toBeFalsy(); @@ -336,6 +365,7 @@ describe('Select', () => { .minute(0) .second(0), showSecond: false, + showMillisecond: false, format: undefined, }); @@ -360,6 +390,7 @@ describe('Select', () => { .minute(0) .second(0), showSecond: false, + showMillisecond: false, format: 'h:mm A', }); @@ -390,6 +421,7 @@ describe('Select', () => { .minute(0) .second(0), showSecond: false, + showMillisecond: false, }); expect(picker.state().open).toBeFalsy(); @@ -440,7 +472,7 @@ describe('Select', () => { }); const clearButton = findClearFunc(picker); - matchValue(picker, '01:02:04'); + matchValue(picker, '01:02:04:05'); clearButton.simulate('click'); expect(picker.state().open).toBeFalsy(); diff --git a/tests/TimePicker.spec.jsx b/tests/TimePicker.spec.jsx index e896c783..0ad7b6f3 100644 --- a/tests/TimePicker.spec.jsx +++ b/tests/TimePicker.spec.jsx @@ -9,31 +9,31 @@ describe('TimePicker', () => { let container; function renderPicker(props, options) { - const showSecond = true; - const format = 'HH:mm:ss'; + const showMillisecond = true; + const format = 'HH:mm:ss:SS'; // eslint-disable-next-line return mount( , options, ); } - function renderPickerWithoutSeconds(props) { - const showSecond = false; - const format = 'HH:mm'; + function renderPickerWithoutMilliseconds(props) { + const showMillisecond = false; + const format = 'HH:mm:ss'; // eslint-disable-next-line return mount( , ); @@ -56,7 +56,7 @@ describe('TimePicker', () => { onChange, }); expect(picker.state().open).toBeFalsy(); - matchValue(picker, '12:57:58'); + matchValue(picker, '12:57:58:65'); clickInput(picker); expect(picker.state().open).toBeTruthy(); @@ -66,7 +66,8 @@ describe('TimePicker', () => { expect(onChange.mock.calls[0][0].hour()).toBe(1); expect(onChange.mock.calls[0][0].minute()).toBe(57); expect(onChange.mock.calls[0][0].second()).toBe(58); - matchValue(picker, '01:57:58'); + expect(onChange.mock.calls[0][0].millisecond()).toBe(650); + matchValue(picker, '01:57:58:65'); expect(picker.state().open).toBeTruthy(); }); @@ -115,14 +116,14 @@ describe('TimePicker', () => { }); }); - describe('render panel to body (without seconds)', () => { + describe('render panel to body (without milliseconds)', () => { it('popup correctly', async () => { const onChange = jest.fn(); - const picker = renderPickerWithoutSeconds({ + const picker = renderPickerWithoutMilliseconds({ onChange, }); expect(picker.state().open).toBeFalsy(); - matchValue(picker, '08:24'); + matchValue(picker, '08:24:32'); clickInput(picker); expect(picker.find('.rc-time-picker-panel-inner').length).toBeTruthy(); @@ -132,7 +133,8 @@ describe('TimePicker', () => { expect(onChange).toBeCalled(); expect(onChange.mock.calls[0][0].hour()).toBe(1); expect(onChange.mock.calls[0][0].minute()).toBe(24); - matchValue(picker, '01:24'); + expect(onChange.mock.calls[0][0].second()).toBe(32); + matchValue(picker, '01:24:32'); expect(picker.state().open).toBeTruthy(); }); }); @@ -140,7 +142,7 @@ describe('TimePicker', () => { describe('render panel to body 12pm mode', () => { it('popup correctly', async () => { const onChange = jest.fn(); - const picker = renderPickerWithoutSeconds({ + const picker = renderPickerWithoutMilliseconds({ use12Hours: true, value: null, onChange, diff --git a/tests/__snapshots__/TimePicker.spec.jsx.snap b/tests/__snapshots__/TimePicker.spec.jsx.snap index 26a8766a..1cd5db6b 100644 --- a/tests/__snapshots__/TimePicker.spec.jsx.snap +++ b/tests/__snapshots__/TimePicker.spec.jsx.snap @@ -9,7 +9,7 @@ exports[`TimePicker allowEmpty cannot allow clear when disabled 1`] = ` disabled="" id="" type="text" - value="12:57:58" + value="12:57:58:65" />