@reltio/components 1.4.2071 → 1.4.2073

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.
Files changed (196) hide show
  1. package/AttributesView/AttributesView.js +1 -1
  2. package/ColumnsSettings/components/ColumnsSettingsPopup/ColumnsSettingsPopup.d.ts +2 -3
  3. package/ColumnsSettings/helpers.d.ts +3 -1
  4. package/ColumnsSettings/types.d.ts +8 -0
  5. package/CommentsContainer/CommentsContainer.js +1 -1
  6. package/ConfigureColumnsPopup/ConfigureColumnsPopup.d.ts +23 -40
  7. package/ConfigureColumnsPopup/ConfigureColumnsPopup.js +6 -26
  8. package/EditModeAttributesList/EditModeAttributesList.js +1 -1
  9. package/EditModeAttributesPager/EditModeAttributesPager.test.js +1 -1
  10. package/EditModeAttributesPager/components/AttributeRenderer/AttributeRenderer.js +1 -1
  11. package/MetadataTypesSelector/MetadataTypesSelector.d.ts +2 -1
  12. package/MetadataTypesSelector/components/SelectMetadataTypesList/SelectMetadataTypesList.d.ts +5 -6
  13. package/MoreAttributesButton/useMoreAttributesItems.d.ts +1 -1
  14. package/ReadOnlyAttributesList/ReadOnlyAttributesList.js +1 -1
  15. package/ReadOnlyAttributesPager/ReadOnlyAttributesPager.js +1 -1
  16. package/ReadOnlyAttributesView/ReadOnlyAttributesView.js +1 -1
  17. package/ScrollableTabs/ScrollableTabs.test.js +69 -19
  18. package/SearchHighlighter/SearchHighlighter.test.js +18 -7
  19. package/SelectAttributesList/SelectAttributesList.d.ts +11 -6
  20. package/SelectAttributesList/SelectAttributesList.js +5 -2
  21. package/SelectorWithOnlyOptionAutoSelect/SelectorWithOnlyOptionAutoSelect.test.js +109 -60
  22. package/SidePanelContentHeader/SidePanelContentHeader.js +2 -2
  23. package/SidePanelContentHeader/SidePanelContentHeader.test.js +104 -0
  24. package/SidePanelEmptyState/SidePanelEmptyState.js +1 -1
  25. package/SidePanelEmptyState/SidePanelEmptyState.test.js +24 -0
  26. package/SimpleAttribute/SimpleAttribute.js +1 -1
  27. package/SimpleAttribute/SimpleAttribute.test.js +155 -80
  28. package/SimpleAttributeEditor/SimpleAttributeEditor.test.js +339 -330
  29. package/SimpleAttributeEditor/useAttributeValuePermissions.js +1 -1
  30. package/SimpleDropDownSelector/SimpleDropDownSelector.test.js +86 -10
  31. package/SimpleDropDownSelector/components/DropDownPlaceholder/DropDownPlaceholder.js +1 -1
  32. package/SimpleDropDownSelector/components/DropDownValue/DropDownValue.js +1 -1
  33. package/SimpleMatchRulesBlock/SimpleMatchRulesBlock.test.js +128 -32
  34. package/SmallIconButton/SmallIconButton.test.js +98 -25
  35. package/TableWithBars/TableWithBars.test.js +98 -60
  36. package/TableWithBars/components/AttributeCellRenderer/AttributeCellRenderer.js +1 -1
  37. package/TableWithBars/components/HeadCellRenderer/HeadCellRenderer.js +1 -1
  38. package/Tags/Tags.d.ts +0 -1
  39. package/Tags/Tags.test.js +8 -7
  40. package/TransitiveMatchBlock/TransitiveMatchBlock.test.js +78 -22
  41. package/TransitiveMatchRule/TransitiveMatchRule.test.js +78 -37
  42. package/TransitiveMatchRulesTooltip/TransitiveMatchRulesTooltip.js +1 -1
  43. package/TransitiveMatchRulesTooltip/TransitiveMatchRulesTooltip.test.js +12 -18
  44. package/UploadFileButton/UploadFileButton.d.ts +2 -2
  45. package/UploadFileButton/UploadFileButton.test.js +199 -0
  46. package/UploadImageDialog/UploadImageDialog.test.js +1 -0
  47. package/UploadImageDialog/components/DividerWithText/DividerWithText.js +1 -1
  48. package/UploadImageDialog/components/ErrorSnackbar/ErrorSnackbar.test.js +80 -22
  49. package/UploadImageDialog/components/ImageByUrlField/ImageByUrlField.js +1 -1
  50. package/UploadImageDialog/components/ImageByUrlField/ImageByUrlField.test.js +162 -49
  51. package/ValueChip/ValueChip.test.js +7 -23
  52. package/VirtualGroupedList/VirtualGroupedList.d.ts +19 -31
  53. package/VirtualGroupedList/VirtualGroupedList.js +11 -36
  54. package/VirtualGroupedList/VirtualGroupedList.test.js +224 -0
  55. package/VirtualGroupedList/helpers.d.ts +7 -2
  56. package/VirtualGroupedList/helpers.js +3 -1
  57. package/VirtualGroupedList/index.d.ts +1 -1
  58. package/VirtualGroupedList/types.d.ts +10 -6
  59. package/VirtualGroupedList/useScrollToFocusItem.d.ts +8 -5
  60. package/WhiteSearchInput/{WhiteSearchInput.spec.js → WhiteSearchInput.test.js} +3 -8
  61. package/cjs/AttributesView/AttributesView.js +2 -2
  62. package/cjs/ColumnsSettings/components/ColumnsSettingsPopup/ColumnsSettingsPopup.d.ts +2 -3
  63. package/cjs/ColumnsSettings/helpers.d.ts +3 -1
  64. package/cjs/ColumnsSettings/types.d.ts +8 -0
  65. package/cjs/ColumnsSettings/types.js +2 -0
  66. package/cjs/CommentsContainer/CommentsContainer.js +1 -1
  67. package/cjs/ConfigureColumnsPopup/ConfigureColumnsPopup.d.ts +23 -40
  68. package/cjs/ConfigureColumnsPopup/ConfigureColumnsPopup.js +6 -26
  69. package/cjs/EditModeAttributesList/EditModeAttributesList.js +2 -2
  70. package/cjs/EditModeAttributesPager/EditModeAttributesPager.test.js +2 -2
  71. package/cjs/EditModeAttributesPager/components/AttributeRenderer/AttributeRenderer.js +2 -2
  72. package/cjs/MetadataTypesSelector/MetadataTypesSelector.d.ts +2 -1
  73. package/cjs/MetadataTypesSelector/components/SelectMetadataTypesList/SelectMetadataTypesList.d.ts +5 -6
  74. package/cjs/MoreAttributesButton/useMoreAttributesItems.d.ts +1 -1
  75. package/cjs/ReadOnlyAttributesList/ReadOnlyAttributesList.js +2 -2
  76. package/cjs/ReadOnlyAttributesPager/ReadOnlyAttributesPager.js +2 -2
  77. package/cjs/ReadOnlyAttributesView/ReadOnlyAttributesView.js +2 -2
  78. package/cjs/ScrollableTabs/ScrollableTabs.test.js +69 -19
  79. package/cjs/SearchHighlighter/SearchHighlighter.test.js +18 -7
  80. package/cjs/SelectAttributesList/SelectAttributesList.d.ts +11 -6
  81. package/cjs/SelectAttributesList/SelectAttributesList.js +5 -2
  82. package/cjs/SelectorWithOnlyOptionAutoSelect/SelectorWithOnlyOptionAutoSelect.test.js +109 -60
  83. package/cjs/SidePanelContentHeader/SidePanelContentHeader.js +2 -2
  84. package/cjs/SidePanelContentHeader/SidePanelContentHeader.test.js +109 -0
  85. package/cjs/SidePanelEmptyState/SidePanelEmptyState.js +1 -1
  86. package/cjs/SidePanelEmptyState/SidePanelEmptyState.test.js +29 -0
  87. package/cjs/SimpleAttribute/SimpleAttribute.js +1 -1
  88. package/cjs/SimpleAttribute/SimpleAttribute.test.js +155 -80
  89. package/cjs/SimpleAttributeEditor/SimpleAttributeEditor.test.js +338 -352
  90. package/cjs/SimpleAttributeEditor/useAttributeValuePermissions.js +2 -2
  91. package/cjs/SimpleDropDownSelector/SimpleDropDownSelector.test.js +86 -10
  92. package/cjs/SimpleDropDownSelector/components/DropDownPlaceholder/DropDownPlaceholder.js +1 -1
  93. package/cjs/SimpleDropDownSelector/components/DropDownValue/DropDownValue.js +1 -1
  94. package/cjs/SimpleMatchRulesBlock/SimpleMatchRulesBlock.test.js +127 -31
  95. package/cjs/SmallIconButton/SmallIconButton.test.js +98 -25
  96. package/cjs/TableWithBars/TableWithBars.test.js +98 -60
  97. package/cjs/TableWithBars/components/AttributeCellRenderer/AttributeCellRenderer.js +1 -1
  98. package/cjs/TableWithBars/components/HeadCellRenderer/HeadCellRenderer.js +1 -1
  99. package/cjs/Tags/Tags.d.ts +0 -1
  100. package/cjs/Tags/Tags.test.js +8 -7
  101. package/cjs/TransitiveMatchBlock/TransitiveMatchBlock.test.js +77 -21
  102. package/cjs/TransitiveMatchRule/TransitiveMatchRule.test.js +78 -37
  103. package/cjs/TransitiveMatchRulesTooltip/TransitiveMatchRulesTooltip.js +1 -1
  104. package/cjs/TransitiveMatchRulesTooltip/TransitiveMatchRulesTooltip.test.js +12 -18
  105. package/cjs/UploadFileButton/UploadFileButton.d.ts +2 -2
  106. package/cjs/UploadFileButton/UploadFileButton.test.js +204 -0
  107. package/cjs/UploadImageDialog/UploadImageDialog.test.js +1 -0
  108. package/cjs/UploadImageDialog/components/DividerWithText/DividerWithText.js +1 -1
  109. package/cjs/UploadImageDialog/components/ErrorSnackbar/ErrorSnackbar.test.js +80 -22
  110. package/cjs/UploadImageDialog/components/ImageByUrlField/ImageByUrlField.js +1 -1
  111. package/cjs/UploadImageDialog/components/ImageByUrlField/ImageByUrlField.test.js +162 -49
  112. package/cjs/ValueChip/ValueChip.test.js +7 -23
  113. package/cjs/VirtualGroupedList/VirtualGroupedList.d.ts +19 -31
  114. package/cjs/VirtualGroupedList/VirtualGroupedList.js +11 -36
  115. package/cjs/VirtualGroupedList/VirtualGroupedList.test.js +252 -0
  116. package/cjs/VirtualGroupedList/helpers.d.ts +7 -2
  117. package/cjs/VirtualGroupedList/helpers.js +3 -1
  118. package/cjs/VirtualGroupedList/index.d.ts +1 -1
  119. package/cjs/VirtualGroupedList/types.d.ts +10 -6
  120. package/cjs/VirtualGroupedList/useScrollToFocusItem.d.ts +8 -5
  121. package/cjs/WhiteSearchInput/{WhiteSearchInput.spec.js → WhiteSearchInput.test.js} +3 -8
  122. package/cjs/features/activity-log/ActivitiesFactory/ActivitiesFactory.js +1 -0
  123. package/cjs/features/activity-log/ActivitiesFactory/ActivitiesFactory.test.js +5 -0
  124. package/cjs/features/activity-log/ActivityFilterEditor/helpers.js +2 -1
  125. package/cjs/features/activity-log/ActivityFilterEditor/helpers.test.js +3 -1
  126. package/cjs/features/activity-log/ActivityLogFilter/ActivityLogFilter.test.js +16 -15
  127. package/cjs/features/activity-log/types.d.ts +1 -0
  128. package/cjs/features/activity-log/types.js +1 -0
  129. package/cjs/features/activity-log/utils/activities.js +1 -0
  130. package/cjs/features/activity-log/utils/filters.js +5 -1
  131. package/cjs/features/activity-log/utils/filters.test.js +4 -2
  132. package/cjs/features/crosswalks/hooks/useAttributeActions.test.js +24 -25
  133. package/cjs/features/crosswalks/hooks/useCrosswalkActions.test.js +10 -11
  134. package/cjs/features/history/types.d.ts +1 -0
  135. package/cjs/features/workflow/hooks/useChangeRequest.test.js +5 -6
  136. package/cjs/hooks/useCommentsEntitiesMap/useCommentsEntitiesMap.test.js +8 -9
  137. package/cjs/hooks/useKeyboardNavigation/useKeyboardNavigation.d.ts +9 -13
  138. package/features/activity-log/ActivitiesFactory/ActivitiesFactory.js +1 -0
  139. package/features/activity-log/ActivitiesFactory/ActivitiesFactory.test.js +5 -0
  140. package/features/activity-log/ActivityFilterEditor/helpers.js +2 -1
  141. package/features/activity-log/ActivityFilterEditor/helpers.test.js +3 -1
  142. package/features/activity-log/ActivityLogFilter/ActivityLogFilter.test.js +16 -15
  143. package/features/activity-log/types.d.ts +1 -0
  144. package/features/activity-log/types.js +1 -0
  145. package/features/activity-log/utils/activities.js +1 -0
  146. package/features/activity-log/utils/filters.js +5 -1
  147. package/features/activity-log/utils/filters.test.js +4 -2
  148. package/features/crosswalks/hooks/useAttributeActions.test.js +1 -2
  149. package/features/crosswalks/hooks/useCrosswalkActions.test.js +1 -2
  150. package/features/history/types.d.ts +1 -0
  151. package/features/workflow/hooks/useChangeRequest.test.js +1 -2
  152. package/hooks/useCommentsEntitiesMap/useCommentsEntitiesMap.test.js +1 -2
  153. package/hooks/useKeyboardNavigation/useKeyboardNavigation.d.ts +9 -13
  154. package/package.json +1 -1
  155. package/SidePanelContentHeader/SidePanelContentHeader.spec.js +0 -49
  156. package/SidePanelEmptyState/SidePanelEmptyState.spec.js +0 -24
  157. package/SimpleAttributeEditor/SimpleAttributeEditorWithoutPermissions.test.js +0 -103
  158. package/SimpleDropDownSelector/components/DropDownPlaceholder/DropDownPlaceholder.test.js +0 -13
  159. package/TableWithBars/components/AttributeCellRenderer/AttributeCellRenderer.test.js +0 -21
  160. package/TableWithBars/components/HeadCellRenderer/HeadCellRenderer.test.js +0 -20
  161. package/UploadFileButton/UploadFileButton.spec.js +0 -219
  162. package/UploadImageDialog/components/DividerWithText/DividerWithText.test.js +0 -9
  163. package/VirtualGroupedList/VirtualGroupedList.spec.js +0 -282
  164. package/cjs/SidePanelContentHeader/SidePanelContentHeader.spec.js +0 -54
  165. package/cjs/SidePanelEmptyState/SidePanelEmptyState.spec.d.ts +0 -1
  166. package/cjs/SidePanelEmptyState/SidePanelEmptyState.spec.js +0 -29
  167. package/cjs/SimpleAttributeEditor/SimpleAttributeEditorWithoutPermissions.test.d.ts +0 -1
  168. package/cjs/SimpleAttributeEditor/SimpleAttributeEditorWithoutPermissions.test.js +0 -108
  169. package/cjs/SimpleDropDownSelector/components/DropDownPlaceholder/DropDownPlaceholder.test.d.ts +0 -1
  170. package/cjs/SimpleDropDownSelector/components/DropDownPlaceholder/DropDownPlaceholder.test.js +0 -18
  171. package/cjs/TableWithBars/components/AttributeCellRenderer/AttributeCellRenderer.test.d.ts +0 -1
  172. package/cjs/TableWithBars/components/AttributeCellRenderer/AttributeCellRenderer.test.js +0 -26
  173. package/cjs/TableWithBars/components/HeadCellRenderer/HeadCellRenderer.test.d.ts +0 -1
  174. package/cjs/TableWithBars/components/HeadCellRenderer/HeadCellRenderer.test.js +0 -25
  175. package/cjs/UploadFileButton/UploadFileButton.spec.d.ts +0 -1
  176. package/cjs/UploadFileButton/UploadFileButton.spec.js +0 -224
  177. package/cjs/UploadImageDialog/components/DividerWithText/DividerWithText.test.d.ts +0 -1
  178. package/cjs/UploadImageDialog/components/DividerWithText/DividerWithText.test.js +0 -14
  179. package/cjs/VirtualGroupedList/VirtualGroupedList.spec.d.ts +0 -1
  180. package/cjs/VirtualGroupedList/VirtualGroupedList.spec.js +0 -287
  181. package/cjs/WhiteSearchInput/WhiteSearchInput.spec.d.ts +0 -1
  182. /package/{SidePanelContentHeader/SidePanelContentHeader.spec.d.ts → ColumnsSettings/types.js} +0 -0
  183. /package/{SidePanelEmptyState/SidePanelEmptyState.spec.d.ts → SidePanelContentHeader/SidePanelContentHeader.test.d.ts} +0 -0
  184. /package/{SimpleAttributeEditor/SimpleAttributeEditorWithoutPermissions.test.d.ts → SidePanelEmptyState/SidePanelEmptyState.test.d.ts} +0 -0
  185. /package/{SimpleDropDownSelector/components/DropDownPlaceholder/DropDownPlaceholder.test.d.ts → UploadFileButton/UploadFileButton.test.d.ts} +0 -0
  186. /package/{TableWithBars/components/AttributeCellRenderer/AttributeCellRenderer.test.d.ts → VirtualGroupedList/VirtualGroupedList.test.d.ts} +0 -0
  187. /package/{TableWithBars/components/HeadCellRenderer/HeadCellRenderer.test.d.ts → WhiteSearchInput/WhiteSearchInput.test.d.ts} +0 -0
  188. /package/{UploadFileButton/UploadFileButton.spec.d.ts → cjs/SidePanelContentHeader/SidePanelContentHeader.test.d.ts} +0 -0
  189. /package/{UploadImageDialog/components/DividerWithText/DividerWithText.test.d.ts → cjs/SidePanelEmptyState/SidePanelEmptyState.test.d.ts} +0 -0
  190. /package/{VirtualGroupedList/VirtualGroupedList.spec.d.ts → cjs/UploadFileButton/UploadFileButton.test.d.ts} +0 -0
  191. /package/{WhiteSearchInput/WhiteSearchInput.spec.d.ts → cjs/VirtualGroupedList/VirtualGroupedList.test.d.ts} +0 -0
  192. /package/cjs/{SidePanelContentHeader/SidePanelContentHeader.spec.d.ts → WhiteSearchInput/WhiteSearchInput.test.d.ts} +0 -0
  193. /package/cjs/contexts/{AllwaysVisibleAttributesContext → AlwaysVisibleAttributesContext}/index.d.ts +0 -0
  194. /package/cjs/contexts/{AllwaysVisibleAttributesContext → AlwaysVisibleAttributesContext}/index.js +0 -0
  195. /package/contexts/{AllwaysVisibleAttributesContext → AlwaysVisibleAttributesContext}/index.d.ts +0 -0
  196. /package/contexts/{AllwaysVisibleAttributesContext → AlwaysVisibleAttributesContext}/index.js +0 -0
