Skip to content

Commit ece4c83

Browse files
committed
add milliseconds test
1 parent 801fb24 commit ece4c83

File tree

4 files changed

+74
-37
lines changed

4 files changed

+74
-37
lines changed

tests/Header.spec.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ describe('Header', () => {
9090
disabledSeconds(h, m) {
9191
return [h + (m % 60)];
9292
},
93+
disabledMilliseconds() {
94+
return [15, 25, 35];
95+
},
9396
});
9497
expect(picker.state().open).toBeFalsy();
9598
clickInput(picker);

tests/Select.spec.jsx

+51-19
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ describe('Select', () => {
99
let container;
1010

1111
function renderPicker(props) {
12-
const showSecond = true;
13-
const format = 'HH:mm:ss';
12+
const showMillisecond = true;
13+
const format = 'HH:mm:ss:SS';
1414

1515
// eslint-disable-next-line
1616
return mount(
1717
<TimePicker
1818
format={format}
19-
showSecond={showSecond}
20-
defaultValue={moment('01:02:04', format)}
19+
showMillisecond={showMillisecond}
20+
defaultValue={moment('01:02:04:05', format)}
2121
{...props}
2222
/>,
2323
);
@@ -81,6 +81,7 @@ describe('Select', () => {
8181
hourStep: 5,
8282
minuteStep: 15,
8383
secondStep: 21,
84+
millisecondStep: 30,
8485
});
8586
clickInput(picker);
8687

@@ -89,6 +90,7 @@ describe('Select', () => {
8990
const hourSelector = selectors.at(0);
9091
const minuteSelector = selectors.at(1);
9192
const secondSelector = selectors.at(2);
93+
const millisecondSelector = selectors.at(3);
9294

9395
const hours = hourSelector.find('li').map(node => node.text());
9496
expect(hours).toEqual(['00', '05', '10', '15', '20']);
@@ -98,6 +100,9 @@ describe('Select', () => {
98100

99101
const seconds = secondSelector.find('li').map(node => node.text());
100102
expect(seconds).toEqual(['00', '21', '42']);
103+
104+
const milliseconds = millisecondSelector.find('li').map(node => node.text());
105+
expect(milliseconds).toEqual(['00', '30', '60', '90']);
101106
});
102107
});
103108

@@ -109,7 +114,7 @@ describe('Select', () => {
109114
clickInput(picker);
110115
expect(picker.state().open).toBeTruthy();
111116

112-
expect(picker.find('.rc-time-picker-panel-select').length).toBe(3);
117+
expect(picker.find('.rc-time-picker-panel-select').length).toBe(4);
113118
});
114119
});
115120

@@ -124,13 +129,13 @@ describe('Select', () => {
124129
clickInput(picker);
125130

126131
expect(picker.state().open).toBeTruthy();
127-
matchAll(picker, '01:02:04');
132+
matchAll(picker, '01:02:04:05');
128133

129134
clickSelectItem(picker, 0, 19);
130135

131136
expect(onChange).toBeCalled();
132137
expect(onChange.mock.calls[0][0].hour()).toBe(19);
133-
matchAll(picker, '19:02:04');
138+
matchAll(picker, '19:02:04:05');
134139
expect(picker.state().open).toBeTruthy();
135140
});
136141

@@ -144,13 +149,13 @@ describe('Select', () => {
144149
clickInput(picker);
145150

146151
expect(picker.state().open).toBeTruthy();
147-
matchAll(picker, '01:02:04');
152+
matchAll(picker, '01:02:04:05');
148153

149154
clickSelectItem(picker, 1, 19);
150155

151156
expect(onChange).toBeCalled();
152157
expect(onChange.mock.calls[0][0].minute()).toBe(19);
153-
matchAll(picker, '01:19:04');
158+
matchAll(picker, '01:19:04:05');
154159
expect(picker.state().open).toBeTruthy();
155160
});
156161

@@ -164,13 +169,33 @@ describe('Select', () => {
164169
clickInput(picker);
165170

166171
expect(picker.state().open).toBeTruthy();
167-
matchAll(picker, '01:02:04');
172+
matchAll(picker, '01:02:04:05');
168173

169174
clickSelectItem(picker, 2, 19);
170175

171176
expect(onChange).toBeCalled();
172177
expect(onChange.mock.calls[0][0].second()).toBe(19);
173-
matchAll(picker, '01:02:19');
178+
matchAll(picker, '01:02:19:05');
179+
expect(picker.state().open).toBeTruthy();
180+
});
181+
182+
it('millisecond correctly', async () => {
183+
const onChange = jest.fn();
184+
const picker = renderPicker({
185+
onChange,
186+
});
187+
expect(picker.state().open).toBeFalsy();
188+
189+
clickInput(picker);
190+
191+
expect(picker.state().open).toBeTruthy();
192+
matchAll(picker, '01:02:04:05');
193+
194+
clickSelectItem(picker, 3, 19);
195+
196+
expect(onChange).toBeCalled();
197+
expect(onChange.mock.calls[0][0].millisecond()).toBe(190);
198+
matchAll(picker, '01:02:04:19');
174199
expect(picker.state().open).toBeTruthy();
175200
});
176201

@@ -184,6 +209,7 @@ describe('Select', () => {
184209
.second(0),
185210
format: undefined,
186211
showSecond: false,
212+
showMillisecond: false,
187213
use12Hours: true,
188214
});
189215
expect(picker.state().open).toBeFalsy();
@@ -216,25 +242,25 @@ describe('Select', () => {
216242

217243
expect(picker.state().open).toBeTruthy();
218244

219-
matchAll(picker, '01:02:04');
245+
matchAll(picker, '01:02:04:05');
220246

221247
clickSelectItem(picker, 1, 1);
222248

223249
expect(onChange).not.toBeCalled();
224-
matchAll(picker, '01:02:04');
250+
matchAll(picker, '01:02:04:05');
225251
expect(picker.state().open).toBeTruthy();
226252

227253
clickSelectItem(picker, 2, 3);
228254

229255
expect(onChange).not.toBeCalled();
230-
matchAll(picker, '01:02:04');
256+
matchAll(picker, '01:02:04:05');
231257
expect(picker.state().open).toBeTruthy();
232258

233259
clickSelectItem(picker, 1, 7);
234260

235261
expect(onChange).toBeCalled();
236262
expect(onChange.mock.calls[0][0].minute()).toBe(7);
237-
matchAll(picker, '01:07:04');
263+
matchAll(picker, '01:07:04:05');
238264
expect(picker.state().open).toBeTruthy();
239265
});
240266

@@ -251,21 +277,21 @@ describe('Select', () => {
251277
clickInput(picker);
252278
expect(picker.state().open).toBeTruthy();
253279

254-
matchAll(picker, '01:02:04');
280+
matchAll(picker, '01:02:04:05');
255281

256282
clickSelectItem(picker, 0, 3);
257283

258284
expect(onChange).toBeCalled();
259285
expect(onChange.mock.calls[0][0].hour()).toBe(6);
260-
matchAll(picker, '06:02:04');
286+
matchAll(picker, '06:02:04:05');
261287
expect(picker.state().open).toBeTruthy();
262288
onChange.mockReset();
263289

264290
clickSelectItem(picker, 0, 4);
265291

266292
expect(onChange).toBeCalled();
267293
expect(onChange.mock.calls[0][0].hour()).toBe(8);
268-
matchAll(picker, '08:02:04');
294+
matchAll(picker, '08:02:04:05');
269295
expect(picker.state().open).toBeTruthy();
270296
});
271297
});
@@ -279,6 +305,7 @@ describe('Select', () => {
279305
.minute(0)
280306
.second(0),
281307
showSecond: false,
308+
showMillisecond: false,
282309
format: undefined,
283310
});
284311

