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