@contentful/field-editor-date 2.0.10 → 2.0.11
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.
|
@@ -79,7 +79,8 @@ const TimepickerInput = ({ disabled, uses12hClock, time = '12:00', ampm = 'AM',
|
|
|
79
79
|
return formatToString(uses12hClock, getDefaultTime());
|
|
80
80
|
});
|
|
81
81
|
(0, _react.useEffect)(()=>{
|
|
82
|
-
|
|
82
|
+
const parsed = uses12hClock ? (0, _datefns.parse)(`${time} ${ampm}`, 'hh:mm a', REF_DATE) : (0, _datefns.parse)(time, 'HH:mm', REF_DATE);
|
|
83
|
+
setSelectedTime(formatToString(uses12hClock, parsed));
|
|
83
84
|
}, [
|
|
84
85
|
time,
|
|
85
86
|
ampm,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
7
|
+
const _react1 = require("@testing-library/react");
|
|
8
|
+
const _TimepickerInput = require("./TimepickerInput");
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
10
|
+
if (typeof WeakMap !== "function") return null;
|
|
11
|
+
var cacheBabelInterop = new WeakMap();
|
|
12
|
+
var cacheNodeInterop = new WeakMap();
|
|
13
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
14
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
15
|
+
})(nodeInterop);
|
|
16
|
+
}
|
|
17
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
18
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
19
|
+
return obj;
|
|
20
|
+
}
|
|
21
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
22
|
+
return {
|
|
23
|
+
default: obj
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
27
|
+
if (cache && cache.has(obj)) {
|
|
28
|
+
return cache.get(obj);
|
|
29
|
+
}
|
|
30
|
+
var newObj = {
|
|
31
|
+
__proto__: null
|
|
32
|
+
};
|
|
33
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
34
|
+
for(var key in obj){
|
|
35
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
36
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
37
|
+
if (desc && (desc.get || desc.set)) {
|
|
38
|
+
Object.defineProperty(newObj, key, desc);
|
|
39
|
+
} else {
|
|
40
|
+
newObj[key] = obj[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
newObj.default = obj;
|
|
45
|
+
if (cache) {
|
|
46
|
+
cache.set(obj, newObj);
|
|
47
|
+
}
|
|
48
|
+
return newObj;
|
|
49
|
+
}
|
|
50
|
+
(0, _react1.configure)({
|
|
51
|
+
testIdAttribute: 'data-test-id'
|
|
52
|
+
});
|
|
53
|
+
describe('TimepickerInput', ()=>{
|
|
54
|
+
afterEach(_react1.cleanup);
|
|
55
|
+
it('renders midnight (00:00) in 24h mode without crashing', ()=>{
|
|
56
|
+
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
57
|
+
disabled: false,
|
|
58
|
+
uses12hClock: false,
|
|
59
|
+
time: "00:00",
|
|
60
|
+
ampm: "AM",
|
|
61
|
+
onChange: jest.fn()
|
|
62
|
+
}));
|
|
63
|
+
expect(getByTestId('time-input')).toHaveValue('00:00');
|
|
64
|
+
});
|
|
65
|
+
it('renders late-night hours (e.g. 23:00) in 24h mode without crashing', ()=>{
|
|
66
|
+
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
67
|
+
disabled: false,
|
|
68
|
+
uses12hClock: false,
|
|
69
|
+
time: "23:00",
|
|
70
|
+
ampm: "PM",
|
|
71
|
+
onChange: jest.fn()
|
|
72
|
+
}));
|
|
73
|
+
expect(getByTestId('time-input')).toHaveValue('23:00');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -28,7 +28,8 @@ export const TimepickerInput = ({ disabled, uses12hClock, time = '12:00', ampm =
|
|
|
28
28
|
return formatToString(uses12hClock, getDefaultTime());
|
|
29
29
|
});
|
|
30
30
|
useEffect(()=>{
|
|
31
|
-
|
|
31
|
+
const parsed = uses12hClock ? parse(`${time} ${ampm}`, 'hh:mm a', REF_DATE) : parse(time, 'HH:mm', REF_DATE);
|
|
32
|
+
setSelectedTime(formatToString(uses12hClock, parsed));
|
|
32
33
|
}, [
|
|
33
34
|
time,
|
|
34
35
|
ampm,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
3
|
+
import { cleanup, configure, render } from '@testing-library/react';
|
|
4
|
+
import { TimepickerInput } from './TimepickerInput';
|
|
5
|
+
configure({
|
|
6
|
+
testIdAttribute: 'data-test-id'
|
|
7
|
+
});
|
|
8
|
+
describe('TimepickerInput', ()=>{
|
|
9
|
+
afterEach(cleanup);
|
|
10
|
+
it('renders midnight (00:00) in 24h mode without crashing', ()=>{
|
|
11
|
+
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
12
|
+
disabled: false,
|
|
13
|
+
uses12hClock: false,
|
|
14
|
+
time: "00:00",
|
|
15
|
+
ampm: "AM",
|
|
16
|
+
onChange: jest.fn()
|
|
17
|
+
}));
|
|
18
|
+
expect(getByTestId('time-input')).toHaveValue('00:00');
|
|
19
|
+
});
|
|
20
|
+
it('renders late-night hours (e.g. 23:00) in 24h mode without crashing', ()=>{
|
|
21
|
+
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
22
|
+
disabled: false,
|
|
23
|
+
uses12hClock: false,
|
|
24
|
+
time: "23:00",
|
|
25
|
+
ampm: "PM",
|
|
26
|
+
onChange: jest.fn()
|
|
27
|
+
}));
|
|
28
|
+
expect(getByTestId('time-input')).toHaveValue('23:00');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-date",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"registry": "https://npm.pkg.github.com/"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "039b71a95db2959bed3977a571b512233a5e375c"
|
|
61
61
|
}
|