@@ -299,6 +326,7 @@ describe('Select', () => {
299326
.minute(0)
300327
.second(0),
301328
showSecond: false,
329+
showMillisecond: false,
302330
format: undefined,
303331
});
304332
expect(picker.state().open).toBeFalsy();
@@ -316,6 +344,7 @@ describe('Select', () => {
316344
.minute(0)
317345
.second(0),
318346
showSecond: false,
347+
showMillisecond: false,
319348
format: undefined,
320349
});
321350
expect(picker.state().open).toBeFalsy();
@@ -336,6 +365,7 @@ describe('Select', () => {
336365
.minute(0)
337366
.second(0),
338367
showSecond: false,
368+
showMillisecond: false,
339369
format: undefined,
340370
});
341371

@@ -360,6 +390,7 @@ describe('Select', () => {
360390
.minute(0)
361391
.second(0),
362392
showSecond: false,
393+
showMillisecond: false,
363394
format: 'h:mm A',
364395
});
365396

@@ -390,6 +421,7 @@ describe('Select', () => {
390421
.minute(0)
391422
.second(0),
392423
showSecond: false,
424+
showMillisecond: false,
393425
});
394426

395427
expect(picker.state().open).toBeFalsy();
@@ -440,7 +472,7 @@ describe('Select', () => {
440472
});
441473

442474
const clearButton = findClearFunc(picker);
443-
matchValue(picker, '01:02:04');
475+
matchValue(picker, '01:02:04:05');
444476