@@ -45,133 +45,102 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
- if (ar || !(i in from)) {
51
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
- ar[i] = from[i];
53
- }
54
- }
55
- return to.concat(ar || Array.prototype.slice.call(from));
56
- };
57
48
  import React from 'react';
58
- import { mount } from 'enzyme';
59
- import { act, screen, render } from '@testing-library/react';
49
+ import { act, screen, render, within } from '@testing-library/react';
60
50
  import userEvent from '@testing-library/user-event';
61
51
  import { Mode, getDependentLookups } from '@reltio/mdm-sdk';
62
- import { DataTypeValueEditor } from '../DataTypeValueEditor';
63
- import * as useAutopopulationContextValueExport from './useAutopopulationContextValue';
64
- import { ErrorWrapper } from '../ErrorWrapper';
65
52
  import SimpleAttributeEditor from './SimpleAttributeEditor';
66
- import { useScrollToAttributeError } from '../hooks/useScrollToAttributeError';
67
53
  import { ProfilePerspectiveViewContext } from '../contexts/ProfilePerspectiveViewContext';
68
54
  import { ScrollType, ScrollToElementContext } from '../contexts/ScrollToElementContext';
69
55
  import { MdmModuleProvider, useMdmDependentLookupEditorContext } from '../contexts/MdmModuleContext';
