Skip to content

Commit 85568d7

Browse files
committed
Improve testing second input in unit tests
1 parent fa13173 commit 85568d7

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

packages/react-datetime-picker/src/DateTimeInput.spec.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('DateTimeInput', () => {
8686
});
8787

8888
it('shows a given date in all inputs correctly given Date (12-hour format)', () => {
89-
const date = new Date(2017, 8, 30, 22, 17, 0);
89+
const date = new Date(2017, 8, 30, 22, 17, 3);
9090

9191
const { container } = render(
9292
<DateTimeInput {...defaultProps} maxDetail="second" value={date} />,
@@ -95,17 +95,17 @@ describe('DateTimeInput', () => {
9595
const nativeInput = container.querySelector('input[type="datetime-local"]');
9696
const customInputs = container.querySelectorAll('input[data-input]');
9797

98-
expect(nativeInput).toHaveValue('2017-09-30T22:17');
98+
expect(nativeInput).toHaveValue('2017-09-30T22:17:03');
9999
expect(customInputs[0]).toHaveValue(9);
100100
expect(customInputs[1]).toHaveValue(30);
101101
expect(customInputs[2]).toHaveValue(2017);
102102
expect(customInputs[3]).toHaveValue(10);
103103
expect(customInputs[4]).toHaveValue(17);
104-
expect(customInputs[5]).toHaveValue(0);
104+
expect(customInputs[5]).toHaveValue(3);
105105
});
106106

107107
it('shows a given date in all inputs correctly given ISO string (12-hour format)', () => {
108-
const date = '2017-09-30T22:17:00.000';
108+
const date = '2017-09-30T22:17:03.000';
109109

110110
const { container } = render(
111111
<DateTimeInput {...defaultProps} maxDetail="second" value={date} />,
@@ -114,17 +114,17 @@ describe('DateTimeInput', () => {
114114
const nativeInput = container.querySelector('input[type="datetime-local"]');
115115
const customInputs = container.querySelectorAll('input[data-input]');
116116

117-
expect(nativeInput).toHaveValue('2017-09-30T22:17');
117+
expect(nativeInput).toHaveValue('2017-09-30T22:17:03');
118118
expect(customInputs[0]).toHaveValue(9);
119119
expect(customInputs[1]).toHaveValue(30);
120120
expect(customInputs[2]).toHaveValue(2017);
121121
expect(customInputs[3]).toHaveValue(10);
122122
expect(customInputs[4]).toHaveValue(17);
123-
expect(customInputs[5]).toHaveValue(0);
123+
expect(customInputs[5]).toHaveValue(3);
124124
});
125125

126126
itIfFullICU('shows a given date in all inputs correctly given Date (24-hour format)', () => {
127-
const date = new Date(2017, 8, 30, 22, 17, 0);
127+
const date = new Date(2017, 8, 30, 22, 17, 3);
128128

129129
const { container } = render(
130130
<DateTimeInput {...defaultProps} locale="de-DE" maxDetail="second" value={date} />,
@@ -133,19 +133,19 @@ describe('DateTimeInput', () => {
133133
const nativeInput = container.querySelector('input[type="datetime-local"]');
134134
const customInputs = container.querySelectorAll('input[data-input]');
135135

136-
expect(nativeInput).toHaveValue('2017-09-30T22:17');
136+
expect(nativeInput).toHaveValue('2017-09-30T22:17:03');
137137
expect(customInputs[0]).toHaveValue(30);
138138
expect(customInputs[1]).toHaveValue(9);
139139
expect(customInputs[2]).toHaveValue(2017);
140140
expect(customInputs[3]).toHaveValue(22);
141141
expect(customInputs[4]).toHaveValue(17);
142-
expect(customInputs[5]).toHaveValue(0);
142+
expect(customInputs[5]).toHaveValue(3);
143143
});
144144

145145
itIfFullICU(
146146
'shows a given date in all inputs correctly given ISO string (24-hour format)',
147147
() => {
148-
const date = '2017-09-30T22:17:00.000';
148+
const date = '2017-09-30T22:17:03.000';
149149

150150
const { container } = render(
151151
<DateTimeInput {...defaultProps} locale="de-DE" maxDetail="second" value={date} />,
@@ -154,13 +154,13 @@ describe('DateTimeInput', () => {
154154
const nativeInput = container.querySelector('input[type="datetime-local"]');
155155
const customInputs = container.querySelectorAll('input[data-input]');
156156

157-
expect(nativeInput).toHaveValue('2017-09-30T22:17');
157+
expect(nativeInput).toHaveValue('2017-09-30T22:17:03');
158158
expect(customInputs[0]).toHaveValue(30);
159159
expect(customInputs[1]).toHaveValue(9);
160160
expect(customInputs[2]).toHaveValue(2017);
161161
expect(customInputs[3]).toHaveValue(22);
162162
expect(customInputs[4]).toHaveValue(17);
163-
expect(customInputs[5]).toHaveValue(0);
163+
expect(customInputs[5]).toHaveValue(3);
164164
},
165165
);
166166

@@ -182,7 +182,7 @@ describe('DateTimeInput', () => {
182182
});
183183

184184
it('clears the value correctly', () => {
185-
const date = new Date(2017, 8, 30, 22, 17, 0);
185+
const date = new Date(2017, 8, 30, 22, 17, 3);
186186

187187
const { container, rerender } = render(
188188
<DateTimeInput {...defaultProps} maxDetail="second" value={date} />,
@@ -704,7 +704,7 @@ describe('DateTimeInput', () => {
704704

705705
it('triggers onChange correctly when cleared custom inputs', () => {
706706
const onChange = vi.fn();
707-
const date = new Date(2017, 8, 30, 22, 17, 0);
707+
const date = new Date(2017, 8, 30, 22, 17, 3);
708708

709709
const { container } = render(
710710
<DateTimeInput {...defaultProps} maxDetail="second" onChange={onChange} value={date} />,
@@ -722,45 +722,45 @@ describe('DateTimeInput', () => {
722722

723723
it('triggers onChange correctly when changed native input', () => {
724724
const onChange = vi.fn();
725-
const date = new Date(2017, 8, 30, 22, 17, 0);
725+
const date = new Date(2017, 8, 30, 22, 17, 3);
726726

727727
const { container } = render(
728728
<DateTimeInput {...defaultProps} onChange={onChange} value={date} />,
729729
);
730730

731731
const nativeInput = container.querySelector('input[type="datetime-local"]') as HTMLInputElement;
732732

733-
fireEvent.change(nativeInput, { target: { value: '2017-09-30T20:17:00' } });
733+
fireEvent.change(nativeInput, { target: { value: '2017-09-30T20:17:03' } });
734734

735735
expect(onChange).toHaveBeenCalled();
736-
expect(onChange).toHaveBeenCalledWith(new Date(2017, 8, 30, 20, 17, 0), false);
736+
expect(onChange).toHaveBeenCalledWith(new Date(2017, 8, 30, 20, 17, 3), false);
737737
});
738738

739739
it('triggers onChange correctly when changed native input with year < 100', () => {
740740
const onChange = vi.fn();
741741
const date = new Date();
742742
date.setFullYear(19, 8, 20);
743-
date.setHours(22, 17, 0, 0);
743+
date.setHours(22, 17, 3, 0);
744744

745745
const { container } = render(
746746
<DateTimeInput {...defaultProps} onChange={onChange} value={date} />,
747747
);
748748

749749
const nativeInput = container.querySelector('input[type="datetime-local"]') as HTMLInputElement;
750750

751-
fireEvent.change(nativeInput, { target: { value: '0019-09-20T20:17:00' } });
751+
fireEvent.change(nativeInput, { target: { value: '0019-09-20T20:17:03' } });
752752

753753
const nextDate = new Date();
754754
nextDate.setFullYear(19, 8, 20);
755-
nextDate.setHours(20, 17, 0, 0);
755+
nextDate.setHours(20, 17, 3, 0);
756756

757757
expect(onChange).toHaveBeenCalled();
758758
expect(onChange).toHaveBeenCalledWith(nextDate, false);
759759
});
760760

761761
it('triggers onChange correctly when cleared native input', () => {
762762
const onChange = vi.fn();
763-
const date = new Date(2017, 8, 30, 22, 17, 0);
763+
const date = new Date(2017, 8, 30, 22, 17, 3);
764764

765765
const { container } = render(
766766
<DateTimeInput {...defaultProps} onChange={onChange} value={date} />,

packages/react-datetime-picker/src/DateTimeInput/NativeInput.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('NativeInput', () => {
4545
// TODO: Investigate why ".000" is added here
4646
it.each`
4747
valueType | parsedValue
48-
${'second'} | ${'2017-09-30T22:17:41.000'}
48+
${'second'} | ${'2017-09-30T22:17:41'}
4949
${'minute'} | ${'2017-09-30T22:17'}
5050
${'hour'} | ${'2017-09-30T22:00'}
5151
`('displays given value properly if valueType is $valueType', ({ valueType, parsedValue }) => {

0 commit comments

Comments
 (0)