445477
clearButton.simulate('click');
446478
expect(picker.state().open).toBeFalsy();

tests/TimePicker.spec.jsx

+18-16
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ describe('TimePicker', () => {
99
let container;
1010

1111
function renderPicker(props, options) {
12-
const showSecond = true;
13-
const format = 'HH:mm:ss';
12+
const showMillisecond = true;
13+
const format = 'HH:mm:ss:SS';
1414

1515
// eslint-disable-next-line
1616
return mount(
1717
<TimePicker
1818
format={format}
19-
showSecond={showSecond}
20-
defaultValue={moment('12:57:58', format)}
19+
showMillisecond={showMillisecond}
20+
defaultValue={moment('12:57:58:65', format)}
2121
{...props}
2222
/>,
2323
options,
2424
);
2525
}
2626

27-
function renderPickerWithoutSeconds(props) {
28-
const showSecond = false;
29-
const format = 'HH:mm';
27+
function renderPickerWithoutMilliseconds(props) {
28+
const showMillisecond = false;
29+
const format = 'HH:mm:ss';
3030

3131
// eslint-disable-next-line
3232
return mount(
3333
<TimePicker
3434
format={format}
35-
showSecond={showSecond}
36-
defaultValue={moment('08:24', format)}
35+
showSecond={showMillisecond}
36+
defaultValue={moment('08:24:32', format)}
3737
{...props}
3838
/>,
3939
);
@@ -56,7 +56,7 @@ describe('TimePicker', () => {
5656
onChange,
5757
});
5858
expect(picker.state().open).toBeFalsy();
59-
matchValue(picker, '12:57:58');
59+
matchValue(picker, '12:57:58:65');
6060
clickInput(picker);
6161

6262
expect(picker.state().open).toBeTruthy();
@@ -66,7 +66,8 @@ describe('TimePicker', () => {
6666
expect(onChange.mock.calls[0][0].hour()).toBe(1);
6767
expect(onChange.mock.calls[0][0].minute()).toBe(57);
6868
expect(onChange.mock.calls[0][0].second()).toBe(58);
69-
matchValue(picker, '01:57:58');
69+
expect(onChange.mock.calls[0][0].millisecond()).toBe(650);
70+
matchValue(picker, '01:57:58:65');
7071
expect(picker.state().open).toBeTruthy();
7172
});
7273

@@ -115,14 +116,14 @@ describe('TimePicker', () => {
115116
});
116117
});
117118

118-
describe('render panel to body (without seconds)', () => {
119+
describe('render panel to body (without milliseconds)', () => {
119120
it('popup correctly', async () => {
120121
const onChange = jest.fn();
121-
const picker = renderPickerWithoutSeconds({
122+
const picker = renderPickerWithoutMilliseconds({
122123
onChange,
123124
});
124125
expect(picker.state().open).toBeFalsy();
125-
matchValue(picker, '08:24');
126+
matchValue(picker, '08:24:32');
126127
clickInput(picker);
127128

128129
expect(picker.find('.rc-time-picker-panel-inner').length).toBeTruthy();
@@ -132,15 +133,16 @@ describe('TimePicker', () => {
132133
expect(onChange).toBeCalled();
133134
expect(onChange.mock.calls[0][0].hour()).toBe(1);
134135
expect(onChange.mock.calls[0][0].minute()).toBe(24);
135-
matchValue(picker, '01:24');
136+
expect(onChange.mock.calls[0][0].second()).toBe(32);
137+
matchValue(picker, '01:24:32');
136138
expect(picker.state().open).toBeTruthy();
137139
});
138140
});
139141

140142
describe('render panel to body 12pm mode', () => {
141143
it('popup correctly', async () => {
142144
const onChange = jest.fn();
143-
const picker = renderPickerWithoutSeconds({
145+
const picker = renderPickerWithoutMilliseconds({
144146
use12Hours: true,
145147
value: null,
146148
onChange,

tests/__snapshots__/TimePicker.spec.jsx.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports[`TimePicker allowEmpty cannot allow clear when disabled 1`] = `
99
disabled=""
1010
id=""
1111
type="text"
12-
value="12:57:58"
12+
value="12:57:58:65"
1313
/>
1414
<span
1515
class="rc-time-picker-icon"
@@ -25,7 +25,7 @@ exports[`TimePicker allowEmpty should allow clear 1`] = `
2525
class="rc-time-picker-input"
2626
id=""
2727
type="text"
28-
value="12:57:58"
28+
value="12:57:58:65"
2929
/>
3030
<span
3131
class="rc-time-picker-icon"

0 commit comments

Comments
 (0)