Skip to content

Commit b871b80

Browse files
committed
add milliseconds test
1 parent b34f58e commit b871b80

File tree

5 files changed

+110
-83
lines changed

5 files changed

+110
-83
lines changed

rc-time-picker.d.ts

-46
This file was deleted.

tests/Header.spec.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ describe('Header', () => {
8888
disabledSeconds(h, m) {
8989
return [h + (m % 60)];
9090
},
91+
disabledMilliseconds() {
92+
return [15, 25, 35];
93+
},
9194
});
9295
expect(picker.state().open).toBeFalsy();
9396
clickInput(picker);

tests/Select.spec.jsx

+51-19
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ 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
return mount(
1616
<TimePicker
1717
format={format}
18-
showSecond={showSecond}
19-
defaultValue={moment('01:02:04', format)}
18+
showMillisecond={showMillisecond}
19+
defaultValue={moment('01:02:04:05', format)}
2020
{...props}
2121
/>,
2222
);
@@ -80,6 +80,7 @@ describe('Select', () => {
8080
hourStep: 5,
8181
minuteStep: 15,
8282
secondStep: 21,
83+
millisecondStep: 30,
8384
});
8485
clickInput(picker);
8586

@@ -88,6 +89,7 @@ describe('Select', () => {
8889
const hourSelector = selectors.at(0);
8990
const minuteSelector = selectors.at(1);
9091
const secondSelector = selectors.at(2);
92+
const millisecondSelector = selectors.at(3);
9193

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

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

@@ -108,7 +113,7 @@ describe('Select', () => {
108113
clickInput(picker);
109114
expect(picker.state().open).toBeTruthy();
110115

111-
expect(picker.find('.rc-time-picker-panel-select').length).toBe(3);
116+
expect(picker.find('.rc-time-picker-panel-select').length).toBe(4);
112117
});
113118
});
114119

@@ -123,13 +128,13 @@ describe('Select', () => {
123128
clickInput(picker);
124129

125130
expect(picker.state().open).toBeTruthy();
126-
matchAll(picker, '01:02:04');
131+
matchAll(picker, '01:02:04:05');
127132

128133
clickSelectItem(picker, 0, 19);
129134

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

@@ -143,13 +148,13 @@ describe('Select', () => {
143148
clickInput(picker);
144149

145150
expect(picker.state().open).toBeTruthy();
146-
matchAll(picker, '01:02:04');
151+
matchAll(picker, '01:02:04:05');
147152

148153
clickSelectItem(picker, 1, 19);
149154

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

@@ -163,13 +168,33 @@ describe('Select', () => {
163168
clickInput(picker);
164169

165170
expect(picker.state().open).toBeTruthy();
166-
matchAll(picker, '01:02:04');
171+
matchAll(picker, '01:02:04:05');
167172

168173
clickSelectItem(picker, 2, 19);
169174

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

@@ -183,6 +208,7 @@ describe('Select', () => {
183208
.second(0),
184209
format: undefined,
185210
showSecond: false,
211+
showMillisecond: false,
186212
use12Hours: true,
187213
});
188214
expect(picker.state().open).toBeFalsy();
@@ -215,25 +241,25 @@ describe('Select', () => {
215241

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

218-
matchAll(picker, '01:02:04');
244+
matchAll(picker, '01:02:04:05');
219245

220246
clickSelectItem(picker, 1, 1);
221247

222248
expect(onChange).not.toBeCalled();
223-
matchAll(picker, '01:02:04');
249+
matchAll(picker, '01:02:04:05');
224250
expect(picker.state().open).toBeTruthy();
225251

226252
clickSelectItem(picker, 2, 3);
227253

228254
expect(onChange).not.toBeCalled();
229-
matchAll(picker, '01:02:04');
255+
matchAll(picker, '01:02:04:05');
230256
expect(picker.state().open).toBeTruthy();
231257

232258
clickSelectItem(picker, 1, 7);
233259

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

@@ -250,21 +276,21 @@ describe('Select', () => {
250276
clickInput(picker);
251277
expect(picker.state().open).toBeTruthy();
252278

253-
matchAll(picker, '01:02:04');
279+
matchAll(picker, '01:02:04:05');
254280

255281
clickSelectItem(picker, 0, 3);
256282

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

263289
clickSelectItem(picker, 0, 4);
264290

265291
expect(onChange).toBeCalled();
266292
expect(onChange.mock.calls[0][0].hour()).toBe(8);
267-
matchAll(picker, '08:02:04');
293+
matchAll(picker, '08:02:04:05');
268294
expect(picker.state().open).toBeTruthy();
269295
});
270296
});
@@ -278,6 +304,7 @@ describe('Select', () => {
278304
.minute(0)
279305
.second(0),
280306
showSecond: false,
307+
showMillisecond: false,
281308
format: undefined,
282309
});
283310

@@ -298,6 +325,7 @@ describe('Select', () => {
298325
.minute(0)
299326
.second(0),
300327
showSecond: false,
328+
showMillisecond: false,
301329
format: undefined,
302330
});
303331
expect(picker.state().open).toBeFalsy();
@@ -315,6 +343,7 @@ describe('Select', () => {
315343
.minute(0)
316344
.second(0),
317345
showSecond: false,
346+
showMillisecond: false,
318347
format: undefined,
319348
});
320349
expect(picker.state().open).toBeFalsy();
@@ -335,6 +364,7 @@ describe('Select', () => {
335364
.minute(0)
336365
.second(0),
337366
showSecond: false,
367+
showMillisecond: false,
338368
format: undefined,
339369
});
340370

@@ -359,6 +389,7 @@ describe('Select', () => {
359389
.minute(0)
360390
.second(0),
361391
showSecond: false,
392+
showMillisecond: false,
362393
format: 'h:mm A',
363394
});
364395

@@ -389,6 +420,7 @@ describe('Select', () => {
389420
.minute(0)
390421
.second(0),
391422
showSecond: false,
423+
showMillisecond: false,
392424
});
393425

394426
expect(picker.state().open).toBeFalsy();
@@ -439,7 +471,7 @@ describe('Select', () => {
439471
});
440472

441473
const clearButton = findClearFunc(picker);
442-
matchValue(picker, '01:02:04');
474+
matchValue(picker, '01:02:04:05');
443475

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

0 commit comments

Comments
 (0)