@reltio/components 1.4.2044 → 1.4.2046
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/AttributesFiltersBuilder/AttributesFiltersBuilder.test.js +72 -50
- package/BasicTable/BasicTable.test.js +232 -278
- package/BlobRenderer/BlobRenderer.js +1 -1
- package/ConnectionRelationTypeSelector/ConnectionRelationTypeSelector.test.js +125 -111
- package/DateIntervalSelector/DateIntervalSelector.test.js +87 -65
- package/DefaultCellValueRenderer/DefaultCellValueRenderer.js +1 -1
- package/DefaultCellValueRenderer/DefaultCellValueRenderer.test.js +16 -46
- package/DeleteButton/DeleteButton.spec.js +53 -15
- package/DependentLookupEditor/DependentLookupEditor.test.js +555 -807
- package/Drawer/Drawer.test.js +9 -20
- package/DropDownEditor/DropDownEditor.test.js +81 -29
- package/DropDownMenuButton/DropDownMenuButton.spec.js +101 -70
- package/DropDownSelector/DropDownSelector.test.js +159 -30
- package/EditModeAttributesFactory/EditModeAttributesFactory.test.js +143 -0
- package/EditModeAttributesList/EditModeAttributesList.test.js +277 -224
- package/EditModeAttributesList/attributes.test-data.d.ts +0 -11
- package/EditModeAttributesList/attributes.test-data.js +1 -1
- package/EditModeAttributesPager/EditModeAttributesPager.test.js +698 -234
- package/EditModeAttributesPager/helpers.test.js +2 -12
- package/EditModeAttributesView/EditModeAttributesView.test.js +263 -157
- package/EditModeComplexAttribute/EditModeComplexAttribute.js +1 -1
- package/EditModeComplexAttribute/EditModeComplexAttribute.test.js +313 -298
- package/EditModeComplexAttribute/nestedAttrType.test-data.d.ts +0 -5
- package/EditModeComplexAttribute/nestedAttrType.test-data.js +3 -44
- package/EmptyState/EmptyState.test.js +99 -38
- package/EntityCreator/EntityCreator.test.js +68 -35
- package/EntitySelector/EntitySelector.js +1 -1
- package/EntitySelector/EntitySelector.test.js +275 -422
- package/EntityTypeIcon/EntityTypeIcon.test.js +16 -16
- package/EntityTypesSelector/EntityTypesSelector.test.js +62 -21
- package/ErrorBoundary/ErrorBoundary.test.js +19 -17
- package/ErrorMessage/ErrorMessage.js +1 -1
- package/ErrorPopup/ErrorPopup.test.js +72 -25
- package/ErrorWrapper/ErrorWrapper.test.js +10 -9
- package/ExpandedValueTooltip/ExpandedValueTooltip.test.js +111 -37
- package/FileTypeEditor/FileTypeEditor.test.js +95 -64
- package/FilterValueEditor/FilterValueEditor.test.js +183 -157
- package/FilterValueEditor/components/RangeDataTypeValueEditor/RangeDataTypeValueEditor.js +2 -2
- package/HierarchicalAttributeTooltip/HierarchicalAttributeTooltip.test.js +114 -24
- package/HierarchyNodeTitle/HierarchyNodeTitle.test.js +61 -100
- package/OvIcon/OvIcon.js +2 -2
- package/ProfileCard/components/ProfileCardPlaceholder/ProfileCardPlaceholder.js +2 -2
- package/ShowLess/ShowLess.js +1 -1
- package/SimpleAttributeEditor/SimpleAttributeEditor.js +2 -2
- package/UploadFileButton/components/UploadMode/UploadMode.js +1 -1
- package/cjs/AttributesFiltersBuilder/AttributesFiltersBuilder.test.js +72 -50
- package/cjs/BasicTable/BasicTable.test.js +230 -299
- package/cjs/BlobRenderer/BlobRenderer.js +1 -1
- package/cjs/ConnectionRelationTypeSelector/ConnectionRelationTypeSelector.test.js +125 -111
- package/cjs/DateIntervalSelector/DateIntervalSelector.test.js +87 -65
- package/cjs/DefaultCellValueRenderer/DefaultCellValueRenderer.js +1 -1
- package/cjs/DefaultCellValueRenderer/DefaultCellValueRenderer.test.js +16 -46
- package/cjs/DeleteButton/DeleteButton.spec.js +53 -15
- package/cjs/DependentLookupEditor/DependentLookupEditor.test.js +569 -821
- package/cjs/Drawer/Drawer.test.js +10 -21
- package/cjs/DropDownEditor/DropDownEditor.test.js +81 -29
- package/cjs/DropDownMenuButton/DropDownMenuButton.spec.js +102 -71
- package/cjs/DropDownSelector/DropDownSelector.test.js +159 -30
- package/cjs/EditModeAttributesFactory/EditModeAttributesFactory.test.js +148 -0
- package/cjs/EditModeAttributesList/EditModeAttributesList.test.js +277 -224
- package/cjs/EditModeAttributesList/attributes.test-data.d.ts +0 -11
- package/cjs/EditModeAttributesList/attributes.test-data.js +1 -1
- package/cjs/EditModeAttributesPager/EditModeAttributesPager.test.js +696 -232
- package/cjs/EditModeAttributesPager/helpers.test.js +2 -12
- package/cjs/EditModeAttributesView/EditModeAttributesView.test.js +262 -156
- package/cjs/EditModeComplexAttribute/EditModeComplexAttribute.js +1 -1
- package/cjs/EditModeComplexAttribute/EditModeComplexAttribute.test.js +312 -297
- package/cjs/EditModeComplexAttribute/nestedAttrType.test-data.d.ts +0 -5
- package/cjs/EditModeComplexAttribute/nestedAttrType.test-data.js +3 -44
- package/cjs/EmptyState/EmptyState.test.js +98 -37
- package/cjs/EntityCreator/EntityCreator.test.js +69 -36
- package/cjs/EntitySelector/EntitySelector.js +1 -1
- package/cjs/EntitySelector/EntitySelector.test.js +274 -421
- package/cjs/EntityTypeIcon/EntityTypeIcon.test.js +17 -17
- package/cjs/EntityTypesSelector/EntityTypesSelector.test.js +62 -21
- package/cjs/ErrorBoundary/ErrorBoundary.test.js +19 -17
- package/cjs/ErrorMessage/ErrorMessage.js +1 -1
- package/cjs/ErrorPopup/ErrorPopup.test.js +71 -24
- package/cjs/ErrorWrapper/ErrorWrapper.test.js +10 -9
- package/cjs/ExpandedValueTooltip/ExpandedValueTooltip.test.js +111 -37
- package/cjs/FileTypeEditor/FileTypeEditor.test.js +95 -64
- package/cjs/FilterValueEditor/FilterValueEditor.test.js +182 -156
- package/cjs/FilterValueEditor/components/RangeDataTypeValueEditor/RangeDataTypeValueEditor.js +2 -2
- package/cjs/HierarchicalAttributeTooltip/HierarchicalAttributeTooltip.test.js +114 -24
- package/cjs/HierarchyNodeTitle/HierarchyNodeTitle.test.js +61 -100
- package/cjs/OvIcon/OvIcon.js +2 -2
- package/cjs/ProfileCard/components/ProfileCardPlaceholder/ProfileCardPlaceholder.js +2 -2
- package/cjs/ShowLess/ShowLess.js +1 -1
- package/cjs/SimpleAttributeEditor/SimpleAttributeEditor.js +2 -2
- package/cjs/UploadFileButton/components/UploadMode/UploadMode.js +1 -1
- package/cjs/contexts/ExpandedAttributesContext/useAttributeExpanded.test.js +25 -18
- package/cjs/contexts/MdmModuleContext/hooks.d.ts +2 -2
- package/cjs/contexts/ReloadDataContext/ReloadDataContext.spec.js +16 -53
- package/cjs/test-utils/TestStylesProvider.js +6 -5
- package/contexts/ExpandedAttributesContext/useAttributeExpanded.test.js +25 -18
- package/contexts/MdmModuleContext/hooks.d.ts +2 -2
- package/contexts/ReloadDataContext/ReloadDataContext.spec.js +16 -30
- package/package.json +2 -2
- package/test-utils/TestStylesProvider.js +3 -2
- package/AttributesFiltersBuilder/components/AttributeSelector/AttributeSelector.test.js +0 -101
- package/AttributesFiltersBuilder/components/RowActions/RowActions.test.js +0 -106
- package/BasicTable/IntegrationBasicTable.test.d.ts +0 -1
- package/BasicTable/IntegrationBasicTable.test.js +0 -203
- package/DependentLookupEditor/IntegrationDependentLookupEditor.test.d.ts +0 -1
- package/DependentLookupEditor/IntegrationDependentLookupEditor.test.js +0 -137
- package/DropDownMenuButton/components/DefaultMenuItemRenderer/DefaultMenuItemRenderer.spec.d.ts +0 -1
- package/DropDownMenuButton/components/DefaultMenuItemRenderer/DefaultMenuItemRenderer.spec.js +0 -32
- package/EditModeAttributesFactory/components/EditModeAttribute/EditModeAttribute.test.d.ts +0 -1
- package/EditModeAttributesFactory/components/EditModeAttribute/EditModeAttribute.test.js +0 -106
- package/EditModeAttributesPager/components/AttributeRenderer/AttributeRenderer.test.d.ts +0 -1
- package/EditModeAttributesPager/components/AttributeRenderer/AttributeRenderer.test.js +0 -338
- package/EditModeAttributesPager/components/AttributeRenderer/IntegrationAttributeRenderer.test.d.ts +0 -1
- package/EditModeAttributesPager/components/AttributeRenderer/IntegrationAttributeRenderer.test.js +0 -225
- package/EditModeAttributesPager/components/ImageLineRenderer/ImageLineRenderer.test.d.ts +0 -1
- package/EditModeAttributesPager/components/ImageLineRenderer/ImageLineRenderer.test.js +0 -47
- package/EditModeAttributesPager/components/SpecialRenderer/SpecialRenderer.test.d.ts +0 -1
- package/EditModeAttributesPager/components/SpecialRenderer/SpecialRenderer.test.js +0 -204
- package/EditModeAttributesView/IntegrationEditModeAttributesView.test.d.ts +0 -1
- package/EditModeAttributesView/IntegrationEditModeAttributesView.test.js +0 -246
- package/EditModeAttributesView/metadata.test-data.d.ts +0 -4
- package/EditModeAttributesView/metadata.test-data.js +0 -119
- package/EntityCreator/entityType.test-data.d.ts +0 -52
- package/EntityCreator/entityType.test-data.js +0 -188
- package/EntitySelector/components/ClearIndicator/ClearIndicator.test.d.ts +0 -1
- package/EntitySelector/components/ClearIndicator/ClearIndicator.test.js +0 -27
- package/EntitySelector/components/EntityOption/EntityOption.test.d.ts +0 -1
- package/EntitySelector/components/EntityOption/EntityOption.test.js +0 -79
- package/EntitySelector/components/Group/Group.test.d.ts +0 -1
- package/EntitySelector/components/Group/Group.test.js +0 -65
- package/EntitySelector/components/SingleValue/SingleValue.test.d.ts +0 -1
- package/EntitySelector/components/SingleValue/SingleValue.test.js +0 -78
- package/FilterValueEditor/components/RangeDataTypeValueEditor/RangeDataTypeValueEditor.test.d.ts +0 -1
- package/FilterValueEditor/components/RangeDataTypeValueEditor/RangeDataTypeValueEditor.test.js +0 -76
- package/cjs/AttributesFiltersBuilder/components/AttributeSelector/AttributeSelector.test.d.ts +0 -1
- package/cjs/AttributesFiltersBuilder/components/AttributeSelector/AttributeSelector.test.js +0 -106
- package/cjs/AttributesFiltersBuilder/components/RowActions/RowActions.test.d.ts +0 -1
- package/cjs/AttributesFiltersBuilder/components/RowActions/RowActions.test.js +0 -111
- package/cjs/BasicTable/IntegrationBasicTable.test.d.ts +0 -1
- package/cjs/BasicTable/IntegrationBasicTable.test.js +0 -208
- package/cjs/DependentLookupEditor/IntegrationDependentLookupEditor.test.d.ts +0 -1
- package/cjs/DependentLookupEditor/IntegrationDependentLookupEditor.test.js +0 -142
- package/cjs/DropDownMenuButton/components/DefaultMenuItemRenderer/DefaultMenuItemRenderer.spec.d.ts +0 -1
- package/cjs/DropDownMenuButton/components/DefaultMenuItemRenderer/DefaultMenuItemRenderer.spec.js +0 -37
- package/cjs/EditModeAttributesFactory/components/EditModeAttribute/EditModeAttribute.test.d.ts +0 -1
- package/cjs/EditModeAttributesFactory/components/EditModeAttribute/EditModeAttribute.test.js +0 -111
- package/cjs/EditModeAttributesPager/components/AttributeRenderer/AttributeRenderer.test.d.ts +0 -1
- package/cjs/EditModeAttributesPager/components/AttributeRenderer/AttributeRenderer.test.js +0 -343
- package/cjs/EditModeAttributesPager/components/AttributeRenderer/IntegrationAttributeRenderer.test.d.ts +0 -1
- package/cjs/EditModeAttributesPager/components/AttributeRenderer/IntegrationAttributeRenderer.test.js +0 -230
- package/cjs/EditModeAttributesPager/components/ImageLineRenderer/ImageLineRenderer.test.d.ts +0 -1
- package/cjs/EditModeAttributesPager/components/ImageLineRenderer/ImageLineRenderer.test.js +0 -52
- package/cjs/EditModeAttributesPager/components/SpecialRenderer/SpecialRenderer.test.d.ts +0 -1
- package/cjs/EditModeAttributesPager/components/SpecialRenderer/SpecialRenderer.test.js +0 -209
- package/cjs/EditModeAttributesView/IntegrationEditModeAttributesView.test.d.ts +0 -1
- package/cjs/EditModeAttributesView/IntegrationEditModeAttributesView.test.js +0 -251
- package/cjs/EditModeAttributesView/metadata.test-data.d.ts +0 -4
- package/cjs/EditModeAttributesView/metadata.test-data.js +0 -123
- package/cjs/EntityCreator/entityType.test-data.d.ts +0 -52
- package/cjs/EntityCreator/entityType.test-data.js +0 -191
- package/cjs/EntitySelector/components/ClearIndicator/ClearIndicator.test.d.ts +0 -1
- package/cjs/EntitySelector/components/ClearIndicator/ClearIndicator.test.js +0 -32
- package/cjs/EntitySelector/components/EntityOption/EntityOption.test.d.ts +0 -1
- package/cjs/EntitySelector/components/EntityOption/EntityOption.test.js +0 -84
- package/cjs/EntitySelector/components/Group/Group.test.d.ts +0 -1
- package/cjs/EntitySelector/components/Group/Group.test.js +0 -70
- package/cjs/EntitySelector/components/SingleValue/SingleValue.test.d.ts +0 -1
- package/cjs/EntitySelector/components/SingleValue/SingleValue.test.js +0 -83
- package/cjs/FilterValueEditor/components/RangeDataTypeValueEditor/RangeDataTypeValueEditor.test.d.ts +0 -1
- package/cjs/FilterValueEditor/components/RangeDataTypeValueEditor/RangeDataTypeValueEditor.test.js +0 -81
- package/cjs/contexts/CollaborationContext/CollaborationContextProvider.test.d.ts +0 -1
- package/cjs/contexts/CollaborationContext/CollaborationContextProvider.test.js +0 -104
- package/contexts/CollaborationContext/CollaborationContextProvider.test.d.ts +0 -1
- package/contexts/CollaborationContext/CollaborationContextProvider.test.js +0 -99
- /package/{AttributesFiltersBuilder/components/AttributeSelector/AttributeSelector.test.d.ts → EditModeAttributesFactory/EditModeAttributesFactory.test.d.ts} +0 -0
- /package/{AttributesFiltersBuilder/components/RowActions/RowActions.test.d.ts → cjs/EditModeAttributesFactory/EditModeAttributesFactory.test.d.ts} +0 -0
|
@@ -51,285 +51,112 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
var react_1 = __importDefault(require("react"));
|
|
54
|
-
var enzyme_1 = require("enzyme");
|
|
55
|
-
var test_utils_1 = require("react-dom/test-utils");
|
|
56
54
|
var mdm_sdk_1 = require("@reltio/mdm-sdk");
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
var ReactSelectOptionWithCheckIcon_1 = require("../ReactSelectOptionWithCheckIcon");
|
|
60
|
-
var helpers_1 = require("./helpers");
|
|
55
|
+
var react_2 = require("@testing-library/react");
|
|
56
|
+
var user_event_1 = __importDefault(require("@testing-library/user-event"));
|
|
61
57
|
var DependentLookupEditor_1 = require("./DependentLookupEditor");
|
|
62
|
-
|
|
58
|
+
var DependentLookupAutopopulationContext_1 = require("../contexts/DependentLookupAutopopulationContext");
|
|
63
59
|
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { debounce: jest.fn() })); });
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
var allLookups = {
|
|
61
|
+
AR: { displayName: 'Argentina' },
|
|
62
|
+
BG: { displayName: 'Bulgaria' },
|
|
63
|
+
CN: { displayName: 'China' },
|
|
64
|
+
PT: { displayName: 'Portugal' }
|
|
65
|
+
};
|
|
66
|
+
var defaultProps = {
|
|
67
|
+
value: { value: 'Portugal', lookupCode: 'PT' },
|
|
68
|
+
lookups: { COUNTRY_CD: { PT: { displayName: 'Portugal' } } },
|
|
69
|
+
lookupCode: 'COUNTRY_CD',
|
|
70
|
+
error: false,
|
|
71
|
+
parents: [],
|
|
72
|
+
disabled: false,
|
|
73
|
+
placeholder: '',
|
|
74
|
+
TextFieldProps: {},
|
|
75
|
+
onChange: jest.fn(),
|
|
76
|
+
resolveLookups: jest.fn(),
|
|
77
|
+
getLookups: jest.fn().mockResolvedValue(allLookups)
|
|
78
|
+
};
|
|
79
|
+
var setUp = function (_a) {
|
|
80
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.props, props = _c === void 0 ? defaultProps : _c, _d = _b.CustomProviders, CustomProviders = _d === void 0 ? react_1.default.Fragment : _d;
|
|
81
|
+
var user = user_event_1.default.setup();
|
|
82
|
+
var Providers = function (_a) {
|
|
83
|
+
var children = _a.children;
|
|
84
|
+
return react_1.default.createElement(CustomProviders, null, children);
|
|
85
|
+
};
|
|
86
|
+
var result = (0, react_2.render)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props)), { wrapper: Providers });
|
|
87
|
+
var rerender = function (newProps) { return result.rerender(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, newProps))); };
|
|
88
|
+
return __assign(__assign({ user: user }, result), { rerender: rerender });
|
|
89
|
+
};
|
|
90
|
+
describe('Dependent lookup editor tests', function () {
|
|
68
91
|
beforeEach(function () {
|
|
69
|
-
mdm_sdk_1.debounce.mockImplementation(
|
|
70
|
-
var requestPromise = new Promise(function (_resolve) {
|
|
71
|
-
resolveOptions = _resolve;
|
|
72
|
-
});
|
|
73
|
-
props = {
|
|
74
|
-
lookupCode: 'COUNTRY_CD',
|
|
75
|
-
getLookups: jest.fn(function (_, __, ___) { return requestPromise; }),
|
|
76
|
-
onChange: jest.fn(),
|
|
77
|
-
parents: [],
|
|
78
|
-
lookups: {},
|
|
79
|
-
resolveLookups: jest.fn()
|
|
80
|
-
};
|
|
81
|
-
props2 = {
|
|
82
|
-
lookupCode: 'COUNTRY_CD',
|
|
83
|
-
getLookups: jest.fn(function (_, __, ___) { return requestPromise; }),
|
|
84
|
-
onChange: jest.fn(),
|
|
85
|
-
parents: [],
|
|
86
|
-
lookups: {},
|
|
87
|
-
resolveLookups: jest.fn(),
|
|
88
|
-
disabled: false
|
|
89
|
-
};
|
|
92
|
+
mdm_sdk_1.debounce.mockImplementation(function (val) { return val; });
|
|
90
93
|
});
|
|
91
94
|
afterEach(function () {
|
|
92
95
|
jest.clearAllMocks();
|
|
93
96
|
});
|
|
94
|
-
it('should render
|
|
95
|
-
var
|
|
96
|
-
var multiple = false;
|
|
97
|
-
var placeholder = '123';
|
|
98
|
-
var wrapper = (0, enzyme_1.shallow)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { multiple: multiple, value: value, placeholder: placeholder })));
|
|
99
|
-
var select = wrapper.find(ReactSelect_1.ReactSelect);
|
|
100
|
-
expect(select.props()).toMatchObject({
|
|
101
|
-
isMulti: multiple,
|
|
102
|
-
value: value,
|
|
103
|
-
placeholder: placeholder
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
it('should render ReactSelect with correct properties in multiple mode', function () {
|
|
107
|
-
var value = [
|
|
108
|
-
{ lookupCode: 'RU', value: 'Russia' },
|
|
109
|
-
{ lookupCode: 'CN', value: 'China' }
|
|
110
|
-
];
|
|
111
|
-
var multiple = true;
|
|
112
|
-
var placeholder = '123';
|
|
113
|
-
var wrapper = (0, enzyme_1.shallow)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { multiple: multiple, value: value, placeholder: placeholder })));
|
|
114
|
-
var select = wrapper.find(ReactSelect_1.ReactSelect);
|
|
115
|
-
expect(select.props()).toMatchObject({
|
|
116
|
-
isMulti: multiple,
|
|
117
|
-
value: value,
|
|
118
|
-
placeholder: placeholder
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
it('should reset inputValue and options on input blur in multiple mode', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
122
|
-
var value, wrapper, newInputValue;
|
|
123
|
-
return __generator(this, function (_a) {
|
|
124
|
-
value = [
|
|
125
|
-
{ lookupCode: 'RU', value: 'Russia' },
|
|
126
|
-
{ lookupCode: 'CN', value: 'China' }
|
|
127
|
-
];
|
|
128
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { value: value, multiple: true })));
|
|
129
|
-
newInputValue = 'u';
|
|
130
|
-
(0, test_utils_1.act)(function () {
|
|
131
|
-
wrapper.find(ReactSelect_1.ReactSelect).prop('onInputChange')(newInputValue, { action: 'input-change' });
|
|
132
|
-
});
|
|
133
|
-
wrapper.update();
|
|
134
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe(newInputValue);
|
|
135
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
136
|
-
expect(props.getLookups).toHaveBeenCalledWith({
|
|
137
|
-
type: 'COUNTRY_CD',
|
|
138
|
-
parents: [],
|
|
139
|
-
displayNamePrefix: newInputValue,
|
|
140
|
-
max: 51,
|
|
141
|
-
offset: 0
|
|
142
|
-
});
|
|
143
|
-
(0, test_utils_1.act)(function () {
|
|
144
|
-
wrapper.find(ReactSelect_1.ReactSelect).prop('onInputChange')('', { action: 'input-blur' });
|
|
145
|
-
});
|
|
146
|
-
wrapper.update();
|
|
147
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe('');
|
|
148
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
149
|
-
expect(props.getLookups).toHaveBeenCalledWith({
|
|
150
|
-
type: 'COUNTRY_CD',
|
|
151
|
-
parents: [],
|
|
152
|
-
displayNamePrefix: '',
|
|
153
|
-
max: 51,
|
|
154
|
-
offset: 0
|
|
155
|
-
});
|
|
156
|
-
return [2 /*return*/];
|
|
157
|
-
});
|
|
158
|
-
}); });
|
|
159
|
-
it('should not reset inputValue on menu-close in multiple mode', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
160
|
-
var value, wrapper, newInputValue;
|
|
161
|
-
return __generator(this, function (_a) {
|
|
162
|
-
value = [
|
|
163
|
-
{ lookupCode: 'RU', value: 'Russia' },
|
|
164
|
-
{ lookupCode: 'CN', value: 'China' }
|
|
165
|
-
];
|
|
166
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { value: value, multiple: true })));
|
|
167
|
-
newInputValue = 'u';
|
|
168
|
-
(0, test_utils_1.act)(function () {
|
|
169
|
-
wrapper.find(ReactSelect_1.ReactSelect).prop('onInputChange')(newInputValue, { action: 'input-change' });
|
|
170
|
-
});
|
|
171
|
-
wrapper.update();
|
|
172
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe(newInputValue);
|
|
173
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
174
|
-
(0, test_utils_1.act)(function () {
|
|
175
|
-
wrapper.find(ReactSelect_1.ReactSelect).prop('onInputChange')('', { action: 'menu-close' });
|
|
176
|
-
});
|
|
177
|
-
wrapper.update();
|
|
178
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe('u');
|
|
179
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
180
|
-
return [2 /*return*/];
|
|
181
|
-
});
|
|
182
|
-
}); });
|
|
183
|
-
it('should set inputValue as value property on input blur, if inputValue is not empty', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
184
|
-
var value, wrapper, newInputValue;
|
|
185
|
-
return __generator(this, function (_a) {
|
|
186
|
-
value = { lookupCode: 'RU', value: 'Russia' };
|
|
187
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { value: value, multiple: false })));
|
|
188
|
-
newInputValue = 'u';
|
|
189
|
-
(0, test_utils_1.act)(function () {
|
|
190
|
-
wrapper.find(ReactSelect_1.ReactSelect).prop('onInputChange')(newInputValue, { action: 'input-change' });
|
|
191
|
-
});
|
|
192
|
-
wrapper.update();
|
|
193
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe(newInputValue);
|
|
194
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
195
|
-
expect(props.getLookups).toHaveBeenCalledWith({
|
|
196
|
-
type: 'COUNTRY_CD',
|
|
197
|
-
parents: [],
|
|
198
|
-
displayNamePrefix: newInputValue,
|
|
199
|
-
max: 51,
|
|
200
|
-
offset: 0
|
|
201
|
-
});
|
|
202
|
-
(0, test_utils_1.act)(function () {
|
|
203
|
-
wrapper.find(ReactSelect_1.ReactSelect).prop('onInputChange')('', { action: 'input-blur' });
|
|
204
|
-
});
|
|
205
|
-
wrapper.update();
|
|
206
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe((0, helpers_1.getOptionLabel)(value));
|
|
207
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
208
|
-
expect(props.getLookups).toHaveBeenCalledWith({
|
|
209
|
-
type: 'COUNTRY_CD',
|
|
210
|
-
parents: [],
|
|
211
|
-
displayNamePrefix: '',
|
|
212
|
-
max: 51,
|
|
213
|
-
offset: 0
|
|
214
|
-
});
|
|
215
|
-
return [2 /*return*/];
|
|
216
|
-
});
|
|
217
|
-
}); });
|
|
218
|
-
it('should set inputValue as value property on menu close, if inputValue is not empty', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
219
|
-
var value, wrapper, newInputValue;
|
|
220
|
-
return __generator(this, function (_a) {
|
|
221
|
-
value = { lookupCode: 'RU', value: 'Russia' };
|
|
222
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { value: value, multiple: false })));
|
|
223
|
-
newInputValue = 'u';
|
|
224
|
-
(0, test_utils_1.act)(function () {
|
|
225
|
-
wrapper.find(ReactSelect_1.ReactSelect).prop('onInputChange')(newInputValue, { action: 'input-change' });
|
|
226
|
-
});
|
|
227
|
-
wrapper.update();
|
|
228
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe(newInputValue);
|
|
229
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
230
|
-
expect(props.getLookups).toHaveBeenCalledWith({
|
|
231
|
-
type: 'COUNTRY_CD',
|
|
232
|
-
parents: [],
|
|
233
|
-
displayNamePrefix: newInputValue,
|
|
234
|
-
max: 51,
|
|
235
|
-
offset: 0
|
|
236
|
-
});
|
|
237
|
-
(0, test_utils_1.act)(function () {
|
|
238
|
-
wrapper.find(ReactSelect_1.ReactSelect).prop('onInputChange')('', { action: 'menu-close' });
|
|
239
|
-
});
|
|
240
|
-
wrapper.update();
|
|
241
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe((0, helpers_1.getOptionLabel)(value));
|
|
242
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
243
|
-
expect(props.getLookups).toHaveBeenCalledWith({
|
|
244
|
-
type: 'COUNTRY_CD',
|
|
245
|
-
parents: [],
|
|
246
|
-
displayNamePrefix: '',
|
|
247
|
-
max: 51,
|
|
248
|
-
offset: 0
|
|
249
|
-
});
|
|
250
|
-
return [2 /*return*/];
|
|
251
|
-
});
|
|
252
|
-
}); });
|
|
253
|
-
var findLoadMoreButton = function (component) {
|
|
254
|
-
var menuListFooter = component.find(ReactSelect_1.ReactSelect).prop('menuListFooter');
|
|
255
|
-
if (menuListFooter) {
|
|
256
|
-
return new enzyme_1.ReactWrapper(menuListFooter);
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
it('should not render menuListFooter if options number is less or equal to max value', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
260
|
-
var wrapper;
|
|
97
|
+
it('should render correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
+
var user, options;
|
|
261
99
|
return __generator(this, function (_a) {
|
|
262
100
|
switch (_a.label) {
|
|
263
101
|
case 0:
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
102
|
+
user = setUp().user;
|
|
103
|
+
expect(react_2.screen.getByRole('combobox')).toHaveValue('Portugal (PT)');
|
|
104
|
+
expect(defaultProps.getLookups).toHaveBeenCalledWith({
|
|
105
|
+
type: defaultProps.lookupCode,
|
|
106
|
+
parents: defaultProps.parents,
|
|
107
|
+
displayNamePrefix: '',
|
|
108
|
+
max: 51,
|
|
109
|
+
offset: 0
|
|
110
|
+
});
|
|
111
|
+
return [4 /*yield*/, user.click(react_2.screen.getByRole('combobox'))];
|
|
274
112
|
case 1:
|
|
275
113
|
_a.sent();
|
|
276
|
-
|
|
277
|
-
expect(
|
|
278
|
-
expect(
|
|
114
|
+
options = react_2.screen.getAllByRole('option');
|
|
115
|
+
expect(options).toHaveLength(4);
|
|
116
|
+
expect(options[0]).toHaveTextContent('Argentina (AR)');
|
|
117
|
+
expect(options[1]).toHaveTextContent('Bulgaria (BG)');
|
|
118
|
+
expect(options[2]).toHaveTextContent('China (CN)');
|
|
119
|
+
expect(options[3]).toHaveTextContent('Portugal (PT)');
|
|
279
120
|
return [2 /*return*/];
|
|
280
121
|
}
|
|
281
122
|
});
|
|
282
123
|
}); });
|
|
283
|
-
it('should render
|
|
284
|
-
var
|
|
124
|
+
it('should render correctly in multiple mode', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
+
var value, props;
|
|
285
126
|
return __generator(this, function (_a) {
|
|
286
127
|
switch (_a.label) {
|
|
287
128
|
case 0:
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
129
|
+
value = [
|
|
130
|
+
{ value: 'Portugal', lookupCode: 'PT' },
|
|
131
|
+
{ lookupCode: 'CN', value: 'China' }
|
|
132
|
+
];
|
|
133
|
+
props = __assign(__assign({}, defaultProps), { value: value, multiple: true });
|
|
134
|
+
setUp({ props: props });
|
|
135
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
291
136
|
return __generator(this, function (_a) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
139
|
+
case 1:
|
|
140
|
+
_a.sent();
|
|
141
|
+
return [2 /*return*/];
|
|
142
|
+
}
|
|
298
143
|
});
|
|
299
144
|
}); })];
|
|
300
145
|
case 1:
|
|
301
146
|
_a.sent();
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
expect(optionsProp[0].value).toBe('China');
|
|
306
|
-
expect(optionsProp[1].value).toBe('Portugal');
|
|
307
|
-
wrapper.find('input').simulate('keyDown', { key: 'ArrowDown' });
|
|
308
|
-
options = wrapper.find(ReactSelectOptionWithCheckIcon_1.ReactSelectOptionWithCheckIcon);
|
|
309
|
-
expect(options.length).toBe(2);
|
|
310
|
-
expect(options.at(0).text()).toBe('China (CN)');
|
|
311
|
-
expect(options.at(1).text()).toBe('Portugal (PT)');
|
|
312
|
-
loadMoreButton = findLoadMoreButton(wrapper);
|
|
313
|
-
expect(loadMoreButton.length).toBe(1);
|
|
314
|
-
expect(loadMoreButton.text()).toEqual('Load more');
|
|
147
|
+
expect(react_2.screen.getByRole('combobox')).toHaveValue('');
|
|
148
|
+
react_2.screen.getByText('Portugal (PT)');
|
|
149
|
+
react_2.screen.getByText('China (CN)');
|
|
315
150
|
return [2 /*return*/];
|
|
316
151
|
}
|
|
317
152
|
});
|
|
318
153
|
}); });
|
|
319
|
-
it('should
|
|
320
|
-
var getLookups, value, wrapper;
|
|
154
|
+
it('should show input value when select is disabled', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
321
155
|
return __generator(this, function (_a) {
|
|
322
156
|
switch (_a.label) {
|
|
323
157
|
case 0:
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
CN: { displayName: 'China' },
|
|
327
|
-
PT: { displayName: 'Portugal' },
|
|
328
|
-
RU: { displayName: 'Russia' }
|
|
329
|
-
}));
|
|
330
|
-
value = { lookupCode: 'US', value: 'USA' };
|
|
331
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { value: value, getLookups: getLookups, max: 2 })));
|
|
332
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
158
|
+
setUp({ props: __assign(__assign({}, defaultProps), { disabled: true }) });
|
|
159
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
333
160
|
return __generator(this, function (_a) {
|
|
334
161
|
switch (_a.label) {
|
|
335
162
|
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
@@ -341,177 +168,260 @@ describe('DependentLookupEditor', function () {
|
|
|
341
168
|
}); })];
|
|
342
169
|
case 1:
|
|
343
170
|
_a.sent();
|
|
344
|
-
|
|
345
|
-
expect(
|
|
346
|
-
expect(
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
171
|
+
expect(react_2.screen.getByRole('combobox')).toHaveValue('Portugal (PT)');
|
|
172
|
+
expect(react_2.screen.getByRole('combobox')).toHaveAttribute('disabled');
|
|
173
|
+
expect(react_2.screen.getByRole('combobox')).toBeVisible();
|
|
174
|
+
return [2 /*return*/];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}); });
|
|
178
|
+
it('should reset inputValue and options on input blur in multiple mode', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
179
|
+
var value, props, _a, user, container, input;
|
|
180
|
+
return __generator(this, function (_b) {
|
|
181
|
+
switch (_b.label) {
|
|
182
|
+
case 0:
|
|
183
|
+
value = [
|
|
184
|
+
{ value: 'Portugal', lookupCode: 'PT' },
|
|
185
|
+
{ lookupCode: 'CN', value: 'China' }
|
|
186
|
+
];
|
|
187
|
+
props = __assign(__assign({}, defaultProps), { value: value, multiple: true });
|
|
188
|
+
_a = setUp({ props: props }), user = _a.user, container = _a.container;
|
|
189
|
+
input = react_2.screen.getByRole('combobox');
|
|
190
|
+
return [4 /*yield*/, user.type(input, 'u')];
|
|
191
|
+
case 1:
|
|
192
|
+
_b.sent();
|
|
193
|
+
expect(input).toHaveValue('u');
|
|
194
|
+
expect(props.onChange).not.toHaveBeenCalled();
|
|
195
|
+
expect(props.getLookups).toHaveBeenCalledWith({
|
|
196
|
+
type: 'COUNTRY_CD',
|
|
197
|
+
parents: [],
|
|
198
|
+
displayNamePrefix: 'u',
|
|
199
|
+
max: 51,
|
|
200
|
+
offset: 0
|
|
201
|
+
});
|
|
202
|
+
return [4 /*yield*/, user.click(container)];
|
|
358
203
|
case 2:
|
|
204
|
+
_b.sent();
|
|
205
|
+
expect(input).toHaveValue('');
|
|
206
|
+
expect(props.onChange).not.toHaveBeenCalled();
|
|
207
|
+
expect(props.getLookups).toHaveBeenCalledWith({
|
|
208
|
+
type: 'COUNTRY_CD',
|
|
209
|
+
parents: [],
|
|
210
|
+
displayNamePrefix: '',
|
|
211
|
+
max: 51,
|
|
212
|
+
offset: 0
|
|
213
|
+
});
|
|
214
|
+
return [2 /*return*/];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}); });
|
|
218
|
+
it('should not reset inputValue on menu-close in multiple mode', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
219
|
+
var value, props, user, input;
|
|
220
|
+
return __generator(this, function (_a) {
|
|
221
|
+
switch (_a.label) {
|
|
222
|
+
case 0:
|
|
223
|
+
value = [
|
|
224
|
+
{ value: 'Portugal', lookupCode: 'PT' },
|
|
225
|
+
{ lookupCode: 'CN', value: 'China' }
|
|
226
|
+
];
|
|
227
|
+
props = __assign(__assign({}, defaultProps), { value: value, multiple: true });
|
|
228
|
+
user = setUp({ props: props }).user;
|
|
229
|
+
input = react_2.screen.getByRole('combobox');
|
|
230
|
+
return [4 /*yield*/, user.type(input, 'u')];
|
|
231
|
+
case 1:
|
|
359
232
|
_a.sent();
|
|
360
|
-
|
|
361
|
-
expect(
|
|
362
|
-
|
|
363
|
-
|
|
233
|
+
expect(input).toHaveValue('u');
|
|
234
|
+
expect(props.onChange).not.toHaveBeenCalled();
|
|
235
|
+
return [4 /*yield*/, user.keyboard('{Escape}')];
|
|
236
|
+
case 2:
|
|
237
|
+
_a.sent();
|
|
238
|
+
expect(input).toHaveValue('u');
|
|
239
|
+
expect(props.onChange).not.toHaveBeenCalled();
|
|
240
|
+
return [2 /*return*/];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}); });
|
|
244
|
+
it('should set inputValue as value property on input blur, if inputValue is not empty', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
245
|
+
var _a, user, container, input;
|
|
246
|
+
return __generator(this, function (_b) {
|
|
247
|
+
switch (_b.label) {
|
|
248
|
+
case 0:
|
|
249
|
+
_a = setUp(), user = _a.user, container = _a.container;
|
|
250
|
+
input = react_2.screen.getByRole('combobox');
|
|
251
|
+
return [4 /*yield*/, user.type(input, 'u')];
|
|
252
|
+
case 1:
|
|
253
|
+
_b.sent();
|
|
254
|
+
expect(input).toHaveValue('Portugal (PT)u');
|
|
255
|
+
expect(defaultProps.onChange).not.toHaveBeenCalled();
|
|
256
|
+
expect(defaultProps.getLookups).toHaveBeenCalledWith({
|
|
257
|
+
type: 'COUNTRY_CD',
|
|
258
|
+
parents: [],
|
|
259
|
+
displayNamePrefix: 'Portugal (PT)u',
|
|
260
|
+
max: 51,
|
|
261
|
+
offset: 0
|
|
262
|
+
});
|
|
263
|
+
return [4 /*yield*/, user.click(container)];
|
|
264
|
+
case 2:
|
|
265
|
+
_b.sent();
|
|
266
|
+
expect(input).toHaveValue('Portugal (PT)');
|
|
267
|
+
expect(defaultProps.onChange).not.toHaveBeenCalled();
|
|
268
|
+
expect(defaultProps.getLookups).toHaveBeenLastCalledWith({
|
|
269
|
+
type: 'COUNTRY_CD',
|
|
270
|
+
parents: [],
|
|
364
271
|
displayNamePrefix: '',
|
|
365
|
-
max:
|
|
366
|
-
offset:
|
|
272
|
+
max: 51,
|
|
273
|
+
offset: 0
|
|
367
274
|
});
|
|
368
|
-
wrapper.update();
|
|
369
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).prop('options').length).toBe(4);
|
|
370
|
-
expect(findLoadMoreButton(wrapper).exists()).toBeTruthy();
|
|
371
275
|
return [2 /*return*/];
|
|
372
276
|
}
|
|
373
277
|
});
|
|
374
278
|
}); });
|
|
375
|
-
it('should
|
|
376
|
-
var
|
|
279
|
+
it('should set inputValue as value property on menu close, if inputValue is not empty', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
280
|
+
var user, input;
|
|
377
281
|
return __generator(this, function (_a) {
|
|
378
282
|
switch (_a.label) {
|
|
379
283
|
case 0:
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
PT: { displayName: 'Portugal' },
|
|
384
|
-
RU: { displayName: 'Russia' }
|
|
385
|
-
}));
|
|
386
|
-
value = { lookupCode: 'US', value: 'USA' };
|
|
387
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { value: value, getLookups: getLookups, max: 2 })));
|
|
388
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
389
|
-
return __generator(this, function (_a) {
|
|
390
|
-
switch (_a.label) {
|
|
391
|
-
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
392
|
-
case 1:
|
|
393
|
-
_a.sent();
|
|
394
|
-
return [2 /*return*/];
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
}); })];
|
|
284
|
+
user = setUp().user;
|
|
285
|
+
input = react_2.screen.getByRole('combobox');
|
|
286
|
+
return [4 /*yield*/, user.type(input, 'u')];
|
|
398
287
|
case 1:
|
|
399
288
|
_a.sent();
|
|
400
|
-
|
|
401
|
-
expect(
|
|
402
|
-
expect(
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
findLoadMoreButton(wrapper).find('button').simulate('click');
|
|
411
|
-
return [2 /*return*/];
|
|
412
|
-
});
|
|
413
|
-
}); })];
|
|
289
|
+
expect(input).toHaveValue('Portugal (PT)u');
|
|
290
|
+
expect(defaultProps.onChange).not.toHaveBeenCalled();
|
|
291
|
+
expect(defaultProps.getLookups).toHaveBeenCalledWith({
|
|
292
|
+
type: 'COUNTRY_CD',
|
|
293
|
+
parents: [],
|
|
294
|
+
displayNamePrefix: 'Portugal (PT)u',
|
|
295
|
+
max: 51,
|
|
296
|
+
offset: 0
|
|
297
|
+
});
|
|
298
|
+
return [4 /*yield*/, user.keyboard('{Escape}')];
|
|
414
299
|
case 2:
|
|
415
300
|
_a.sent();
|
|
416
|
-
|
|
417
|
-
expect(
|
|
418
|
-
expect(
|
|
301
|
+
expect(input).toHaveValue('Portugal (PT)');
|
|
302
|
+
expect(defaultProps.onChange).not.toHaveBeenCalled();
|
|
303
|
+
expect(defaultProps.getLookups).toHaveBeenLastCalledWith({
|
|
304
|
+
type: 'COUNTRY_CD',
|
|
305
|
+
parents: [],
|
|
306
|
+
displayNamePrefix: '',
|
|
307
|
+
max: 51,
|
|
308
|
+
offset: 0
|
|
309
|
+
});
|
|
419
310
|
return [2 /*return*/];
|
|
420
311
|
}
|
|
421
312
|
});
|
|
422
313
|
}); });
|
|
423
|
-
it('should not
|
|
424
|
-
var
|
|
314
|
+
it('should not render menu list footer if options number is less or equal to max value', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
315
|
+
var props, user;
|
|
425
316
|
return __generator(this, function (_a) {
|
|
426
317
|
switch (_a.label) {
|
|
427
318
|
case 0:
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
resolveOptions({
|
|
432
|
-
PT: { displayName: 'Portugal' },
|
|
433
|
-
RU: { displayName: 'Russia' }
|
|
434
|
-
});
|
|
435
|
-
return [2 /*return*/];
|
|
436
|
-
});
|
|
437
|
-
}); })];
|
|
319
|
+
props = __assign(__assign({}, defaultProps), { max: 2, getLookups: jest.fn().mockResolvedValue({ CN: { displayName: 'China' }, PT: { displayName: 'Portugal' } }) });
|
|
320
|
+
user = setUp({ props: props }).user;
|
|
321
|
+
return [4 /*yield*/, user.click(react_2.screen.getByRole('combobox'))];
|
|
438
322
|
case 1:
|
|
439
323
|
_a.sent();
|
|
440
|
-
|
|
324
|
+
expect(react_2.screen.queryByText('Load more')).not.toBeInTheDocument();
|
|
441
325
|
return [2 /*return*/];
|
|
442
326
|
}
|
|
443
327
|
});
|
|
444
328
|
}); });
|
|
445
|
-
it('should render
|
|
446
|
-
var
|
|
329
|
+
it('should render menu list footer with load more button if there are more options available', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
330
|
+
var props, user;
|
|
447
331
|
return __generator(this, function (_a) {
|
|
448
332
|
switch (_a.label) {
|
|
449
333
|
case 0:
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
resolveOptions({
|
|
454
|
-
CN: { displayName: 'China' },
|
|
455
|
-
RU: { displayName: 'Russia' }
|
|
456
|
-
});
|
|
457
|
-
return [2 /*return*/];
|
|
458
|
-
});
|
|
459
|
-
}); })];
|
|
334
|
+
props = __assign(__assign({}, defaultProps), { max: 2 });
|
|
335
|
+
user = setUp({ props: props }).user;
|
|
336
|
+
return [4 /*yield*/, user.click(react_2.screen.getByRole('combobox'))];
|
|
460
337
|
case 1:
|
|
461
338
|
_a.sent();
|
|
462
|
-
|
|
463
|
-
options = wrapper.find(ReactSelectOptionWithCheckIcon_1.ReactSelectOptionWithCheckIcon);
|
|
464
|
-
expect(options.length).toBe(2);
|
|
465
|
-
expect(options.at(0).text()).toBe('China (CN)');
|
|
466
|
-
expect(options.at(1).text()).toBe('Russia (RU)');
|
|
339
|
+
react_2.screen.getByText('Load more');
|
|
467
340
|
return [2 /*return*/];
|
|
468
341
|
}
|
|
469
342
|
});
|
|
470
343
|
}); });
|
|
471
|
-
it('should
|
|
472
|
-
var
|
|
344
|
+
it('should load next options page on load more button click, button should exist if not all options are loaded', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
345
|
+
var props, user, options;
|
|
473
346
|
return __generator(this, function (_a) {
|
|
474
347
|
switch (_a.label) {
|
|
475
348
|
case 0:
|
|
476
|
-
|
|
477
|
-
|
|
349
|
+
props = __assign(__assign({}, defaultProps), { max: 2, getLookups: jest.fn().mockResolvedValue(allLookups) });
|
|
350
|
+
user = setUp({ props: props }).user;
|
|
351
|
+
return [4 /*yield*/, user.click(react_2.screen.getByRole('combobox'))];
|
|
352
|
+
case 1:
|
|
353
|
+
_a.sent();
|
|
354
|
+
options = react_2.screen.getAllByRole('option');
|
|
355
|
+
expect(options).toHaveLength(2);
|
|
356
|
+
expect(options[0]).toHaveTextContent('Argentina (AR)');
|
|
357
|
+
expect(options[1]).toHaveTextContent('Bulgaria (BG)');
|
|
358
|
+
props.getLookups.mockResolvedValue({
|
|
359
|
+
RU: { displayName: 'Russia' },
|
|
360
|
+
USA: { displayName: 'USA' },
|
|
361
|
+
MEX: { displayName: 'MEXICO' }
|
|
362
|
+
});
|
|
363
|
+
return [4 /*yield*/, user.click(react_2.screen.getByText('Load more'))];
|
|
364
|
+
case 2:
|
|
365
|
+
_a.sent();
|
|
478
366
|
expect(props.getLookups).toHaveBeenCalledWith({
|
|
479
367
|
type: props.lookupCode,
|
|
480
368
|
parents: props.parents,
|
|
481
369
|
displayNamePrefix: '',
|
|
482
|
-
max:
|
|
483
|
-
offset:
|
|
370
|
+
max: 3,
|
|
371
|
+
offset: 2
|
|
484
372
|
});
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
373
|
+
options = react_2.screen.getAllByRole('option');
|
|
374
|
+
expect(options).toHaveLength(4);
|
|
375
|
+
expect(options[0]).toHaveTextContent('Argentina (AR)');
|
|
376
|
+
expect(options[1]).toHaveTextContent('Bulgaria (BG)');
|
|
377
|
+
expect(options[2]).toHaveTextContent('MEXICO (MEX)');
|
|
378
|
+
expect(options[3]).toHaveTextContent('Russia (RU)');
|
|
379
|
+
react_2.screen.getByText('Load more');
|
|
380
|
+
return [2 /*return*/];
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}); });
|
|
384
|
+
it('should load next options page on load more button click, load more button disappears if all options loaded', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
385
|
+
var props, user, options;
|
|
386
|
+
return __generator(this, function (_a) {
|
|
387
|
+
switch (_a.label) {
|
|
388
|
+
case 0:
|
|
389
|
+
props = __assign(__assign({}, defaultProps), { max: 2, getLookups: jest.fn().mockResolvedValue(allLookups) });
|
|
390
|
+
user = setUp({ props: props }).user;
|
|
391
|
+
return [4 /*yield*/, user.click(react_2.screen.getByRole('combobox'))];
|
|
494
392
|
case 1:
|
|
495
393
|
_a.sent();
|
|
496
|
-
|
|
497
|
-
expect(
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
394
|
+
options = react_2.screen.getAllByRole('option');
|
|
395
|
+
expect(options).toHaveLength(2);
|
|
396
|
+
expect(options[0]).toHaveTextContent('Argentina (AR)');
|
|
397
|
+
expect(options[1]).toHaveTextContent('Bulgaria (BG)');
|
|
398
|
+
props.getLookups.mockResolvedValue({ RU: { displayName: 'Russia' }, USA: { displayName: 'USA' } });
|
|
399
|
+
return [4 /*yield*/, user.click(react_2.screen.getByText('Load more'))];
|
|
400
|
+
case 2:
|
|
401
|
+
_a.sent();
|
|
402
|
+
options = react_2.screen.getAllByRole('option');
|
|
403
|
+
expect(options).toHaveLength(4);
|
|
404
|
+
expect(options[0]).toHaveTextContent('Argentina (AR)');
|
|
405
|
+
expect(options[1]).toHaveTextContent('Bulgaria (BG)');
|
|
406
|
+
expect(options[2]).toHaveTextContent('Russia (RU)');
|
|
407
|
+
expect(options[3]).toHaveTextContent('USA');
|
|
408
|
+
expect(react_2.screen.queryByText('Load more')).not.toBeInTheDocument();
|
|
501
409
|
return [2 /*return*/];
|
|
502
410
|
}
|
|
503
411
|
});
|
|
504
412
|
}); });
|
|
505
413
|
it('should request default options on props.lookupCode change', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
506
|
-
var
|
|
507
|
-
return __generator(this, function (
|
|
508
|
-
switch (
|
|
414
|
+
var props, _a, user, rerender, options;
|
|
415
|
+
return __generator(this, function (_b) {
|
|
416
|
+
switch (_b.label) {
|
|
509
417
|
case 0:
|
|
510
|
-
|
|
418
|
+
props = __assign(__assign({}, defaultProps), { getLookups: jest.fn().mockResolvedValue(allLookups) });
|
|
419
|
+
_a = setUp({ props: props }), user = _a.user, rerender = _a.rerender;
|
|
511
420
|
props.getLookups.mockClear();
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
421
|
+
props.getLookups
|
|
422
|
+
.mockClear()
|
|
423
|
+
.mockResolvedValue({ GERO: { displayName: 'Gerontology' }, IMMU: { displayName: 'Immunology' } });
|
|
424
|
+
rerender({ lookupCode: 'SPEC' });
|
|
515
425
|
expect(props.getLookups).toHaveBeenCalledWith({
|
|
516
426
|
type: 'SPEC',
|
|
517
427
|
parents: [],
|
|
@@ -519,148 +429,72 @@ describe('DependentLookupEditor', function () {
|
|
|
519
429
|
max: 51,
|
|
520
430
|
offset: 0
|
|
521
431
|
});
|
|
522
|
-
return [4 /*yield*/, (
|
|
523
|
-
return __generator(this, function (_a) {
|
|
524
|
-
resolveOptions({
|
|
525
|
-
GERO: { displayName: 'Gerontology' },
|
|
526
|
-
IMMU: { displayName: 'Immunology' }
|
|
527
|
-
});
|
|
528
|
-
return [2 /*return*/];
|
|
529
|
-
});
|
|
530
|
-
}); })];
|
|
432
|
+
return [4 /*yield*/, user.click(react_2.screen.getByRole('combobox'))];
|
|
531
433
|
case 1:
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
expect(
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
]);
|
|
434
|
+
_b.sent();
|
|
435
|
+
options = react_2.screen.getAllByRole('option');
|
|
436
|
+
expect(options).toHaveLength(2);
|
|
437
|
+
expect(options[0]).toHaveTextContent('Gerontology (GERO)');
|
|
438
|
+
expect(options[1]).toHaveTextContent('Immunology (IMMU)');
|
|
538
439
|
return [2 /*return*/];
|
|
539
440
|
}
|
|
540
441
|
});
|
|
541
442
|
}); });
|
|
542
443
|
it('should call props.onChange with correct value on option click', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
543
|
-
var
|
|
444
|
+
var user;
|
|
544
445
|
return __generator(this, function (_a) {
|
|
545
446
|
switch (_a.label) {
|
|
546
447
|
case 0:
|
|
547
|
-
|
|
548
|
-
return [4 /*yield*/, (
|
|
549
|
-
return __generator(this, function (_a) {
|
|
550
|
-
resolveOptions({
|
|
551
|
-
CN: { displayName: 'China' },
|
|
552
|
-
RU: { displayName: 'Russia' }
|
|
553
|
-
});
|
|
554
|
-
return [2 /*return*/];
|
|
555
|
-
});
|
|
556
|
-
}); })];
|
|
448
|
+
user = setUp().user;
|
|
449
|
+
return [4 /*yield*/, user.click(react_2.screen.getByRole('combobox'))];
|
|
557
450
|
case 1:
|
|
558
451
|
_a.sent();
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
wrapper.find(ReactSelectOptionWithCheckIcon_1.ReactSelectOptionWithCheckIcon).at(1).find('div').at(0).simulate('click');
|
|
562
|
-
expect(props.onChange).toHaveBeenCalledWith({
|
|
563
|
-
value: 'Russia',
|
|
564
|
-
lookupCode: 'RU'
|
|
565
|
-
});
|
|
566
|
-
return [2 /*return*/];
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
}); });
|
|
570
|
-
it('should call props.getLookups with correct values on select input change', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
571
|
-
var wrapper, newInputValue;
|
|
572
|
-
return __generator(this, function (_a) {
|
|
573
|
-
switch (_a.label) {
|
|
574
|
-
case 0:
|
|
575
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props)));
|
|
576
|
-
newInputValue = 'Ch';
|
|
577
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
578
|
-
return __generator(this, function (_a) {
|
|
579
|
-
wrapper.find('Select').prop('onInputChange')(newInputValue, { action: 'input-change' });
|
|
580
|
-
return [2 /*return*/];
|
|
581
|
-
});
|
|
582
|
-
}); })];
|
|
583
|
-
case 1:
|
|
452
|
+
return [4 /*yield*/, user.click(react_2.screen.getByText('Argentina (AR)'))];
|
|
453
|
+
case 2:
|
|
584
454
|
_a.sent();
|
|
585
|
-
expect(
|
|
586
|
-
type: props.lookupCode,
|
|
587
|
-
parents: props.parents,
|
|
588
|
-
displayNamePrefix: newInputValue,
|
|
589
|
-
max: 51,
|
|
590
|
-
offset: 0
|
|
591
|
-
});
|
|
455
|
+
expect(defaultProps.onChange).toHaveBeenCalledWith({ value: 'Argentina', lookupCode: 'AR' });
|
|
592
456
|
return [2 /*return*/];
|
|
593
457
|
}
|
|
594
458
|
});
|
|
595
459
|
}); });
|
|
596
460
|
it('should call props.getLookups with correct values on select input change and set offset to default', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
597
|
-
var
|
|
461
|
+
var props, user, input;
|
|
598
462
|
return __generator(this, function (_a) {
|
|
599
463
|
switch (_a.label) {
|
|
600
464
|
case 0:
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
RU: { displayName: 'Russia' }
|
|
606
|
-
}));
|
|
607
|
-
value = { lookupCode: 'US', value: 'USA' };
|
|
608
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { value: value, getLookups: getLookups, max: 2 })));
|
|
609
|
-
newInputValue = 'Ch';
|
|
610
|
-
(0, test_utils_1.act)(function () {
|
|
611
|
-
wrapper.find('Select').prop('onInputChange')(newInputValue, { action: 'input-change' });
|
|
612
|
-
});
|
|
613
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
614
|
-
return __generator(this, function (_a) {
|
|
615
|
-
switch (_a.label) {
|
|
616
|
-
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
617
|
-
case 1:
|
|
618
|
-
_a.sent();
|
|
619
|
-
return [2 /*return*/];
|
|
620
|
-
}
|
|
621
|
-
});
|
|
622
|
-
}); })];
|
|
465
|
+
props = __assign(__assign({}, defaultProps), { max: 2, getLookups: jest.fn().mockResolvedValue(allLookups) });
|
|
466
|
+
user = setUp({ props: props }).user;
|
|
467
|
+
input = react_2.screen.getByRole('combobox');
|
|
468
|
+
return [4 /*yield*/, user.type(input, 'Ch')];
|
|
623
469
|
case 1:
|
|
624
470
|
_a.sent();
|
|
625
|
-
|
|
626
|
-
expect(getLookups).toHaveBeenCalledWith({
|
|
471
|
+
expect(props.getLookups).toHaveBeenCalledWith({
|
|
627
472
|
type: props.lookupCode,
|
|
628
473
|
parents: props.parents,
|
|
629
|
-
displayNamePrefix:
|
|
474
|
+
displayNamePrefix: 'Portugal (PT)Ch',
|
|
630
475
|
max: 3,
|
|
631
476
|
offset: 0
|
|
632
477
|
});
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
RU: { displayName: 'Russia' },
|
|
636
|
-
USA: { displayName: 'USA' },
|
|
637
|
-
MEX: { displayName: 'MEXICO' }
|
|
638
|
-
}));
|
|
639
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
640
|
-
return __generator(this, function (_a) {
|
|
641
|
-
findLoadMoreButton(wrapper).find('button').simulate('click');
|
|
642
|
-
return [2 /*return*/];
|
|
643
|
-
});
|
|
644
|
-
}); })];
|
|
478
|
+
props.getLookups.mockReturnValue(Promise.resolve({ RU: { displayName: 'Russia' }, USA: { displayName: 'USA' }, MEX: { displayName: 'MEXICO' } }));
|
|
479
|
+
return [4 /*yield*/, user.click(react_2.screen.getByText('Load more'))];
|
|
645
480
|
case 2:
|
|
646
481
|
_a.sent();
|
|
647
482
|
// offset === max
|
|
648
|
-
expect(getLookups).toHaveBeenCalledWith({
|
|
483
|
+
expect(props.getLookups).toHaveBeenCalledWith({
|
|
649
484
|
type: props.lookupCode,
|
|
650
485
|
parents: props.parents,
|
|
651
|
-
displayNamePrefix:
|
|
486
|
+
displayNamePrefix: 'Portugal (PT)Ch',
|
|
652
487
|
max: 3,
|
|
653
488
|
offset: 2
|
|
654
489
|
});
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
});
|
|
490
|
+
return [4 /*yield*/, user.type(input, 'i')];
|
|
491
|
+
case 3:
|
|
492
|
+
_a.sent();
|
|
659
493
|
// set offset to default: 0
|
|
660
|
-
expect(getLookups).toHaveBeenCalledWith({
|
|
494
|
+
expect(props.getLookups).toHaveBeenCalledWith({
|
|
661
495
|
type: props.lookupCode,
|
|
662
496
|
parents: props.parents,
|
|
663
|
-
displayNamePrefix:
|
|
497
|
+
displayNamePrefix: 'Portugal (PT)Chi',
|
|
664
498
|
max: 3,
|
|
665
499
|
offset: 0
|
|
666
500
|
});
|
|
@@ -668,19 +502,71 @@ describe('DependentLookupEditor', function () {
|
|
|
668
502
|
}
|
|
669
503
|
});
|
|
670
504
|
}); });
|
|
671
|
-
it
|
|
672
|
-
var
|
|
505
|
+
it('should render empty state if there is no options', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
506
|
+
var props, user;
|
|
507
|
+
return __generator(this, function (_a) {
|
|
508
|
+
switch (_a.label) {
|
|
509
|
+
case 0:
|
|
510
|
+
props = __assign(__assign({}, defaultProps), { getLookups: jest.fn().mockReturnValue(Promise.resolve({})) });
|
|
511
|
+
user = setUp({ props: props }).user;
|
|
512
|
+
return [4 /*yield*/, user.click(react_2.screen.getByRole('combobox'))];
|
|
513
|
+
case 1:
|
|
514
|
+
_a.sent();
|
|
515
|
+
react_2.screen.getByText('No results found');
|
|
516
|
+
return [2 /*return*/];
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
}); });
|
|
520
|
+
it('should save focus on select after changing disable props', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
521
|
+
var _a, user, rerender, input;
|
|
522
|
+
return __generator(this, function (_b) {
|
|
523
|
+
switch (_b.label) {
|
|
524
|
+
case 0:
|
|
525
|
+
_a = setUp(), user = _a.user, rerender = _a.rerender;
|
|
526
|
+
input = react_2.screen.getByRole('combobox');
|
|
527
|
+
return [4 /*yield*/, user.click(input)];
|
|
528
|
+
case 1:
|
|
529
|
+
_b.sent();
|
|
530
|
+
rerender({ disabled: true });
|
|
531
|
+
expect(input).toHaveFocus();
|
|
532
|
+
rerender({ disabled: false });
|
|
533
|
+
expect(input).toHaveFocus();
|
|
534
|
+
return [2 /*return*/];
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}); });
|
|
538
|
+
it('should change inputValue, call onChange property to remove value property and call getLookups as well on input clear', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
539
|
+
var user, input;
|
|
540
|
+
return __generator(this, function (_a) {
|
|
541
|
+
switch (_a.label) {
|
|
542
|
+
case 0:
|
|
543
|
+
user = setUp().user;
|
|
544
|
+
input = react_2.screen.getByRole('combobox');
|
|
545
|
+
return [4 /*yield*/, user.clear(input)];
|
|
546
|
+
case 1:
|
|
547
|
+
_a.sent();
|
|
548
|
+
expect(input).toHaveValue('');
|
|
549
|
+
expect(defaultProps.onChange).toHaveBeenCalledWith('');
|
|
550
|
+
expect(defaultProps.getLookups).toHaveBeenCalledWith({
|
|
551
|
+
type: 'COUNTRY_CD',
|
|
552
|
+
parents: [],
|
|
553
|
+
displayNamePrefix: '',
|
|
554
|
+
max: 51,
|
|
555
|
+
offset: 0
|
|
556
|
+
});
|
|
557
|
+
return [2 /*return*/];
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
}); });
|
|
561
|
+
it('should call props.onChange if lookup is unresolved but has resolved value in lookups', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
562
|
+
var value, props;
|
|
673
563
|
return __generator(this, function (_a) {
|
|
674
564
|
switch (_a.label) {
|
|
675
565
|
case 0:
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
RU: { displayName: 'Russia' }
|
|
681
|
-
}));
|
|
682
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { getLookups: getLookups, max: 2 })));
|
|
683
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
566
|
+
value = { value: '', lookupCode: 'PT' };
|
|
567
|
+
props = __assign(__assign({}, defaultProps), { value: value });
|
|
568
|
+
setUp({ props: props });
|
|
569
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
684
570
|
return __generator(this, function (_a) {
|
|
685
571
|
switch (_a.label) {
|
|
686
572
|
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
@@ -692,355 +578,213 @@ describe('DependentLookupEditor', function () {
|
|
|
692
578
|
}); })];
|
|
693
579
|
case 1:
|
|
694
580
|
_a.sent();
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
581
|
+
expect(props.onChange).toHaveBeenCalledWith({ lookupCode: 'PT', value: 'Portugal' });
|
|
582
|
+
return [2 /*return*/];
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
}); });
|
|
586
|
+
it('should call props.resolveLookups if lookup is unresolved and has no resolved value in lookups', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
587
|
+
var value, props;
|
|
588
|
+
return __generator(this, function (_a) {
|
|
589
|
+
switch (_a.label) {
|
|
590
|
+
case 0:
|
|
591
|
+
value = { lookupCode: 'AR', value: '' };
|
|
592
|
+
props = __assign(__assign({}, defaultProps), { value: value });
|
|
593
|
+
setUp({ props: props });
|
|
594
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
710
595
|
return __generator(this, function (_a) {
|
|
711
|
-
|
|
712
|
-
|
|
596
|
+
switch (_a.label) {
|
|
597
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
598
|
+
case 1:
|
|
599
|
+
_a.sent();
|
|
600
|
+
return [2 /*return*/];
|
|
601
|
+
}
|
|
713
602
|
});
|
|
714
603
|
}); })];
|
|
715
|
-
case
|
|
604
|
+
case 1:
|
|
716
605
|
_a.sent();
|
|
717
|
-
expect(
|
|
718
|
-
type: props.lookupCode,
|
|
719
|
-
parents: props.parents,
|
|
720
|
-
displayNamePrefix: '',
|
|
721
|
-
max: 3,
|
|
722
|
-
offset: 2
|
|
723
|
-
});
|
|
724
|
-
newLookupCode = {
|
|
725
|
-
CODE: {
|
|
726
|
-
NC: {
|
|
727
|
-
displayName: 'some code'
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
wrapper.setProps({ lookupCode: newLookupCode });
|
|
732
|
-
// set offset to default: 0
|
|
733
|
-
expect(getLookups).toHaveBeenCalledWith({
|
|
734
|
-
type: newLookupCode,
|
|
735
|
-
parents: props.parents,
|
|
736
|
-
displayNamePrefix: '',
|
|
737
|
-
max: 3,
|
|
738
|
-
offset: 0
|
|
739
|
-
});
|
|
606
|
+
expect(props.resolveLookups).toHaveBeenCalledWith(props.lookupCode, ['AR']);
|
|
740
607
|
return [2 /*return*/];
|
|
741
608
|
}
|
|
742
609
|
});
|
|
743
610
|
}); });
|
|
744
|
-
it('should
|
|
745
|
-
var
|
|
611
|
+
it('should call props.resolveLookups once if lookup is unresolved and has no resolved value in lookups and has no resolved value in response', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
612
|
+
var value, props, rerender;
|
|
746
613
|
return __generator(this, function (_a) {
|
|
747
614
|
switch (_a.label) {
|
|
748
615
|
case 0:
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
616
|
+
value = { lookupCode: 'AR', value: '' };
|
|
617
|
+
props = __assign(__assign({}, defaultProps), { value: value });
|
|
618
|
+
rerender = setUp({ props: props }).rerender;
|
|
619
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
754
620
|
return __generator(this, function (_a) {
|
|
755
|
-
|
|
756
|
-
|
|
621
|
+
switch (_a.label) {
|
|
622
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
623
|
+
case 1:
|
|
624
|
+
_a.sent();
|
|
625
|
+
return [2 /*return*/];
|
|
626
|
+
}
|
|
757
627
|
});
|
|
758
628
|
}); })];
|
|
759
629
|
case 1:
|
|
760
630
|
_a.sent();
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
expect(
|
|
631
|
+
rerender({ value: __assign({}, value) });
|
|
632
|
+
expect(props.resolveLookups).toHaveBeenCalledTimes(1);
|
|
633
|
+
expect(props.resolveLookups).toHaveBeenCalledWith(props.lookupCode, ['AR']);
|
|
764
634
|
return [2 /*return*/];
|
|
765
635
|
}
|
|
766
636
|
});
|
|
767
637
|
}); });
|
|
768
|
-
it('should
|
|
769
|
-
var
|
|
770
|
-
return __generator(this, function (_a) {
|
|
771
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props2)), { attachTo: document.body });
|
|
772
|
-
inputNode = wrapper.find('input').getDOMNode();
|
|
773
|
-
spy = jest.spyOn(wrapper.find('Select').instance(), 'focus');
|
|
774
|
-
(0, test_utils_1.act)(function () {
|
|
775
|
-
wrapper.find('Select').instance().focus();
|
|
776
|
-
wrapper.setProps(__assign(__assign({}, props2), { disabled: true }));
|
|
777
|
-
});
|
|
778
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
779
|
-
wrapper.setProps(__assign(__assign({}, props2), { disabled: false }));
|
|
780
|
-
expect(document.activeElement).toBe(inputNode);
|
|
781
|
-
expect(spy).toHaveBeenCalledTimes(2);
|
|
782
|
-
return [2 /*return*/];
|
|
783
|
-
});
|
|
784
|
-
}); });
|
|
785
|
-
it('should change inputValue, not call onChange property, call getLookups as well on input change', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
786
|
-
var getLookups, value, wrapper, newInputValue;
|
|
638
|
+
it('should disable editor according "disabled" prop', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
639
|
+
var props;
|
|
787
640
|
return __generator(this, function (_a) {
|
|
788
641
|
switch (_a.label) {
|
|
789
642
|
case 0:
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
RU: { displayName: 'Russia' }
|
|
794
|
-
}));
|
|
795
|
-
value = { lookupCode: 'US', value: 'USA' };
|
|
796
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { getLookups: getLookups, value: value, multiple: false })));
|
|
797
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe('USA (US)');
|
|
798
|
-
newInputValue = 'u';
|
|
799
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
643
|
+
props = __assign(__assign({}, defaultProps), { disabled: true });
|
|
644
|
+
setUp({ props: props });
|
|
645
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
800
646
|
return __generator(this, function (_a) {
|
|
801
|
-
|
|
802
|
-
|
|
647
|
+
switch (_a.label) {
|
|
648
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
649
|
+
case 1:
|
|
650
|
+
_a.sent();
|
|
651
|
+
return [2 /*return*/];
|
|
652
|
+
}
|
|
803
653
|
});
|
|
804
654
|
}); })];
|
|
805
655
|
case 1:
|
|
806
656
|
_a.sent();
|
|
807
|
-
|
|
808
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe(newInputValue);
|
|
809
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
810
|
-
expect(getLookups).toHaveBeenCalledWith({
|
|
811
|
-
type: 'COUNTRY_CD',
|
|
812
|
-
parents: [],
|
|
813
|
-
displayNamePrefix: newInputValue,
|
|
814
|
-
max: 51,
|
|
815
|
-
offset: 0
|
|
816
|
-
});
|
|
657
|
+
expect(react_2.screen.getByRole('combobox')).toBeDisabled();
|
|
817
658
|
return [2 /*return*/];
|
|
818
659
|
}
|
|
819
660
|
});
|
|
820
661
|
}); });
|
|
821
|
-
it('should
|
|
822
|
-
var
|
|
662
|
+
it('should use "parents" prop for lookups request', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
663
|
+
var parents, props;
|
|
823
664
|
return __generator(this, function (_a) {
|
|
824
665
|
switch (_a.label) {
|
|
825
666
|
case 0:
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
}));
|
|
831
|
-
value = { lookupCode: 'US', value: 'USA' };
|
|
832
|
-
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { getLookups: getLookups, value: value, multiple: false })));
|
|
833
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe('USA (US)');
|
|
834
|
-
newInputValue = '';
|
|
835
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
667
|
+
parents = ['parent1', 'parent2'];
|
|
668
|
+
props = __assign(__assign({}, defaultProps), { parents: parents });
|
|
669
|
+
setUp({ props: props });
|
|
670
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
836
671
|
return __generator(this, function (_a) {
|
|
837
|
-
|
|
838
|
-
|
|
672
|
+
switch (_a.label) {
|
|
673
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
674
|
+
case 1:
|
|
675
|
+
_a.sent();
|
|
676
|
+
return [2 /*return*/];
|
|
677
|
+
}
|
|
839
678
|
});
|
|
840
679
|
}); })];
|
|
841
680
|
case 1:
|
|
842
681
|
_a.sent();
|
|
843
|
-
|
|
844
|
-
expect(wrapper.find(ReactSelect_1.ReactSelect).find('Input').last().prop('value')).toBe(newInputValue);
|
|
845
|
-
expect(props.onChange).toHaveBeenCalledWith('');
|
|
846
|
-
expect(getLookups).toHaveBeenCalledWith({
|
|
847
|
-
type: 'COUNTRY_CD',
|
|
848
|
-
parents: [],
|
|
682
|
+
expect(props.getLookups).toHaveBeenCalledWith({
|
|
849
683
|
displayNamePrefix: '',
|
|
850
684
|
max: 51,
|
|
851
|
-
offset: 0
|
|
685
|
+
offset: 0,
|
|
686
|
+
type: props.lookupCode,
|
|
687
|
+
parents: parents
|
|
852
688
|
});
|
|
853
689
|
return [2 /*return*/];
|
|
854
690
|
}
|
|
855
691
|
});
|
|
856
692
|
}); });
|
|
857
|
-
it('should
|
|
858
|
-
var
|
|
859
|
-
COUNTRY_CD: {
|
|
860
|
-
DE: {
|
|
861
|
-
displayName: 'Germany'
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
};
|
|
865
|
-
var value = { lookupCode: 'DE', value: '' };
|
|
866
|
-
(0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { lookups: lookups, value: value })));
|
|
867
|
-
expect(props.onChange).toHaveBeenCalledWith({
|
|
868
|
-
lookupCode: 'DE',
|
|
869
|
-
value: 'Germany'
|
|
870
|
-
});
|
|
871
|
-
});
|
|
872
|
-
it('should call props.resolveLookups if lookup is unresolved and has no resolved value in lookups', function () {
|
|
873
|
-
var value = { lookupCode: 'DE', value: '' };
|
|
874
|
-
(0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { value: value })));
|
|
875
|
-
expect(props.resolveLookups).toHaveBeenCalledWith(props.lookupCode, ['DE']);
|
|
876
|
-
});
|
|
877
|
-
it('should call props.resolveLookups once if lookup is unresolved and has no resolved value in lookups and has no resolved value in response', function () {
|
|
878
|
-
var value = { lookupCode: 'DE', value: '' };
|
|
879
|
-
var component = (0, enzyme_1.mount)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { value: value })));
|
|
880
|
-
component.setProps({ value: __assign({}, value) });
|
|
881
|
-
expect(props.resolveLookups).toHaveBeenCalledTimes(1);
|
|
882
|
-
expect(props.resolveLookups).toHaveBeenCalledWith(props.lookupCode, ['DE']);
|
|
883
|
-
});
|
|
884
|
-
it('should use debounced variant of loadOptions on input change', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
885
|
-
var getLookups, component, select;
|
|
693
|
+
it('should not send lookups request if "parents" prop is null', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
694
|
+
var props, user;
|
|
886
695
|
return __generator(this, function (_a) {
|
|
887
696
|
switch (_a.label) {
|
|
888
697
|
case 0:
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
US: { displayName: 'USA' },
|
|
893
|
-
RU: { displayName: 'Russia' }
|
|
894
|
-
}));
|
|
895
|
-
component = (0, enzyme_1.shallow)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { getLookups: getLookups })));
|
|
896
|
-
select = component.find(ReactSelect_1.ReactSelect);
|
|
897
|
-
(0, test_utils_1.act)(function () {
|
|
898
|
-
select.prop('onInputChange')('u', { action: 'input-change' });
|
|
899
|
-
});
|
|
900
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
901
|
-
return __generator(this, function (_a) {
|
|
902
|
-
jest.advanceTimersByTime(DependentLookupEditor_1.DEBOUNCE_INTERVAL);
|
|
903
|
-
return [2 /*return*/];
|
|
904
|
-
});
|
|
905
|
-
}); })];
|
|
698
|
+
props = __assign(__assign({}, defaultProps), { parents: null });
|
|
699
|
+
user = setUp({ props: props }).user;
|
|
700
|
+
return [4 /*yield*/, user.type(react_2.screen.getByRole('combobox'), 'Ch')];
|
|
906
701
|
case 1:
|
|
907
702
|
_a.sent();
|
|
908
|
-
|
|
909
|
-
expect(
|
|
910
|
-
{
|
|
911
|
-
lookupCode: 'RU',
|
|
912
|
-
value: 'Russia'
|
|
913
|
-
},
|
|
914
|
-
{ lookupCode: 'US', value: 'USA' }
|
|
915
|
-
]);
|
|
916
|
-
expect(mdm_sdk_1.debounce).toHaveBeenCalled();
|
|
917
|
-
jest.useRealTimers();
|
|
703
|
+
react_2.screen.getByText('No results found');
|
|
704
|
+
expect(props.getLookups).not.toHaveBeenCalled();
|
|
918
705
|
return [2 /*return*/];
|
|
919
706
|
}
|
|
920
707
|
});
|
|
921
708
|
}); });
|
|
922
|
-
it('should
|
|
923
|
-
var
|
|
924
|
-
var select = component.find(ReactSelect_1.ReactSelect);
|
|
925
|
-
expect(select.prop('isDisabled')).toBe(true);
|
|
926
|
-
expect(select.prop('TextFieldProps').disabled).toBe(true);
|
|
927
|
-
});
|
|
928
|
-
it('should use "parents" prop for lookups request', function () {
|
|
929
|
-
var parents = [
|
|
930
|
-
{
|
|
931
|
-
type: 'PARENT',
|
|
932
|
-
codeValues: ['3', '4']
|
|
933
|
-
}
|
|
934
|
-
];
|
|
935
|
-
var component = (0, enzyme_1.shallow)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { parents: parents })));
|
|
936
|
-
var select = component.find(ReactSelect_1.ReactSelect);
|
|
937
|
-
(0, test_utils_1.act)(function () {
|
|
938
|
-
select.prop('onInputChange')('u', { action: 'input-change' });
|
|
939
|
-
});
|
|
940
|
-
expect(component.prop('isDisabled')).toBeFalsy();
|
|
941
|
-
expect(props.getLookups).toHaveBeenCalledTimes(1);
|
|
942
|
-
expect(props.getLookups).toHaveBeenCalledWith({
|
|
943
|
-
displayNamePrefix: 'u',
|
|
944
|
-
max: 51,
|
|
945
|
-
offset: 0,
|
|
946
|
-
type: props.lookupCode,
|
|
947
|
-
parents: parents
|
|
948
|
-
});
|
|
949
|
-
});
|
|
950
|
-
it('should not send lookups request if "parents" prop is null', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
951
|
-
var parents, component, select;
|
|
709
|
+
it('should send lookups request if "parents" is undefined', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
710
|
+
var props;
|
|
952
711
|
return __generator(this, function (_a) {
|
|
953
712
|
switch (_a.label) {
|
|
954
713
|
case 0:
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
714
|
+
props = __assign(__assign({}, defaultProps), { parents: undefined });
|
|
715
|
+
setUp({ props: props });
|
|
716
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
959
717
|
return __generator(this, function (_a) {
|
|
960
|
-
|
|
961
|
-
|
|
718
|
+
switch (_a.label) {
|
|
719
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
720
|
+
case 1:
|
|
721
|
+
_a.sent();
|
|
722
|
+
return [2 /*return*/];
|
|
723
|
+
}
|
|
962
724
|
});
|
|
963
725
|
}); })];
|
|
964
726
|
case 1:
|
|
965
727
|
_a.sent();
|
|
966
|
-
expect(props.getLookups).
|
|
967
|
-
|
|
728
|
+
expect(props.getLookups).toHaveBeenCalledWith({
|
|
729
|
+
displayNamePrefix: '',
|
|
730
|
+
max: 51,
|
|
731
|
+
offset: 0,
|
|
732
|
+
type: props.lookupCode
|
|
733
|
+
});
|
|
968
734
|
return [2 /*return*/];
|
|
969
735
|
}
|
|
970
736
|
});
|
|
971
737
|
}); });
|
|
972
|
-
it('should send lookups request if "parents" is undefined', function () {
|
|
973
|
-
var parents = undefined;
|
|
974
|
-
var component = (0, enzyme_1.shallow)(react_1.default.createElement(DependentLookupEditor_1.DependentLookupEditor, __assign({}, props, { parents: parents })));
|
|
975
|
-
var select = component.find(ReactSelect_1.ReactSelect);
|
|
976
|
-
(0, test_utils_1.act)(function () {
|
|
977
|
-
select.prop('onInputChange')('u', { action: 'input-change' });
|
|
978
|
-
});
|
|
979
|
-
expect(props.getLookups).toHaveBeenCalledTimes(1);
|
|
980
|
-
expect(props.getLookups).toHaveBeenCalledWith({
|
|
981
|
-
displayNamePrefix: 'u',
|
|
982
|
-
max: 51,
|
|
983
|
-
offset: 0,
|
|
984
|
-
type: props.lookupCode,
|
|
985
|
-
parents: parents
|
|
986
|
-
});
|
|
987
|
-
});
|
|
988
738
|
describe('Autopopulation behavior', function () {
|
|
989
|
-
var
|
|
990
|
-
beforeEach(function () {
|
|
991
|
-
var requestPromise = new Promise(function (_resolve) {
|
|
992
|
-
resolveOptions = _resolve;
|
|
993
|
-
});
|
|
994
|
-
getLookups = function () { return requestPromise; };
|
|
995
|
-
});
|
|
996
|
-
var defaultAutopopulationContextValue = {
|
|
997
|
-
id: 'id',
|
|
998
|
-
onTouch: jest.fn(),
|
|
999
|
-
isTouched: false
|
|
1000
|
-
};
|
|
739
|
+
var defaultAutopopulationContextValue = { id: 'id', onTouch: jest.fn(), isTouched: false };
|
|
1001
740
|
it('should call onChange on component mount when there is only one possible option, value is empty and autopopulation is enabled', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1002
|
-
var
|
|
741
|
+
var props, CustomProviders;
|
|
1003
742
|
return __generator(this, function (_a) {
|
|
1004
743
|
switch (_a.label) {
|
|
1005
744
|
case 0:
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
react_1.default.createElement(
|
|
1010
|
-
|
|
1011
|
-
|
|
745
|
+
props = __assign(__assign({}, defaultProps), { value: { lookupCode: '', value: '' }, autopopulationId: defaultAutopopulationContextValue.id, getLookups: jest.fn().mockReturnValue(Promise.resolve({ AR: { displayName: 'Argentina' } })) });
|
|
746
|
+
CustomProviders = function (_a) {
|
|
747
|
+
var children = _a.children;
|
|
748
|
+
return (react_1.default.createElement(DependentLookupAutopopulationContext_1.DependentLookupAutopopulationContext.Provider, { value: defaultAutopopulationContextValue }, children));
|
|
749
|
+
};
|
|
750
|
+
setUp({ props: props, CustomProviders: CustomProviders });
|
|
751
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1012
752
|
return __generator(this, function (_a) {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
753
|
+
switch (_a.label) {
|
|
754
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
755
|
+
case 1:
|
|
756
|
+
_a.sent();
|
|
757
|
+
return [2 /*return*/];
|
|
758
|
+
}
|
|
1017
759
|
});
|
|
1018
760
|
}); })];
|
|
1019
761
|
case 1:
|
|
1020
762
|
_a.sent();
|
|
1021
|
-
expect(props.onChange).toHaveBeenCalledWith({
|
|
1022
|
-
lookupCode: 'RU',
|
|
1023
|
-
value: 'Russia'
|
|
1024
|
-
});
|
|
763
|
+
expect(props.onChange).toHaveBeenCalledWith({ lookupCode: 'AR', value: 'Argentina' });
|
|
1025
764
|
return [2 /*return*/];
|
|
1026
765
|
}
|
|
1027
766
|
});
|
|
1028
767
|
}); });
|
|
1029
768
|
it('should not autopopulate editor if autopopulationId is not set', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1030
|
-
var
|
|
769
|
+
var props, autopopulationContextValue, CustomProviders;
|
|
1031
770
|
return __generator(this, function (_a) {
|
|
1032
771
|
switch (_a.label) {
|
|
1033
772
|
case 0:
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
773
|
+
props = __assign(__assign({}, defaultProps), { value: { lookupCode: '', value: '' }, getLookups: jest.fn().mockReturnValue(Promise.resolve({ AR: { displayName: 'Argentina' } })) });
|
|
774
|
+
autopopulationContextValue = __assign(__assign({}, defaultAutopopulationContextValue), { id: undefined });
|
|
775
|
+
CustomProviders = function (_a) {
|
|
776
|
+
var children = _a.children;
|
|
777
|
+
return (react_1.default.createElement(DependentLookupAutopopulationContext_1.DependentLookupAutopopulationContext.Provider, { value: autopopulationContextValue }, children));
|
|
778
|
+
};
|
|
779
|
+
setUp({ props: props, CustomProviders: CustomProviders });
|
|
780
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1039
781
|
return __generator(this, function (_a) {
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
782
|
+
switch (_a.label) {
|
|
783
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
784
|
+
case 1:
|
|
785
|
+
_a.sent();
|
|
786
|
+
return [2 /*return*/];
|
|
787
|
+
}
|
|
1044
788
|
});
|
|
1045
789
|
}); })];
|
|
1046
790
|
case 1:
|
|
@@ -1051,20 +795,24 @@ describe('DependentLookupEditor', function () {
|
|
|
1051
795
|
});
|
|
1052
796
|
}); });
|
|
1053
797
|
it('should not autopopulate editor if value is not empty', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1054
|
-
var
|
|
798
|
+
var props, CustomProviders;
|
|
1055
799
|
return __generator(this, function (_a) {
|
|
1056
800
|
switch (_a.label) {
|
|
1057
801
|
case 0:
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
react_1.default.createElement(
|
|
1062
|
-
|
|
802
|
+
props = __assign(__assign({}, defaultProps), { value: { lookupCode: 'AR', value: '' }, autopopulationId: defaultAutopopulationContextValue.id, getLookups: jest.fn().mockReturnValue(Promise.resolve({ AR: { displayName: 'Argentina' } })) });
|
|
803
|
+
CustomProviders = function (_a) {
|
|
804
|
+
var children = _a.children;
|
|
805
|
+
return (react_1.default.createElement(DependentLookupAutopopulationContext_1.DependentLookupAutopopulationContext.Provider, { value: defaultAutopopulationContextValue }, children));
|
|
806
|
+
};
|
|
807
|
+
setUp({ props: props, CustomProviders: CustomProviders });
|
|
808
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1063
809
|
return __generator(this, function (_a) {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
810
|
+
switch (_a.label) {
|
|
811
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
812
|
+
case 1:
|
|
813
|
+
_a.sent();
|
|
814
|
+
return [2 /*return*/];
|
|
815
|
+
}
|
|
1068
816
|
});
|
|
1069
817
|
}); })];
|
|
1070
818
|
case 1:
|
|
@@ -1075,21 +823,24 @@ describe('DependentLookupEditor', function () {
|
|
|
1075
823
|
});
|
|
1076
824
|
}); });
|
|
1077
825
|
it('should not autopopulate editor if there are more then one option', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1078
|
-
var
|
|
826
|
+
var props, CustomProviders;
|
|
1079
827
|
return __generator(this, function (_a) {
|
|
1080
828
|
switch (_a.label) {
|
|
1081
829
|
case 0:
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
react_1.default.createElement(
|
|
1086
|
-
|
|
830
|
+
props = __assign(__assign({}, defaultProps), { value: { lookupCode: '', value: '' }, autopopulationId: defaultAutopopulationContextValue.id });
|
|
831
|
+
CustomProviders = function (_a) {
|
|
832
|
+
var children = _a.children;
|
|
833
|
+
return (react_1.default.createElement(DependentLookupAutopopulationContext_1.DependentLookupAutopopulationContext.Provider, { value: defaultAutopopulationContextValue }, children));
|
|
834
|
+
};
|
|
835
|
+
setUp({ props: props, CustomProviders: CustomProviders });
|
|
836
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1087
837
|
return __generator(this, function (_a) {
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
838
|
+
switch (_a.label) {
|
|
839
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
840
|
+
case 1:
|
|
841
|
+
_a.sent();
|
|
842
|
+
return [2 /*return*/];
|
|
843
|
+
}
|
|
1093
844
|
});
|
|
1094
845
|
}); })];
|
|
1095
846
|
case 1:
|
|
@@ -1100,41 +851,27 @@ describe('DependentLookupEditor', function () {
|
|
|
1100
851
|
});
|
|
1101
852
|
}); });
|
|
1102
853
|
it('should not autopopulate editor if there is only one option but not for first time', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1103
|
-
var
|
|
854
|
+
var times, getLookups, props, CustomProviders, user;
|
|
1104
855
|
return __generator(this, function (_a) {
|
|
1105
856
|
switch (_a.label) {
|
|
1106
857
|
case 0:
|
|
1107
|
-
autopopulationId = 'uri4';
|
|
1108
858
|
times = 0;
|
|
1109
859
|
getLookups = jest.fn().mockImplementation(function () {
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
});
|
|
1116
|
-
default:
|
|
1117
|
-
return Promise.resolve({
|
|
1118
|
-
RU: { displayName: 'Russia' }
|
|
1119
|
-
});
|
|
860
|
+
if (times === 0) {
|
|
861
|
+
return Promise.resolve({ RU: { displayName: 'Russia' }, CN: { displayName: 'China' } });
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
return Promise.resolve({ RU: { displayName: 'Russia' } });
|
|
1120
865
|
}
|
|
1121
866
|
});
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
867
|
+
props = __assign(__assign({}, defaultProps), { value: { lookupCode: '', value: '' }, autopopulationId: defaultAutopopulationContextValue.id, getLookups: getLookups });
|
|
868
|
+
CustomProviders = function (_a) {
|
|
869
|
+
var children = _a.children;
|
|
870
|
+
return (react_1.default.createElement(DependentLookupAutopopulationContext_1.DependentLookupAutopopulationContext.Provider, { value: defaultAutopopulationContextValue }, children));
|
|
871
|
+
};
|
|
872
|
+
user = setUp({ props: props, CustomProviders: CustomProviders }).user;
|
|
873
|
+
return [4 /*yield*/, user.type(react_2.screen.getByRole('combobox'), 'u')];
|
|
1128
874
|
case 1:
|
|
1129
|
-
_a.sent();
|
|
1130
|
-
select = component.find(ReactSelect_1.ReactSelect);
|
|
1131
|
-
return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1132
|
-
return __generator(this, function (_a) {
|
|
1133
|
-
select.prop('onInputChange')('Ru', { action: 'input-change' });
|
|
1134
|
-
return [2 /*return*/];
|
|
1135
|
-
});
|
|
1136
|
-
}); })];
|
|
1137
|
-
case 2:
|
|
1138
875
|
_a.sent();
|
|
1139
876
|
expect(getLookups).toHaveBeenCalledTimes(2);
|
|
1140
877
|
expect(props.onChange).not.toHaveBeenCalled();
|
|
@@ -1142,51 +879,62 @@ describe('DependentLookupEditor', function () {
|
|
|
1142
879
|
}
|
|
1143
880
|
});
|
|
1144
881
|
}); });
|
|
1145
|
-
it('should
|
|
1146
|
-
var
|
|
882
|
+
it('should call onTouch on change value', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
883
|
+
var props, CustomProviders, user;
|
|
1147
884
|
return __generator(this, function (_a) {
|
|
1148
885
|
switch (_a.label) {
|
|
1149
886
|
case 0:
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
return [4 /*yield*/, (0,
|
|
887
|
+
props = __assign(__assign({}, defaultProps), { value: { lookupCode: '', value: '' }, autopopulationId: defaultAutopopulationContextValue.id, getLookups: jest.fn().mockReturnValue(Promise.resolve({ AR: { displayName: 'Argentina' } })) });
|
|
888
|
+
CustomProviders = function (_a) {
|
|
889
|
+
var children = _a.children;
|
|
890
|
+
return (react_1.default.createElement(DependentLookupAutopopulationContext_1.DependentLookupAutopopulationContext.Provider, { value: defaultAutopopulationContextValue }, children));
|
|
891
|
+
};
|
|
892
|
+
user = setUp({ props: props, CustomProviders: CustomProviders }).user;
|
|
893
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1157
894
|
return __generator(this, function (_a) {
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
895
|
+
switch (_a.label) {
|
|
896
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
897
|
+
case 1:
|
|
898
|
+
_a.sent();
|
|
899
|
+
return [2 /*return*/];
|
|
900
|
+
}
|
|
1162
901
|
});
|
|
1163
902
|
}); })];
|
|
1164
903
|
case 1:
|
|
1165
904
|
_a.sent();
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
905
|
+
return [4 /*yield*/, user.type(react_2.screen.getByRole('combobox'), '{Backspace}{Enter}')];
|
|
906
|
+
case 2:
|
|
907
|
+
_a.sent();
|
|
908
|
+
expect(defaultAutopopulationContextValue.onTouch).toHaveBeenCalledWith(defaultAutopopulationContextValue.id);
|
|
909
|
+
return [2 /*return*/];
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
}); });
|
|
913
|
+
it('should not autopopulate editor if isTouched prop is true', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
914
|
+
var props, autopopulationContextValue, CustomProviders;
|
|
915
|
+
return __generator(this, function (_a) {
|
|
916
|
+
switch (_a.label) {
|
|
917
|
+
case 0:
|
|
918
|
+
props = __assign(__assign({}, defaultProps), { value: { lookupCode: '', value: '' }, autopopulationId: defaultAutopopulationContextValue.id, getLookups: jest.fn().mockReturnValue(Promise.resolve({ AR: { displayName: 'Argentina' } })) });
|
|
919
|
+
autopopulationContextValue = __assign(__assign({}, defaultAutopopulationContextValue), { isTouched: true });
|
|
920
|
+
CustomProviders = function (_a) {
|
|
921
|
+
var children = _a.children;
|
|
922
|
+
return (react_1.default.createElement(DependentLookupAutopopulationContext_1.DependentLookupAutopopulationContext.Provider, { value: autopopulationContextValue }, children));
|
|
923
|
+
};
|
|
924
|
+
setUp({ props: props, CustomProviders: CustomProviders });
|
|
925
|
+
return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1180
926
|
return __generator(this, function (_a) {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
927
|
+
switch (_a.label) {
|
|
928
|
+
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
929
|
+
case 1:
|
|
930
|
+
_a.sent();
|
|
931
|
+
return [2 /*return*/];
|
|
932
|
+
}
|
|
1185
933
|
});
|
|
1186
934
|
}); })];
|
|
1187
|
-
case
|
|
935
|
+
case 1:
|
|
1188
936
|
_a.sent();
|
|
1189
|
-
expect(props.onChange).
|
|
937
|
+
expect(props.onChange).not.toHaveBeenCalled();
|
|
1190
938
|
return [2 /*return*/];
|
|
1191
939
|
}
|
|
1192
940
|
});
|