56
+ import { AlwaysVisibleAttributesContext } from '../contexts/AlwaysVisibleAttributesContext';
57
+ import { useAutopopulationContextValue } from './useAutopopulationContextValue';
58
+ import { useScrollToAttributeError } from '../hooks/useScrollToAttributeError';
59
+ import { useAsyncMount } from '../hooks/useAsyncMount';
70
60
  jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getDependentLookups: jest.fn(function () { return Promise.resolve(); }), getLookups: jest.fn(function () { return Promise.resolve(); }) })); });
71
61
  jest.mock('../contexts/MdmModuleContext', function () { return (__assign(__assign({}, jest.requireActual('../contexts/MdmModuleContext')), { useMdmDependentLookupEditorContext: jest.fn() })); });
62
+ jest.mock('./useAutopopulationContextValue', function () { return (__assign(__assign({}, jest.requireActual('./useAutopopulationContextValue')), { useAutopopulationContextValue: jest.fn() })); });
72
63
  jest.mock('../hooks/useScrollToAttributeError', function () { return (__assign(__assign({}, jest.requireActual('../hooks/useScrollToAttributeError')), { useScrollToAttributeError: jest.fn() })); });
64
+ jest.mock('../hooks/useAsyncMount', function () { return (__assign(__assign({}, jest.requireActual('../hooks/useAsyncMount')), { useAsyncMount: jest.fn() })); });
73
65
  describe('SimpleAttributeEditor', function () {
74
- var onAddFn = jest.fn();
75
- var onDeleteFn = jest.fn();
76
- var onChangeFn = jest.fn();
77
- var onDeactivateErrorFn = jest.fn();
78
- var scrollToAttributeError = {
79
- ref: React.createRef(),
80
- errorClassName: 'errorClassName',
81
- path: []
66
+ var getScrollToElementContextValue = function (error) {
67
+ if (error === void 0) { error = null; }
68
+ return ({
69
+ element: error,
70
+ highlightError: jest.fn(),
71
+ scrollIntoRef: jest.fn(),
72
+ type: ScrollType.Error
73
+ });
74
+ };
75
+ var mdmValues = {
76
+ dependentLookups: {
77
+ editors: {},
78
+ structure: {},
79
+ initedTypeUris: []
80
+ }
82
81
  };
83
- var highlightErrorSpy = jest.fn();
84
- var scrollIntoRefSpy = jest.fn();
85
82
  beforeAll(function () {
86
- useScrollToAttributeError.mockReturnValue(scrollToAttributeError);
83
+ useScrollToAttributeError.mockImplementation(jest.requireActual('../hooks/useScrollToAttributeError').useScrollToAttributeError);
84
+ useAsyncMount.mockImplementation(jest.requireActual('../hooks/useAsyncMount').useAsyncMount);
85
+ useAutopopulationContextValue.mockImplementation(jest.requireActual('./useAutopopulationContextValue').useAutopopulationContextValue);
87
86
  });
88
87
  beforeEach(function () {
89
- onAddFn = jest.fn();
90
- onDeleteFn = jest.fn();
91
- onChangeFn = jest.fn();
92
- onDeactivateErrorFn = jest.fn();
93
- });
94
- afterEach(function () {
95
88
  jest.clearAllMocks();
96
89
  });
97
- describe('String attribute', function () {
98
- var mountComponent = function (_a) {
99
- var _b = _a === void 0 ? {} : _a, access = _b.access, ownError = _b.ownError, additionalControlsRenderer = _b.additionalControlsRenderer, state = _b.state;
100
- var mdmValues = {
101
- dependentLookups: {
102
- editors: {},
103
- structure: {},
104
- initedTypeUris: []
105
- }
106
- };
107
- var data = {
108
- attributeValue: {
109
- value: 'some string',
110
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
111
- },
112
- attributeType: {
113
- access: access || ['UPDATE', 'DELETE', 'CREATE', 'READ'],
114
- type: 'String',
115
- uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
116
- },
117
- ownError: ownError,
118
- isReltioCrosswalk: true,
119
- mode: Mode.Editing,
120
- onAddOneMore: onAddFn,
121
- onDeleteAttribute: onDeleteFn,
122
- onChangeAttribute: onChangeFn,
123
- onDeactivateError: onDeactivateErrorFn,
124
- additionalControlsRenderer: additionalControlsRenderer,
125
- state: state
126
- };
127
- return mount(React.createElement(MdmModuleProvider, { values: mdmValues },
128
- React.createElement(ScrollToElementContext.Provider, { value: {
129
- element: null,
130
- highlightError: highlightErrorSpy,
131
- scrollIntoRef: scrollIntoRefSpy,
132
- type: ScrollType.Error
133
- } },
134
- React.createElement(SimpleAttributeEditor, __assign({}, data)))));
135
- };
136
- var findActionButtons = function (component) {
137
- return component
138
- .findWhere(function (n) { return n.prop('className') && n.prop('className').includes('editor-actions'); })
139
- .children();
90
+ var defaultProps = {
91
+ attributeValue: {
92
+ value: 'some string',
93
+ uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
94
+ },
95
+ attributeType: {
96
+ access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
97
+ type: 'String',
98
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
99
+ },
100
+ isReltioCrosswalk: true,
101
+ mode: Mode.Editing,
102
+ onAddOneMore: jest.fn(),
103
+ onDeleteAttribute: jest.fn(),
104
+ onChangeAttribute: jest.fn(),
105
+ onDeactivateError: jest.fn()
106
+ };
107
+ var setUp = function (_a) {
108
+ var _b = _a === void 0 ? {} : _a, _c = _b.props, props = _c === void 0 ? {} : _c, _d = _b.error, error = _d === void 0 ? null : _d, _e = _b.isProfilePerspective, isProfilePerspective = _e === void 0 ? false : _e, _f = _b.alwaysVisibleAttributes, alwaysVisibleAttributes = _f === void 0 ? [] : _f;
109
+ var user = userEvent.setup();
110
+ var scrollToElementContextValue = getScrollToElementContextValue(error);
111
+ var Providers = function (_a) {
112
+ var children = _a.children;
113
+ return (React.createElement(MdmModuleProvider, { values: mdmValues },
114
+ React.createElement(AlwaysVisibleAttributesContext.Provider, { value: alwaysVisibleAttributes },
115
+ React.createElement(ProfilePerspectiveViewContext.Provider, { value: isProfilePerspective },
116
+ React.createElement(ScrollToElementContext.Provider, { value: scrollToElementContextValue }, children)))));
140
117
  };
118
+ return __assign({ user: user, scrollToElementContextValue: scrollToElementContextValue }, render(React.createElement(SimpleAttributeEditor, __assign({}, defaultProps, props)), { wrapper: Providers }));
119
+ };
120
+ describe('String attribute', function () {
141
121
  it('should render the simple attribute to edit with action buttons', function () {
142
- var component = mountComponent();
143
- var errorWrapper = component.find(ErrorWrapper);
144
- expect(errorWrapper.find(DataTypeValueEditor).props()).toMatchObject({
145
- fieldName: 'attributes.InternalCustomer',
146
- value: 'some string',
147
- dataTypeDefinition: {
148
- type: 'String',
149
- uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
150
- }
151
- });
152
- expect(errorWrapper.prop('errorMessage')).toBeFalsy();
153
- var editor = component.find('.editor');
154
- expect(editor.hasClass(scrollToAttributeError.errorClassName)).toBeTruthy();
155
- expect(editor.getElement().ref).toBe(scrollToAttributeError.ref);
156
- var actionButtons = findActionButtons(component);
157
- expect(actionButtons.length).toBe(2);
158
- actionButtons.at(0).find('button').simulate('click');
159
- expect(onAddFn).toHaveBeenCalled();
160
- actionButtons.at(1).find('button').simulate('click');
161
- expect(onDeleteFn).toHaveBeenCalled();
122
+ setUp();
123
+ expect(screen.getByRole('textbox')).toHaveValue('some string');
124
+ expect(screen.queryByTestId('error-message')).not.toBeInTheDocument();
125
+ var actions = screen.getByTestId('reltio-attribute-actions');
126
+ expect(within(actions).getAllByRole('button')).toHaveLength(2);
127
+ expect(screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
128
+ expect(screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
162
129
  });
163
130
  it('should render additional control between plus and delete buttons if additionalControlsRenderer prop is specified', function () {
164
- var AdditionalControls = function () { return React.createElement("div", null); };
165
- var component = mountComponent({
166
- additionalControlsRenderer: function (_a) {
167
- var attributeValue = _a.attributeValue, attributeType = _a.attributeType;
168
- return (React.createElement(AdditionalControls, { attributeValue: attributeValue, attributeType: attributeType }));
131
+ setUp({
132
+ props: {
133
+ additionalControlsRenderer: function (_a) {
134
+ var attributeValue = _a.attributeValue, attributeType = _a.attributeType;
135
+ return (React.createElement("div", { "data-reltio-id": "additional-controls" },
136
+ React.createElement("div", { "data-reltio-id": "attribute-value" }, attributeValue.uri),
137
+ React.createElement("div", { "data-reltio-id": "attribute-type" }, attributeType.uri)));
138
+ }
169
139
  }
170
140
  });
171
- var actionButtons = findActionButtons(component);
172
- expect(actionButtons.length).toBe(3);
173
- expect(actionButtons.at(1).prop('attributeValue').uri).toBe('entities/eNt1/attributes/InternalCustomer/gd42423');
174
- expect(actionButtons.at(1).prop('attributeType').uri).toBe('configuration/entityTypes/HCA/attributes/InternalCustomer');
141
+ expect(screen.getByTestId('additional-controls')).toBeInTheDocument();
142
+ expect(screen.getByTestId('attribute-value')).toHaveTextContent('entities/eNt1/attributes/InternalCustomer/gd42423');
143
+ expect(screen.getByTestId('attribute-type')).toHaveTextContent('configuration/entityTypes/HCA/attributes/InternalCustomer');
175
144
  });
176
145
  it('should render error message if ownError prop is specified', function () {
177
146
  var ownError = {
@@ -181,209 +150,216 @@ describe('SimpleAttributeEditor', function () {
181
150
  message: 'Error!!!',
182
151
  type: 'invalid'
183
152
  };
184
- var component = mountComponent({ ownError: ownError });
185
- var errorWrapper = component.find(ErrorWrapper);
186
- expect(errorWrapper.find(DataTypeValueEditor).prop('value')).toEqual('some string');
187
- expect(errorWrapper.prop('errorMessage')).toBe(ownError.message);
153
+ setUp({ props: { ownError: ownError } });
154
+ expect(screen.getByRole('textbox')).toHaveValue('some string');
155
+ expect(screen.getByTestId('error-message')).toHaveTextContent('Error!!!');
188
156
  });
189
157
  it('should not render delete button in case of missed DELETE permission', function () {
190
- var component = mountComponent({ access: ['UPDATE', 'CREATE', 'READ'] });
191
- expect(component.find(DataTypeValueEditor).prop('value')).toEqual('some string');
192
- var actionButtons = findActionButtons(component);
193
- expect(actionButtons.length).toBe(1);
194
- actionButtons.at(0).find('button').simulate('click');
195
- expect(onAddFn).toHaveBeenCalled();
158
+ var attributeType = __assign(__assign({}, defaultProps.attributeType), { access: ['UPDATE', 'CREATE', 'READ'] });
159
+ setUp({ props: { attributeType: attributeType } });
160
+ expect(screen.getByRole('textbox')).toHaveValue('some string');
161
+ expect(screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
162
+ expect(screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
196
163
  });
197
164
  it('should not render plus button in case of missed CREATE permission', function () {
198
- var component = mountComponent({ access: ['UPDATE', 'DELETE', 'READ'] });
199
- expect(component.find(DataTypeValueEditor).prop('value')).toEqual('some string');
200
- var actionButtons = findActionButtons(component);
201
- expect(actionButtons.length).toBe(1);
202
- actionButtons.at(0).find('button').simulate('click');
203
- expect(onDeleteFn).toHaveBeenCalledWith({
204
- attributeType: {
205
- access: ['UPDATE', 'DELETE', 'READ'],
206
- type: 'String',
207
- uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
208
- },
209
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
210
- });
165
+ var attributeType = __assign(__assign({}, defaultProps.attributeType), { access: ['UPDATE', 'DELETE', 'READ'] });
166
+ setUp({ props: { attributeType: attributeType } });
167
+ expect(screen.getByRole('textbox')).toHaveValue('some string');
168
+ expect(screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
169
+ expect(screen.queryByTestId('reltio-add-one-more-simple-attribute-button')).not.toBeInTheDocument();
211
170
  });
212
- it('should call onChangeAttribute prop when input value changes', function () {
213
- var component = mountComponent();
214
- var editor = component.find(DataTypeValueEditor);
215
- editor.prop('onChange')('new string');
216
- expect(onChangeFn).toHaveBeenCalledWith({
217
- attributeType: {
218
- access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
219
- type: 'String',
220
- uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
221
- },
222
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
223
- value: 'new string'
171
+ it('should call onChangeAttribute prop when input value changes', function () { return __awaiter(void 0, void 0, void 0, function () {
172
+ var user;
173
+ return __generator(this, function (_a) {
174
+ switch (_a.label) {
175
+ case 0:
176
+ user = setUp().user;
177
+ return [4 /*yield*/, user.type(screen.getByRole('textbox'), ' new{enter}')];
178
+ case 1:
179
+ _a.sent();
180
+ expect(defaultProps.onChangeAttribute).toHaveBeenCalledWith({
181
+ attributeType: {
182
+ access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
183
+ type: 'String',
184
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
185
+ },
186
+ uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
187
+ value: 'some string new'
188
+ });
189
+ expect(defaultProps.onDeactivateError).not.toHaveBeenCalled();
190
+ return [2 /*return*/];
191
+ }
224
192
  });
225
- expect(onDeactivateErrorFn).not.toHaveBeenCalled();
226
- });
227
- it('should deactivate error when input value changes', function () {
228
- var ownError = {
229
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
230
- parentUri: 'entities/eNt1',
231
- attributeTypeUri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
232
- message: 'Error!!!',
233
- type: 'invalid'
234
- };
235
- var component = mountComponent({ ownError: ownError });
236
- var editor = component.find(DataTypeValueEditor);
237
- editor.prop('onChange')('new string');
238
- expect(onChangeFn).toHaveBeenCalledWith({
239
- attributeType: {
240
- access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
241
- type: 'String',
242
- uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
243
- },
244
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
245
- value: 'new string'
193
+ }); });
194
+ it('should deactivate error when input value changes', function () { return __awaiter(void 0, void 0, void 0, function () {
195
+ var ownError, user;
196
+ return __generator(this, function (_a) {
197
+ switch (_a.label) {
198
+ case 0:
199
+ ownError = {
200
+ uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
201
+ parentUri: 'entities/eNt1',
202
+ attributeTypeUri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
203
+ message: 'Error!!!',
204
+ type: 'invalid'
205
+ };
206
+ user = setUp({ props: { ownError: ownError } }).user;
207
+ return [4 /*yield*/, user.type(screen.getByRole('textbox'), ' new{enter}')];
208
+ case 1:
209
+ _a.sent();
210
+ expect(defaultProps.onChangeAttribute).toHaveBeenCalledWith({
211
+ attributeType: {
212
+ access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
213
+ type: 'String',
214
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
215
+ },
216
+ uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
217
+ value: 'some string new'
218
+ });
219
+ expect(defaultProps.onDeactivateError).toHaveBeenCalledWith('configuration/entityTypes/HCA/attributes/InternalCustomer-entities/eNt1/attributes/InternalCustomer/gd42423-entities/eNt1');
220
+ return [2 /*return*/];
221
+ }
246
222
  });
247
- expect(onDeactivateErrorFn).toHaveBeenCalledWith('configuration/entityTypes/HCA/attributes/InternalCustomer-entities/eNt1/attributes/InternalCustomer/gd42423-entities/eNt1');
248
- });
249
- it('should call onDeleteAttribute after click on delete button', function () {
250
- var component = mountComponent();
251
- var actionButtons = findActionButtons(component);
252
- expect(actionButtons.length).toBe(2);
253
- actionButtons.at(1).find('button').simulate('click');
254
- expect(onDeleteFn).toHaveBeenCalledWith({
255
- attributeType: {
256
- access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
257
- type: 'String',
258
- uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
259
- },
260
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
223
+ }); });
224
+ it('should call onDeleteAttribute after click on delete button', function () { return __awaiter(void 0, void 0, void 0, function () {
225
+ var user;
226
+ return __generator(this, function (_a) {
227
+ switch (_a.label) {
228
+ case 0:
229
+ user = setUp().user;
230
+ return [4 /*yield*/, user.click(screen.getByTestId('reltio-delete-simple-attribute-button'))];
231
+ case 1:
232
+ _a.sent();
233
+ expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
234
+ attributeType: {
235
+ access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
236
+ type: 'String',
237
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
238
+ },
239
+ uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
240
+ });
241
+ expect(defaultProps.onDeactivateError).not.toHaveBeenCalled();
242
+ return [2 /*return*/];
243
+ }
261
244
  });
262
- expect(onDeactivateErrorFn).not.toHaveBeenCalled();
263
- });
264
- it('should deactivate "invalid" error after click on delete button', function () {
265
- var ownError = {
266
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
267
- parentUri: 'entities/eNt1',
268
- attributeTypeUri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
269
- message: 'Error!!!',
270
- type: 'invalid'
271
- };
272
- var component = mountComponent({ ownError: ownError });
273
- var actionButtons = findActionButtons(component);
274
- expect(actionButtons.length).toBe(2);
275
- actionButtons.at(1).find('button').simulate('click');
276
- expect(onDeleteFn).toHaveBeenCalledWith({
277
- attributeType: {
278
- access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
279
- type: 'String',
280
- uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
281
- },
282
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
245
+ }); });
246
+ it('should call onAddOneMore on click on add more button', function () { return __awaiter(void 0, void 0, void 0, function () {
247
+ var user;
248
+ return __generator(this, function (_a) {
249
+ switch (_a.label) {
250
+ case 0:
251
+ user = setUp().user;
252
+ return [4 /*yield*/, user.click(screen.getByTestId('reltio-add-one-more-simple-attribute-button'))];
253
+ case 1:
254
+ _a.sent();
255
+ expect(defaultProps.onAddOneMore).toHaveBeenCalledTimes(1);
256
+ return [2 /*return*/];
257
+ }
283
258
  });
284
- expect(onDeactivateErrorFn).toHaveBeenCalledWith('configuration/entityTypes/HCA/attributes/InternalCustomer-entities/eNt1/attributes/InternalCustomer/gd42423-entities/eNt1');
285
- });
286
- it('should not deactivate "missed" error after click on delete button', function () {
287
- var ownError = {
288
- uri: '',
289
- parentUri: 'entities/eNt1',
290
- attributeTypeUri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
291
- message: 'Error!!!',
292
- type: 'missed'
293
- };
294
- var component = mountComponent({ ownError: ownError });
295
- var actionButtons = findActionButtons(component);
296
- expect(actionButtons.length).toBe(2);
297
- actionButtons.at(1).find('button').simulate('click');
298
- expect(onDeleteFn).toHaveBeenCalledWith({
299
- attributeType: {
300
- access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
301
- type: 'String',
302
- uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
303
- },
304
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
259
+ }); });
260
+ it('should deactivate "invalid" error after click on delete button', function () { return __awaiter(void 0, void 0, void 0, function () {
261
+ var ownError, user;
262
+ return __generator(this, function (_a) {
263
+ switch (_a.label) {
264
+ case 0:
265
+ ownError = {
266
+ uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
267
+ parentUri: 'entities/eNt1',
268
+ attributeTypeUri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
269
+ message: 'Error!!!',
270
+ type: 'invalid'
271
+ };
272
+ user = setUp({ props: { ownError: ownError } }).user;
273
+ return [4 /*yield*/, user.click(screen.getByTestId('reltio-delete-simple-attribute-button'))];
274
+ case 1:
275
+ _a.sent();
276
+ expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
277
+ attributeType: {
278
+ access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
279
+ type: 'String',
280
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
281
+ },
282
+ uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
283
+ });
284
+ expect(defaultProps.onDeactivateError).toHaveBeenCalledWith('configuration/entityTypes/HCA/attributes/InternalCustomer-entities/eNt1/attributes/InternalCustomer/gd42423-entities/eNt1');
285
+ return [2 /*return*/];
286
+ }
305
287
  });
306
- expect(onDeactivateErrorFn).not.toHaveBeenCalled();
307
- });
288
+ }); });
289
+ it('should not deactivate "missed" error after click on delete button', function () { return __awaiter(void 0, void 0, void 0, function () {
290
+ var ownError, user;
291
+ return __generator(this, function (_a) {
292
+ switch (_a.label) {
293
+ case 0:
294
+ ownError = {
295
+ uri: '',
296
+ parentUri: 'entities/eNt1',
297
+ attributeTypeUri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
298
+ message: 'Error!!!',
299
+ type: 'missed'
300
+ };
301
+ user = setUp({ props: { ownError: ownError } }).user;
302
+ return [4 /*yield*/, user.click(screen.getByTestId('reltio-delete-simple-attribute-button'))];
303
+ case 1:
304
+ _a.sent();
305
+ expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
306
+ attributeType: {
307
+ access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
308
+ type: 'String',
309
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
310
+ },
311
+ uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
312
+ });
313
+ expect(defaultProps.onDeactivateError).not.toHaveBeenCalled();
314
+ return [2 /*return*/];
315
+ }
316
+ });
317
+ }); });
308
318
  it('should be wrapped in withAsyncMount HOC', function () {
309
- var component = mountComponent();
310
- expect(component.find('WithAsyncMount').exists()).toBe(true);
311
- expect(component.find('WithAsyncMount').find('SimpleAttributeEditor').exists()).toBe(true);
319
+ setUp();
320
+ expect(useAsyncMount).toHaveBeenCalled();
312
321
  });
313
322
  it('should render component in "deleted" state', function () {
314
- var component = mountComponent({ state: 'deleted' });
315
- expect(component.find(DataTypeValueEditor).prop('disabled')).toBe(true);
316
- expect(component.find('.editor-value').hasClass('deleted')).toBe(true);
317
- expect(findActionButtons(component).length).toBe(1);
318
- expect(component.find('.editor-actions').text()).toBe('');
323
+ setUp({ props: { state: 'deleted' } });
324
+ expect(screen.getByRole('textbox')).toBeDisabled();
325
+ expect(screen.getByTestId('reltio-attribute-value')).toHaveClass('deleted');
326
+ expect(screen.getAllByRole('button')).toHaveLength(1);
327
+ expect(screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
328
+ expect(screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
329
+ expect(screen.getByTestId('reltio-attribute-actions')).toHaveTextContent('');
319
330
  });
320
331
  it('should render component in "edited" state', function () {
321
- var component = mountComponent({ state: 'edited' });
322
- expect(component.find(DataTypeValueEditor).prop('disabled')).toBeFalsy();
323
- expect(component.find('.editor-value').hasClass('deleted')).toBeFalsy();
324
- expect(findActionButtons(component).length).toBe(3);
325
- expect(component.find('.editor-actions').text()).toBe('(edited)');
332
+ setUp({ props: { state: 'edited' } });
333
+ expect(screen.getByRole('textbox')).not.toBeDisabled();
334
+ expect(screen.getByTestId('reltio-attribute-value')).not.toHaveClass('deleted');
335
+ expect(screen.getAllByRole('button')).toHaveLength(2);
336
+ expect(screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
337
+ expect(screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
338
+ expect(screen.getByTestId('reltio-attribute-actions')).toHaveTextContent('(edited)');
326
339
  });
327
340
  });
328
341
  describe('Dependent Lookup attribute', function () {
329
342
  beforeEach(function () {
330
343
  useMdmDependentLookupEditorContext.mockReturnValue({});
331
- jest.spyOn(useAutopopulationContextValueExport, 'useAutopopulationContextValue').mockReturnValue({
332
- autopopulationContextValue: null
333
- });
344
+ useAutopopulationContextValue.mockReturnValue({ autopopulationContextValue: null });
334
345
  });
335
- var defaultProps = {
336
- attributeValue: {
337
- value: 'some string',
338
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
339
- },
340
- attributeType: {
341
- type: 'String',
342
- uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
343
- dependentLookupCode: 'Code'
344
- },
345
- mode: Mode.Editing,
346
- onChangeAttribute: jest.fn()
347
- };
348
- var setUp = function () {
349
- var args_1 = [];
350
- for (var _i = 0; _i < arguments.length; _i++) {
351
- args_1[_i] = arguments[_i];
352
- }
353
- return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (props, _a) {
354
- var user, renderResult;
355
- if (props === void 0) { props = {}; }
356
- var _b = _a === void 0 ? {} : _a, _c = _b.isProfilePerspective, isProfilePerspective = _c === void 0 ? true : _c;
357
- return __generator(this, function (_d) {
358
- switch (_d.label) {
359
- case 0:
360
- user = userEvent.setup();
361
- renderResult = render(React.createElement(ProfilePerspectiveViewContext.Provider, { value: isProfilePerspective },
362
- React.createElement(ScrollToElementContext.Provider, { value: {
363
- element: null,
364
- highlightError: highlightErrorSpy,
365
- scrollIntoRef: scrollIntoRefSpy,
366
- type: ScrollType.Error
367
- } },
368
- React.createElement(SimpleAttributeEditor, __assign({}, defaultProps, props)))));
369
- return [4 /*yield*/, act(function () { return Promise.resolve(); })];
370
- case 1:
371
- _d.sent();
372
- return [2 /*return*/, __assign({ user: user }, renderResult)];
373
- }
374
- });
375
- });
346
+ var attributeType = {
347
+ type: 'String',
348
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
349
+ dependentLookupCode: 'Code'
376
350
  };
377
351
  it('should call getDependentLookupEditorContext selector with correct arguments', function () { return __awaiter(void 0, void 0, void 0, function () {
378
352
  return __generator(this, function (_a) {
379
353
  switch (_a.label) {
380
- case 0: return [4 /*yield*/, setUp()];
354
+ case 0:
355
+ setUp({ props: { attributeType: attributeType }, isProfilePerspective: true });
356
+ return [4 /*yield*/, act(function () { return Promise.resolve(); })];
381
357
  case 1:
382
358
  _a.sent();
383
- expect(useMdmDependentLookupEditorContext).toHaveBeenCalledWith(defaultProps.attributeValue, defaultProps.attributeType);
384
- expect(useAutopopulationContextValueExport.useAutopopulationContextValue).toHaveBeenCalledWith({
359
+ expect(useMdmDependentLookupEditorContext).toHaveBeenCalledWith(defaultProps.attributeValue, attributeType);
360
+ expect(useAutopopulationContextValue).toHaveBeenCalledWith({
385
361
  enabled: true,
386
- attributeTypeUri: defaultProps.attributeType.uri,
362
+ attributeTypeUri: attributeType.uri,
387
363
  valueUri: defaultProps.attributeValue.uri
388
364
  });
389
365
  return [2 /*return*/];
@@ -393,12 +369,14 @@ describe('SimpleAttributeEditor', function () {
393
369
  it('should call useAutopopulationContextValue with enabled: false if component is outside of Profile perspective', function () { return __awaiter(void 0, void 0, void 0, function () {
394
370
  return __generator(this, function (_a) {
395
371
  switch (_a.label) {
396
- case 0: return [4 /*yield*/, setUp({}, { isProfilePerspective: false })];
372
+ case 0:
373
+ setUp({ props: { attributeType: attributeType }, isProfilePerspective: false });
374
+ return [4 /*yield*/, act(function () { return Promise.resolve(); })];
397
375
  case 1:
398
376
  _a.sent();
399
- expect(useAutopopulationContextValueExport.useAutopopulationContextValue).toHaveBeenCalledWith({
377
+ expect(useAutopopulationContextValue).toHaveBeenCalledWith({
400
378
  enabled: false,
401
- attributeTypeUri: defaultProps.attributeType.uri,
379
+ attributeTypeUri: attributeType.uri,
402
380
  valueUri: defaultProps.attributeValue.uri
403
381
  });
404
382
  return [2 /*return*/];
@@ -422,7 +400,8 @@ describe('SimpleAttributeEditor', function () {
422
400
  value: null
423
401
  };
424
402
  useMdmDependentLookupEditorContext.mockReturnValue(dlEditorContext);
425
- return [4 /*yield*/, setUp()];
403
+ setUp({ props: { attributeType: attributeType }, isProfilePerspective: true });
404
+ return [4 /*yield*/, act(function () { return Promise.resolve(); })];
426
405
  case 1:
427
406
  _a.sent();
428
407
  expect(screen.getByText('Some placeholder')).toBeDefined();
@@ -435,7 +414,7 @@ describe('SimpleAttributeEditor', function () {
435
414
  max: 51,
436
415
  offset: 0,
437
416
  parents: dlEditorContext.parents,
438
- type: defaultProps.attributeType.dependentLookupCode
417
+ type: attributeType.dependentLookupCode
439
418
  });
440
419
  return [2 /*return*/];
441
420
  }
@@ -451,12 +430,11 @@ describe('SimpleAttributeEditor', function () {
451
430
  isTouched: true,
452
431
  onTouch: jest.fn()
453
432
  };
454
- jest.spyOn(useAutopopulationContextValueExport, 'useAutopopulationContextValue').mockReturnValue({
455
- autopopulationContextValue: autopopulationContextValue
456
- });
457
- return [4 /*yield*/, setUp()];
433
+ useAutopopulationContextValue.mockReturnValue({ autopopulationContextValue: autopopulationContextValue });
434
+ user = setUp({ props: { attributeType: attributeType }, isProfilePerspective: true }).user;
435
+ return [4 /*yield*/, act(function () { return Promise.resolve(); })];
458
436
  case 1:
459
- user = (_a.sent()).user;
437
+ _a.sent();
460
438
  input = screen.getByRole('combobox');
461
439
  expect(input).toBeDefined();
462
440
  return [4 /*yield*/, user.clear(input)];
@@ -469,33 +447,6 @@ describe('SimpleAttributeEditor', function () {
469
447
  }); });
470
448
  });
471
449
  describe('useScrollToAttributeError tests', function () {
472
- var mdmValues = {
473
- dependentLookups: {
474
- editors: {}
475
- }
476
- };
477
- var defaultProps = {
478
- attributeValue: {
479
- value: 'some string',
480
- uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
481
- },
482
- attributeType: {
483
- type: 'String',
484
- uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
485
- },
486
- mode: Mode.Editing
487
- };
488
- var setUp = function (error) {
489
- if (error === void 0) { error = null; }
490
- return mount(React.createElement(MdmModuleProvider, { values: mdmValues },
491
- React.createElement(ScrollToElementContext.Provider, { value: {
492
- element: error,
493
- highlightError: highlightErrorSpy,
494
- scrollIntoRef: scrollIntoRefSpy,
495
- type: ScrollType.Error
496
- } },
497
- React.createElement(SimpleAttributeEditor, __assign({}, defaultProps)))));
498
- };
499
450
  var fullError = {
500
451
  type: 'invalid',
501
452
  attributeTypeUri: defaultProps.attributeType.uri,
@@ -505,24 +456,82 @@ describe('SimpleAttributeEditor', function () {
505
456
  severity: 'ERROR'
506
457
  };
507
458
  it('should not highlight error if it have wrong uri', function () {
508
- var component = setUp(fullError);
509
- expect(component.find('SimpleAttributeEditor').prop('highlightedError')).toBe(null);
510
- expect(useScrollToAttributeError.mock.calls[0][0]).toMatchObject({
511
- highlightedError: null,
512
- isSimple: true
513
- });
459
+ setUp({ error: fullError });
460
+ expect(screen.getByTestId('simple-attribute-editor')).not.toHaveClass('highlightError simpleAttribute');
461
+ expect(useScrollToAttributeError).toHaveBeenCalledWith({ highlightedError: null, isSimple: true });
514
462
  });
515
463
  it('should highlight error if it have right uri', function () {
516
464
  var error = __assign(__assign({}, fullError), { uri: defaultProps.attributeValue.uri });
517
- var component = setUp(error);
518
- var highlightedError = {
519
- element: error,
520
- highlightError: highlightErrorSpy,
521
- scrollIntoRef: scrollIntoRefSpy,
522
- type: ScrollType.Error
465
+ var scrollToElementContextValue = setUp({ error: error }).scrollToElementContextValue;
466
+ expect(screen.getByTestId('simple-attribute-editor')).toHaveClass('highlightError simpleAttribute');
467
+ expect(useScrollToAttributeError).toHaveBeenCalledWith({
468
+ highlightedError: scrollToElementContextValue,
469
+ isSimple: true
470
+ });
471
+ });
472
+ });
473
+ describe('without permissions', function () {
474
+ it('should render just text, if there is only READ permission', function () {
475
+ var props = {
476
+ attributeValue: {
477
+ value: 'some string',
478
+ uri: '1'
479
+ },
480
+ attributeType: {
481
+ access: ['READ'],
482
+ type: 'String',
483
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
484
+ }
485
+ };
486
+ setUp({ props: props });
487
+ expect(screen.getByText('some string')).toBeInTheDocument();
488
+ expect(screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
489
+ });
490
+ it('should render text and DELETE button, if there are only READ and DELETE permission', function () {
491
+ var props = {
492
+ attributeValue: {
493
+ value: 'some string',
494
+ uri: '1'
495
+ },
496
+ attributeType: {
497
+ access: ['READ', 'DELETE'],
498
+ type: 'String',
499
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
500
+ }
501
+ };
502
+ setUp({ props: props });
503
+ expect(screen.getByText('some string')).toBeInTheDocument();
504
+ expect(screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
505
+ });
506
+ it('should render always visible attribute without value correct, if there are only READ permission', function () {
507
+ var props = {
508
+ attributeValue: {
509
+ uri: 'uri$$'
510
+ },
511
+ attributeType: {
512
+ access: ['READ'],
513
+ type: 'String',
514
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
515
+ }
516
+ };
517
+ setUp({ props: props, alwaysVisibleAttributes: ['configuration/entityTypes/HCA/attributes/InternalCustomer'] });
518
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
519
+ expect(screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
520
+ });
521
+ it('should render always visible attribute without value correct, if there are only READ and DELETE permission', function () {
522
+ var props = {
523
+ attributeValue: {
524
+ uri: 'uri$$'
525
+ },
526
+ attributeType: {
527
+ access: ['READ', 'DELETE'],
528
+ type: 'String',
529
+ uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
530
+ }
523
531
  };
524
- expect(component.find('SimpleAttributeEditor').prop('highlightedError')).toMatchObject(highlightedError);
525
- expect(useScrollToAttributeError.mock.calls[0][0]).toMatchObject({ highlightedError: highlightedError, isSimple: true });
532
+ setUp({ props: props, alwaysVisibleAttributes: ['configuration/entityTypes/HCA/attributes/InternalCustomer'] });
533
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
534
+ expect(screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
526
535
  });
527
536
  });
528
537
  });