orc-shared 1.5.0-dev.11 → 1.5.0-dev.13
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/dist/actions/requestsApi.js +1 -0
- package/dist/components/CategoryList.js +6 -0
- package/dist/components/MaterialUI/DataDisplay/PredefinedElements/DiscountedPrice.js +1 -0
- package/dist/components/MaterialUI/Inputs/PredefinedElements/SearchControl.js +43 -46
- package/dist/components/MaterialUI/hocs/withDeferredTooltip.js +0 -1
- package/dist/components/Navigation/index.js +0 -1
- package/dist/components/Routing/withWaypointing.js +1 -1
- package/dist/whyDidYouRerender.js +1 -0
- package/package.json +1 -1
- package/src/components/MaterialUI/Inputs/PredefinedElements/SearchControl.js +39 -27
- package/src/components/MaterialUI/Inputs/PredefinedElements/SearchControl.test.js +39 -34
|
@@ -24,6 +24,7 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
|
|
|
24
24
|
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
25
25
|
return a;
|
|
26
26
|
};
|
|
27
|
+
/* istanbul ignore file */
|
|
27
28
|
var acquireEntityLockRequest = {
|
|
28
29
|
name: "acquireEntityLockRequest",
|
|
29
30
|
buildUrl: function buildUrl(scopeId, entity, entityId) {
|
|
@@ -35,6 +35,12 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
|
|
|
35
35
|
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
36
36
|
return a;
|
|
37
37
|
};
|
|
38
|
+
/*
|
|
39
|
+
Multiple lists with a single header, aligned with each other
|
|
40
|
+
No virtualization or page loading
|
|
41
|
+
Categories can be folded up to hide content
|
|
42
|
+
Sortable, within categories
|
|
43
|
+
*/
|
|
38
44
|
var arrayToggle = function arrayToggle(array, item) {
|
|
39
45
|
return array.includes(item) ? array.filter(function (x) {
|
|
40
46
|
return x !== item;
|
|
@@ -21,6 +21,7 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
|
|
|
21
21
|
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
|
+
/* eslint-disable react/style-prop-object */
|
|
24
25
|
var useStyles = (0, _styles.makeStyles)(function (theme) {
|
|
25
26
|
return {
|
|
26
27
|
regular: {
|
|
@@ -21,12 +21,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
21
21
|
var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
|
|
22
22
|
enterModule && enterModule(module);
|
|
23
23
|
})();
|
|
24
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
25
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
26
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
28
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
29
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
30
24
|
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
31
25
|
return a;
|
|
32
26
|
};
|
|
@@ -107,15 +101,9 @@ var useStyles = (0, _styles.makeStyles)(function (theme) {
|
|
|
107
101
|
},
|
|
108
102
|
parentInput: {
|
|
109
103
|
flex: "13 0 0",
|
|
110
|
-
zIndex:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
border: function border(props) {
|
|
114
|
-
return props.focused ? "".concat(theme.spacing(0.1), " solid ").concat(theme.palette.focus) : "".concat(theme.spacing(0.1), " solid ").concat(theme.palette.grey.borders);
|
|
115
|
-
},
|
|
116
|
-
boxShadow: function boxShadow(props) {
|
|
117
|
-
return props.focused ? "0 0 4px ".concat(theme.palette.focus) : "none";
|
|
118
|
-
},
|
|
104
|
+
zIndex: 1,
|
|
105
|
+
border: "".concat(theme.spacing(0.1), " solid ").concat(theme.palette.grey.borders),
|
|
106
|
+
boxShadow: "none",
|
|
119
107
|
width: "100%",
|
|
120
108
|
display: "inherit",
|
|
121
109
|
marginLeft: theme.spacing(-0.1),
|
|
@@ -133,6 +121,11 @@ var useStyles = (0, _styles.makeStyles)(function (theme) {
|
|
|
133
121
|
borderTopLeftRadius: 0,
|
|
134
122
|
borderBottomLeftRadius: 0
|
|
135
123
|
}
|
|
124
|
+
},
|
|
125
|
+
"&:focus-within": {
|
|
126
|
+
zIndex: 99,
|
|
127
|
+
border: "".concat(theme.spacing(0.1), " solid ").concat(theme.palette.focus),
|
|
128
|
+
boxShadow: "0 0 4px ".concat(theme.palette.focus)
|
|
136
129
|
}
|
|
137
130
|
},
|
|
138
131
|
selectRoot: {
|
|
@@ -182,19 +175,29 @@ var SearchControl = function SearchControl(_ref) {
|
|
|
182
175
|
searchOption = _ref.searchOption,
|
|
183
176
|
_ref$onSearch = _ref.onSearch,
|
|
184
177
|
onSearch = _ref$onSearch === void 0 ? function () {} : _ref$onSearch,
|
|
185
|
-
disabled = _ref.disabled
|
|
178
|
+
disabled = _ref.disabled,
|
|
179
|
+
_ref$focusAndSelectSe = _ref.focusAndSelectSearchFieldOnLoad,
|
|
180
|
+
focusAndSelectSearchFieldOnLoad = _ref$focusAndSelectSe === void 0 ? true : _ref$focusAndSelectSe,
|
|
181
|
+
_ref$focusSearchOnSea = _ref.focusSearchOnSearchOptionChange,
|
|
182
|
+
focusSearchOnSearchOptionChange = _ref$focusSearchOnSea === void 0 ? false : _ref$focusSearchOnSea;
|
|
186
183
|
searchOptions = !((_searchOptions = searchOptions) != null && _searchOptions.length) ? null : searchOptions;
|
|
187
184
|
searchOption = getSearchOptionValue(searchOptions, searchOption);
|
|
188
|
-
var
|
|
189
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
190
|
-
inputFocused = _useState2[0],
|
|
191
|
-
setInputFocused = _useState2[1];
|
|
192
|
-
var classes = useStyles({
|
|
193
|
-
focused: inputFocused
|
|
194
|
-
});
|
|
185
|
+
var classes = useStyles();
|
|
195
186
|
var inputRef = (0, _react.useRef)();
|
|
196
187
|
var update = function update(value) {
|
|
197
|
-
|
|
188
|
+
if (focusSearchOnSearchOptionChange && inputRef.current) {
|
|
189
|
+
onSearch(value, "");
|
|
190
|
+
setTimeout(function () {
|
|
191
|
+
/* istanbul ignore next */
|
|
192
|
+
if (inputRef.current) {
|
|
193
|
+
inputRef.current.value = "";
|
|
194
|
+
inputRef.current.focus();
|
|
195
|
+
inputRef.current.select();
|
|
196
|
+
}
|
|
197
|
+
}, 0);
|
|
198
|
+
} else {
|
|
199
|
+
onSearch(value, defaultValue);
|
|
200
|
+
}
|
|
198
201
|
};
|
|
199
202
|
var selectProps = new _SelectProps.default();
|
|
200
203
|
selectProps.set(_SelectProps.default.propNames.update, update);
|
|
@@ -211,18 +214,13 @@ var SearchControl = function SearchControl(_ref) {
|
|
|
211
214
|
});
|
|
212
215
|
selectProps.setStyle(_SelectProps.default.ruleNames.root, classes.selectRoot);
|
|
213
216
|
selectProps.setStyle(_SelectProps.default.ruleNames.paper, classes.selectPaper);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
(0, _react.useEffect)(function () {
|
|
218
|
+
/* istanbul ignore next */
|
|
219
|
+
if (focusAndSelectSearchFieldOnLoad && inputRef.current) {
|
|
220
|
+
inputRef.current.focus();
|
|
221
|
+
inputRef.current.select();
|
|
219
222
|
}
|
|
220
|
-
};
|
|
221
|
-
var onFocusedEvent = function onFocusedEvent(event, focused) {
|
|
222
|
-
setInputFocused(focused);
|
|
223
|
-
event.preventDefault();
|
|
224
|
-
event.stopPropagation();
|
|
225
|
-
};
|
|
223
|
+
}, [focusAndSelectSearchFieldOnLoad]);
|
|
226
224
|
var SelectSection = function SelectSection() {
|
|
227
225
|
if (searchOptions === null) return null;else return /*#__PURE__*/_react.default.createElement(_Select.default, {
|
|
228
226
|
className: classes.selectInput,
|
|
@@ -230,13 +228,19 @@ var SearchControl = function SearchControl(_ref) {
|
|
|
230
228
|
selectProps: selectProps
|
|
231
229
|
});
|
|
232
230
|
};
|
|
231
|
+
var onSubmit = function onSubmit(event) {
|
|
232
|
+
var _inputRef$current;
|
|
233
|
+
// using form submit instead of a keydown (with key=enter) to allow the 'enter key' event to be canceled elsewhere to avoid the submit event
|
|
234
|
+
onSearch(searchOption, (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.value);
|
|
235
|
+
event.preventDefault();
|
|
236
|
+
};
|
|
233
237
|
var inputSection = /*#__PURE__*/_react.default.createElement("div", {
|
|
234
238
|
"data-qa": "searchInput",
|
|
235
|
-
"data-qa-is-focused": inputFocused,
|
|
236
239
|
className: classes.parentInput
|
|
237
240
|
}, /*#__PURE__*/_react.default.createElement("form", {
|
|
238
241
|
"data-qa": "searchForm",
|
|
239
|
-
className: classes.fullWidth
|
|
242
|
+
className: classes.fullWidth,
|
|
243
|
+
onSubmitCapture: onSubmit
|
|
240
244
|
}, /*#__PURE__*/_react.default.createElement(_Input.default, {
|
|
241
245
|
placeholder: placeholder,
|
|
242
246
|
defaultValue: defaultValue,
|
|
@@ -246,14 +250,7 @@ var SearchControl = function SearchControl(_ref) {
|
|
|
246
250
|
classes: {
|
|
247
251
|
input: classes.controlInput
|
|
248
252
|
},
|
|
249
|
-
onKeyDown: handleKeyDown,
|
|
250
253
|
disableUnderline: true,
|
|
251
|
-
onFocus: function onFocus(e) {
|
|
252
|
-
return onFocusedEvent(e, true);
|
|
253
|
-
},
|
|
254
|
-
onBlur: function onBlur(e) {
|
|
255
|
-
return onFocusedEvent(e, false);
|
|
256
|
-
},
|
|
257
254
|
endAdornment: /*#__PURE__*/_react.default.createElement(_InputAdornment.default, {
|
|
258
255
|
position: "start"
|
|
259
256
|
}, /*#__PURE__*/_react.default.createElement(_IconButton.default, {
|
|
@@ -287,10 +284,10 @@ var SearchControl = function SearchControl(_ref) {
|
|
|
287
284
|
className: classes.container
|
|
288
285
|
}, /*#__PURE__*/_react.default.createElement(SelectSection, null), inputSection, searchSection);
|
|
289
286
|
};
|
|
290
|
-
__signature__(SearchControl, "
|
|
287
|
+
__signature__(SearchControl, "useStyles{classes}\nuseRef{inputRef}\nuseEffect{}", function () {
|
|
291
288
|
return [useStyles];
|
|
292
289
|
});
|
|
293
|
-
__signature__(SearchControl, "
|
|
290
|
+
__signature__(SearchControl, "useStyles{classes}\nuseRef{inputRef}\nuseEffect{}", function () {
|
|
294
291
|
return [useStyles];
|
|
295
292
|
});
|
|
296
293
|
var _default = SearchControl;
|
|
@@ -35,7 +35,6 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
|
|
|
35
35
|
// Pay attention that if component you are passed to this HOC contains titleValue property
|
|
36
36
|
// by itself then that property will be disappeared after using that HOC.
|
|
37
37
|
// To fix it rename that property and pass titleValue just as a title for tooltip.
|
|
38
|
-
|
|
39
38
|
var withDeferredTooltip = function withDeferredTooltip(Comp) {
|
|
40
39
|
return __signature__(__signature__(function (_ref) {
|
|
41
40
|
var titleValue = _ref.titleValue,
|
|
@@ -26,7 +26,6 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
|
|
|
26
26
|
// Scope concern: Changing scope means subpages may no longer be valid.
|
|
27
27
|
// Grey out other-scoped tabs, change scope when opened?
|
|
28
28
|
// Warn when changing scopes, close out-scope tabs?
|
|
29
|
-
|
|
30
29
|
var Navigation = (0, _withErrorBoundary.default)("Navigation")(__signature__(__signature__(function (_ref) {
|
|
31
30
|
var modules = _ref.modules;
|
|
32
31
|
return /*#__PURE__*/_react.default.createElement(_TabBar.default, (0, _useNavigationState.useNavigationState)(modules));
|
|
@@ -27,7 +27,7 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
|
|
|
27
27
|
};
|
|
28
28
|
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
29
29
|
return a;
|
|
30
|
-
};
|
|
30
|
+
}; // HOC that sets the currently matched route of a component in state, including params
|
|
31
31
|
var withWaypointing = function withWaypointing(Comp, isVisible, componentProps) {
|
|
32
32
|
if (isVisible === void 0) {
|
|
33
33
|
isVisible = true;
|
|
@@ -8,6 +8,7 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
|
|
|
8
8
|
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
9
9
|
return a;
|
|
10
10
|
};
|
|
11
|
+
/* istanbul ignore file */
|
|
11
12
|
// If you want to investigate rerenderer of components, import that file before "react-hot-loader", usually in App.js
|
|
12
13
|
if (process.env.NODE_ENV === "development") {
|
|
13
14
|
var whyDidYouRender = require("@welldone-software/why-did-you-render");
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useRef, useEffect } from "react";
|
|
2
2
|
import { makeStyles } from "@material-ui/core/styles";
|
|
3
3
|
import SelectProps from "../SelectProps";
|
|
4
4
|
import Icon from "../../DataDisplay/Icon";
|
|
@@ -80,12 +80,9 @@ export const useStyles = makeStyles(theme => ({
|
|
|
80
80
|
},
|
|
81
81
|
parentInput: {
|
|
82
82
|
flex: "13 0 0",
|
|
83
|
-
zIndex:
|
|
84
|
-
border:
|
|
85
|
-
|
|
86
|
-
? `${theme.spacing(0.1)} solid ${theme.palette.focus}`
|
|
87
|
-
: `${theme.spacing(0.1)} solid ${theme.palette.grey.borders}`,
|
|
88
|
-
boxShadow: props => (props.focused ? `0 0 4px ${theme.palette.focus}` : "none"),
|
|
83
|
+
zIndex: 1,
|
|
84
|
+
border: `${theme.spacing(0.1)} solid ${theme.palette.grey.borders}`,
|
|
85
|
+
boxShadow: "none",
|
|
89
86
|
width: "100%",
|
|
90
87
|
display: "inherit",
|
|
91
88
|
marginLeft: theme.spacing(-0.1),
|
|
@@ -104,6 +101,11 @@ export const useStyles = makeStyles(theme => ({
|
|
|
104
101
|
borderBottomLeftRadius: 0,
|
|
105
102
|
},
|
|
106
103
|
},
|
|
104
|
+
"&:focus-within": {
|
|
105
|
+
zIndex: 99,
|
|
106
|
+
border: `${theme.spacing(0.1)} solid ${theme.palette.focus}`,
|
|
107
|
+
boxShadow: `0 0 4px ${theme.palette.focus}`,
|
|
108
|
+
},
|
|
107
109
|
},
|
|
108
110
|
selectRoot: {
|
|
109
111
|
zIndex: 10,
|
|
@@ -149,17 +151,30 @@ const SearchControl = ({
|
|
|
149
151
|
searchOption,
|
|
150
152
|
onSearch = () => {},
|
|
151
153
|
disabled,
|
|
154
|
+
focusAndSelectSearchFieldOnLoad = true,
|
|
155
|
+
focusSearchOnSearchOptionChange = false,
|
|
152
156
|
}) => {
|
|
153
157
|
searchOptions = !searchOptions?.length ? null : searchOptions;
|
|
154
158
|
searchOption = getSearchOptionValue(searchOptions, searchOption);
|
|
155
|
-
const [inputFocused, setInputFocused] = useState(false);
|
|
156
159
|
|
|
157
|
-
const classes = useStyles(
|
|
160
|
+
const classes = useStyles();
|
|
158
161
|
|
|
159
162
|
const inputRef = useRef();
|
|
160
163
|
|
|
161
164
|
const update = value => {
|
|
162
|
-
|
|
165
|
+
if (focusSearchOnSearchOptionChange && inputRef.current) {
|
|
166
|
+
onSearch(value, "");
|
|
167
|
+
setTimeout(() => {
|
|
168
|
+
/* istanbul ignore next */
|
|
169
|
+
if (inputRef.current) {
|
|
170
|
+
inputRef.current.value = "";
|
|
171
|
+
inputRef.current.focus();
|
|
172
|
+
inputRef.current.select();
|
|
173
|
+
}
|
|
174
|
+
}, 0);
|
|
175
|
+
} else {
|
|
176
|
+
onSearch(value, defaultValue);
|
|
177
|
+
}
|
|
163
178
|
};
|
|
164
179
|
|
|
165
180
|
const selectProps = new SelectProps();
|
|
@@ -178,28 +193,28 @@ const SearchControl = ({
|
|
|
178
193
|
selectProps.setStyle(SelectProps.ruleNames.root, classes.selectRoot);
|
|
179
194
|
selectProps.setStyle(SelectProps.ruleNames.paper, classes.selectPaper);
|
|
180
195
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
/* istanbul ignore next */
|
|
198
|
+
if (focusAndSelectSearchFieldOnLoad && inputRef.current) {
|
|
199
|
+
inputRef.current.focus();
|
|
200
|
+
inputRef.current.select();
|
|
186
201
|
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
const onFocusedEvent = (event, focused) => {
|
|
190
|
-
setInputFocused(focused);
|
|
191
|
-
event.preventDefault();
|
|
192
|
-
event.stopPropagation();
|
|
193
|
-
};
|
|
202
|
+
}, [focusAndSelectSearchFieldOnLoad]);
|
|
194
203
|
|
|
195
204
|
const SelectSection = () => {
|
|
196
205
|
if (searchOptions === null) return null;
|
|
197
206
|
else return <Select className={classes.selectInput} options={searchOptions} selectProps={selectProps} />;
|
|
198
207
|
};
|
|
199
208
|
|
|
209
|
+
const onSubmit = event => {
|
|
210
|
+
// using form submit instead of a keydown (with key=enter) to allow the 'enter key' event to be canceled elsewhere to avoid the submit event
|
|
211
|
+
onSearch(searchOption, inputRef.current?.value);
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
};
|
|
214
|
+
|
|
200
215
|
const inputSection = (
|
|
201
|
-
<div data-qa="searchInput"
|
|
202
|
-
<form data-qa="searchForm" className={classes.fullWidth}>
|
|
216
|
+
<div data-qa="searchInput" className={classes.parentInput}>
|
|
217
|
+
<form data-qa="searchForm" className={classes.fullWidth} onSubmitCapture={onSubmit}>
|
|
203
218
|
<Input
|
|
204
219
|
placeholder={placeholder}
|
|
205
220
|
defaultValue={defaultValue}
|
|
@@ -207,10 +222,7 @@ const SearchControl = ({
|
|
|
207
222
|
type="text"
|
|
208
223
|
disabled={disabled}
|
|
209
224
|
classes={{ input: classes.controlInput }}
|
|
210
|
-
onKeyDown={handleKeyDown}
|
|
211
225
|
disableUnderline={true}
|
|
212
|
-
onFocus={e => onFocusedEvent(e, true)}
|
|
213
|
-
onBlur={e => onFocusedEvent(e, false)}
|
|
214
226
|
endAdornment={
|
|
215
227
|
<InputAdornment position="start">
|
|
216
228
|
<IconButton
|
|
@@ -53,10 +53,11 @@ describe("useStyles", () => {
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
describe("SearchControl Component", () => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
jest.useFakeTimers();
|
|
58
|
+
});
|
|
59
59
|
afterEach(() => {
|
|
60
|
+
jest.useRealTimers();
|
|
60
61
|
jest.clearAllMocks();
|
|
61
62
|
});
|
|
62
63
|
|
|
@@ -232,8 +233,7 @@ describe("SearchControl Component", () => {
|
|
|
232
233
|
expect(searchInput.length, "to be", 1);
|
|
233
234
|
|
|
234
235
|
searchInput.instance().value = "abc";
|
|
235
|
-
|
|
236
|
-
searchInput.simulate("keydown", { key: "Enter" });
|
|
236
|
+
mountedComponent.find("form").simulate("submit", { preventDefault: () => {} });
|
|
237
237
|
|
|
238
238
|
expect(onSearchEvent, "to have calls satisfying", [{ args: ["aValue", "abc"] }]);
|
|
239
239
|
});
|
|
@@ -371,7 +371,7 @@ describe("SearchControl Component", () => {
|
|
|
371
371
|
expect(onSearchEvent, "to have calls satisfying", [{ args: ["anotherValue", "abcdef123"] }]);
|
|
372
372
|
});
|
|
373
373
|
|
|
374
|
-
it("Search Control should
|
|
374
|
+
it("Search Control should clear the search when changing the option", () => {
|
|
375
375
|
const options = [
|
|
376
376
|
{ value: "aValue", label: "aLabel" },
|
|
377
377
|
{ value: "anotherValue", label: "anotherLabel" },
|
|
@@ -385,8 +385,8 @@ describe("SearchControl Component", () => {
|
|
|
385
385
|
placeholder="placeHolderTest"
|
|
386
386
|
defaultValue={"abcdef123"}
|
|
387
387
|
searchOptions={options}
|
|
388
|
-
searchOption={"anotherValue"}
|
|
389
388
|
onSearch={onSearchEvent}
|
|
389
|
+
focusSearchOnSearchOptionChange={true}
|
|
390
390
|
/>
|
|
391
391
|
</TestWrapper>
|
|
392
392
|
);
|
|
@@ -395,48 +395,53 @@ describe("SearchControl Component", () => {
|
|
|
395
395
|
|
|
396
396
|
const selectMui = mountedComponent.find(SelectMUI);
|
|
397
397
|
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
const event = {
|
|
399
|
+
target: {
|
|
400
|
+
value: "anotherValue",
|
|
401
|
+
},
|
|
402
|
+
};
|
|
400
403
|
|
|
401
|
-
|
|
402
|
-
|
|
404
|
+
onSearchEvent.resetHistory();
|
|
405
|
+
|
|
406
|
+
selectMui.invoke("onChange")(event);
|
|
407
|
+
|
|
408
|
+
expect(onSearchEvent.callCount, "to equal", 1);
|
|
409
|
+
expect(onSearchEvent, "to have calls satisfying", [{ args: ["anotherValue", ""] }]);
|
|
410
|
+
|
|
411
|
+
const allInputs = mountedComponent.find("input");
|
|
412
|
+
const searchInput = allInputs.find("[placeholder='placeHolderTest']");
|
|
413
|
+
expect(searchInput.length, "to be", 1);
|
|
403
414
|
|
|
415
|
+
expect(searchInput.instance().value, "to be", "abcdef123");
|
|
416
|
+
jest.runOnlyPendingTimers();
|
|
417
|
+
expect(searchInput.instance().value, "to be", "");
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it("Search Control should render with the 2nd value", () => {
|
|
404
421
|
const options = [
|
|
405
422
|
{ value: "aValue", label: "aLabel" },
|
|
406
423
|
{ value: "anotherValue", label: "anotherLabel" },
|
|
407
424
|
];
|
|
408
425
|
|
|
426
|
+
const onSearchEvent = sinon.spy().named("search");
|
|
427
|
+
|
|
409
428
|
const component = (
|
|
410
429
|
<TestWrapper stylesProvider muiThemeProvider={{ theme }}>
|
|
411
|
-
<SearchControl
|
|
430
|
+
<SearchControl
|
|
431
|
+
placeholder="placeHolderTest"
|
|
432
|
+
defaultValue={"abcdef123"}
|
|
433
|
+
searchOptions={options}
|
|
434
|
+
searchOption={"anotherValue"}
|
|
435
|
+
onSearch={onSearchEvent}
|
|
436
|
+
/>
|
|
412
437
|
</TestWrapper>
|
|
413
438
|
);
|
|
414
439
|
|
|
415
440
|
const mountedComponent = mount(component);
|
|
416
441
|
|
|
417
|
-
const
|
|
418
|
-
const searchInput = allInputs.find("[placeholder='placeHolderTest']");
|
|
419
|
-
expect(searchInput.length, "to be", 1);
|
|
420
|
-
|
|
421
|
-
let searchEditParent = mountedComponent.find('[data-qa="searchInput"]');
|
|
422
|
-
expect(searchEditParent.length, "to be", 1);
|
|
423
|
-
|
|
424
|
-
expect(searchEditParent.props()["data-qa-is-focused"], "to be", false);
|
|
425
|
-
|
|
426
|
-
const event = {
|
|
427
|
-
preventDefault: () => {},
|
|
428
|
-
stopPropagation: () => {},
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
searchInput.invoke("onFocus")(event);
|
|
432
|
-
|
|
433
|
-
searchEditParent = mountedComponent.find('[data-qa="searchInput"]');
|
|
434
|
-
expect(searchEditParent.props()["data-qa-is-focused"], "to be", true);
|
|
435
|
-
|
|
436
|
-
searchInput.invoke("onBlur")(event);
|
|
442
|
+
const selectMui = mountedComponent.find(SelectMUI);
|
|
437
443
|
|
|
438
|
-
|
|
439
|
-
expect(searchEditParent.props()["data-qa-is-focused"], "to be", false);
|
|
444
|
+
expect(selectMui.props().value, "to equal", "anotherValue");
|
|
440
445
|
});
|
|
441
446
|
|
|
442
447
|
it("Renders Search Control component without errors when disabled", () => {
|