@k-int/stripes-kint-components 5.8.1 → 5.8.3
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.
- package/CHANGELOG.md +14 -0
- package/es/lib/CustomProperties/Config/CustomPropertiesLookup.test.js +1 -1
- package/es/lib/CustomProperties/Config/CustomPropertiesSettings.js +2 -2
- package/es/lib/CustomProperties/Config/CustomPropertiesSettings.test.js +1 -1
- package/es/lib/CustomProperties/Config/CustomPropertyForm.test.js +1 -1
- package/es/lib/CustomProperties/Config/CustomPropertyView.test.js +1 -1
- package/es/lib/CustomProperties/Edit/CustomPropertiesEdit.test.js +1 -1
- package/es/lib/CustomProperties/Edit/CustomPropertiesEditCtx.test.js +1 -1
- package/es/lib/CustomProperties/Edit/CustomPropertiesListField.test.js +1 -1
- package/es/lib/CustomProperties/Edit/CustomPropertyField.test.js +5 -5
- package/es/lib/CustomProperties/Edit/CustomPropertyFormCard.test.js +1 -1
- package/es/lib/CustomProperties/Filter/CustomPropertiesFilter.test.js +1 -1
- package/es/lib/CustomProperties/Filter/CustomPropertiesFilterField.test.js +1 -1
- package/es/lib/CustomProperties/Filter/CustomPropertiesFilterFieldArray.test.js +1 -1
- package/es/lib/CustomProperties/Filter/CustomPropertiesFilterForm.test.js +1 -1
- package/es/lib/CustomProperties/Filter/CustomPropertiesRule.test.js +1 -1
- package/es/lib/CustomProperties/View/CustomPropertiesView.test.js +1 -1
- package/es/lib/CustomProperties/View/CustomPropertiesViewCtx.test.js +1 -1
- package/es/lib/EditableSettingsList/EditableSettingsListFieldArray.test.js +3 -3
- package/es/lib/EditableSettingsList/SettingField/EditSettingValue.test.js +8 -8
- package/es/lib/EditableSettingsList/SettingField/RenderSettingValue.test.js +12 -12
- package/es/lib/EditableSettingsList/SettingField/SettingField.test.js +1 -1
- package/es/lib/NumberField/NumberField.js +23 -6
- package/es/lib/NumberField/NumberField.test.js +200 -0
- package/package.json +1 -1
- package/src/lib/NumberField/NumberField.js +26 -8
- package/src/lib/NumberField/NumberField.test.js +258 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [5.8.3](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.8.2...v5.8.3) (2024-10-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* ERM-3391--NumberField doesnt update display value from form state changes ([cb44d06](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/cb44d063aed221cb544204b8b5d9df6dc313e9c2))
|
|
7
|
+
|
|
8
|
+
## [5.8.2](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.8.1...v5.8.2) (2024-09-11)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* NumberField blur ([54ed21f](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/54ed21f60e89ec2035ea2b42c1f9b158c657c0be))
|
|
14
|
+
|
|
1
15
|
## [5.8.1](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.8.0...v5.8.1) (2024-07-22)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -13,7 +13,7 @@ jest.mock('../../SearchField', () => () => /*#__PURE__*/(0, _jsxRuntime.jsx)("di
|
|
|
13
13
|
describe('CustomPropertiesLookup', () => {
|
|
14
14
|
let renderComponent;
|
|
15
15
|
beforeEach(() => {
|
|
16
|
-
renderComponent = (0, _renderWithKintHarness.default)(
|
|
16
|
+
renderComponent = (0, _renderWithKintHarness.default)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.MemoryRouter, {
|
|
17
17
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertiesLookup.default, {
|
|
18
18
|
contextFilterOptions: [{
|
|
19
19
|
'value': '',
|
|
@@ -174,7 +174,7 @@ const CustomPropertiesSettings = _ref => {
|
|
|
174
174
|
} = _ref2;
|
|
175
175
|
const actionsArray = [];
|
|
176
176
|
if (editCondition) {
|
|
177
|
-
actionsArray.push(
|
|
177
|
+
actionsArray.push(/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
178
178
|
buttonStyle: "dropdownItem",
|
|
179
179
|
marginBottom0: true,
|
|
180
180
|
onClick: () => setMode(EDITING),
|
|
@@ -188,7 +188,7 @@ const CustomPropertiesSettings = _ref => {
|
|
|
188
188
|
}, `${customProperty.name}-action-edit`));
|
|
189
189
|
}
|
|
190
190
|
if (deleteCondition) {
|
|
191
|
-
actionsArray.push(
|
|
191
|
+
actionsArray.push(/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
192
192
|
buttonStyle: "dropdownItem",
|
|
193
193
|
marginBottom0: true,
|
|
194
194
|
onClick: () => {
|
|
@@ -17,7 +17,7 @@ jest.mock('./CustomPropertiesLookup', () => () => /*#__PURE__*/(0, _jsxRuntime.j
|
|
|
17
17
|
describe('CustomPropertiesSettings', () => {
|
|
18
18
|
let renderComponent;
|
|
19
19
|
beforeEach(() => {
|
|
20
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
20
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.MemoryRouter, {
|
|
21
21
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertiesSettings.default, {
|
|
22
22
|
contextFilterOptions: [{
|
|
23
23
|
'value': '',
|
|
@@ -22,7 +22,7 @@ jest.mock('../../hooks');
|
|
|
22
22
|
describe('CustomPropertyForm', () => {
|
|
23
23
|
let renderComponent;
|
|
24
24
|
beforeEach(() => {
|
|
25
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
25
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
26
26
|
initialValues: initialValues,
|
|
27
27
|
onSubmit: onSubmit,
|
|
28
28
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertyForm.default, {
|
|
@@ -11,7 +11,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
11
11
|
jest.mock('../../hooks');
|
|
12
12
|
describe('CustomPropertyView', () => {
|
|
13
13
|
beforeEach(() => {
|
|
14
|
-
(0, _jest.renderWithKintHarness)(
|
|
14
|
+
(0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.MemoryRouter, {
|
|
15
15
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertyView.default, {
|
|
16
16
|
customProperty: _customProperties.default?.find(cp => cp.name === 'Eligible authors')
|
|
17
17
|
})
|
|
@@ -13,7 +13,7 @@ jest.mock('./CustomPropertiesEditCtx', () => () => /*#__PURE__*/(0, _jsxRuntime.
|
|
|
13
13
|
describe('CustomPropertiesEdit', () => {
|
|
14
14
|
let renderComponent;
|
|
15
15
|
beforeEach(() => {
|
|
16
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
16
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.MemoryRouter, {
|
|
17
17
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertiesEdit.default, {
|
|
18
18
|
contexts: ['isNull', 'OpenAccess'],
|
|
19
19
|
customPropertiesEndpoint: "erm/custprops",
|
|
@@ -14,7 +14,7 @@ jest.mock('../../hooks');
|
|
|
14
14
|
describe('CustomPropertiesEditCtx', () => {
|
|
15
15
|
let renderComponent;
|
|
16
16
|
beforeEach(() => {
|
|
17
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
17
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.MemoryRouter, {
|
|
18
18
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertiesEditCtx.default, {
|
|
19
19
|
ctx: "OpenAccess",
|
|
20
20
|
customPropertiesEndpoint: "erm/custprops",
|
|
@@ -16,7 +16,7 @@ jest.mock('./CustomPropertyFormCard', () => () => /*#__PURE__*/(0, _jsxRuntime.j
|
|
|
16
16
|
describe('CustomPropertiesListField', () => {
|
|
17
17
|
let renderComponent;
|
|
18
18
|
beforeEach(() => {
|
|
19
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
19
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
20
20
|
initialValues: _testResources.initialValues,
|
|
21
21
|
onSubmit: onSubmit,
|
|
22
22
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertiesListField.default, {
|
|
@@ -30,7 +30,7 @@ describe('CustomPropertyField', () => {
|
|
|
30
30
|
let renderComponent;
|
|
31
31
|
describe('CustomPropertyField', () => {
|
|
32
32
|
beforeEach(() => {
|
|
33
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
33
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
34
34
|
initialValues: _testResources.initialValues,
|
|
35
35
|
onSubmit: onSubmit,
|
|
36
36
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertyField.default, {
|
|
@@ -82,7 +82,7 @@ describe('CustomPropertyField', () => {
|
|
|
82
82
|
});
|
|
83
83
|
describe('Decimal field', () => {
|
|
84
84
|
beforeEach(() => {
|
|
85
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
85
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
86
86
|
initialValues: _testResources.initialValues,
|
|
87
87
|
onSubmit: onSubmit,
|
|
88
88
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertyField.default, {
|
|
@@ -100,7 +100,7 @@ describe('CustomPropertyField', () => {
|
|
|
100
100
|
});
|
|
101
101
|
describe('Integer field', () => {
|
|
102
102
|
beforeEach(() => {
|
|
103
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
103
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
104
104
|
initialValues: _testResources.initialValues,
|
|
105
105
|
onSubmit: onSubmit,
|
|
106
106
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertyField.default, {
|
|
@@ -120,7 +120,7 @@ describe('CustomPropertyField', () => {
|
|
|
120
120
|
});
|
|
121
121
|
describe('Refdata multi-select field', () => {
|
|
122
122
|
beforeEach(() => {
|
|
123
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
123
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
124
124
|
initialValues: _testResources.initialValues,
|
|
125
125
|
onSubmit: onSubmit,
|
|
126
126
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertyField.default, {
|
|
@@ -147,7 +147,7 @@ describe('CustomPropertyField', () => {
|
|
|
147
147
|
});
|
|
148
148
|
describe('Date field', () => {
|
|
149
149
|
beforeEach(() => {
|
|
150
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
150
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
151
151
|
initialValues: _testResources.initialValues,
|
|
152
152
|
onSubmit: onSubmit,
|
|
153
153
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertyField.default, {
|
|
@@ -18,7 +18,7 @@ const setCustomProperties = jest.fn();
|
|
|
18
18
|
describe('CustomPropertyFormCard', () => {
|
|
19
19
|
let renderComponent;
|
|
20
20
|
beforeEach(() => {
|
|
21
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
21
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertyFormCard.default, {
|
|
22
22
|
availableCustomProperties: _customProperties.availableCustomProperties,
|
|
23
23
|
customProperties: _customProperties.default,
|
|
24
24
|
customProperty: customProperty,
|
|
@@ -16,7 +16,7 @@ jest.mock('./CustomPropertiesFilterForm', () => () => /*#__PURE__*/(0, _jsxRunti
|
|
|
16
16
|
describe('CustomPropertiesFilter', () => {
|
|
17
17
|
let renderComponent;
|
|
18
18
|
beforeEach(() => {
|
|
19
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
19
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.MemoryRouter, {
|
|
20
20
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertiesFilter.default, {
|
|
21
21
|
activeFilters: _testResources.activeFilters,
|
|
22
22
|
customPropertiesEndpoint: "erm/custprops",
|
|
@@ -14,7 +14,7 @@ jest.mock('../../hooks');
|
|
|
14
14
|
const onSubmit = jest.fn();
|
|
15
15
|
let renderComponent;
|
|
16
16
|
describe('CustomPropertiesFilterField', () => {
|
|
17
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
17
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.MemoryRouter, {
|
|
18
18
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
19
19
|
initialValues: {
|
|
20
20
|
filters: _testResources.data.filters
|
|
@@ -16,7 +16,7 @@ const onSubmit = jest.fn();
|
|
|
16
16
|
let renderComponent;
|
|
17
17
|
describe('CustomPropertiesFilterFieldArray', () => {
|
|
18
18
|
beforeEach(() => {
|
|
19
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
19
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
20
20
|
onSubmit: onSubmit,
|
|
21
21
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalFormArrays.FieldArray, {
|
|
22
22
|
component: _CustomPropertiesFilterFieldArray.default,
|
|
@@ -15,7 +15,7 @@ const onSubmit = jest.fn();
|
|
|
15
15
|
describe('CustomPropertyFiltersForm', () => {
|
|
16
16
|
let renderComponent;
|
|
17
17
|
beforeEach(() => {
|
|
18
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
18
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertiesFilterForm.default, {
|
|
19
19
|
onSubmit: onSubmit,
|
|
20
20
|
..._testResources.data
|
|
21
21
|
}));
|
|
@@ -13,7 +13,7 @@ jest.mock('../../hooks');
|
|
|
13
13
|
const clearRuleValue = () => {};
|
|
14
14
|
describe('CustomPropertiesRule', () => {
|
|
15
15
|
beforeEach(() => {
|
|
16
|
-
(0, _jest.renderWithKintHarness)(
|
|
16
|
+
(0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.MemoryRouter, {
|
|
17
17
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
18
18
|
onSubmit: onSubmit,
|
|
19
19
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertiesRule.default, {
|
|
@@ -15,7 +15,7 @@ jest.mock('./CustomPropertiesViewCtx', () => () => /*#__PURE__*/(0, _jsxRuntime.
|
|
|
15
15
|
describe('CustomPropertiesView', () => {
|
|
16
16
|
let renderComponent;
|
|
17
17
|
beforeEach(() => {
|
|
18
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
18
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.MemoryRouter, {
|
|
19
19
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertiesView.default, {
|
|
20
20
|
contexts: _testResources.contexts,
|
|
21
21
|
customProperties: _testResources.customProperties,
|
|
@@ -15,7 +15,7 @@ jest.mock('./CustomPropertyCard', () => () => /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
|
15
15
|
describe('CustomPropertiesViewCtx', () => {
|
|
16
16
|
let renderComponent;
|
|
17
17
|
beforeEach(() => {
|
|
18
|
-
renderComponent = (0, _jest.renderWithKintHarness)(
|
|
18
|
+
renderComponent = (0, _jest.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.MemoryRouter, {
|
|
19
19
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPropertiesViewCtx.default, {
|
|
20
20
|
..._testResources.data
|
|
21
21
|
})
|
|
@@ -44,7 +44,7 @@ describe('EditableSettingsListFieldArray', () => {
|
|
|
44
44
|
describe('with empty initial values', () => {
|
|
45
45
|
let renderComponent;
|
|
46
46
|
beforeEach(async () => {
|
|
47
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
47
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
48
48
|
initialValues: {},
|
|
49
49
|
onSubmit: onSubmit,
|
|
50
50
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalFormArrays.FieldArray, {
|
|
@@ -63,7 +63,7 @@ describe('EditableSettingsListFieldArray', () => {
|
|
|
63
63
|
describe('with initial value set', () => {
|
|
64
64
|
let renderComponent;
|
|
65
65
|
beforeEach(async () => {
|
|
66
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
66
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
67
67
|
initialValues: {
|
|
68
68
|
settings
|
|
69
69
|
},
|
|
@@ -84,7 +84,7 @@ describe('EditableSettingsListFieldArray', () => {
|
|
|
84
84
|
describe('with multiple initial values set', () => {
|
|
85
85
|
let renderComponent;
|
|
86
86
|
beforeEach(async () => {
|
|
87
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
87
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
88
88
|
initialValues: {
|
|
89
89
|
settings: multipleSettings
|
|
90
90
|
},
|
|
@@ -79,7 +79,7 @@ describe('EditSettingValue', () => {
|
|
|
79
79
|
describe('with no initial value', () => {
|
|
80
80
|
let renderComponent;
|
|
81
81
|
beforeEach(() => {
|
|
82
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
82
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
83
83
|
initialValues: {},
|
|
84
84
|
onSubmit: onSubmit,
|
|
85
85
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_EditSettingValue.default, {
|
|
@@ -102,7 +102,7 @@ describe('EditSettingValue', () => {
|
|
|
102
102
|
describe('with initial value', () => {
|
|
103
103
|
let renderComponent;
|
|
104
104
|
beforeEach(() => {
|
|
105
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
105
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
106
106
|
initialValues: {
|
|
107
107
|
test: {
|
|
108
108
|
value: stringSetting.value
|
|
@@ -134,7 +134,7 @@ describe('EditSettingValue', () => {
|
|
|
134
134
|
describe('with no initial value for refdata with <4 options', () => {
|
|
135
135
|
let renderComponent;
|
|
136
136
|
beforeEach(() => {
|
|
137
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
137
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
138
138
|
initialValues: {},
|
|
139
139
|
onSubmit: onSubmit,
|
|
140
140
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_EditSettingValue.default, {
|
|
@@ -178,7 +178,7 @@ describe('EditSettingValue', () => {
|
|
|
178
178
|
describe('with initial value for refdata with <4 options', () => {
|
|
179
179
|
let renderComponent;
|
|
180
180
|
beforeEach(() => {
|
|
181
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
181
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
182
182
|
initialValues: {
|
|
183
183
|
test: {
|
|
184
184
|
value: refdataSetting.value
|
|
@@ -226,7 +226,7 @@ describe('EditSettingValue', () => {
|
|
|
226
226
|
describe('with no initial value for refdata with >4 options', () => {
|
|
227
227
|
let renderComponent;
|
|
228
228
|
beforeEach(() => {
|
|
229
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
229
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
230
230
|
initialValues: {},
|
|
231
231
|
onSubmit: onSubmit,
|
|
232
232
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_EditSettingValue.default, {
|
|
@@ -273,7 +273,7 @@ describe('EditSettingValue', () => {
|
|
|
273
273
|
describe('with initial value for refdata with >4 options', () => {
|
|
274
274
|
let renderComponent;
|
|
275
275
|
beforeEach(() => {
|
|
276
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
276
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
277
277
|
initialValues: {
|
|
278
278
|
test: {
|
|
279
279
|
value: refdataSetting.value
|
|
@@ -326,7 +326,7 @@ describe('EditSettingValue', () => {
|
|
|
326
326
|
describe('with no initial value', () => {
|
|
327
327
|
let renderComponent;
|
|
328
328
|
beforeEach(() => {
|
|
329
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
329
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
330
330
|
initialValues: {},
|
|
331
331
|
onSubmit: onSubmit,
|
|
332
332
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_EditSettingValue.default, {
|
|
@@ -372,7 +372,7 @@ describe('EditSettingValue', () => {
|
|
|
372
372
|
describe('with initial value', () => {
|
|
373
373
|
let renderComponent;
|
|
374
374
|
beforeEach(() => {
|
|
375
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
375
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
376
376
|
initialValues: {
|
|
377
377
|
test: {
|
|
378
378
|
value: templateSetting.value
|
|
@@ -108,7 +108,7 @@ describe('RenderSettingValue', () => {
|
|
|
108
108
|
describe('render a string setting', () => {
|
|
109
109
|
let renderComponent;
|
|
110
110
|
beforeEach(async () => {
|
|
111
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
111
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
112
112
|
currentSetting: stringSetting,
|
|
113
113
|
input: {
|
|
114
114
|
name: 'test'
|
|
@@ -125,7 +125,7 @@ describe('RenderSettingValue', () => {
|
|
|
125
125
|
describe('render a string setting without a value', () => {
|
|
126
126
|
let renderComponent;
|
|
127
127
|
beforeEach(async () => {
|
|
128
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
128
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
129
129
|
currentSetting: stringSettingNoValue,
|
|
130
130
|
input: {
|
|
131
131
|
name: 'test'
|
|
@@ -142,7 +142,7 @@ describe('RenderSettingValue', () => {
|
|
|
142
142
|
describe('render a string setting without a value or default', () => {
|
|
143
143
|
let renderComponent;
|
|
144
144
|
beforeEach(async () => {
|
|
145
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
145
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
146
146
|
currentSetting: stringSettingNoValueOrDefault,
|
|
147
147
|
input: {
|
|
148
148
|
name: 'test'
|
|
@@ -161,7 +161,7 @@ describe('RenderSettingValue', () => {
|
|
|
161
161
|
describe('render a refdata setting', () => {
|
|
162
162
|
let renderComponent;
|
|
163
163
|
beforeEach(async () => {
|
|
164
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
164
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
165
165
|
currentSetting: refdataSetting,
|
|
166
166
|
input: {
|
|
167
167
|
name: 'test'
|
|
@@ -179,7 +179,7 @@ describe('RenderSettingValue', () => {
|
|
|
179
179
|
describe('render a refdata setting without a value', () => {
|
|
180
180
|
let renderComponent;
|
|
181
181
|
beforeEach(async () => {
|
|
182
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
182
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
183
183
|
currentSetting: refdataSettingNoValue,
|
|
184
184
|
input: {
|
|
185
185
|
name: 'test'
|
|
@@ -197,7 +197,7 @@ describe('RenderSettingValue', () => {
|
|
|
197
197
|
describe('render a refdata setting without a value or default', () => {
|
|
198
198
|
let renderComponent;
|
|
199
199
|
beforeEach(async () => {
|
|
200
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
200
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
201
201
|
currentSetting: refdataSettingNoValueOrDefault,
|
|
202
202
|
input: {
|
|
203
203
|
name: 'test'
|
|
@@ -217,7 +217,7 @@ describe('RenderSettingValue', () => {
|
|
|
217
217
|
describe('render a password setting', () => {
|
|
218
218
|
let renderComponent;
|
|
219
219
|
beforeEach(async () => {
|
|
220
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
220
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
221
221
|
currentSetting: passwordSetting,
|
|
222
222
|
input: {
|
|
223
223
|
name: 'test'
|
|
@@ -234,7 +234,7 @@ describe('RenderSettingValue', () => {
|
|
|
234
234
|
describe('render a password setting without a value', () => {
|
|
235
235
|
let renderComponent;
|
|
236
236
|
beforeEach(async () => {
|
|
237
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
237
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
238
238
|
currentSetting: passwordSettingNoValue,
|
|
239
239
|
input: {
|
|
240
240
|
name: 'test'
|
|
@@ -251,7 +251,7 @@ describe('RenderSettingValue', () => {
|
|
|
251
251
|
describe('render a password setting without a value or default', () => {
|
|
252
252
|
let renderComponent;
|
|
253
253
|
beforeEach(async () => {
|
|
254
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
254
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
255
255
|
currentSetting: passwordSettingNoValueOrDefault,
|
|
256
256
|
input: {
|
|
257
257
|
name: 'test'
|
|
@@ -270,7 +270,7 @@ describe('RenderSettingValue', () => {
|
|
|
270
270
|
describe('render a template setting', () => {
|
|
271
271
|
let renderComponent;
|
|
272
272
|
beforeEach(async () => {
|
|
273
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
273
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
274
274
|
currentSetting: templateSetting,
|
|
275
275
|
input: {
|
|
276
276
|
name: 'test'
|
|
@@ -288,7 +288,7 @@ describe('RenderSettingValue', () => {
|
|
|
288
288
|
describe('render a template setting without a value', () => {
|
|
289
289
|
let renderComponent;
|
|
290
290
|
beforeEach(async () => {
|
|
291
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
291
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
292
292
|
currentSetting: templateSettingNoValue,
|
|
293
293
|
input: {
|
|
294
294
|
name: 'test'
|
|
@@ -306,7 +306,7 @@ describe('RenderSettingValue', () => {
|
|
|
306
306
|
describe('render a template setting without a value or default', () => {
|
|
307
307
|
let renderComponent;
|
|
308
308
|
beforeEach(async () => {
|
|
309
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
309
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_RenderSettingValue.default, {
|
|
310
310
|
currentSetting: templateSettingNoValueOrDefault,
|
|
311
311
|
input: {
|
|
312
312
|
name: 'test'
|
|
@@ -27,7 +27,7 @@ const setting = {
|
|
|
27
27
|
describe('SettingField', () => {
|
|
28
28
|
let renderComponent;
|
|
29
29
|
beforeEach(async () => {
|
|
30
|
-
renderComponent = (0, _helpers.renderWithKintHarness)(
|
|
30
|
+
renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
31
31
|
initialValues: {},
|
|
32
32
|
onSubmit: onSubmit,
|
|
33
33
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
@@ -4,14 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _react = require("react");
|
|
9
9
|
var _noop = _interopRequireDefault(require("lodash/noop"));
|
|
10
10
|
var _components = require("@folio/stripes/components");
|
|
11
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
const NumberField = props => {
|
|
14
14
|
const {
|
|
15
|
+
onBlur: passedOnBlur = _noop.default,
|
|
15
16
|
onChange: passedOnChange = _noop.default,
|
|
16
17
|
input,
|
|
17
18
|
value,
|
|
@@ -30,13 +31,18 @@ const NumberField = props => {
|
|
|
30
31
|
|
|
31
32
|
// Allow direct control of field
|
|
32
33
|
(0, _react.useEffect)(() => {
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const valueToUse = value ?? input.value;
|
|
35
|
+
if (!valueToUse && numValue) {
|
|
36
|
+
// Make sure to empty out if it's cleared. Treating '' as empty instead of undefined
|
|
37
|
+
setNumValue('');
|
|
38
|
+
}
|
|
39
|
+
if (valueToUse && numValue !== valueToUse) {
|
|
40
|
+
setNumValue(valueToUse);
|
|
35
41
|
}
|
|
36
|
-
if (
|
|
42
|
+
if (forceControl !== numValue) {
|
|
37
43
|
setForceControl(numValue);
|
|
38
44
|
}
|
|
39
|
-
}, [forceControl, numValue, value]);
|
|
45
|
+
}, [forceControl, numValue, value, input]);
|
|
40
46
|
const handleChange = e => {
|
|
41
47
|
// Actually set the value in the form
|
|
42
48
|
if (input?.onChange) {
|
|
@@ -54,7 +60,7 @@ const NumberField = props => {
|
|
|
54
60
|
const handleUserChange = e => {
|
|
55
61
|
const parsedValue = parseFloat(e.target.value);
|
|
56
62
|
|
|
57
|
-
// ReturnValue needed for
|
|
63
|
+
// ReturnValue needed for controlled components
|
|
58
64
|
if (parsedValue || parsedValue === 0) {
|
|
59
65
|
setNumValue(parsedValue);
|
|
60
66
|
changeField(parsedValue);
|
|
@@ -68,6 +74,13 @@ const NumberField = props => {
|
|
|
68
74
|
ref: userInputRef,
|
|
69
75
|
...rest,
|
|
70
76
|
// Keep an eye on this
|
|
77
|
+
onBlur: event => {
|
|
78
|
+
// Make sure blur propogates to input
|
|
79
|
+
if (input.onBlur) {
|
|
80
|
+
input.onBlur(event);
|
|
81
|
+
}
|
|
82
|
+
passedOnBlur(event);
|
|
83
|
+
},
|
|
71
84
|
onChange: handleUserChange,
|
|
72
85
|
type: "number",
|
|
73
86
|
value: forceControl
|
|
@@ -75,6 +88,7 @@ const NumberField = props => {
|
|
|
75
88
|
ref: inputRef,
|
|
76
89
|
...input,
|
|
77
90
|
hidden: true,
|
|
91
|
+
id: input?.name,
|
|
78
92
|
onChange: handleChange,
|
|
79
93
|
type: "number",
|
|
80
94
|
value: numValue
|
|
@@ -82,9 +96,12 @@ const NumberField = props => {
|
|
|
82
96
|
});
|
|
83
97
|
};
|
|
84
98
|
NumberField.propTypes = {
|
|
99
|
+
onBlur: _propTypes.default.func,
|
|
85
100
|
onChange: _propTypes.default.func,
|
|
86
101
|
input: _propTypes.default.shape({
|
|
102
|
+
name: _propTypes.default.string.isRequired,
|
|
87
103
|
onChange: _propTypes.default.func.isRequired,
|
|
104
|
+
onBlur: _propTypes.default.func,
|
|
88
105
|
value: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
89
106
|
}),
|
|
90
107
|
value: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("react");
|
|
4
|
+
var _reactFinalForm = require("react-final-form");
|
|
5
|
+
var _userEvent = _interopRequireDefault(require("@folio/jest-config-stripes/testing-library/user-event"));
|
|
6
|
+
var _react2 = require("@folio/jest-config-stripes/testing-library/react");
|
|
7
|
+
var _stripesErmTesting = require("@folio/stripes-erm-testing");
|
|
8
|
+
var _components = require("@folio/stripes/components");
|
|
9
|
+
var _NumberField = _interopRequireDefault(require("./NumberField"));
|
|
10
|
+
var _helpers = require("../../../test/jest/helpers");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
const onSubmit = jest.fn();
|
|
14
|
+
const NUMBER_FIELD_LABEL = 'TEST NUMBER FIELD';
|
|
15
|
+
const NUMBER_FIELD_ID = 'number-field-test';
|
|
16
|
+
const NUMBER_FIELD_INPUT_ID = 'input-id-test';
|
|
17
|
+
const RESET_BUTTON_LABEL = 'RESET NUMBER FIELD';
|
|
18
|
+
|
|
19
|
+
// We need to use jest selectors instead of interactors as the TextField interactor
|
|
20
|
+
// can't handle the double-text-field nature of NumberField
|
|
21
|
+
const getTextField = () => {
|
|
22
|
+
// Spinbutton because it's a "number" type textField...
|
|
23
|
+
return _react2.screen.getByRole('spinbutton', {
|
|
24
|
+
name: NUMBER_FIELD_LABEL
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const submitForm = async () => {
|
|
28
|
+
await (0, _react2.waitFor)(async () => {
|
|
29
|
+
await (0, _stripesErmTesting.Button)('Submit').click();
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const SpecialResetButton = () => {
|
|
33
|
+
const {
|
|
34
|
+
change
|
|
35
|
+
} = (0, _reactFinalForm.useForm)();
|
|
36
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
37
|
+
onClick: () => change(NUMBER_FIELD_INPUT_ID, undefined),
|
|
38
|
+
children: RESET_BUTTON_LABEL
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const NonControlledComponent = () => {
|
|
42
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
43
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(SpecialResetButton, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
44
|
+
component: _NumberField.default,
|
|
45
|
+
id: NUMBER_FIELD_ID,
|
|
46
|
+
label: NUMBER_FIELD_LABEL,
|
|
47
|
+
name: NUMBER_FIELD_INPUT_ID
|
|
48
|
+
})]
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const ControlledComponent = () => {
|
|
52
|
+
const [value, setValue] = (0, _react.useState)();
|
|
53
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
54
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(SpecialResetButton, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
55
|
+
component: _NumberField.default,
|
|
56
|
+
id: NUMBER_FIELD_ID,
|
|
57
|
+
label: NUMBER_FIELD_LABEL,
|
|
58
|
+
name: NUMBER_FIELD_INPUT_ID,
|
|
59
|
+
onChange: e => setValue(e.target.value),
|
|
60
|
+
value: value
|
|
61
|
+
})]
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// EXAMPLE nesting repeated tests with describe.each or test.each might speed up some of our test writing
|
|
66
|
+
describe.each([['Non-Controlled', /*#__PURE__*/(0, _jsxRuntime.jsx)(NonControlledComponent, {})], ['Controlled', /*#__PURE__*/(0, _jsxRuntime.jsx)(ControlledComponent, {})]])('NumberField', (controlType, component) => {
|
|
67
|
+
let _renderComponent;
|
|
68
|
+
let textField;
|
|
69
|
+
describe(`Regular usage (${controlType})`, () => {
|
|
70
|
+
beforeEach(async () => {
|
|
71
|
+
onSubmit.mockClear();
|
|
72
|
+
_renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
73
|
+
initialValues: {},
|
|
74
|
+
onSubmit: onSubmit,
|
|
75
|
+
children: component
|
|
76
|
+
}));
|
|
77
|
+
textField = getTextField();
|
|
78
|
+
});
|
|
79
|
+
it('renders text field as expected', () => {
|
|
80
|
+
expect(textField).toBeInTheDocument();
|
|
81
|
+
});
|
|
82
|
+
describe.each([['non-numeric characters', 'sdhukjasklfs', '', {}], ['numeric characters', '12345', '12345', {
|
|
83
|
+
[NUMBER_FIELD_INPUT_ID]: '12345'
|
|
84
|
+
}], ['scientific notation', '1e5', '100000', {
|
|
85
|
+
[NUMBER_FIELD_INPUT_ID]: '100000'
|
|
86
|
+
}], ['negative numbers', '-100', '-100', {
|
|
87
|
+
[NUMBER_FIELD_INPUT_ID]: '-100'
|
|
88
|
+
}]])('Typing', (characterType, typedChars, expectedDisplay, expectedSubmit) => {
|
|
89
|
+
describe(`typing ${characterType}`, () => {
|
|
90
|
+
beforeEach(async () => {
|
|
91
|
+
await (0, _react2.waitFor)(async () => {
|
|
92
|
+
await _userEvent.default.type(textField, typedChars);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
it('does not render typed characters', async () => {
|
|
96
|
+
expect(textField).toHaveDisplayValue(expectedDisplay);
|
|
97
|
+
});
|
|
98
|
+
describe('submitting the form', () => {
|
|
99
|
+
beforeEach(submitForm);
|
|
100
|
+
it('submits with expected values', () => {
|
|
101
|
+
expect(onSubmit.mock.calls[0][0]).toEqual(expectedSubmit);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe.each([['numeric initialvalues', {
|
|
108
|
+
[NUMBER_FIELD_INPUT_ID]: '7654321'
|
|
109
|
+
}, '7654321', {
|
|
110
|
+
[NUMBER_FIELD_INPUT_ID]: '7654321'
|
|
111
|
+
}], ['regular scientific initialvalue NOTE: scientific value parsing does NOT work from initialValues', {
|
|
112
|
+
[NUMBER_FIELD_INPUT_ID]: '3e7'
|
|
113
|
+
}, '3e7', {
|
|
114
|
+
[NUMBER_FIELD_INPUT_ID]: '3e7'
|
|
115
|
+
}], ['negative initialvalue', {
|
|
116
|
+
[NUMBER_FIELD_INPUT_ID]: '-100'
|
|
117
|
+
}, '-100', {
|
|
118
|
+
[NUMBER_FIELD_INPUT_ID]: '-100'
|
|
119
|
+
}]])(`Initial values (${controlType})`, (describeTitle, initialValues, displayValue, submitValue) => {
|
|
120
|
+
describe(describeTitle, () => {
|
|
121
|
+
beforeEach(async () => {
|
|
122
|
+
onSubmit.mockClear();
|
|
123
|
+
_renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
124
|
+
initialValues: initialValues,
|
|
125
|
+
onSubmit: onSubmit,
|
|
126
|
+
children: component
|
|
127
|
+
}));
|
|
128
|
+
textField = getTextField();
|
|
129
|
+
});
|
|
130
|
+
it('renders initial value', async () => {
|
|
131
|
+
expect(textField).toHaveDisplayValue(displayValue);
|
|
132
|
+
});
|
|
133
|
+
describe('submitting the form', () => {
|
|
134
|
+
beforeEach(submitForm);
|
|
135
|
+
it('submits with expected values', () => {
|
|
136
|
+
expect(onSubmit.mock.calls[0][0]).toEqual(submitValue);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
describe.each([['Clear after typing', async () => {
|
|
142
|
+
onSubmit.mockClear();
|
|
143
|
+
_renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
144
|
+
initialValues: {},
|
|
145
|
+
onSubmit: onSubmit,
|
|
146
|
+
children: component
|
|
147
|
+
}));
|
|
148
|
+
textField = getTextField();
|
|
149
|
+
await (0, _react2.waitFor)(async () => {
|
|
150
|
+
await _userEvent.default.type(textField, '32786843');
|
|
151
|
+
});
|
|
152
|
+
}], ['Clear from initialValues', async () => {
|
|
153
|
+
onSubmit.mockClear();
|
|
154
|
+
_renderComponent = (0, _helpers.renderWithKintHarness)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_stripesErmTesting.TestForm, {
|
|
155
|
+
initialValues: {
|
|
156
|
+
[NUMBER_FIELD_INPUT_ID]: '32786843'
|
|
157
|
+
},
|
|
158
|
+
onSubmit: onSubmit,
|
|
159
|
+
children: component
|
|
160
|
+
}));
|
|
161
|
+
textField = getTextField();
|
|
162
|
+
}]])(`ERM-3391: state change underneath component (${controlType})`, (clearType, beforeEachFunc) => {
|
|
163
|
+
describe(clearType, () => {
|
|
164
|
+
beforeEach(beforeEachFunc);
|
|
165
|
+
it('renders text field', () => {
|
|
166
|
+
expect(textField).toBeInTheDocument();
|
|
167
|
+
});
|
|
168
|
+
it('renders special reset button', async () => {
|
|
169
|
+
await (0, _stripesErmTesting.Button)(RESET_BUTTON_LABEL).exists();
|
|
170
|
+
});
|
|
171
|
+
describe.each([['Control', false, '32786843', {
|
|
172
|
+
[NUMBER_FIELD_INPUT_ID]: '32786843'
|
|
173
|
+
}], ['After reset', true, '', {}]])('Test reset', (describeTitle, clearField, expectedValue, expectedSubmit) => {
|
|
174
|
+
describe(describeTitle, () => {
|
|
175
|
+
beforeEach(async () => {
|
|
176
|
+
onSubmit.mockClear();
|
|
177
|
+
if (clearField) {
|
|
178
|
+
await (0, _react2.waitFor)(async () => {
|
|
179
|
+
await (0, _stripesErmTesting.Button)(RESET_BUTTON_LABEL).click();
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
it(`renders text field with display value: ${expectedValue}`, async () => {
|
|
184
|
+
await (0, _react2.waitFor)(() => {
|
|
185
|
+
expect(textField).toHaveDisplayValue(expectedValue);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
describe('submitting', () => {
|
|
189
|
+
describe('submitting the form', () => {
|
|
190
|
+
beforeEach(submitForm);
|
|
191
|
+
it('submits with expected values', () => {
|
|
192
|
+
expect(onSubmit.mock.calls[0][0]).toEqual(expectedSubmit);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
1
2
|
import {
|
|
2
3
|
useEffect,
|
|
3
4
|
useRef,
|
|
4
5
|
useState
|
|
5
6
|
} from 'react';
|
|
6
|
-
|
|
7
|
+
|
|
7
8
|
import noop from 'lodash/noop';
|
|
8
9
|
|
|
9
10
|
import {
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
|
|
15
16
|
const NumberField = (props) => {
|
|
16
17
|
const {
|
|
18
|
+
onBlur: passedOnBlur = noop,
|
|
17
19
|
onChange: passedOnChange = noop,
|
|
18
20
|
input,
|
|
19
21
|
value,
|
|
@@ -35,14 +37,21 @@ const NumberField = (props) => {
|
|
|
35
37
|
|
|
36
38
|
// Allow direct control of field
|
|
37
39
|
useEffect(() => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
const valueToUse = value ?? input.value;
|
|
41
|
+
|
|
42
|
+
if (!valueToUse && numValue) {
|
|
43
|
+
// Make sure to empty out if it's cleared. Treating '' as empty instead of undefined
|
|
44
|
+
setNumValue('');
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
if (
|
|
47
|
+
if (valueToUse && numValue !== valueToUse) {
|
|
48
|
+
setNumValue(valueToUse);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (forceControl !== numValue) {
|
|
43
52
|
setForceControl(numValue);
|
|
44
53
|
}
|
|
45
|
-
}, [forceControl, numValue, value]);
|
|
54
|
+
}, [forceControl, numValue, value, input]);
|
|
46
55
|
|
|
47
56
|
const handleChange = (e) => {
|
|
48
57
|
// Actually set the value in the form
|
|
@@ -59,12 +68,10 @@ const NumberField = (props) => {
|
|
|
59
68
|
}
|
|
60
69
|
};
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
64
71
|
const handleUserChange = (e) => {
|
|
65
72
|
const parsedValue = parseFloat(e.target.value);
|
|
66
73
|
|
|
67
|
-
// ReturnValue needed for
|
|
74
|
+
// ReturnValue needed for controlled components
|
|
68
75
|
if (parsedValue || parsedValue === 0) {
|
|
69
76
|
setNumValue(parsedValue);
|
|
70
77
|
changeField(parsedValue);
|
|
@@ -79,6 +86,13 @@ const NumberField = (props) => {
|
|
|
79
86
|
<TextField
|
|
80
87
|
ref={userInputRef}
|
|
81
88
|
{...rest} // Keep an eye on this
|
|
89
|
+
onBlur={(event) => {
|
|
90
|
+
// Make sure blur propogates to input
|
|
91
|
+
if (input.onBlur) {
|
|
92
|
+
input.onBlur(event);
|
|
93
|
+
}
|
|
94
|
+
passedOnBlur(event);
|
|
95
|
+
}}
|
|
82
96
|
onChange={handleUserChange}
|
|
83
97
|
type="number"
|
|
84
98
|
value={forceControl}
|
|
@@ -87,6 +101,7 @@ const NumberField = (props) => {
|
|
|
87
101
|
ref={inputRef}
|
|
88
102
|
{...input}
|
|
89
103
|
hidden
|
|
104
|
+
id={input?.name}
|
|
90
105
|
onChange={handleChange}
|
|
91
106
|
type="number"
|
|
92
107
|
value={numValue}
|
|
@@ -96,9 +111,12 @@ const NumberField = (props) => {
|
|
|
96
111
|
};
|
|
97
112
|
|
|
98
113
|
NumberField.propTypes = {
|
|
114
|
+
onBlur: PropTypes.func,
|
|
99
115
|
onChange: PropTypes.func,
|
|
100
116
|
input: PropTypes.shape({
|
|
117
|
+
name: PropTypes.string.isRequired,
|
|
101
118
|
onChange: PropTypes.func.isRequired,
|
|
119
|
+
onBlur: PropTypes.func,
|
|
102
120
|
value: PropTypes.oneOfType([
|
|
103
121
|
PropTypes.number,
|
|
104
122
|
PropTypes.string
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Field, useForm } from 'react-final-form';
|
|
3
|
+
|
|
4
|
+
import userEvent from '@folio/jest-config-stripes/testing-library/user-event';
|
|
5
|
+
import { screen, waitFor } from '@folio/jest-config-stripes/testing-library/react';
|
|
6
|
+
|
|
7
|
+
import { Button, TestForm, TextField } from '@folio/stripes-erm-testing';
|
|
8
|
+
import { Button as StripesButton } from '@folio/stripes/components';
|
|
9
|
+
|
|
10
|
+
import NumberField from './NumberField';
|
|
11
|
+
|
|
12
|
+
import { renderWithKintHarness } from '../../../test/jest/helpers';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const onSubmit = jest.fn();
|
|
16
|
+
|
|
17
|
+
const NUMBER_FIELD_LABEL = 'TEST NUMBER FIELD';
|
|
18
|
+
const NUMBER_FIELD_ID = 'number-field-test';
|
|
19
|
+
const NUMBER_FIELD_INPUT_ID = 'input-id-test';
|
|
20
|
+
|
|
21
|
+
const RESET_BUTTON_LABEL = 'RESET NUMBER FIELD';
|
|
22
|
+
|
|
23
|
+
// We need to use jest selectors instead of interactors as the TextField interactor
|
|
24
|
+
// can't handle the double-text-field nature of NumberField
|
|
25
|
+
const getTextField = () => {
|
|
26
|
+
// Spinbutton because it's a "number" type textField...
|
|
27
|
+
return screen.getByRole('spinbutton', { name: NUMBER_FIELD_LABEL });
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const submitForm = async () => {
|
|
31
|
+
await waitFor(async () => {
|
|
32
|
+
await Button('Submit').click();
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const SpecialResetButton = () => {
|
|
37
|
+
const { change } = useForm();
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<StripesButton
|
|
41
|
+
onClick={() => change(NUMBER_FIELD_INPUT_ID, undefined)}
|
|
42
|
+
>
|
|
43
|
+
{RESET_BUTTON_LABEL}
|
|
44
|
+
</StripesButton>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const NonControlledComponent = () => {
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<SpecialResetButton />
|
|
52
|
+
<Field
|
|
53
|
+
component={NumberField}
|
|
54
|
+
id={NUMBER_FIELD_ID}
|
|
55
|
+
label={NUMBER_FIELD_LABEL}
|
|
56
|
+
name={NUMBER_FIELD_INPUT_ID}
|
|
57
|
+
/>
|
|
58
|
+
</>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const ControlledComponent = () => {
|
|
63
|
+
const [value, setValue] = useState();
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<SpecialResetButton />
|
|
68
|
+
<Field
|
|
69
|
+
component={NumberField}
|
|
70
|
+
id={NUMBER_FIELD_ID}
|
|
71
|
+
label={NUMBER_FIELD_LABEL}
|
|
72
|
+
name={NUMBER_FIELD_INPUT_ID}
|
|
73
|
+
onChange={e => setValue(e.target.value)}
|
|
74
|
+
value={value}
|
|
75
|
+
/>
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// EXAMPLE nesting repeated tests with describe.each or test.each might speed up some of our test writing
|
|
81
|
+
describe.each([
|
|
82
|
+
['Non-Controlled', <NonControlledComponent />],
|
|
83
|
+
['Controlled', <ControlledComponent />],
|
|
84
|
+
])('NumberField', (controlType, component) => {
|
|
85
|
+
let _renderComponent;
|
|
86
|
+
let textField;
|
|
87
|
+
describe(`Regular usage (${controlType})`, () => {
|
|
88
|
+
beforeEach(async () => {
|
|
89
|
+
onSubmit.mockClear();
|
|
90
|
+
_renderComponent = renderWithKintHarness(
|
|
91
|
+
<TestForm
|
|
92
|
+
initialValues={{}}
|
|
93
|
+
onSubmit={onSubmit}
|
|
94
|
+
>
|
|
95
|
+
{component}
|
|
96
|
+
</TestForm>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
textField = getTextField();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('renders text field as expected', () => {
|
|
103
|
+
expect(textField).toBeInTheDocument();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe.each([
|
|
107
|
+
['non-numeric characters', 'sdhukjasklfs', '', {}],
|
|
108
|
+
['numeric characters', '12345', '12345', { [NUMBER_FIELD_INPUT_ID]: '12345' }],
|
|
109
|
+
['scientific notation', '1e5', '100000', { [NUMBER_FIELD_INPUT_ID]: '100000' }],
|
|
110
|
+
['negative numbers', '-100', '-100', { [NUMBER_FIELD_INPUT_ID]: '-100' }],
|
|
111
|
+
])('Typing', (characterType, typedChars, expectedDisplay, expectedSubmit) => {
|
|
112
|
+
describe(`typing ${characterType}`, () => {
|
|
113
|
+
beforeEach(async () => {
|
|
114
|
+
await waitFor(async () => {
|
|
115
|
+
await userEvent.type(textField, typedChars);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('does not render typed characters', async () => {
|
|
120
|
+
expect(textField).toHaveDisplayValue(expectedDisplay);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('submitting the form', () => {
|
|
124
|
+
beforeEach(submitForm);
|
|
125
|
+
|
|
126
|
+
it('submits with expected values', () => {
|
|
127
|
+
expect(onSubmit.mock.calls[0][0]).toEqual(expectedSubmit);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe.each([
|
|
135
|
+
['numeric initialvalues', { [NUMBER_FIELD_INPUT_ID]: '7654321' }, '7654321', { [NUMBER_FIELD_INPUT_ID]: '7654321' }],
|
|
136
|
+
['regular scientific initialvalue NOTE: scientific value parsing does NOT work from initialValues', { [NUMBER_FIELD_INPUT_ID]: '3e7' }, '3e7', { [NUMBER_FIELD_INPUT_ID]: '3e7' }],
|
|
137
|
+
['negative initialvalue', { [NUMBER_FIELD_INPUT_ID]: '-100' }, '-100', { [NUMBER_FIELD_INPUT_ID]: '-100' }],
|
|
138
|
+
])(`Initial values (${controlType})`, (describeTitle, initialValues, displayValue, submitValue) => {
|
|
139
|
+
describe(describeTitle, () => {
|
|
140
|
+
beforeEach(async () => {
|
|
141
|
+
onSubmit.mockClear();
|
|
142
|
+
_renderComponent = renderWithKintHarness(
|
|
143
|
+
<TestForm
|
|
144
|
+
initialValues={initialValues}
|
|
145
|
+
onSubmit={onSubmit}
|
|
146
|
+
>
|
|
147
|
+
{component}
|
|
148
|
+
</TestForm>
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
textField = getTextField();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('renders initial value', async () => {
|
|
155
|
+
expect(textField).toHaveDisplayValue(displayValue);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('submitting the form', () => {
|
|
159
|
+
beforeEach(submitForm);
|
|
160
|
+
|
|
161
|
+
it('submits with expected values', () => {
|
|
162
|
+
expect(onSubmit.mock.calls[0][0]).toEqual(submitValue);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe.each([
|
|
169
|
+
[
|
|
170
|
+
'Clear after typing',
|
|
171
|
+
async () => {
|
|
172
|
+
onSubmit.mockClear();
|
|
173
|
+
_renderComponent = renderWithKintHarness(
|
|
174
|
+
<TestForm
|
|
175
|
+
initialValues={{}}
|
|
176
|
+
onSubmit={onSubmit}
|
|
177
|
+
>
|
|
178
|
+
{component}
|
|
179
|
+
</TestForm>
|
|
180
|
+
);
|
|
181
|
+
textField = getTextField();
|
|
182
|
+
|
|
183
|
+
await waitFor(async () => {
|
|
184
|
+
await userEvent.type(textField, '32786843');
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
[
|
|
189
|
+
'Clear from initialValues',
|
|
190
|
+
async () => {
|
|
191
|
+
onSubmit.mockClear();
|
|
192
|
+
_renderComponent = renderWithKintHarness(
|
|
193
|
+
<TestForm
|
|
194
|
+
initialValues={{ [NUMBER_FIELD_INPUT_ID]: '32786843' }}
|
|
195
|
+
onSubmit={onSubmit}
|
|
196
|
+
>
|
|
197
|
+
{component}
|
|
198
|
+
</TestForm>
|
|
199
|
+
);
|
|
200
|
+
textField = getTextField();
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
])(`ERM-3391: state change underneath component (${controlType})`, (clearType, beforeEachFunc) => {
|
|
204
|
+
describe(clearType, () => {
|
|
205
|
+
beforeEach(beforeEachFunc);
|
|
206
|
+
|
|
207
|
+
it('renders text field', () => {
|
|
208
|
+
expect(textField).toBeInTheDocument();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('renders special reset button', async () => {
|
|
212
|
+
await Button(RESET_BUTTON_LABEL).exists();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe.each([
|
|
216
|
+
[
|
|
217
|
+
'Control',
|
|
218
|
+
false,
|
|
219
|
+
'32786843',
|
|
220
|
+
{ [NUMBER_FIELD_INPUT_ID]: '32786843' }
|
|
221
|
+
],
|
|
222
|
+
[
|
|
223
|
+
'After reset',
|
|
224
|
+
true,
|
|
225
|
+
'',
|
|
226
|
+
{}
|
|
227
|
+
]
|
|
228
|
+
])('Test reset', (describeTitle, clearField, expectedValue, expectedSubmit) => {
|
|
229
|
+
describe(describeTitle, () => {
|
|
230
|
+
beforeEach(async () => {
|
|
231
|
+
onSubmit.mockClear();
|
|
232
|
+
if (clearField) {
|
|
233
|
+
await waitFor(async () => {
|
|
234
|
+
await Button(RESET_BUTTON_LABEL).click();
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it(`renders text field with display value: ${expectedValue}`, async () => {
|
|
240
|
+
await waitFor(() => {
|
|
241
|
+
expect(textField).toHaveDisplayValue(expectedValue);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe('submitting', () => {
|
|
246
|
+
describe('submitting the form', () => {
|
|
247
|
+
beforeEach(submitForm);
|
|
248
|
+
|
|
249
|
+
it('submits with expected values', () => {
|
|
250
|
+
expect(onSubmit.mock.calls[0][0]).toEqual(expectedSubmit);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
});
|