Skip to content

Commit

Permalink
add milliseconds test
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHeer committed May 15, 2019
1 parent 801fb24 commit ece4c83
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 37 deletions.
3 changes: 3 additions & 0 deletions tests/Header.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
70 changes: 51 additions & 19 deletions tests/Select.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<TimePicker
format={format}
showSecond={showSecond}
defaultValue={moment('01:02:04', format)}
showMillisecond={showMillisecond}
defaultValue={moment('01:02:04:05', format)}
{...props}
/>,
);
Expand Down Expand Up @@ -81,6 +81,7 @@ describe('Select', () => {
hourStep: 5,
minuteStep: 15,
secondStep: 21,
millisecondStep: 30,
});
clickInput(picker);

Expand All @@ -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']);
Expand All @@ -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']);
});
});

Expand All @@ -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);
});
});

Expand All @@ -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();
});

Expand All @@ -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();
});

Expand All @@ -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();
});

Expand All @@ -184,6 +209,7 @@ describe('Select', () => {
.second(0),
format: undefined,
showSecond: false,
showMillisecond: false,
use12Hours: true,
});
expect(picker.state().open).toBeFalsy();
Expand Down Expand Up @@ -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();
});

Expand All @@ -251,21 +277,21 @@ 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();

clickSelectItem(picker, 0, 4);

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();
});
});
Expand All @@ -279,6 +305,7 @@ describe('Select', () => {
.minute(0)
.second(0),
showSecond: false,
showMillisecond: false,
format: undefined,
});

Expand All @@ -299,6 +326,7 @@ describe('Select', () => {
.minute(0)
.second(0),
showSecond: false,
showMillisecond: false,
format: undefined,
});
expect(picker.state().open).toBeFalsy();
Expand All @@ -316,6 +344,7 @@ describe('Select', () => {
.minute(0)
.second(0),
showSecond: false,
showMillisecond: false,
format: undefined,
});
expect(picker.state().open).toBeFalsy();
Expand All @@ -336,6 +365,7 @@ describe('Select', () => {
.minute(0)
.second(0),
showSecond: false,
showMillisecond: false,
format: undefined,
});

Expand All @@ -360,6 +390,7 @@ describe('Select', () => {
.minute(0)
.second(0),
showSecond: false,
showMillisecond: false,
format: 'h:mm A',
});

Expand Down Expand Up @@ -390,6 +421,7 @@ describe('Select', () => {
.minute(0)
.second(0),
showSecond: false,
showMillisecond: false,
});

expect(picker.state().open).toBeFalsy();
Expand Down Expand Up @@ -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();
Expand Down
34 changes: 18 additions & 16 deletions tests/TimePicker.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<TimePicker
format={format}
showSecond={showSecond}
defaultValue={moment('12:57:58', format)}
showMillisecond={showMillisecond}
defaultValue={moment('12:57:58:65', format)}
{...props}
/>,
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(
<TimePicker
format={format}
showSecond={showSecond}
defaultValue={moment('08:24', format)}
showSecond={showMillisecond}
defaultValue={moment('08:24:32', format)}
{...props}
/>,
);
Expand All @@ -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();
Expand All @@ -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();
});

Expand Down Expand Up @@ -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();
Expand All @@ -132,15 +133,16 @@ 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();
});
});

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,
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/TimePicker.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
<span
class="rc-time-picker-icon"
Expand All @@ -25,7 +25,7 @@ exports[`TimePicker allowEmpty should allow clear 1`] = `
class="rc-time-picker-input"
id=""
type="text"
value="12:57:58"
value="12:57:58:65"
/>
<span
class="rc-time-picker-icon"
Expand Down

0 comments on commit ece4c83

Please sign in to comment.