@contentful/field-editor-date 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
|
-
require("@testing-library/jest-dom/extend-expect");
|
|
7
6
|
const _react1 = require("@testing-library/react");
|
|
8
7
|
const _userevent = /*#__PURE__*/ _interop_require_default(require("@testing-library/user-event"));
|
|
8
|
+
const _vitest = require("vitest");
|
|
9
9
|
const _TimepickerInput = require("./TimepickerInput");
|
|
10
10
|
function _interop_require_default(obj) {
|
|
11
11
|
return obj && obj.__esModule ? obj : {
|
|
@@ -56,47 +56,47 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
56
56
|
(0, _react1.configure)({
|
|
57
57
|
testIdAttribute: 'data-test-id'
|
|
58
58
|
});
|
|
59
|
-
describe('TimepickerInput', ()=>{
|
|
60
|
-
afterEach(_react1.cleanup);
|
|
61
|
-
it('renders midnight (00:00) in 24h mode without crashing', ()=>{
|
|
59
|
+
(0, _vitest.describe)('TimepickerInput', ()=>{
|
|
60
|
+
(0, _vitest.afterEach)(_react1.cleanup);
|
|
61
|
+
(0, _vitest.it)('renders midnight (00:00) in 24h mode without crashing', ()=>{
|
|
62
62
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
63
63
|
disabled: false,
|
|
64
64
|
uses12hClock: false,
|
|
65
65
|
time: "00:00",
|
|
66
66
|
ampm: "AM",
|
|
67
|
-
onChange:
|
|
67
|
+
onChange: _vitest.vi.fn()
|
|
68
68
|
}));
|
|
69
|
-
expect(getByTestId('time-input')).toHaveValue('00:00');
|
|
69
|
+
(0, _vitest.expect)(getByTestId('time-input')).toHaveValue('00:00');
|
|
70
70
|
});
|
|
71
|
-
it('defaults to 00:00 in 24h mode when no time prop is provided', ()=>{
|
|
71
|
+
(0, _vitest.it)('defaults to 00:00 in 24h mode when no time prop is provided', ()=>{
|
|
72
72
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
73
73
|
disabled: false,
|
|
74
74
|
uses12hClock: false,
|
|
75
|
-
onChange:
|
|
75
|
+
onChange: _vitest.vi.fn()
|
|
76
76
|
}));
|
|
77
|
-
expect(getByTestId('time-input')).toHaveValue('00:00');
|
|
77
|
+
(0, _vitest.expect)(getByTestId('time-input')).toHaveValue('00:00');
|
|
78
78
|
});
|
|
79
|
-
it('defaults to 12:00 AM in 12h mode when no time prop is provided', ()=>{
|
|
79
|
+
(0, _vitest.it)('defaults to 12:00 AM in 12h mode when no time prop is provided', ()=>{
|
|
80
80
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
81
81
|
disabled: false,
|
|
82
82
|
uses12hClock: true,
|
|
83
|
-
onChange:
|
|
83
|
+
onChange: _vitest.vi.fn()
|
|
84
84
|
}));
|
|
85
|
-
expect(getByTestId('time-input')).toHaveValue('12:00 AM');
|
|
85
|
+
(0, _vitest.expect)(getByTestId('time-input')).toHaveValue('12:00 AM');
|
|
86
86
|
});
|
|
87
|
-
it('renders late-night hours (e.g. 23:00) in 24h mode without crashing', ()=>{
|
|
87
|
+
(0, _vitest.it)('renders late-night hours (e.g. 23:00) in 24h mode without crashing', ()=>{
|
|
88
88
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
89
89
|
disabled: false,
|
|
90
90
|
uses12hClock: false,
|
|
91
91
|
time: "23:00",
|
|
92
92
|
ampm: "PM",
|
|
93
|
-
onChange:
|
|
93
|
+
onChange: _vitest.vi.fn()
|
|
94
94
|
}));
|
|
95
|
-
expect(getByTestId('time-input')).toHaveValue('23:00');
|
|
95
|
+
(0, _vitest.expect)(getByTestId('time-input')).toHaveValue('23:00');
|
|
96
96
|
});
|
|
97
|
-
describe('onChange on blur — 24h mode', ()=>{
|
|
98
|
-
it('emits 19:00 (not 07:00) when user types 19:00 in 24h mode', ()=>{
|
|
99
|
-
const onChange =
|
|
97
|
+
(0, _vitest.describe)('onChange on blur — 24h mode', ()=>{
|
|
98
|
+
(0, _vitest.it)('emits 19:00 (not 07:00) when user types 19:00 in 24h mode', ()=>{
|
|
99
|
+
const onChange = _vitest.vi.fn();
|
|
100
100
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
101
101
|
disabled: false,
|
|
102
102
|
uses12hClock: false,
|
|
@@ -107,13 +107,13 @@ describe('TimepickerInput', ()=>{
|
|
|
107
107
|
_userevent.default.clear(getByTestId('time-input'));
|
|
108
108
|
_userevent.default.type(getByTestId('time-input'), '19:00');
|
|
109
109
|
_userevent.default.tab();
|
|
110
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
110
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
111
111
|
time: '19:00',
|
|
112
112
|
ampm: 'PM'
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
|
-
it('emits 23:59 (not 11:59) when user types 23:59 in 24h mode', ()=>{
|
|
116
|
-
const onChange =
|
|
115
|
+
(0, _vitest.it)('emits 23:59 (not 11:59) when user types 23:59 in 24h mode', ()=>{
|
|
116
|
+
const onChange = _vitest.vi.fn();
|
|
117
117
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
118
118
|
disabled: false,
|
|
119
119
|
uses12hClock: false,
|
|
@@ -124,13 +124,13 @@ describe('TimepickerInput', ()=>{
|
|
|
124
124
|
_userevent.default.clear(getByTestId('time-input'));
|
|
125
125
|
_userevent.default.type(getByTestId('time-input'), '23:59');
|
|
126
126
|
_userevent.default.tab();
|
|
127
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
127
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
128
128
|
time: '23:59',
|
|
129
129
|
ampm: 'PM'
|
|
130
130
|
});
|
|
131
131
|
});
|
|
132
|
-
it('emits 00:00 when user types 00:00 in 24h mode', ()=>{
|
|
133
|
-
const onChange =
|
|
132
|
+
(0, _vitest.it)('emits 00:00 when user types 00:00 in 24h mode', ()=>{
|
|
133
|
+
const onChange = _vitest.vi.fn();
|
|
134
134
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
135
135
|
disabled: false,
|
|
136
136
|
uses12hClock: false,
|
|
@@ -141,13 +141,13 @@ describe('TimepickerInput', ()=>{
|
|
|
141
141
|
_userevent.default.clear(getByTestId('time-input'));
|
|
142
142
|
_userevent.default.type(getByTestId('time-input'), '00:00');
|
|
143
143
|
_userevent.default.tab();
|
|
144
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
144
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
145
145
|
time: '00:00',
|
|
146
146
|
ampm: 'AM'
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
|
-
it('emits 12:00 (noon) correctly in 24h mode', ()=>{
|
|
150
|
-
const onChange =
|
|
149
|
+
(0, _vitest.it)('emits 12:00 (noon) correctly in 24h mode', ()=>{
|
|
150
|
+
const onChange = _vitest.vi.fn();
|
|
151
151
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
152
152
|
disabled: false,
|
|
153
153
|
uses12hClock: false,
|
|
@@ -158,13 +158,13 @@ describe('TimepickerInput', ()=>{
|
|
|
158
158
|
_userevent.default.clear(getByTestId('time-input'));
|
|
159
159
|
_userevent.default.type(getByTestId('time-input'), '12:00');
|
|
160
160
|
_userevent.default.tab();
|
|
161
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
161
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
162
162
|
time: '12:00',
|
|
163
163
|
ampm: 'PM'
|
|
164
164
|
});
|
|
165
165
|
});
|
|
166
|
-
it('emits 13:00 (not 01:00) when user types 13:00 in 24h mode', ()=>{
|
|
167
|
-
const onChange =
|
|
166
|
+
(0, _vitest.it)('emits 13:00 (not 01:00) when user types 13:00 in 24h mode', ()=>{
|
|
167
|
+
const onChange = _vitest.vi.fn();
|
|
168
168
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
169
169
|
disabled: false,
|
|
170
170
|
uses12hClock: false,
|
|
@@ -175,15 +175,15 @@ describe('TimepickerInput', ()=>{
|
|
|
175
175
|
_userevent.default.clear(getByTestId('time-input'));
|
|
176
176
|
_userevent.default.type(getByTestId('time-input'), '13:00');
|
|
177
177
|
_userevent.default.tab();
|
|
178
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
178
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
179
179
|
time: '13:00',
|
|
180
180
|
ampm: 'PM'
|
|
181
181
|
});
|
|
182
182
|
});
|
|
183
183
|
});
|
|
184
|
-
describe('shorthand input without colon', ()=>{
|
|
185
|
-
it('parses 1005 as 10:05 in 24h mode', ()=>{
|
|
186
|
-
const onChange =
|
|
184
|
+
(0, _vitest.describe)('shorthand input without colon', ()=>{
|
|
185
|
+
(0, _vitest.it)('parses 1005 as 10:05 in 24h mode', ()=>{
|
|
186
|
+
const onChange = _vitest.vi.fn();
|
|
187
187
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
188
188
|
disabled: false,
|
|
189
189
|
uses12hClock: false,
|
|
@@ -194,13 +194,13 @@ describe('TimepickerInput', ()=>{
|
|
|
194
194
|
_userevent.default.clear(getByTestId('time-input'));
|
|
195
195
|
_userevent.default.type(getByTestId('time-input'), '1005');
|
|
196
196
|
_userevent.default.tab();
|
|
197
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
197
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
198
198
|
time: '10:05',
|
|
199
199
|
ampm: 'AM'
|
|
200
200
|
});
|
|
201
201
|
});
|
|
202
|
-
it('parses 1900 as 19:00 in 24h mode', ()=>{
|
|
203
|
-
const onChange =
|
|
202
|
+
(0, _vitest.it)('parses 1900 as 19:00 in 24h mode', ()=>{
|
|
203
|
+
const onChange = _vitest.vi.fn();
|
|
204
204
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
205
205
|
disabled: false,
|
|
206
206
|
uses12hClock: false,
|
|
@@ -211,13 +211,13 @@ describe('TimepickerInput', ()=>{
|
|
|
211
211
|
_userevent.default.clear(getByTestId('time-input'));
|
|
212
212
|
_userevent.default.type(getByTestId('time-input'), '1900');
|
|
213
213
|
_userevent.default.tab();
|
|
214
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
214
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
215
215
|
time: '19:00',
|
|
216
216
|
ampm: 'PM'
|
|
217
217
|
});
|
|
218
218
|
});
|
|
219
|
-
it('parses 0700 as 07:00 AM in 12h mode', ()=>{
|
|
220
|
-
const onChange =
|
|
219
|
+
(0, _vitest.it)('parses 0700 as 07:00 AM in 12h mode', ()=>{
|
|
220
|
+
const onChange = _vitest.vi.fn();
|
|
221
221
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
222
222
|
disabled: false,
|
|
223
223
|
uses12hClock: true,
|
|
@@ -228,15 +228,15 @@ describe('TimepickerInput', ()=>{
|
|
|
228
228
|
_userevent.default.clear(getByTestId('time-input'));
|
|
229
229
|
_userevent.default.type(getByTestId('time-input'), '0700');
|
|
230
230
|
_userevent.default.tab();
|
|
231
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
231
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
232
232
|
time: '07:00',
|
|
233
233
|
ampm: 'AM'
|
|
234
234
|
});
|
|
235
235
|
});
|
|
236
236
|
});
|
|
237
|
-
describe('am/pm without space separator', ()=>{
|
|
238
|
-
it('parses 1:15pm (no space) correctly in 12h mode', ()=>{
|
|
239
|
-
const onChange =
|
|
237
|
+
(0, _vitest.describe)('am/pm without space separator', ()=>{
|
|
238
|
+
(0, _vitest.it)('parses 1:15pm (no space) correctly in 12h mode', ()=>{
|
|
239
|
+
const onChange = _vitest.vi.fn();
|
|
240
240
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
241
241
|
disabled: false,
|
|
242
242
|
uses12hClock: true,
|
|
@@ -247,13 +247,13 @@ describe('TimepickerInput', ()=>{
|
|
|
247
247
|
_userevent.default.clear(getByTestId('time-input'));
|
|
248
248
|
_userevent.default.type(getByTestId('time-input'), '1:15pm');
|
|
249
249
|
_userevent.default.tab();
|
|
250
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
250
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
251
251
|
time: '01:15',
|
|
252
252
|
ampm: 'PM'
|
|
253
253
|
});
|
|
254
254
|
});
|
|
255
|
-
it('parses 1:15PM (no space, uppercase) correctly in 12h mode', ()=>{
|
|
256
|
-
const onChange =
|
|
255
|
+
(0, _vitest.it)('parses 1:15PM (no space, uppercase) correctly in 12h mode', ()=>{
|
|
256
|
+
const onChange = _vitest.vi.fn();
|
|
257
257
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
258
258
|
disabled: false,
|
|
259
259
|
uses12hClock: true,
|
|
@@ -264,13 +264,13 @@ describe('TimepickerInput', ()=>{
|
|
|
264
264
|
_userevent.default.clear(getByTestId('time-input'));
|
|
265
265
|
_userevent.default.type(getByTestId('time-input'), '1:15PM');
|
|
266
266
|
_userevent.default.tab();
|
|
267
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
267
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
268
268
|
time: '01:15',
|
|
269
269
|
ampm: 'PM'
|
|
270
270
|
});
|
|
271
271
|
});
|
|
272
|
-
it('parses 1pm (no space, no minutes) correctly in 12h mode', ()=>{
|
|
273
|
-
const onChange =
|
|
272
|
+
(0, _vitest.it)('parses 1pm (no space, no minutes) correctly in 12h mode', ()=>{
|
|
273
|
+
const onChange = _vitest.vi.fn();
|
|
274
274
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
275
275
|
disabled: false,
|
|
276
276
|
uses12hClock: true,
|
|
@@ -281,15 +281,15 @@ describe('TimepickerInput', ()=>{
|
|
|
281
281
|
_userevent.default.clear(getByTestId('time-input'));
|
|
282
282
|
_userevent.default.type(getByTestId('time-input'), '1pm');
|
|
283
283
|
_userevent.default.tab();
|
|
284
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
284
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
285
285
|
time: '01:00',
|
|
286
286
|
ampm: 'PM'
|
|
287
287
|
});
|
|
288
288
|
});
|
|
289
289
|
});
|
|
290
|
-
describe('onChange on blur — 12h mode', ()=>{
|
|
291
|
-
it('emits 07:00 AM correctly in 12h mode', ()=>{
|
|
292
|
-
const onChange =
|
|
290
|
+
(0, _vitest.describe)('onChange on blur — 12h mode', ()=>{
|
|
291
|
+
(0, _vitest.it)('emits 07:00 AM correctly in 12h mode', ()=>{
|
|
292
|
+
const onChange = _vitest.vi.fn();
|
|
293
293
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
294
294
|
disabled: false,
|
|
295
295
|
uses12hClock: true,
|
|
@@ -300,13 +300,13 @@ describe('TimepickerInput', ()=>{
|
|
|
300
300
|
_userevent.default.clear(getByTestId('time-input'));
|
|
301
301
|
_userevent.default.type(getByTestId('time-input'), '07:00 AM');
|
|
302
302
|
_userevent.default.tab();
|
|
303
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
303
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
304
304
|
time: '07:00',
|
|
305
305
|
ampm: 'AM'
|
|
306
306
|
});
|
|
307
307
|
});
|
|
308
|
-
it('emits 07:00 PM correctly in 12h mode', ()=>{
|
|
309
|
-
const onChange =
|
|
308
|
+
(0, _vitest.it)('emits 07:00 PM correctly in 12h mode', ()=>{
|
|
309
|
+
const onChange = _vitest.vi.fn();
|
|
310
310
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
311
311
|
disabled: false,
|
|
312
312
|
uses12hClock: true,
|
|
@@ -317,7 +317,7 @@ describe('TimepickerInput', ()=>{
|
|
|
317
317
|
_userevent.default.clear(getByTestId('time-input'));
|
|
318
318
|
_userevent.default.type(getByTestId('time-input'), '07:00 PM');
|
|
319
319
|
_userevent.default.tab();
|
|
320
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
320
|
+
(0, _vitest.expect)(onChange).toHaveBeenCalledWith({
|
|
321
321
|
time: '07:00',
|
|
322
322
|
ampm: 'PM'
|
|
323
323
|
});
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
const _vitest = require("vitest");
|
|
5
6
|
const _date = require("./date");
|
|
6
|
-
describe('date utils', ()=>{
|
|
7
|
-
describe('buildFieldValue', ()=>{
|
|
8
|
-
it('should work properly', ()=>{
|
|
9
|
-
expect((0, _date.buildFieldValue)({
|
|
7
|
+
(0, _vitest.describe)('date utils', ()=>{
|
|
8
|
+
(0, _vitest.describe)('buildFieldValue', ()=>{
|
|
9
|
+
(0, _vitest.it)('should work properly', ()=>{
|
|
10
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
10
11
|
data: {
|
|
11
12
|
date: new Date('2018-02-02'),
|
|
12
13
|
time: '05:00',
|
|
@@ -19,7 +20,7 @@ describe('date utils', ()=>{
|
|
|
19
20
|
invalid: false,
|
|
20
21
|
valid: '2018-02-02T17:00+03:00'
|
|
21
22
|
});
|
|
22
|
-
expect((0, _date.buildFieldValue)({
|
|
23
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
23
24
|
data: {
|
|
24
25
|
date: new Date('2015-01-14'),
|
|
25
26
|
time: '05:00',
|
|
@@ -32,7 +33,7 @@ describe('date utils', ()=>{
|
|
|
32
33
|
invalid: false,
|
|
33
34
|
valid: '2015-01-14T05:00-05:00'
|
|
34
35
|
});
|
|
35
|
-
expect((0, _date.buildFieldValue)({
|
|
36
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
36
37
|
data: {
|
|
37
38
|
date: new Date('2015-01-14'),
|
|
38
39
|
time: '17:00',
|
|
@@ -46,8 +47,8 @@ describe('date utils', ()=>{
|
|
|
46
47
|
valid: '2015-01-14T17:00-05:00'
|
|
47
48
|
});
|
|
48
49
|
});
|
|
49
|
-
it('returns date-only format when usesTime and usesTimezone are false', ()=>{
|
|
50
|
-
expect((0, _date.buildFieldValue)({
|
|
50
|
+
(0, _vitest.it)('returns date-only format when usesTime and usesTimezone are false', ()=>{
|
|
51
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
51
52
|
data: {
|
|
52
53
|
date: new Date('2020-06-15'),
|
|
53
54
|
time: '10:30',
|
|
@@ -61,8 +62,8 @@ describe('date utils', ()=>{
|
|
|
61
62
|
valid: '2020-06-15'
|
|
62
63
|
});
|
|
63
64
|
});
|
|
64
|
-
it('returns datetime without timezone when usesTime=true, usesTimezone=false', ()=>{
|
|
65
|
-
expect((0, _date.buildFieldValue)({
|
|
65
|
+
(0, _vitest.it)('returns datetime without timezone when usesTime=true, usesTimezone=false', ()=>{
|
|
66
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
66
67
|
data: {
|
|
67
68
|
date: new Date('2020-06-15'),
|
|
68
69
|
time: '14:30',
|
|
@@ -76,8 +77,8 @@ describe('date utils', ()=>{
|
|
|
76
77
|
valid: '2020-06-15T14:30'
|
|
77
78
|
});
|
|
78
79
|
});
|
|
79
|
-
it('returns valid: null when no date is provided', ()=>{
|
|
80
|
-
expect((0, _date.buildFieldValue)({
|
|
80
|
+
(0, _vitest.it)('returns valid: null when no date is provided', ()=>{
|
|
81
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
81
82
|
data: {
|
|
82
83
|
time: '10:00',
|
|
83
84
|
ampm: 'AM',
|
|
@@ -90,8 +91,8 @@ describe('date utils', ()=>{
|
|
|
90
91
|
valid: null
|
|
91
92
|
});
|
|
92
93
|
});
|
|
93
|
-
it('handles midnight (12:00 AM) correctly', ()=>{
|
|
94
|
-
expect((0, _date.buildFieldValue)({
|
|
94
|
+
(0, _vitest.it)('handles midnight (12:00 AM) correctly', ()=>{
|
|
95
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
95
96
|
data: {
|
|
96
97
|
date: new Date('2021-03-01'),
|
|
97
98
|
time: '12:00',
|
|
@@ -105,8 +106,8 @@ describe('date utils', ()=>{
|
|
|
105
106
|
valid: '2021-03-01T00:00+00:00'
|
|
106
107
|
});
|
|
107
108
|
});
|
|
108
|
-
it('handles noon (12:00 PM) correctly', ()=>{
|
|
109
|
-
expect((0, _date.buildFieldValue)({
|
|
109
|
+
(0, _vitest.it)('handles noon (12:00 PM) correctly', ()=>{
|
|
110
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
110
111
|
data: {
|
|
111
112
|
date: new Date('2021-03-01'),
|
|
112
113
|
time: '12:00',
|
|
@@ -120,8 +121,8 @@ describe('date utils', ()=>{
|
|
|
120
121
|
valid: '2021-03-01T12:00+00:00'
|
|
121
122
|
});
|
|
122
123
|
});
|
|
123
|
-
it('preserves half-hour offset +05:30 (India)', ()=>{
|
|
124
|
-
expect((0, _date.buildFieldValue)({
|
|
124
|
+
(0, _vitest.it)('preserves half-hour offset +05:30 (India)', ()=>{
|
|
125
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
125
126
|
data: {
|
|
126
127
|
date: new Date('2023-08-15'),
|
|
127
128
|
time: '10:00',
|
|
@@ -135,8 +136,8 @@ describe('date utils', ()=>{
|
|
|
135
136
|
valid: '2023-08-15T10:00+05:30'
|
|
136
137
|
});
|
|
137
138
|
});
|
|
138
|
-
it('preserves negative half-hour offset -09:30', ()=>{
|
|
139
|
-
expect((0, _date.buildFieldValue)({
|
|
139
|
+
(0, _vitest.it)('preserves negative half-hour offset -09:30', ()=>{
|
|
140
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
140
141
|
data: {
|
|
141
142
|
date: new Date('2023-08-15'),
|
|
142
143
|
time: '03:30',
|
|
@@ -150,8 +151,8 @@ describe('date utils', ()=>{
|
|
|
150
151
|
valid: '2023-08-15T03:30-09:30'
|
|
151
152
|
});
|
|
152
153
|
});
|
|
153
|
-
it('preserves quarter-hour offset +05:45 (Nepal)', ()=>{
|
|
154
|
-
expect((0, _date.buildFieldValue)({
|
|
154
|
+
(0, _vitest.it)('preserves quarter-hour offset +05:45 (Nepal)', ()=>{
|
|
155
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
155
156
|
data: {
|
|
156
157
|
date: new Date('2023-08-15'),
|
|
157
158
|
time: '05:45',
|
|
@@ -165,8 +166,8 @@ describe('date utils', ()=>{
|
|
|
165
166
|
valid: '2023-08-15T05:45+05:45'
|
|
166
167
|
});
|
|
167
168
|
});
|
|
168
|
-
it('preserves UTC +00:00 offset', ()=>{
|
|
169
|
-
expect((0, _date.buildFieldValue)({
|
|
169
|
+
(0, _vitest.it)('preserves UTC +00:00 offset', ()=>{
|
|
170
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
170
171
|
data: {
|
|
171
172
|
date: new Date('2023-01-01'),
|
|
172
173
|
time: '00:00',
|
|
@@ -180,8 +181,8 @@ describe('date utils', ()=>{
|
|
|
180
181
|
valid: '2023-01-01T00:00+00:00'
|
|
181
182
|
});
|
|
182
183
|
});
|
|
183
|
-
it('preserves far-west offset -12:00', ()=>{
|
|
184
|
-
expect((0, _date.buildFieldValue)({
|
|
184
|
+
(0, _vitest.it)('preserves far-west offset -12:00', ()=>{
|
|
185
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
185
186
|
data: {
|
|
186
187
|
date: new Date('2023-01-01'),
|
|
187
188
|
time: '23:59',
|
|
@@ -195,8 +196,8 @@ describe('date utils', ()=>{
|
|
|
195
196
|
valid: '2023-01-01T23:59-12:00'
|
|
196
197
|
});
|
|
197
198
|
});
|
|
198
|
-
it('preserves far-east offset +14:00', ()=>{
|
|
199
|
-
expect((0, _date.buildFieldValue)({
|
|
199
|
+
(0, _vitest.it)('preserves far-east offset +14:00', ()=>{
|
|
200
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
200
201
|
data: {
|
|
201
202
|
date: new Date('2023-01-01'),
|
|
202
203
|
time: '01:00',
|
|
@@ -210,8 +211,8 @@ describe('date utils', ()=>{
|
|
|
210
211
|
valid: '2023-01-01T01:00+14:00'
|
|
211
212
|
});
|
|
212
213
|
});
|
|
213
|
-
it('11:59 PM → 23:59', ()=>{
|
|
214
|
-
expect((0, _date.buildFieldValue)({
|
|
214
|
+
(0, _vitest.it)('11:59 PM → 23:59', ()=>{
|
|
215
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
215
216
|
data: {
|
|
216
217
|
date: new Date('2023-06-01'),
|
|
217
218
|
time: '11:59',
|
|
@@ -225,8 +226,8 @@ describe('date utils', ()=>{
|
|
|
225
226
|
valid: '2023-06-01T23:59+00:00'
|
|
226
227
|
});
|
|
227
228
|
});
|
|
228
|
-
it('01:00 AM → 01:00 (no shift)', ()=>{
|
|
229
|
-
expect((0, _date.buildFieldValue)({
|
|
229
|
+
(0, _vitest.it)('01:00 AM → 01:00 (no shift)', ()=>{
|
|
230
|
+
(0, _vitest.expect)((0, _date.buildFieldValue)({
|
|
230
231
|
data: {
|
|
231
232
|
date: new Date('2023-06-01'),
|
|
232
233
|
time: '01:00',
|
|
@@ -241,147 +242,147 @@ describe('date utils', ()=>{
|
|
|
241
242
|
});
|
|
242
243
|
});
|
|
243
244
|
});
|
|
244
|
-
describe('userInputFromDatetime', ()=>{
|
|
245
|
-
it('parses a full ISO datetime string with timezone', ()=>{
|
|
245
|
+
(0, _vitest.describe)('userInputFromDatetime', ()=>{
|
|
246
|
+
(0, _vitest.it)('parses a full ISO datetime string with timezone', ()=>{
|
|
246
247
|
const result = (0, _date.userInputFromDatetime)({
|
|
247
248
|
value: '2018-02-02T17:00+03:00',
|
|
248
249
|
uses12hClock: false
|
|
249
250
|
});
|
|
250
|
-
expect(result.time).toBe('17:00');
|
|
251
|
-
expect(result.ampm).toBe('PM');
|
|
252
|
-
expect(result.utcOffset).toBe('+03:00');
|
|
251
|
+
(0, _vitest.expect)(result.time).toBe('17:00');
|
|
252
|
+
(0, _vitest.expect)(result.ampm).toBe('PM');
|
|
253
|
+
(0, _vitest.expect)(result.utcOffset).toBe('+03:00');
|
|
253
254
|
});
|
|
254
|
-
it('parses a full ISO datetime string with 12h clock', ()=>{
|
|
255
|
+
(0, _vitest.it)('parses a full ISO datetime string with 12h clock', ()=>{
|
|
255
256
|
const result = (0, _date.userInputFromDatetime)({
|
|
256
257
|
value: '2018-02-02T05:00+03:00',
|
|
257
258
|
uses12hClock: true
|
|
258
259
|
});
|
|
259
|
-
expect(result.time).toBe('05:00');
|
|
260
|
-
expect(result.ampm).toBe('AM');
|
|
261
|
-
expect(result.utcOffset).toBe('+03:00');
|
|
260
|
+
(0, _vitest.expect)(result.time).toBe('05:00');
|
|
261
|
+
(0, _vitest.expect)(result.ampm).toBe('AM');
|
|
262
|
+
(0, _vitest.expect)(result.utcOffset).toBe('+03:00');
|
|
262
263
|
});
|
|
263
|
-
it('returns defaults when value is null', ()=>{
|
|
264
|
+
(0, _vitest.it)('returns defaults when value is null', ()=>{
|
|
264
265
|
const result = (0, _date.userInputFromDatetime)({
|
|
265
266
|
value: null,
|
|
266
267
|
uses12hClock: false
|
|
267
268
|
});
|
|
268
|
-
expect(result.date).toBeUndefined();
|
|
269
|
-
expect(result.ampm).toBe((0, _date.getDefaultAMPM)());
|
|
270
|
-
expect(result.utcOffset).toBe((0, _date.getDefaultUtcOffset)());
|
|
269
|
+
(0, _vitest.expect)(result.date).toBeUndefined();
|
|
270
|
+
(0, _vitest.expect)(result.ampm).toBe((0, _date.getDefaultAMPM)());
|
|
271
|
+
(0, _vitest.expect)(result.utcOffset).toBe((0, _date.getDefaultUtcOffset)());
|
|
271
272
|
});
|
|
272
|
-
it('returns defaults when value is undefined', ()=>{
|
|
273
|
+
(0, _vitest.it)('returns defaults when value is undefined', ()=>{
|
|
273
274
|
const result = (0, _date.userInputFromDatetime)({
|
|
274
275
|
value: undefined,
|
|
275
276
|
uses12hClock: false
|
|
276
277
|
});
|
|
277
|
-
expect(result.date).toBeUndefined();
|
|
278
|
-
expect(result.ampm).toBe((0, _date.getDefaultAMPM)());
|
|
278
|
+
(0, _vitest.expect)(result.date).toBeUndefined();
|
|
279
|
+
(0, _vitest.expect)(result.ampm).toBe((0, _date.getDefaultAMPM)());
|
|
279
280
|
});
|
|
280
|
-
it('returns defaults when value is empty string', ()=>{
|
|
281
|
+
(0, _vitest.it)('returns defaults when value is empty string', ()=>{
|
|
281
282
|
const result = (0, _date.userInputFromDatetime)({
|
|
282
283
|
value: '',
|
|
283
284
|
uses12hClock: false
|
|
284
285
|
});
|
|
285
|
-
expect(result.date).toBeUndefined();
|
|
286
|
+
(0, _vitest.expect)(result.date).toBeUndefined();
|
|
286
287
|
});
|
|
287
|
-
it('parses a date-only string', ()=>{
|
|
288
|
+
(0, _vitest.it)('parses a date-only string', ()=>{
|
|
288
289
|
const result = (0, _date.userInputFromDatetime)({
|
|
289
290
|
value: '2022-09-16',
|
|
290
291
|
uses12hClock: false
|
|
291
292
|
});
|
|
292
|
-
expect(result.utcOffset).toBe('+00:00');
|
|
293
|
+
(0, _vitest.expect)(result.utcOffset).toBe('+00:00');
|
|
293
294
|
});
|
|
294
|
-
it('preserves raw time and does not shift by system timezone (positive offset)', ()=>{
|
|
295
|
+
(0, _vitest.it)('preserves raw time and does not shift by system timezone (positive offset)', ()=>{
|
|
295
296
|
const result = (0, _date.userInputFromDatetime)({
|
|
296
297
|
value: '2020-03-15T14:00+05:30',
|
|
297
298
|
uses12hClock: false
|
|
298
299
|
});
|
|
299
|
-
expect(result.time).toBe('14:00');
|
|
300
|
-
expect(result.ampm).toBe('PM');
|
|
301
|
-
expect(result.utcOffset).toBe('+05:30');
|
|
300
|
+
(0, _vitest.expect)(result.time).toBe('14:00');
|
|
301
|
+
(0, _vitest.expect)(result.ampm).toBe('PM');
|
|
302
|
+
(0, _vitest.expect)(result.utcOffset).toBe('+05:30');
|
|
302
303
|
});
|
|
303
|
-
it('preserves raw time and does not shift by system timezone (negative offset)', ()=>{
|
|
304
|
+
(0, _vitest.it)('preserves raw time and does not shift by system timezone (negative offset)', ()=>{
|
|
304
305
|
const result = (0, _date.userInputFromDatetime)({
|
|
305
306
|
value: '2020-03-15T08:30-05:30',
|
|
306
307
|
uses12hClock: false
|
|
307
308
|
});
|
|
308
|
-
expect(result.time).toBe('08:30');
|
|
309
|
-
expect(result.ampm).toBe('AM');
|
|
310
|
-
expect(result.utcOffset).toBe('-05:30');
|
|
309
|
+
(0, _vitest.expect)(result.time).toBe('08:30');
|
|
310
|
+
(0, _vitest.expect)(result.ampm).toBe('AM');
|
|
311
|
+
(0, _vitest.expect)(result.utcOffset).toBe('-05:30');
|
|
311
312
|
});
|
|
312
|
-
it('handles UTC "Z" suffix — normalizes offset to +00:00', ()=>{
|
|
313
|
+
(0, _vitest.it)('handles UTC "Z" suffix — normalizes offset to +00:00', ()=>{
|
|
313
314
|
const result = (0, _date.userInputFromDatetime)({
|
|
314
315
|
value: '2021-06-01T12:00Z',
|
|
315
316
|
uses12hClock: false
|
|
316
317
|
});
|
|
317
|
-
expect(result.time).toBe('12:00');
|
|
318
|
-
expect(result.ampm).toBe('PM');
|
|
319
|
-
expect(result.utcOffset).toBe('+00:00');
|
|
318
|
+
(0, _vitest.expect)(result.time).toBe('12:00');
|
|
319
|
+
(0, _vitest.expect)(result.ampm).toBe('PM');
|
|
320
|
+
(0, _vitest.expect)(result.utcOffset).toBe('+00:00');
|
|
320
321
|
});
|
|
321
|
-
it('handles midnight UTC correctly', ()=>{
|
|
322
|
+
(0, _vitest.it)('handles midnight UTC correctly', ()=>{
|
|
322
323
|
const result = (0, _date.userInputFromDatetime)({
|
|
323
324
|
value: '2021-06-01T00:00Z',
|
|
324
325
|
uses12hClock: false
|
|
325
326
|
});
|
|
326
|
-
expect(result.time).toBe('00:00');
|
|
327
|
-
expect(result.ampm).toBe('AM');
|
|
327
|
+
(0, _vitest.expect)(result.time).toBe('00:00');
|
|
328
|
+
(0, _vitest.expect)(result.ampm).toBe('AM');
|
|
328
329
|
});
|
|
329
|
-
it('converts PM hour to 12h display (17:00 → 05:00 PM)', ()=>{
|
|
330
|
+
(0, _vitest.it)('converts PM hour to 12h display (17:00 → 05:00 PM)', ()=>{
|
|
330
331
|
const result = (0, _date.userInputFromDatetime)({
|
|
331
332
|
value: '2018-02-02T17:00+03:00',
|
|
332
333
|
uses12hClock: true
|
|
333
334
|
});
|
|
334
|
-
expect(result.time).toBe('05:00');
|
|
335
|
-
expect(result.ampm).toBe('PM');
|
|
335
|
+
(0, _vitest.expect)(result.time).toBe('05:00');
|
|
336
|
+
(0, _vitest.expect)(result.ampm).toBe('PM');
|
|
336
337
|
});
|
|
337
|
-
it('converts noon to 12h display (12:00 → 12:00 PM)', ()=>{
|
|
338
|
+
(0, _vitest.it)('converts noon to 12h display (12:00 → 12:00 PM)', ()=>{
|
|
338
339
|
const result = (0, _date.userInputFromDatetime)({
|
|
339
340
|
value: '2021-03-01T12:00+00:00',
|
|
340
341
|
uses12hClock: true
|
|
341
342
|
});
|
|
342
|
-
expect(result.time).toBe('12:00');
|
|
343
|
-
expect(result.ampm).toBe('PM');
|
|
343
|
+
(0, _vitest.expect)(result.time).toBe('12:00');
|
|
344
|
+
(0, _vitest.expect)(result.ampm).toBe('PM');
|
|
344
345
|
});
|
|
345
|
-
it('converts midnight to 12h display (00:00 → 12:00 AM)', ()=>{
|
|
346
|
+
(0, _vitest.it)('converts midnight to 12h display (00:00 → 12:00 AM)', ()=>{
|
|
346
347
|
const result = (0, _date.userInputFromDatetime)({
|
|
347
348
|
value: '2021-03-01T00:00+00:00',
|
|
348
349
|
uses12hClock: true
|
|
349
350
|
});
|
|
350
|
-
expect(result.time).toBe('12:00');
|
|
351
|
-
expect(result.ampm).toBe('AM');
|
|
351
|
+
(0, _vitest.expect)(result.time).toBe('12:00');
|
|
352
|
+
(0, _vitest.expect)(result.ampm).toBe('AM');
|
|
352
353
|
});
|
|
353
|
-
it('handles quarter-hour offset +05:45 (Nepal)', ()=>{
|
|
354
|
+
(0, _vitest.it)('handles quarter-hour offset +05:45 (Nepal)', ()=>{
|
|
354
355
|
const result = (0, _date.userInputFromDatetime)({
|
|
355
356
|
value: '2023-07-20T09:45+05:45',
|
|
356
357
|
uses12hClock: false
|
|
357
358
|
});
|
|
358
|
-
expect(result.time).toBe('09:45');
|
|
359
|
-
expect(result.utcOffset).toBe('+05:45');
|
|
359
|
+
(0, _vitest.expect)(result.time).toBe('09:45');
|
|
360
|
+
(0, _vitest.expect)(result.utcOffset).toBe('+05:45');
|
|
360
361
|
});
|
|
361
|
-
it('handles -12:00 (far-west) offset without date shift', ()=>{
|
|
362
|
+
(0, _vitest.it)('handles -12:00 (far-west) offset without date shift', ()=>{
|
|
362
363
|
const result = (0, _date.userInputFromDatetime)({
|
|
363
364
|
value: '2023-01-01T23:59-12:00',
|
|
364
365
|
uses12hClock: false
|
|
365
366
|
});
|
|
366
|
-
expect(result.time).toBe('23:59');
|
|
367
|
-
expect(result.utcOffset).toBe('-12:00');
|
|
367
|
+
(0, _vitest.expect)(result.time).toBe('23:59');
|
|
368
|
+
(0, _vitest.expect)(result.utcOffset).toBe('-12:00');
|
|
368
369
|
});
|
|
369
|
-
it('handles +14:00 (far-east) offset without date shift', ()=>{
|
|
370
|
+
(0, _vitest.it)('handles +14:00 (far-east) offset without date shift', ()=>{
|
|
370
371
|
const result = (0, _date.userInputFromDatetime)({
|
|
371
372
|
value: '2023-01-01T01:00+14:00',
|
|
372
373
|
uses12hClock: false
|
|
373
374
|
});
|
|
374
|
-
expect(result.time).toBe('01:00');
|
|
375
|
-
expect(result.utcOffset).toBe('+14:00');
|
|
375
|
+
(0, _vitest.expect)(result.time).toBe('01:00');
|
|
376
|
+
(0, _vitest.expect)(result.utcOffset).toBe('+14:00');
|
|
376
377
|
});
|
|
377
378
|
});
|
|
378
|
-
describe('getDefaultAMPM', ()=>{
|
|
379
|
-
it('returns AM', ()=>{
|
|
380
|
-
expect((0, _date.getDefaultAMPM)()).toBe('AM');
|
|
379
|
+
(0, _vitest.describe)('getDefaultAMPM', ()=>{
|
|
380
|
+
(0, _vitest.it)('returns AM', ()=>{
|
|
381
|
+
(0, _vitest.expect)((0, _date.getDefaultAMPM)()).toBe('AM');
|
|
381
382
|
});
|
|
382
383
|
});
|
|
383
|
-
describe('buildFieldValue — date does not shift due to timezone offset', ()=>{
|
|
384
|
-
it('April 27 23:00-02:00 round-trips as April 27 (UTC would parse as April 28 01:00Z)', ()=>{
|
|
384
|
+
(0, _vitest.describe)('buildFieldValue — date does not shift due to timezone offset', ()=>{
|
|
385
|
+
(0, _vitest.it)('April 27 23:00-02:00 round-trips as April 27 (UTC would parse as April 28 01:00Z)', ()=>{
|
|
385
386
|
const result = (0, _date.userInputFromDatetime)({
|
|
386
387
|
value: '2026-04-27T23:00-02:00',
|
|
387
388
|
uses12hClock: false
|
|
@@ -391,9 +392,9 @@ describe('date utils', ()=>{
|
|
|
391
392
|
usesTime: true,
|
|
392
393
|
usesTimezone: true
|
|
393
394
|
});
|
|
394
|
-
expect(built.valid).toBe('2026-04-27T23:00-02:00');
|
|
395
|
+
(0, _vitest.expect)(built.valid).toBe('2026-04-27T23:00-02:00');
|
|
395
396
|
});
|
|
396
|
-
it('April 28 01:00+02:00 round-trips as April 28 (UTC would parse as April 27 23:00Z)', ()=>{
|
|
397
|
+
(0, _vitest.it)('April 28 01:00+02:00 round-trips as April 28 (UTC would parse as April 27 23:00Z)', ()=>{
|
|
397
398
|
const result = (0, _date.userInputFromDatetime)({
|
|
398
399
|
value: '2026-04-28T01:00+02:00',
|
|
399
400
|
uses12hClock: false
|
|
@@ -403,9 +404,9 @@ describe('date utils', ()=>{
|
|
|
403
404
|
usesTime: true,
|
|
404
405
|
usesTimezone: true
|
|
405
406
|
});
|
|
406
|
-
expect(built.valid).toBe('2026-04-28T01:00+02:00');
|
|
407
|
+
(0, _vitest.expect)(built.valid).toBe('2026-04-28T01:00+02:00');
|
|
407
408
|
});
|
|
408
|
-
it('preserves date for 23:59-01:00 (UTC: April 28 00:59Z → would show as April 28)', ()=>{
|
|
409
|
+
(0, _vitest.it)('preserves date for 23:59-01:00 (UTC: April 28 00:59Z → would show as April 28)', ()=>{
|
|
409
410
|
const result = (0, _date.userInputFromDatetime)({
|
|
410
411
|
value: '2026-06-15T23:59-01:00',
|
|
411
412
|
uses12hClock: false
|
|
@@ -415,7 +416,7 @@ describe('date utils', ()=>{
|
|
|
415
416
|
usesTime: true,
|
|
416
417
|
usesTimezone: true
|
|
417
418
|
});
|
|
418
|
-
expect(built.valid).toBe('2026-06-15T23:59-01:00');
|
|
419
|
+
(0, _vitest.expect)(built.valid).toBe('2026-06-15T23:59-01:00');
|
|
419
420
|
});
|
|
420
421
|
});
|
|
421
422
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import '@testing-library/jest-dom/extend-expect';
|
|
3
2
|
import { cleanup, configure, render } from '@testing-library/react';
|
|
4
3
|
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
import { TimepickerInput } from './TimepickerInput';
|
|
6
6
|
configure({
|
|
7
7
|
testIdAttribute: 'data-test-id'
|
|
@@ -14,7 +14,7 @@ describe('TimepickerInput', ()=>{
|
|
|
14
14
|
uses12hClock: false,
|
|
15
15
|
time: "00:00",
|
|
16
16
|
ampm: "AM",
|
|
17
|
-
onChange:
|
|
17
|
+
onChange: vi.fn()
|
|
18
18
|
}));
|
|
19
19
|
expect(getByTestId('time-input')).toHaveValue('00:00');
|
|
20
20
|
});
|
|
@@ -22,7 +22,7 @@ describe('TimepickerInput', ()=>{
|
|
|
22
22
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
23
23
|
disabled: false,
|
|
24
24
|
uses12hClock: false,
|
|
25
|
-
onChange:
|
|
25
|
+
onChange: vi.fn()
|
|
26
26
|
}));
|
|
27
27
|
expect(getByTestId('time-input')).toHaveValue('00:00');
|
|
28
28
|
});
|
|
@@ -30,7 +30,7 @@ describe('TimepickerInput', ()=>{
|
|
|
30
30
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
31
31
|
disabled: false,
|
|
32
32
|
uses12hClock: true,
|
|
33
|
-
onChange:
|
|
33
|
+
onChange: vi.fn()
|
|
34
34
|
}));
|
|
35
35
|
expect(getByTestId('time-input')).toHaveValue('12:00 AM');
|
|
36
36
|
});
|
|
@@ -40,13 +40,13 @@ describe('TimepickerInput', ()=>{
|
|
|
40
40
|
uses12hClock: false,
|
|
41
41
|
time: "23:00",
|
|
42
42
|
ampm: "PM",
|
|
43
|
-
onChange:
|
|
43
|
+
onChange: vi.fn()
|
|
44
44
|
}));
|
|
45
45
|
expect(getByTestId('time-input')).toHaveValue('23:00');
|
|
46
46
|
});
|
|
47
47
|
describe('onChange on blur — 24h mode', ()=>{
|
|
48
48
|
it('emits 19:00 (not 07:00) when user types 19:00 in 24h mode', ()=>{
|
|
49
|
-
const onChange =
|
|
49
|
+
const onChange = vi.fn();
|
|
50
50
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
51
51
|
disabled: false,
|
|
52
52
|
uses12hClock: false,
|
|
@@ -63,7 +63,7 @@ describe('TimepickerInput', ()=>{
|
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
it('emits 23:59 (not 11:59) when user types 23:59 in 24h mode', ()=>{
|
|
66
|
-
const onChange =
|
|
66
|
+
const onChange = vi.fn();
|
|
67
67
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
68
68
|
disabled: false,
|
|
69
69
|
uses12hClock: false,
|
|
@@ -80,7 +80,7 @@ describe('TimepickerInput', ()=>{
|
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
82
|
it('emits 00:00 when user types 00:00 in 24h mode', ()=>{
|
|
83
|
-
const onChange =
|
|
83
|
+
const onChange = vi.fn();
|
|
84
84
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
85
85
|
disabled: false,
|
|
86
86
|
uses12hClock: false,
|
|
@@ -97,7 +97,7 @@ describe('TimepickerInput', ()=>{
|
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
99
|
it('emits 12:00 (noon) correctly in 24h mode', ()=>{
|
|
100
|
-
const onChange =
|
|
100
|
+
const onChange = vi.fn();
|
|
101
101
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
102
102
|
disabled: false,
|
|
103
103
|
uses12hClock: false,
|
|
@@ -114,7 +114,7 @@ describe('TimepickerInput', ()=>{
|
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
116
|
it('emits 13:00 (not 01:00) when user types 13:00 in 24h mode', ()=>{
|
|
117
|
-
const onChange =
|
|
117
|
+
const onChange = vi.fn();
|
|
118
118
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
119
119
|
disabled: false,
|
|
120
120
|
uses12hClock: false,
|
|
@@ -133,7 +133,7 @@ describe('TimepickerInput', ()=>{
|
|
|
133
133
|
});
|
|
134
134
|
describe('shorthand input without colon', ()=>{
|
|
135
135
|
it('parses 1005 as 10:05 in 24h mode', ()=>{
|
|
136
|
-
const onChange =
|
|
136
|
+
const onChange = vi.fn();
|
|
137
137
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
138
138
|
disabled: false,
|
|
139
139
|
uses12hClock: false,
|
|
@@ -150,7 +150,7 @@ describe('TimepickerInput', ()=>{
|
|
|
150
150
|
});
|
|
151
151
|
});
|
|
152
152
|
it('parses 1900 as 19:00 in 24h mode', ()=>{
|
|
153
|
-
const onChange =
|
|
153
|
+
const onChange = vi.fn();
|
|
154
154
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
155
155
|
disabled: false,
|
|
156
156
|
uses12hClock: false,
|
|
@@ -167,7 +167,7 @@ describe('TimepickerInput', ()=>{
|
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
169
|
it('parses 0700 as 07:00 AM in 12h mode', ()=>{
|
|
170
|
-
const onChange =
|
|
170
|
+
const onChange = vi.fn();
|
|
171
171
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
172
172
|
disabled: false,
|
|
173
173
|
uses12hClock: true,
|
|
@@ -186,7 +186,7 @@ describe('TimepickerInput', ()=>{
|
|
|
186
186
|
});
|
|
187
187
|
describe('am/pm without space separator', ()=>{
|
|
188
188
|
it('parses 1:15pm (no space) correctly in 12h mode', ()=>{
|
|
189
|
-
const onChange =
|
|
189
|
+
const onChange = vi.fn();
|
|
190
190
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
191
191
|
disabled: false,
|
|
192
192
|
uses12hClock: true,
|
|
@@ -203,7 +203,7 @@ describe('TimepickerInput', ()=>{
|
|
|
203
203
|
});
|
|
204
204
|
});
|
|
205
205
|
it('parses 1:15PM (no space, uppercase) correctly in 12h mode', ()=>{
|
|
206
|
-
const onChange =
|
|
206
|
+
const onChange = vi.fn();
|
|
207
207
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
208
208
|
disabled: false,
|
|
209
209
|
uses12hClock: true,
|
|
@@ -220,7 +220,7 @@ describe('TimepickerInput', ()=>{
|
|
|
220
220
|
});
|
|
221
221
|
});
|
|
222
222
|
it('parses 1pm (no space, no minutes) correctly in 12h mode', ()=>{
|
|
223
|
-
const onChange =
|
|
223
|
+
const onChange = vi.fn();
|
|
224
224
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
225
225
|
disabled: false,
|
|
226
226
|
uses12hClock: true,
|
|
@@ -239,7 +239,7 @@ describe('TimepickerInput', ()=>{
|
|
|
239
239
|
});
|
|
240
240
|
describe('onChange on blur — 12h mode', ()=>{
|
|
241
241
|
it('emits 07:00 AM correctly in 12h mode', ()=>{
|
|
242
|
-
const onChange =
|
|
242
|
+
const onChange = vi.fn();
|
|
243
243
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
244
244
|
disabled: false,
|
|
245
245
|
uses12hClock: true,
|
|
@@ -256,7 +256,7 @@ describe('TimepickerInput', ()=>{
|
|
|
256
256
|
});
|
|
257
257
|
});
|
|
258
258
|
it('emits 07:00 PM correctly in 12h mode', ()=>{
|
|
259
|
-
const onChange =
|
|
259
|
+
const onChange = vi.fn();
|
|
260
260
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
261
261
|
disabled: false,
|
|
262
262
|
uses12hClock: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-date",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -32,20 +32,20 @@
|
|
|
32
32
|
"build:types": "tsc --outDir dist/types --emitDeclarationOnly",
|
|
33
33
|
"build:cjs": "swc src --config-file ../../.swcrc -d dist/cjs -C module.type=commonjs",
|
|
34
34
|
"build:esm": "swc src --config-file ../../.swcrc -d dist/esm",
|
|
35
|
-
"test": "
|
|
36
|
-
"test:ci": "
|
|
35
|
+
"test": "vitest",
|
|
36
|
+
"test:ci": "vitest run",
|
|
37
37
|
"tsc": "tsc -p ./ --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@contentful/f36-components": "^6.7.1",
|
|
41
41
|
"@contentful/f36-tokens": "^6.1.2",
|
|
42
|
-
"@contentful/field-editor-shared": "^4.4.
|
|
42
|
+
"@contentful/field-editor-shared": "^4.4.1",
|
|
43
43
|
"@emotion/css": "^11.13.5",
|
|
44
44
|
"date-fns": "^2.30.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/core": "^7.7.4",
|
|
48
|
-
"@contentful/field-editor-test-utils": "^3.1.
|
|
48
|
+
"@contentful/field-editor-test-utils": "^3.1.1",
|
|
49
49
|
"@lingui/core": "5.3.0",
|
|
50
50
|
"@types/timezoned-date": "^3.0.0",
|
|
51
51
|
"timezoned-date": "^3.0.2"
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"registry": "https://npm.pkg.github.com/"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "5fb6c32d2590e72e56a53cb180a155f84d6505d9"
|
|
62
62
|
}
|