@reltio/components 1.4.2070 → 1.4.2071

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 (159) hide show
  1. package/FacetViewHeader/FacetViewHeader.js +1 -1
  2. package/ImageAttributesLine/imageAttributeValues.test-data.js +8 -0
  3. package/ImageAttributesLine/index.d.ts +1 -1
  4. package/ImageAttributesLine/index.js +1 -1
  5. package/ImageDetailsView/components/ImageDetailsViewCarousel/ImageDetailsViewCarousel.js +1 -1
  6. package/MergeButton/MergeButton.spec.js +55 -124
  7. package/MetadataTypesSelector/MetadataTypesSelector.js +1 -1
  8. package/MetadataTypesSelector/MetadataTypesSelector.test.js +193 -190
  9. package/MoreAttributesButton/MoreAttributesButton.test.js +173 -166
  10. package/MultiValueSelector/MultiValueSelector.test.js +78 -38
  11. package/MultipliableSelect/MultipliableSelect.test.js +111 -47
  12. package/NestedAttribute/NestedAttribute.test.js +121 -42
  13. package/NestedAttributeEditor/NestedAttributeEditor.test.js +95 -41
  14. package/NotMatchButton/NotMatchButton.spec.js +51 -100
  15. package/PieChart/PieChart.test.js +130 -114
  16. package/PinButton/PinButton.spec.js +89 -22
  17. package/PivotingTooltip/PivotingTooltip.test.js +338 -174
  18. package/PotentialMatchReviewCard/PotentialMatchReviewCard.spec.js +94 -29
  19. package/ProfileBand/ProfileBand.spec.js +60 -53
  20. package/ProfileCard/ProfileCard.test.js +109 -27
  21. package/ProfilesList/ProfilesList.d.ts +1 -3
  22. package/ProfilesList/ProfilesList.js +1 -1
  23. package/ProfilesList/ProfilesList.spec.js +226 -211
  24. package/QueryBuilderRow/QueryBuilderRow.spec.js +83 -90
  25. package/QueryBuilderRowsGroup/QueryBuilderRowsGroup.spec.js +195 -86
  26. package/ReactSelectLoadMoreButton/ReactSelectLoadMoreButton.test.js +73 -15
  27. package/ReactSelectMenuWithPopper/ReactSelectMenuWithPopper.test.js +71 -117
  28. package/ReadOnlyAttributeValuesBlock/ReadOnlyAttributeValuesBlock.test.js +128 -61
  29. package/ReadOnlyAttributesFactory/components/ReadOnlyAttribute/ReadOnlyAttribute.test.js +179 -44
  30. package/ReadOnlyAttributesList/ReadOnlyAttributesList.test.js +254 -211
  31. package/ReadOnlyAttributesList/attributes.test-data.js +4 -4
  32. package/ReadOnlyAttributesPager/ReadOnlyAttributesPager.test.js +75 -18
  33. package/ReadOnlyAttributesView/ReadOnlyAttributesView.test.js +187 -312
  34. package/ReadOnlyComplexAttribute/ReadOnlyComplexAttribute.test.js +210 -219
  35. package/ReadOnlyImageAttributesLine/ReadOnlyImageAttributesLine.test.js +89 -89
  36. package/ReferenceAttributeEditor/ReferenceAttributeEditor.test.js +556 -602
  37. package/ReferenceAttributeEditor/metadata.test-data.d.ts +13 -13
  38. package/ReferenceAttributeEditor/metadata.test-data.js +2 -2
  39. package/ReferenceAttributeEditor/styles.d.ts +1 -1
  40. package/RelationEditor/RelationEditor.test.js +1448 -1392
  41. package/RelationTypeSelector/RelationTypeSelector.test.js +99 -17
  42. package/RelationTypesSelector/RelationTypesSelector.test.js +73 -22
  43. package/ReltioMap/ReltioMap.spec.js +51 -25
  44. package/Roles/Roles.test.js +54 -10
  45. package/ScreenProfileBand/ScreenProfileBand.test.js +142 -72
  46. package/cjs/FacetViewHeader/FacetViewHeader.js +1 -1
  47. package/cjs/ImageAttributesLine/imageAttributeValues.test-data.js +8 -0
  48. package/cjs/ImageAttributesLine/index.d.ts +1 -1
  49. package/cjs/ImageAttributesLine/index.js +2 -1
  50. package/cjs/ImageDetailsView/components/ImageDetailsViewCarousel/ImageDetailsViewCarousel.js +1 -1
  51. package/cjs/MergeButton/MergeButton.spec.js +55 -124
  52. package/cjs/MetadataTypesSelector/MetadataTypesSelector.js +1 -1
  53. package/cjs/MetadataTypesSelector/MetadataTypesSelector.test.js +193 -190
  54. package/cjs/MoreAttributesButton/MoreAttributesButton.test.js +172 -165
  55. package/cjs/MultiValueSelector/MultiValueSelector.test.js +78 -38
  56. package/cjs/MultipliableSelect/MultipliableSelect.test.js +111 -47
  57. package/cjs/NestedAttribute/NestedAttribute.test.js +121 -42
  58. package/cjs/NestedAttributeEditor/NestedAttributeEditor.test.js +94 -40
  59. package/cjs/NotMatchButton/NotMatchButton.spec.js +51 -100
  60. package/cjs/PieChart/PieChart.test.js +130 -114
  61. package/cjs/PinButton/PinButton.spec.js +89 -22
  62. package/cjs/PivotingTooltip/PivotingTooltip.test.js +338 -174
  63. package/cjs/PotentialMatchReviewCard/PotentialMatchReviewCard.spec.js +94 -29
  64. package/cjs/ProfileBand/ProfileBand.spec.js +60 -53
  65. package/cjs/ProfileCard/ProfileCard.test.js +109 -27
  66. package/cjs/ProfilesList/ProfilesList.d.ts +1 -3
  67. package/cjs/ProfilesList/ProfilesList.js +1 -1
  68. package/cjs/ProfilesList/ProfilesList.spec.js +226 -211
  69. package/cjs/QueryBuilderRow/QueryBuilderRow.spec.js +83 -90
  70. package/cjs/QueryBuilderRowsGroup/QueryBuilderRowsGroup.spec.js +195 -86
  71. package/cjs/ReactSelectLoadMoreButton/ReactSelectLoadMoreButton.test.js +73 -15
  72. package/cjs/ReactSelectMenuWithPopper/ReactSelectMenuWithPopper.test.js +71 -117
  73. package/cjs/ReadOnlyAttributeValuesBlock/ReadOnlyAttributeValuesBlock.test.js +128 -61
  74. package/cjs/ReadOnlyAttributesFactory/components/ReadOnlyAttribute/ReadOnlyAttribute.test.js +179 -44
  75. package/cjs/ReadOnlyAttributesList/ReadOnlyAttributesList.test.js +254 -211
  76. package/cjs/ReadOnlyAttributesList/attributes.test-data.js +4 -4
  77. package/cjs/ReadOnlyAttributesPager/ReadOnlyAttributesPager.test.js +75 -18
  78. package/cjs/ReadOnlyAttributesView/ReadOnlyAttributesView.test.js +185 -310
  79. package/cjs/ReadOnlyComplexAttribute/ReadOnlyComplexAttribute.test.js +209 -218
  80. package/cjs/ReadOnlyImageAttributesLine/ReadOnlyImageAttributesLine.test.js +89 -89
  81. package/cjs/ReferenceAttributeEditor/ReferenceAttributeEditor.test.js +555 -601
  82. package/cjs/ReferenceAttributeEditor/metadata.test-data.d.ts +13 -13
  83. package/cjs/ReferenceAttributeEditor/metadata.test-data.js +2 -2
  84. package/cjs/ReferenceAttributeEditor/styles.d.ts +1 -1
  85. package/cjs/RelationEditor/RelationEditor.test.js +1446 -1390
  86. package/cjs/RelationTypeSelector/RelationTypeSelector.test.js +99 -17
  87. package/cjs/RelationTypesSelector/RelationTypesSelector.test.js +73 -22
  88. package/cjs/ReltioMap/ReltioMap.spec.js +51 -25
  89. package/cjs/Roles/Roles.test.js +54 -10
  90. package/cjs/ScreenProfileBand/ScreenProfileBand.test.js +141 -71
  91. package/package.json +1 -1
  92. package/MetadataTypesSelector/components/ListLabel/ListLabel.test.d.ts +0 -1
  93. package/MetadataTypesSelector/components/ListLabel/ListLabel.test.js +0 -24
  94. package/PivotingTooltip/IntegrationPivotingTooltip.test.d.ts +0 -1
  95. package/PivotingTooltip/IntegrationPivotingTooltip.test.js +0 -356
  96. package/PivotingTooltip/components/PivotingTooltipContent/PivotingTooltipContent.test.d.ts +0 -1
  97. package/PivotingTooltip/components/PivotingTooltipContent/PivotingTooltipContent.test.js +0 -201
  98. package/ProfileCard/components/ProfileCardContent/ProfileCardContent.test.d.ts +0 -1
  99. package/ProfileCard/components/ProfileCardContent/ProfileCardContent.test.js +0 -43
  100. package/QueryBuilderRow/components/ReadOnlyFilter/ReadOnlyFilter.spec.d.ts +0 -1
  101. package/QueryBuilderRow/components/ReadOnlyFilter/ReadOnlyFilter.spec.js +0 -31
  102. package/QueryBuilderRow/components/ReadOnlyLogicOperator/ReadOnlyLogicOperator.spec.d.ts +0 -1
  103. package/QueryBuilderRow/components/ReadOnlyLogicOperator/ReadOnlyLogicOperator.spec.js +0 -31
  104. package/ReadOnlyAttributesPager/components/ImageLineRenderer/ImageLineRenderer.test.d.ts +0 -1
  105. package/ReadOnlyAttributesPager/components/ImageLineRenderer/ImageLineRenderer.test.js +0 -45
  106. package/ReadOnlyAttributesPager/components/MultiLineRenderer/MultiLineRenderer.test.d.ts +0 -1
  107. package/ReadOnlyAttributesPager/components/MultiLineRenderer/MultiLineRenderer.test.js +0 -114
  108. package/ReadOnlyAttributesPager/components/OneLineRenderer/OneLineRenderer.test.d.ts +0 -1
  109. package/ReadOnlyAttributesPager/components/OneLineRenderer/OneLineRenderer.test.js +0 -107
  110. package/ReadOnlyAttributesPager/components/SpecialRenderer/SpecialRenderer.test.d.ts +0 -1
  111. package/ReadOnlyAttributesPager/components/SpecialRenderer/SpecialRenderer.test.js +0 -72
  112. package/RelationEditor/IntegrationRelationEditor.test.d.ts +0 -1
  113. package/RelationEditor/IntegrationRelationEditor.test.js +0 -337
  114. package/ReltioMap/components/MapControlContainer/MapControlContainer.d.ts +0 -10
  115. package/ReltioMap/components/MapControlContainer/MapControlContainer.js +0 -24
  116. package/ReltioMap/components/MapControlContainer/MapControlContainer.spec.d.ts +0 -1
  117. package/ReltioMap/components/MapControlContainer/MapControlContainer.spec.js +0 -33
  118. package/ReltioMap/components/MapControlContainer/index.d.ts +0 -1
  119. package/ReltioMap/components/MapControlContainer/index.js +0 -1
  120. package/ReltioMap/components/TopCenterMapControls/TopCenterMapControls.spec.d.ts +0 -1
  121. package/ReltioMap/components/TopCenterMapControls/TopCenterMapControls.spec.js +0 -36
  122. package/ReltioMap/components/TopRightMapControls/TopRightMapControls.spec.d.ts +0 -1
  123. package/ReltioMap/components/TopRightMapControls/TopRightMapControls.spec.js +0 -60
  124. package/Roles/components/Role/Role.test.d.ts +0 -1
  125. package/Roles/components/Role/Role.test.js +0 -55
  126. package/cjs/MetadataTypesSelector/components/ListLabel/ListLabel.test.d.ts +0 -1
  127. package/cjs/MetadataTypesSelector/components/ListLabel/ListLabel.test.js +0 -52
  128. package/cjs/PivotingTooltip/IntegrationPivotingTooltip.test.d.ts +0 -1
  129. package/cjs/PivotingTooltip/IntegrationPivotingTooltip.test.js +0 -361
  130. package/cjs/PivotingTooltip/components/PivotingTooltipContent/PivotingTooltipContent.test.d.ts +0 -1
  131. package/cjs/PivotingTooltip/components/PivotingTooltipContent/PivotingTooltipContent.test.js +0 -206
  132. package/cjs/ProfileCard/components/ProfileCardContent/ProfileCardContent.test.d.ts +0 -1
  133. package/cjs/ProfileCard/components/ProfileCardContent/ProfileCardContent.test.js +0 -48
  134. package/cjs/QueryBuilderRow/components/ReadOnlyFilter/ReadOnlyFilter.spec.d.ts +0 -1
  135. package/cjs/QueryBuilderRow/components/ReadOnlyFilter/ReadOnlyFilter.spec.js +0 -36
  136. package/cjs/QueryBuilderRow/components/ReadOnlyLogicOperator/ReadOnlyLogicOperator.spec.d.ts +0 -1
  137. package/cjs/QueryBuilderRow/components/ReadOnlyLogicOperator/ReadOnlyLogicOperator.spec.js +0 -36
  138. package/cjs/ReadOnlyAttributesPager/components/ImageLineRenderer/ImageLineRenderer.test.d.ts +0 -1
  139. package/cjs/ReadOnlyAttributesPager/components/ImageLineRenderer/ImageLineRenderer.test.js +0 -50
  140. package/cjs/ReadOnlyAttributesPager/components/MultiLineRenderer/MultiLineRenderer.test.d.ts +0 -1
  141. package/cjs/ReadOnlyAttributesPager/components/MultiLineRenderer/MultiLineRenderer.test.js +0 -119
  142. package/cjs/ReadOnlyAttributesPager/components/OneLineRenderer/OneLineRenderer.test.d.ts +0 -1
  143. package/cjs/ReadOnlyAttributesPager/components/OneLineRenderer/OneLineRenderer.test.js +0 -112
  144. package/cjs/ReadOnlyAttributesPager/components/SpecialRenderer/SpecialRenderer.test.d.ts +0 -1
  145. package/cjs/ReadOnlyAttributesPager/components/SpecialRenderer/SpecialRenderer.test.js +0 -77
  146. package/cjs/RelationEditor/IntegrationRelationEditor.test.d.ts +0 -1
  147. package/cjs/RelationEditor/IntegrationRelationEditor.test.js +0 -342
  148. package/cjs/ReltioMap/components/MapControlContainer/MapControlContainer.d.ts +0 -10
  149. package/cjs/ReltioMap/components/MapControlContainer/MapControlContainer.js +0 -28
  150. package/cjs/ReltioMap/components/MapControlContainer/MapControlContainer.spec.d.ts +0 -1
  151. package/cjs/ReltioMap/components/MapControlContainer/MapControlContainer.spec.js +0 -38
  152. package/cjs/ReltioMap/components/MapControlContainer/index.d.ts +0 -1
  153. package/cjs/ReltioMap/components/MapControlContainer/index.js +0 -5
  154. package/cjs/ReltioMap/components/TopCenterMapControls/TopCenterMapControls.spec.d.ts +0 -1
  155. package/cjs/ReltioMap/components/TopCenterMapControls/TopCenterMapControls.spec.js +0 -41
  156. package/cjs/ReltioMap/components/TopRightMapControls/TopRightMapControls.spec.d.ts +0 -1
  157. package/cjs/ReltioMap/components/TopRightMapControls/TopRightMapControls.spec.js +0 -65
  158. package/cjs/Roles/components/Role/Role.test.d.ts +0 -1
  159. package/cjs/Roles/components/Role/Role.test.js +0 -60
@@ -9,1483 +9,1539 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
- if (ar || !(i in from)) {
15
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
- ar[i] = from[i];
17
- }
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
18
46
  }
19
- return to.concat(ar || Array.prototype.slice.call(from));
20
47
  };
21
48
  import React from 'react';
22
- import { mount } from 'enzyme';
23
- import Button from '@mui/material/Button';
24
- import Typography from '@mui/material/Typography';
25
- import { ACTIVENESS_ATTR_TYPES, Directions, ErrorSource, Mode, createTemporaryEntity, getEntityType, getInOutRelations, validateConnection } from '@reltio/mdm-sdk';
26
- import RelationEditor from './RelationEditor';
27
- import { ConnectionRelationTypeSelector } from '../ConnectionRelationTypeSelector';
28
- import { ErrorWrapper } from '../ErrorWrapper';
29
- import { EntitySelector } from '../EntitySelector';
30
- import { config, config2, relationTypes } from './relations.test-data';
31
- import { EditModeAttributesList } from '../EditModeAttributesList';
32
- import { EditModeComplexAttribute } from '../EditModeComplexAttribute';
33
- import { EmptyStub } from '../EmptyStub';
49
+ import { screen, render, within } from '@testing-library/react';
50
+ import userEvent from '@testing-library/user-event';
51
+ import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
52
+ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
53
+ import { Mode, ScreenType, ProfileViewType, typeAheadSearch, ErrorType, ActivityFilter, ErrorSource, ErrorSeverity } from '@reltio/mdm-sdk';
34
54
  import { ScrollToElementContext, ScrollType } from '../contexts/ScrollToElementContext';
35
- import { MdmModuleProvider, useMdmInitialConnection, useMdmInitialConnectionTempEntity, useMdmModifiedEntity, useMdmModifiedEntities, useMdmProfileErrors, useMdmEntityUri } from '../contexts/MdmModuleContext';
36
- import { useScrollToAttributeError } from '../hooks/useScrollToAttributeError';
37
- var editing = Mode.Editing;
38
- jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getEntityType: jest.fn(), createTemporaryEntity: jest.fn(), validateConnection: jest.fn().mockImplementation(jest.requireActual('@reltio/mdm-sdk').validateConnection), getInOutRelations: jest.fn().mockImplementation(jest.requireActual('@reltio/mdm-sdk').getInOutRelations) })); });
39
- jest.mock('../EditModeAttributesList', function () { return ({
40
- EditModeAttributesList: jest.fn()
41
- }); });
42
- jest.mock('../EditModeComplexAttribute', function () { return ({
43
- EditModeComplexAttribute: jest.fn()
44
- }); });
45
- jest.mock('../EntitySelector', function () { return ({
46
- EntitySelector: jest.fn()
47
- }); });
48
- jest.mock('../contexts/MdmModuleContext', function () { return (__assign(__assign({}, jest.requireActual('../contexts/MdmModuleContext')), { useMdmInitialConnection: jest.fn(), useMdmInitialConnectionTempEntity: jest.fn(), useMdmModifiedEntity: jest.fn(), useMdmModifiedEntities: jest.fn(), useMdmProfileErrors: jest.fn(), useMdmEntityUri: jest.fn() })); });
49
- jest.mock('../hooks/useScrollToAttributeError', function () { return (__assign(__assign({}, jest.requireActual('../hooks/useScrollToAttributeError')), { useScrollToAttributeError: jest.fn() })); });
50
- describe('RelationEditor', function () {
51
- var scrollToAttributeError = {
52
- ref: React.createRef(),
53
- errorClassName: 'errorClassName',
54
- path: []
55
- };
56
- var highlightErrorSpy = jest.fn();
57
- var scrollIntoRefSpy = jest.fn();
58
- var relationUri = 'relations/1';
59
- var mdmAction = jest.fn();
60
- var mdmActions = {
61
- setInitialInfo: jest.fn(function () { return mdmAction(); }),
62
- setRelationType: jest.fn(function () { return mdmAction(); }),
63
- closeRelationEditor: jest.fn(function () { return mdmAction(); }),
64
- entityCreated: jest.fn(function () { return mdmAction(); }),
65
- entityDeleted: jest.fn(function () { return mdmAction(); }),
66
- setRelationEntity: jest.fn(function () { return mdmAction(); }),
67
- errorDeactivated: jest.fn(function () { return mdmAction(); }),
68
- errorsSet: jest.fn(function () { return mdmAction(); }),
69
- addAttributes: jest.fn(function () { return mdmAction(); }),
70
- modifyAttribute: jest.fn(function () { return mdmAction(); }),
71
- removeAttribute: jest.fn(function () { return mdmAction(); }),
72
- addRelation: jest.fn(function (_id, _connection) { return mdmAction(); }),
73
- editRelation: jest.fn(function (_id, _connection) { return mdmAction(); })
74
- };
75
- var defaultMdmValues = {
76
- initialConnection: { connection: { relation: { relationUri: relationUri }, entity: {} } },
77
- initialModifiedEntity: null,
78
- modifiedEntity: null,
79
- uiConfigLayout: [],
80
- uiConfigProfile: [],
81
- entityUri: 'entities/123abc'
82
- };
83
- var defaultProps = {
84
- connection: { relation: { relationUri: relationUri }, entity: {} },
85
- config: { id: 'relationView1', content: { entityTypes: ['Type1'] } },
86
- metadata: {
87
- relationTypes: []
88
- },
89
- mode: editing
55
+ import { MdmModuleProvider } from '../contexts/MdmModuleContext';
56
+ import { HiddenAttributesContext } from '../contexts/HiddenAttributesContext';
57
+ import RelationEditor from './RelationEditor';
58
+ jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { typeAheadSearch: jest.fn() })); });
59
+ var highlightError = jest.fn();
60
+ var scrollIntoRef = jest.fn();
61
+ var mdmAction = jest.fn();
62
+ var mdmActions = {
63
+ setInitialInfo: jest.fn(function () { return mdmAction(); }),
64
+ setRelationType: jest.fn(function () { return mdmAction(); }),
65
+ closeRelationEditor: jest.fn(function () { return mdmAction(); }),
66
+ entityCreated: jest.fn(function () { return mdmAction(); }),
67
+ entityDeleted: jest.fn(function () { return mdmAction(); }),
68
+ setRelationEntity: jest.fn(function () { return mdmAction(); }),
69
+ errorDeactivated: jest.fn(function () { return mdmAction(); }),
70
+ errorsSet: jest.fn(function () { return mdmAction(); }),
71
+ addAttributes: jest.fn(function () { return mdmAction(); }),
72
+ modifyAttribute: jest.fn(function () { return mdmAction(); }),
73
+ removeAttribute: jest.fn(function () { return mdmAction(); }),
74
+ addRelation: jest.fn(function (_id, _connection) { return mdmAction(); }),
75
+ editRelation: jest.fn(function (_id, _connection) { return mdmAction(); })
76
+ };
77
+ var defaultRelation = {
78
+ relationUri: 'relations/uri$$Qgs4qfvmR3Daksyb1697627670006',
79
+ relationType: 'configuration/relationTypes/HasAddress',
80
+ relationLabel: 'has address',
81
+ object: {
82
+ type: 'configuration/relationTypes/HasAddress',
83
+ attributes: {},
84
+ uri: 'relations/uri$$Qgs4qfvmR3Daksyb1697627670006'
85
+ },
86
+ direction: 'out'
87
+ };
88
+ var defaultEntity = {
89
+ uri: 'entities/uri$$123',
90
+ type: 'configuration/entityTypes/HCP',
91
+ attributes: {}
92
+ };
93
+ var defaultMdmValues = {
94
+ relations: {},
95
+ modifiedEntities: {},
96
+ entity: defaultEntity,
97
+ dependentLookups: { editors: {}, structure: {}, initedTypeUris: [] },
98
+ uiConfigLayout: [],
99
+ uiConfigProfile: [],
100
+ profileErrors: []
101
+ };
102
+ var defaultProps = {
103
+ connection: { relation: defaultRelation, entity: {} },
104
+ config: {
105
+ id: 'relationView',
106
+ component: ProfileViewType.Relations,
107
+ content: {
108
+ entityTypes: ['configuration/entityTypes/Location'],
109
+ outRelations: [{ uri: 'configuration/relationTypes/HasAddress', label: '{directionalLabel}' }]
110
+ }
111
+ },
112
+ metadata: {
113
+ entityTypes: [
114
+ {
115
+ uri: 'configuration/entityTypes/HCP',
116
+ label: 'HCP'
117
+ },
118
+ {
119
+ uri: 'configuration/entityTypes/Location',
120
+ label: 'Address',
121
+ dataLabelPattern: '{FirstName}',
122
+ attributes: [
123
+ {
124
+ uri: 'configuration/entityTypes/Location/attributes/FirstName',
125
+ type: 'String',
126
+ name: 'FirstName',
127
+ label: 'First Name'
128
+ },
129
+ {
130
+ uri: 'configuration/entityTypes/Location/attributes/Address',
131
+ type: 'Reference',
132
+ name: 'Address',
133
+ label: 'Address',
134
+ referencedAttributeURIs: []
135
+ }
136
+ ]
137
+ },
138
+ {
139
+ uri: 'configuration/entityTypes/HCA',
140
+ label: 'HCA'
141
+ }
142
+ ],
143
+ relationTypes: [
144
+ {
145
+ uri: 'configuration/relationTypes/HasAddress',
146
+ label: 'has address',
147
+ startObject: {
148
+ objectTypeURI: 'configuration/entityTypes/HCP',
149
+ uri: 'configuration/relationTypes/HasAddress/startObject'
150
+ },
151
+ endObject: {
152
+ objectTypeURI: 'configuration/entityTypes/Location',
153
+ uri: 'configuration/relationTypes/HasAddress/endObject'
154
+ },
155
+ attributes: [
156
+ {
157
+ label: 'ActiveHiddenAttribute',
158
+ name: 'Active',
159
+ type: 'Boolean',
160
+ uri: 'configuration/relationTypes/HasAddress/attributes/Active'
161
+ },
162
+ {
163
+ label: 'Name',
164
+ name: 'Name',
165
+ type: 'String',
166
+ uri: 'configuration/relationTypes/HasAddress/attributes/Name',
167
+ required: true
168
+ }
169
+ ]
170
+ },
171
+ {
172
+ uri: 'configuration/relationTypes/InternalHCAtoHCA',
173
+ label: 'InternalHCAtoHCA affiliation',
174
+ startObject: {
175
+ objectTypeURI: 'configuration/entityTypes/HCA',
176
+ uri: 'configuration/relationTypes/InternalHCAtoHCA/startObject'
177
+ },
178
+ endObject: {
179
+ objectTypeURI: 'configuration/entityTypes/HCA',
180
+ uri: 'configuration/relationTypes/InternalHCAtoHCA/endObject'
181
+ },
182
+ attributes: [
183
+ {
184
+ label: 'Title',
185
+ name: 'Title',
186
+ type: 'String',
187
+ uri: 'configuration/relationTypes/InternalHCAtoHCA/attributes/Title'
188
+ },
189
+ {
190
+ label: 'Affiliation Status',
191
+ name: 'AffiliationStatus',
192
+ type: 'String',
193
+ uri: 'configuration/relationTypes/InternalHCAtoHCA/attributes/AffiliationStatus'
194
+ }
195
+ ]
196
+ }
197
+ ]
198
+ },
199
+ mode: Mode.Editing
200
+ };
201
+ var setUp = function (_a) {
202
+ var _b = _a === void 0 ? {} : _a, _c = _b.props, props = _c === void 0 ? defaultProps : _c, _d = _b.mdmValues, mdmValues = _d === void 0 ? defaultMdmValues : _d, _e = _b.error, error = _e === void 0 ? null : _e, _f = _b.hiddenAttributes, hiddenAttributes = _f === void 0 ? {} : _f;
203
+ var user = userEvent.setup();
204
+ var Providers = function (_a) {
205
+ var children = _a.children;
206
+ return (React.createElement(HiddenAttributesContext.Provider, { value: hiddenAttributes },
207
+ React.createElement(ScrollToElementContext.Provider, { value: { element: error, highlightError: highlightError, scrollIntoRef: scrollIntoRef, type: ScrollType.Error } },
208
+ React.createElement(LocalizationProvider, { dateAdapter: AdapterMoment }, children))));
90
209
  };
91
- var setUp = function (_a) {
92
- var _b = _a === void 0 ? {} : _a, _c = _b.props, props = _c === void 0 ? defaultProps : _c, _d = _b.mdmValues, mdmValues = _d === void 0 ? defaultMdmValues : _d, _e = _b.contextError, contextError = _e === void 0 ? null : _e;
93
- useMdmInitialConnection.mockReturnValue(mdmValues.initialConnection);
94
- useMdmInitialConnectionTempEntity.mockReturnValue(mdmValues.initialModifiedEntity);
95
- useMdmModifiedEntity.mockReturnValue(mdmValues.modifiedEntity);
96
- useMdmModifiedEntities.mockReturnValue(mdmValues.modifiedEntities);
97
- useMdmProfileErrors.mockReturnValue(mdmValues.profileErrors);
98
- useMdmEntityUri.mockReturnValue(mdmValues.entityUri);
99
- var Component = function (props) {
100
- return (React.createElement(MdmModuleProvider, { actions: mdmActions, values: mdmValues },
101
- React.createElement(ScrollToElementContext.Provider, { value: {
102
- element: contextError,
103
- highlightError: highlightErrorSpy,
104
- scrollIntoRef: scrollIntoRefSpy,
105
- type: ScrollType.Error
106
- } },
107
- React.createElement(RelationEditor, __assign({}, props)))));
108
- };
109
- return mount(React.createElement(Component, __assign({}, props)));
210
+ var result = render(React.createElement(MdmModuleProvider, { actions: mdmActions, values: mdmValues },
211
+ React.createElement(RelationEditor, __assign({}, props))), { wrapper: Providers });
212
+ var rerender = function (_a) {
213
+ var newProps = _a.props, newMdmValues = _a.mdmValues;
214
+ return result.rerender(React.createElement(MdmModuleProvider, { actions: mdmActions, values: __assign(__assign({}, mdmValues), newMdmValues) },
215
+ React.createElement(RelationEditor, __assign({}, props, newProps))));
110
216
  };
111
- beforeAll(function () {
112
- EditModeComplexAttribute.mockImplementation(function (_a) {
113
- var children = _a.children;
114
- return React.createElement("div", null, children);
115
- });
116
- EntitySelector.mockImplementation(EmptyStub);
117
- EditModeAttributesList.mockImplementation(EmptyStub);
118
- useScrollToAttributeError.mockReturnValue(scrollToAttributeError);
217
+ return __assign(__assign({}, result), { user: user, rerender: rerender });
218
+ };
219
+ describe('relation editor behaviour', function () {
220
+ beforeEach(function () {
221
+ typeAheadSearch.mockResolvedValue([]);
119
222
  });
120
223
  afterEach(function () {
121
224
  jest.clearAllMocks();
122
225
  });
123
- var findEditorTitle = function (component) { return component.find(Typography).filterWhere(function (t) { return t.hasClass('title'); }); };
124
- var findApplyButton = function (component) { return component.find(Button).filterWhere(function (b) { return b.text() === 'Apply'; }); };
125
- var findCancelButton = function (component) { return component.find(Button).filterWhere(function (b) { return b.text() === 'Cancel'; }); };
126
- it('should render main parts', function () {
127
- var component = setUp();
128
- var editorTitle = findEditorTitle(component);
129
- expect(editorTitle.length).toBe(1);
130
- expect(editorTitle.text()).toBe('Edit item');
131
- expect(component.find(ConnectionRelationTypeSelector).length).toBe(1);
132
- var applyButton = findApplyButton(component);
133
- var cancelButton = findCancelButton(component);
134
- expect(applyButton.length).toBe(1);
135
- expect(applyButton.prop('disabled')).toBe(true);
136
- expect(cancelButton.length).toBe(1);
137
- expect(component.find(EntitySelector).length).toBe(0);
138
- expect(component.find(EditModeAttributesList).length).toBe(0);
139
- });
140
- it('should show Add item label for new connection', function () {
141
- var connection = { relation: { relationUri: relationUri, object: { attributes: {} } }, entity: {}, isNew: true };
142
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialConnection: connection });
143
- var props = __assign(__assign({}, defaultProps), { connection: connection });
144
- var component = setUp({ mdmValues: mdmValues, props: props });
145
- component.update();
146
- var editorTitle = findEditorTitle(component);
147
- expect(editorTitle.length).toBe(1);
148
- expect(editorTitle.text()).toBe('Add new item');
149
- expect(component.find(ConnectionRelationTypeSelector).length).toBe(1);
150
- var applyButton = findApplyButton(component);
151
- var cancelButton = findCancelButton(component);
152
- expect(applyButton.length).toBe(1);
153
- expect(applyButton.prop('disabled')).toBe(true);
154
- expect(cancelButton.length).toBe(1);
155
- expect(component.find(EntitySelector).length).toBe(0);
156
- expect(component.find(EditModeAttributesList).length).toBe(0);
157
- });
158
- it('should render EntitySelector and AttributeList if relationType is specified', function () {
159
- var connection = {
160
- relation: { relationUri: relationUri, relationType: 'configuration/relationTypes/AccountTeam' },
161
- entity: {}
162
- };
163
- var props = __assign(__assign({}, defaultProps), { connection: connection });
164
- var component = setUp({ props: props });
165
- expect(component.find(EntitySelector).length).toBe(1);
166
- expect(component.find(EditModeAttributesList).length).toBe(1);
167
- var errorWrapper = component.find(".".concat(scrollToAttributeError.errorClassName));
168
- expect(errorWrapper).toHaveLength(1);
169
- expect(errorWrapper.getElement().ref).toBe(scrollToAttributeError.ref);
170
- });
171
- it('should call getInOutRelations with correctly params if connection.parentEntityUri does not exist', function () {
172
- var connection = {
173
- relation: {
174
- relationUri: relationUri,
175
- relationType: 'configuration/relationTypes/AccountTeam',
176
- direction: Directions.IN
177
- },
178
- entity: {}
179
- };
180
- var config = {
181
- id: 'relationView1',
182
- content: { entityTypes: ['Type1'] }
183
- };
184
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
185
- setUp({ props: props });
186
- expect(getInOutRelations).toHaveBeenCalledWith({
187
- content: config.content,
188
- direction: Directions.IN,
189
- relationType: 'configuration/relationTypes/AccountTeam',
190
- mode: editing,
191
- metadata: {
192
- relationTypes: []
226
+ it('should render entity selector correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
227
+ var activityFilter, searchOptions, mdmValues, user, options;
228
+ return __generator(this, function (_a) {
229
+ switch (_a.label) {
230
+ case 0:
231
+ typeAheadSearch.mockResolvedValue([
232
+ { type: 'configuration/entityTypes/Location', label: 'location entity 1', uri: 'entities/0C32GxR' },
233
+ { type: 'configuration/entityTypes/Location', label: 'location entity 2', uri: 'entities/0G49Cnu' }
234
+ ]);
235
+ activityFilter = ActivityFilter.ACTIVE_ONLY;
236
+ searchOptions = { searchByOv: true, ovOnly: true };
237
+ mdmValues = __assign(__assign({}, defaultMdmValues), { activityFilter: activityFilter, searchOptions: searchOptions });
238
+ user = setUp({ mdmValues: mdmValues }).user;
239
+ screen.getByText('Select Address profile');
240
+ screen.getByRole('combobox');
241
+ return [4 /*yield*/, user.click(screen.getByTestId('select-dropdown-indicator'))];
242
+ case 1:
243
+ _a.sent();
244
+ options = screen.getAllByRole('option');
245
+ expect(options).toHaveLength(2);
246
+ expect(options[0]).toHaveTextContent('location entity 1');
247
+ expect(options[1]).toHaveTextContent('location entity 2');
248
+ expect(typeAheadSearch).toHaveBeenCalledWith([defaultProps.metadata.entityTypes[1]], '', {
249
+ activityFilter: 'active',
250
+ globalFilter: '',
251
+ max: 20,
252
+ searchOptions: 'searchByOv',
253
+ sendMasked: false
254
+ });
255
+ return [2 /*return*/];
193
256
  }
194
257
  });
195
- });
196
- it('should call getInOutRelations with correctly params if connection.parentEntityUri exists', function () {
197
- var connection = {
198
- relation: {
199
- relationUri: relationUri,
200
- relationType: 'configuration/relationTypes/AccountTeam',
201
- direction: Directions.IN
202
- },
203
- entity: {},
204
- parentEntityUri: 'entities/123'
205
- };
206
- var config = {
207
- id: 'relationView1',
208
- content: { entityTypes: ['Type1'] },
209
- contentSecondLevel: { entityTypes: ['Type2'] }
210
- };
211
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
212
- setUp({ props: props });
213
- expect(getInOutRelations).toHaveBeenCalledWith({
214
- content: config.contentSecondLevel,
215
- direction: Directions.IN,
216
- relationType: 'configuration/relationTypes/AccountTeam',
217
- mode: editing,
218
- metadata: {
219
- relationTypes: []
258
+ }); });
259
+ it('should render attributes list correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
260
+ var labels, values;
261
+ return __generator(this, function (_a) {
262
+ switch (_a.label) {
263
+ case 0:
264
+ setUp();
265
+ return [4 /*yield*/, screen.findByText('More attributes')];
266
+ case 1:
267
+ _a.sent();
268
+ labels = screen.getAllByTestId('reltio-attribute-label');
269
+ values = screen.getAllByTestId('reltio-attribute-value');
270
+ expect(labels).toHaveLength(4);
271
+ expect(values).toHaveLength(4);
272
+ expect(labels[0]).toHaveTextContent('Start date');
273
+ expect(within(values[0]).getByRole('textbox')).toHaveValue('');
274
+ expect(labels[1]).toHaveTextContent('End date');
275
+ expect(within(values[1]).getByRole('textbox')).toHaveValue('');
276
+ expect(labels[2]).toHaveTextContent('ActiveHiddenAttribute');
277
+ expect(within(values[2]).getAllByRole('checkbox')[0]).not.toBeChecked();
278
+ expect(within(values[2]).getAllByRole('checkbox')[1]).not.toBeChecked();
279
+ expect(labels[3]).toHaveTextContent('Name*');
280
+ expect(within(values[3]).getByRole('textbox')).toHaveValue('');
281
+ return [2 /*return*/];
220
282
  }
221
283
  });
222
- });
223
- it('should set entityTypesUris prop correctly for EntitySelector if contentSecondLevel is missing in config', function () {
224
- var connection = {
225
- relation: {
226
- relationUri: relationUri,
227
- relationType: 'configuration/relationTypes/AccountTeam'
228
- },
229
- entity: {}
230
- };
231
- var config = {
232
- id: 'relationView1',
233
- content: { entityTypes: ['Type1'] }
234
- };
235
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
236
- var component = setUp({ props: props });
237
- expect(component.find(EntitySelector).prop('entityTypesUris')).toEqual(['Type1']);
238
- });
239
- it('should set entityTypesUris prop correctly for EntitySelector if parentEntityUri is missing in connection', function () {
240
- var connection = {
241
- relation: {
242
- relationUri: relationUri,
243
- relationType: 'configuration/relationTypes/AccountTeam'
244
- },
245
- entity: {}
246
- };
247
- var config = {
248
- id: 'relationView1',
249
- content: { entityTypes: ['Type1'] },
250
- contentSecondLevel: { entityTypes: ['Type2'] }
251
- };
252
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
253
- var component = setUp({ props: props });
254
- expect(component.find(EntitySelector).prop('entityTypesUris')).toEqual(['Type1']);
255
- });
256
- it('should set entityTypesUris prop correctly for EntitySelector if contentSecondLevel and parentEntityUri exists', function () {
257
- var connection = {
258
- relation: {
259
- relationUri: relationUri,
260
- relationType: 'configuration/relationTypes/AccountTeam'
261
- },
262
- entity: {},
263
- parentEntityUri: 'entities/123'
264
- };
265
- var config = {
266
- id: 'relationView1',
267
- content: { entityTypes: ['Type1'] },
268
- contentSecondLevel: { entityTypes: ['Type2'] }
269
- };
270
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
271
- var component = setUp({ props: props });
272
- expect(component.find(EntitySelector).prop('entityTypesUris')).toEqual(['Type2']);
273
- });
274
- it('should render ErrorWrapper for EntitySelector and show error', function () {
275
- var connection = {
276
- relation: {
277
- relationUri: relationUri,
278
- relationType: 'configuration/relationTypes/AccountTeam'
279
- },
280
- entity: {}
281
- };
282
- var profileErrors = [
283
- {
284
- parentUri: 'relations/11',
285
- uri: '',
286
- attributeTypeUri: 'configuration/relationTypes/AccountTeam',
287
- message: 'Entity is required',
288
- deactivated: true,
289
- type: 'missedRefEntity'
290
- },
291
- {
292
- parentUri: connection.relation.relationUri,
293
- uri: '',
294
- attributeTypeUri: 'configuration/relationTypes/AccountTeam',
295
- message: 'Entity is required - deactivated',
296
- deactivated: true,
297
- type: 'missedRefEntity'
298
- },
299
- {
300
- parentUri: connection.relation.relationUri,
301
- uri: '',
302
- attributeTypeUri: 'configuration/relationTypes/AccountTeam',
303
- message: 'Entity is required',
304
- type: 'missedRefEntity'
284
+ }); });
285
+ it('should render label correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
286
+ return __generator(this, function (_a) {
287
+ switch (_a.label) {
288
+ case 0:
289
+ setUp();
290
+ return [4 /*yield*/, screen.findByText('Edit item')];
291
+ case 1:
292
+ _a.sent();
293
+ return [2 /*return*/];
305
294
  }
306
- ];
307
- var mdmValues = __assign(__assign({}, defaultMdmValues), { profileErrors: profileErrors });
308
- var props = __assign(__assign({}, defaultProps), { connection: connection });
309
- var component = setUp({ props: props, mdmValues: mdmValues });
310
- var errorWrapper = component.find(ErrorWrapper);
311
- expect(errorWrapper.length).toBe(1);
312
- expect(errorWrapper.prop('errorMessage')).toBe(profileErrors[2].message);
313
- expect(errorWrapper.find(EntitySelector).length).toBe(1);
314
- });
315
- it('should set correct outRelationTypes and inRelationTypes for RelationTypeSelector', function () {
316
- var connection = { relation: { relationUri: relationUri }, entity: {} };
317
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config, metadata: { relationTypes: relationTypes, entityTypes: [] } });
318
- var component = setUp({ props: props });
319
- var relationTypeSelector = component.find(ConnectionRelationTypeSelector);
320
- expect(relationTypeSelector.length).toBe(1);
321
- expect(relationTypeSelector.prop('relation')).toBe(connection.relation);
322
- expect(relationTypeSelector.prop('outRelationTypes')).toEqual([relationTypes[0]]);
323
- expect(relationTypeSelector.prop('inRelationTypes')).toEqual([relationTypes[1]]);
324
- });
325
- it('should render default relation type label instead of RelationTypeSelector if there is only one relation type', function () {
326
- var props = __assign(__assign({}, defaultProps), { config: config, metadata: { relationTypes: relationTypes.slice(0, 1), entityTypes: [] } });
327
- var component = setUp({ props: props });
328
- expect(component.find(ConnectionRelationTypeSelector).length).toBe(0);
329
- });
330
- it('should dispatch setRelationType action on RelationTypeSelector change', function () {
331
- var props = __assign(__assign({}, defaultProps), { config: config, metadata: { relationTypes: relationTypes, entityTypes: [] } });
332
- var component = setUp({ props: props });
333
- var relationTypeSelector = component.find(ConnectionRelationTypeSelector);
334
- expect(relationTypeSelector.length).toBe(1);
335
- relationTypeSelector.prop('onChange')({ type: relationTypes[1], direction: Directions.IN });
336
- expect(mdmActions.setRelationType).toHaveBeenCalledWith(config.id, relationUri, {
337
- type: relationTypes[1],
338
- direction: Directions.IN
339
- });
340
- });
341
- it('should set correct props for EditModeAttributesList', function () {
342
- var connection = {
343
- relation: {
344
- relationUri: relationUri,
345
- relationType: 'configuration/relationTypes/AccountTeam',
346
- object: {
347
- attributes: {
348
- Role: []
349
- }
350
- },
351
- startDate: 12345,
352
- endDate: 678910
353
- },
354
- entity: {}
355
- };
356
- var props = __assign(__assign({}, defaultProps), { connection: connection, metadata: { relationTypes: relationTypes, entityTypes: [] } });
357
- var component = setUp({ props: props });
358
- var attributesList = component.find(EditModeAttributesList);
359
- expect(attributesList.length).toBe(1);
360
- expect(attributesList.prop('attrTypes')).toEqual(__spreadArray(__spreadArray([], ACTIVENESS_ATTR_TYPES, true), relationTypes[0].attributes, true));
361
- expect(attributesList.prop('entity')).toEqual({
362
- attributes: {
363
- Role: []
364
- },
365
- startDate: 12345,
366
- endDate: 678910
367
295
  });
368
- expect(attributesList.prop('showEmptyEditors')).toBe(true);
369
- expect(attributesList.prop('parentUri')).toBe(relationUri);
370
- });
371
- it('should get search options without ovOnly', function () {
372
- var activityFilter = 'active';
373
- var searchOptions = { searchByOv: true, ovOnly: true };
374
- var connection = {
375
- relation: {
376
- relationUri: relationUri,
377
- relationType: 'configuration/relationTypes/AccountTeam'
378
- },
379
- entity: {}
380
- };
381
- var metadata = { relationTypes: [] };
382
- var mdmValues = __assign(__assign({}, defaultMdmValues), { activityFilter: activityFilter, searchOptions: searchOptions });
383
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config, metadata: metadata });
384
- var component = setUp({ props: props, mdmValues: mdmValues });
385
- var entitySelector = component.find(EntitySelector);
386
- expect(entitySelector.prop('globalSearchRequestOptions')).toEqual({
387
- activityFilter: 'active',
388
- searchOptions: 'searchByOv',
389
- globalFilter: ''
296
+ }); });
297
+ it('should label for new connection correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
298
+ var connection, props;
299
+ return __generator(this, function (_a) {
300
+ switch (_a.label) {
301
+ case 0:
302
+ connection = __assign(__assign({}, defaultProps.connection), { isNew: true });
303
+ props = __assign(__assign({}, defaultProps), { connection: connection });
304
+ setUp({ props: props });
305
+ return [4 /*yield*/, screen.findByText('Add new item')];
306
+ case 1:
307
+ _a.sent();
308
+ return [2 /*return*/];
309
+ }
390
310
  });
391
- });
392
- describe('Apply button behavior', function () {
393
- it('should be disables for new connections with added default values', function () {
394
- var connection = {
395
- relation: {
396
- relationUri: relationUri,
397
- object: {
398
- attributes: {
399
- Simple: [
400
- {
401
- value: 'simple default'
402
- }
403
- ]
404
- }
405
- }
406
- },
407
- entity: {},
408
- isNew: true
409
- };
410
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config, metadata: { relationTypes: relationTypes, entityTypes: [] } });
411
- var component = setUp({ props: props });
412
- var applyButton = findApplyButton(component);
413
- expect(applyButton.prop('disabled')).toBe(true);
311
+ }); });
312
+ it('should render correctly if parentEntityUri and contentSecondLevel exists', function () { return __awaiter(void 0, void 0, void 0, function () {
313
+ var connection, config, props;
314
+ return __generator(this, function (_a) {
315
+ switch (_a.label) {
316
+ case 0:
317
+ connection = __assign(__assign({}, defaultProps.connection), { parentEntityUri: 'entities/HsPM72G' });
318
+ config = __assign(__assign({}, defaultProps.config), { contentSecondLevel: {
319
+ entityTypes: ['configuration/entityTypes/HCA'],
320
+ outRelations: [{ uri: 'configuration/relationTypes/InternalHCAtoHCA', label: '{directionalLabel}' }]
321
+ } });
322
+ props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
323
+ setUp({ props: props });
324
+ return [4 /*yield*/, screen.findByText('Select HCA profile')];
325
+ case 1:
326
+ _a.sent();
327
+ return [2 /*return*/];
328
+ }
414
329
  });
415
- it('should call addRelation action on Apply button click for new connections', function () {
416
- var connection = {
417
- relation: { relationUri: relationUri, object: { attributes: {} } },
418
- entity: {},
419
- isNew: true
420
- };
421
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialConnection: connection });
422
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config, metadata: { relationTypes: relationTypes, entityTypes: [] } });
423
- var component = setUp({ props: props, mdmValues: mdmValues });
424
- var applyButton = findApplyButton(component);
425
- expect(applyButton.prop('disabled')).toBe(true);
426
- component.setProps({
427
- connection: {
428
- __metadata: {
429
- draft: 'added'
430
- },
431
- relation: {
432
- relationUri: relationUri,
433
- relationType: '123',
434
- object: {
435
- type: '123'
436
- }
437
- },
438
- entity: {
439
- entityUri: 'entities/456'
440
- },
441
- isNew: true,
442
- initial: {
443
- connection: {
444
- __metadata: {
445
- draft: 'added'
446
- },
447
- relation: {
448
- relationUri: relationUri,
449
- relationType: '123',
450
- object: {
451
- type: '123'
452
- }
453
- },
454
- entity: {
455
- entityUri: 'entities/456'
456
- },
457
- isNew: true
458
- }
459
- }
460
- }
461
- });
462
- applyButton = findApplyButton(component);
463
- expect(applyButton.prop('disabled')).toBe(false);
464
- applyButton.find('button').simulate('click');
465
- var clearedConnection = {
466
- relation: {
467
- relationUri: relationUri,
468
- relationType: '123',
469
- object: {
470
- type: '123'
471
- }
472
- },
473
- entity: {
474
- entityUri: 'entities/456'
475
- },
476
- initial: {
477
- connection: {
478
- __metadata: {
479
- draft: 'added'
330
+ }); });
331
+ it('should show error for entity selector correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
332
+ var profileErrors, mdmValues, errorMessage;
333
+ return __generator(this, function (_a) {
334
+ switch (_a.label) {
335
+ case 0:
336
+ profileErrors = [
337
+ {
338
+ parentUri: 'relations/11',
339
+ uri: '',
340
+ attributeTypeUri: defaultRelation.relationType,
341
+ message: 'Entity is required',
342
+ deactivated: true,
343
+ type: ErrorType.missedRefEntity
480
344
  },
481
- entity: {
482
- entityUri: 'entities/456'
345
+ {
346
+ parentUri: defaultRelation.relationUri,
347
+ uri: '',
348
+ attributeTypeUri: defaultRelation.relationType,
349
+ message: 'Entity is required - deactivated',
350
+ deactivated: true,
351
+ type: ErrorType.missedRefEntity
483
352
  },
484
- isNew: true,
485
- relation: {
486
- object: {
487
- type: '123'
488
- },
489
- relationType: '123',
490
- relationUri: 'relations/1'
353
+ {
354
+ parentUri: defaultRelation.relationUri,
355
+ uri: '',
356
+ attributeTypeUri: defaultRelation.relationType,
357
+ message: 'Entity is required',
358
+ type: ErrorType.missedRefEntity
491
359
  }
492
- }
493
- },
494
- isNew: true
495
- };
496
- expect(mdmActions.addRelation).toHaveBeenCalledWith(config.id, clearedConnection);
497
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, clearedConnection.relation.relationUri);
360
+ ];
361
+ mdmValues = __assign(__assign({}, defaultMdmValues), { profileErrors: profileErrors });
362
+ setUp({ mdmValues: mdmValues });
363
+ return [4 /*yield*/, screen.findByTestId('error-message')];
364
+ case 1:
365
+ errorMessage = _a.sent();
366
+ expect(errorMessage).toHaveTextContent('Entity is required');
367
+ return [2 /*return*/];
368
+ }
498
369
  });
499
- it('should not call addRelation action on Apply button if connection has validation errors', function () {
500
- var relationUri = 'relations/uri$$123';
501
- var connection = {
502
- relation: { relationUri: relationUri, object: { attributes: {} } },
503
- entity: {},
504
- isNew: true
505
- };
506
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialConnection: connection });
507
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config2, metadata: { relationTypes: relationTypes, entityTypes: [] } });
508
- var component = setUp({ props: props, mdmValues: mdmValues });
509
- var applyButton = findApplyButton(component);
510
- expect(applyButton.prop('disabled')).toBe(true);
511
- var addedConnection = {
512
- __metadata: {
513
- draft: 'added'
514
- },
515
- relation: {
516
- relationUri: relationUri,
517
- relationType: 'configuration/relationTypes/HCPtoHCA',
518
- object: {
519
- attributes: {
520
- Role: [
521
- {
522
- ov: true,
523
- type: 'configuration/relationTypes/HCPtoHCA/attributes/Role',
524
- uri: 'relations/uri$$123/attributes/Role/uri$$abc',
525
- value: ''
526
- }
527
- ]
528
- },
529
- type: 'configuration/relationTypes/HCPtoHCA',
530
- uri: relationUri
531
- }
532
- },
533
- entity: {
534
- entityUri: 'entities/456'
535
- },
536
- isNew: true
537
- };
538
- component.setProps({
539
- connection: addedConnection
540
- });
541
- applyButton = findApplyButton(component);
542
- expect(applyButton.prop('disabled')).toBe(false);
543
- applyButton.find('button').simulate('click');
544
- expect(mdmActions.errorsSet).toHaveBeenCalledWith([
545
- {
546
- attributeType: {
547
- label: 'Role',
548
- name: 'Role',
549
- type: 'String',
550
- hidden: false,
551
- important: false,
552
- system: false,
553
- required: true,
554
- attributeOrdering: {
555
- orderType: 'ASC',
556
- orderingStrategy: 'LUD'
557
- },
558
- uri: 'configuration/relationTypes/HCPtoHCA/attributes/Role'
559
- },
560
- attributeTypeUri: 'configuration/relationTypes/HCPtoHCA/attributes/Role',
561
- message: 'Attribute is required',
562
- parentUri: relationUri,
563
- type: 'missed',
564
- uri: '',
565
- source: ErrorSource.local,
566
- path: [
370
+ }); });
371
+ it('should render relation type selector correctly if it is not possible to evaluate default relation type', function () { return __awaiter(void 0, void 0, void 0, function () {
372
+ var config, props, user, relationTypeSelector, options;
373
+ return __generator(this, function (_a) {
374
+ switch (_a.label) {
375
+ case 0:
376
+ config = __assign(__assign({}, defaultProps.config), { content: {
377
+ entityTypes: ['configuration/entityTypes/Location'],
378
+ inRelations: [{ uri: 'configuration/relationTypes/InternalHCAtoHCA', label: '{directionalLabel}' }],
379
+ outRelations: [{ uri: 'configuration/relationTypes/HasAddress', label: '{directionalLabel}' }]
380
+ } });
381
+ props = __assign(__assign({}, defaultProps), { config: config });
382
+ user = setUp({ props: props }).user;
383
+ relationTypeSelector = screen.getByTestId('relation-type-selector');
384
+ within(relationTypeSelector).getByText('Select relationship type');
385
+ within(relationTypeSelector).getByText('has address');
386
+ within(relationTypeSelector).getByRole('combobox');
387
+ return [4 /*yield*/, user.click(within(relationTypeSelector).getByTestId('select-dropdown-indicator'))];
388
+ case 1:
389
+ _a.sent();
390
+ options = screen.getAllByRole('option');
391
+ expect(options).toHaveLength(2);
392
+ expect(options[0]).toHaveTextContent('InternalHCAtoHCA affiliation');
393
+ expect(options[1]).toHaveTextContent('has address');
394
+ return [2 /*return*/];
395
+ }
396
+ });
397
+ }); });
398
+ it('should dispatch setRelationType action on relation type selector change', function () { return __awaiter(void 0, void 0, void 0, function () {
399
+ var config, props, user;
400
+ return __generator(this, function (_a) {
401
+ switch (_a.label) {
402
+ case 0:
403
+ config = __assign(__assign({}, defaultProps.config), { content: {
404
+ entityTypes: ['configuration/entityTypes/Location'],
405
+ inRelations: [{ uri: 'configuration/relationTypes/InternalHCAtoHCA', label: '{directionalLabel}' }],
406
+ outRelations: [{ uri: 'configuration/relationTypes/HasAddress', label: '{directionalLabel}' }]
407
+ } });
408
+ props = __assign(__assign({}, defaultProps), { config: config });
409
+ user = setUp({ props: props }).user;
410
+ return [4 /*yield*/, user.click(within(screen.getByTestId('relation-type-selector')).getByTestId('select-dropdown-indicator'))];
411
+ case 1:
412
+ _a.sent();
413
+ return [4 /*yield*/, user.click(screen.getByText('InternalHCAtoHCA affiliation'))];
414
+ case 2:
415
+ _a.sent();
416
+ expect(mdmActions.setRelationType).toHaveBeenCalledWith(props.config.id, expect.any(String), {
417
+ direction: 'in',
418
+ type: __assign(__assign({}, defaultProps.metadata.relationTypes[1]), { endObject: __assign(__assign({}, defaultProps.metadata.relationTypes[1].endObject), { objectType: { label: 'HCA', uri: 'configuration/entityTypes/HCA' } }), startObject: __assign(__assign({}, defaultProps.metadata.relationTypes[1].startObject), { objectType: { label: 'HCA', uri: 'configuration/entityTypes/HCA' } }) })
419
+ });
420
+ return [2 /*return*/];
421
+ }
422
+ });
423
+ }); });
424
+ it('should show "create entity" button if mode is not suggesting', function () { return __awaiter(void 0, void 0, void 0, function () {
425
+ var user, inputs;
426
+ return __generator(this, function (_a) {
427
+ switch (_a.label) {
428
+ case 0:
429
+ user = setUp().user;
430
+ inputs = screen.getAllByRole('combobox');
431
+ return [4 /*yield*/, user.click(inputs[0])];
432
+ case 1:
433
+ _a.sent();
434
+ expect(typeAheadSearch).toHaveBeenCalledWith([defaultProps.metadata.entityTypes[1]], '', {
435
+ globalFilter: '',
436
+ max: 20,
437
+ searchOptions: '',
438
+ sendMasked: false
439
+ });
440
+ screen.getByText('Create new Address');
441
+ return [2 /*return*/];
442
+ }
443
+ });
444
+ }); });
445
+ it('should show "create entity" button if mode is suggesting, but main entity uri is not temporary', function () { return __awaiter(void 0, void 0, void 0, function () {
446
+ var props, mdmValues, user, inputs;
447
+ return __generator(this, function (_a) {
448
+ switch (_a.label) {
449
+ case 0:
450
+ props = __assign(__assign({}, defaultProps), { mode: Mode.Suggesting });
451
+ mdmValues = __assign(__assign({}, defaultMdmValues), { entity: __assign(__assign({}, defaultEntity), { uri: 'entities/123' }) });
452
+ user = setUp({ props: props, mdmValues: mdmValues }).user;
453
+ inputs = screen.getAllByRole('combobox');
454
+ return [4 /*yield*/, user.click(inputs[0])];
455
+ case 1:
456
+ _a.sent();
457
+ screen.getByText('Create new Address');
458
+ return [2 /*return*/];
459
+ }
460
+ });
461
+ }); });
462
+ it('should show "create entity" button if mode is suggesting, main entity uri is temporary, but authoring mode is enabled for current entity type', function () { return __awaiter(void 0, void 0, void 0, function () {
463
+ var uiConfigProfile, props, mdmValues, user, inputs;
464
+ return __generator(this, function (_a) {
465
+ switch (_a.label) {
466
+ case 0:
467
+ uiConfigProfile = [
567
468
  {
568
- label: '<No label>, Affiliated with',
569
- type: 'relationConnection',
570
- value: addedConnection,
571
- valueType: relationTypes[2],
572
- viewId: 'relationView2'
469
+ label: 'Profile',
470
+ id: 'com.reltio.plugins.ProfileEntityAction',
471
+ class: ScreenType.Profile,
472
+ entityTypes: {
473
+ 'configuration/entityTypes/HCP': {
474
+ views: [],
475
+ layout: [],
476
+ sidePanelViews: [],
477
+ authoring: [{ label: 'Profile details', views: [], layout: [] }]
478
+ }
479
+ }
573
480
  }
574
- ]
575
- }
576
- ]);
577
- expect(mdmActions.addRelation).not.toHaveBeenCalledWith(config.id, expect.any(Object));
578
- expect(mdmActions.closeRelationEditor).not.toHaveBeenCalledWith(config.id, expect.any(String));
481
+ ];
482
+ props = __assign(__assign({}, defaultProps), { mode: Mode.Suggesting });
483
+ mdmValues = __assign(__assign({}, defaultMdmValues), { uiConfigProfile: uiConfigProfile });
484
+ user = setUp({ props: props, mdmValues: mdmValues }).user;
485
+ inputs = screen.getAllByRole('combobox');
486
+ return [4 /*yield*/, user.click(inputs[0])];
487
+ case 1:
488
+ _a.sent();
489
+ screen.getByText('Create new Address');
490
+ return [2 /*return*/];
491
+ }
579
492
  });
580
- it('should call editRelation action on Apply button click for existing connections', function () {
581
- var props = __assign(__assign({}, defaultProps), { config: config, metadata: { relationTypes: relationTypes, entityTypes: [] } });
582
- var component = setUp({ props: props });
583
- var applyButton = findApplyButton(component);
584
- expect(applyButton.prop('disabled')).toBe(true);
585
- component.setProps({
586
- connection: {
587
- __metadata: {
588
- draft: 'edited'
589
- },
590
- relation: {
591
- relationUri: relationUri,
592
- relationType: '123',
593
- object: {
594
- type: '123'
595
- }
596
- },
597
- entity: {
598
- entityUri: 'entities/456'
599
- }
600
- }
601
- });
602
- applyButton = findApplyButton(component);
603
- expect(applyButton.prop('disabled')).toBe(false);
604
- applyButton.find('button').simulate('click');
605
- var clearedConnection = {
606
- relation: {
607
- relationUri: relationUri,
608
- relationType: '123',
609
- object: {
610
- type: '123'
611
- }
612
- },
613
- entity: {
614
- entityUri: 'entities/456'
615
- }
616
- };
617
- expect(mdmActions.editRelation).toHaveBeenCalledWith(config.id, clearedConnection);
618
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, clearedConnection.relation.relationUri);
493
+ }); });
494
+ it('should not show "create entity" button if mode is "Suggesting", main entity uri is temporary and authoring mode is not enabled for current entity type', function () { return __awaiter(void 0, void 0, void 0, function () {
495
+ var props, user, inputs;
496
+ return __generator(this, function (_a) {
497
+ switch (_a.label) {
498
+ case 0:
499
+ props = __assign(__assign({}, defaultProps), { mode: Mode.Suggesting });
500
+ user = setUp({ props: props }).user;
501
+ inputs = screen.getAllByRole('combobox');
502
+ return [4 /*yield*/, user.click(inputs[0])];
503
+ case 1:
504
+ _a.sent();
505
+ expect(screen.queryByText('Create new Address')).not.toBeInTheDocument();
506
+ return [2 /*return*/];
507
+ }
619
508
  });
620
- it('should not call editRelation action on Apply button click if connection has validation errors', function () {
621
- var props = __assign(__assign({}, defaultProps), { config: config2, metadata: { relationTypes: relationTypes, entityTypes: [] } });
622
- var component = setUp({ props: props });
623
- var applyButton = findApplyButton(component);
624
- expect(applyButton.prop('disabled')).toBe(true);
625
- var editedConnection = {
626
- __metadata: {
627
- draft: 'edited'
628
- },
629
- relation: {
630
- relationUri: relationUri,
631
- relationType: 'configuration/relationTypes/HCPtoHCA',
632
- object: {
633
- attributes: {
634
- Role: [
635
- {
636
- ov: true,
637
- type: 'configuration/relationTypes/HCPtoHCA/attributes/Role',
638
- uri: 'relations/uri$$123/attributes/Role/uri$$abc',
639
- value: ''
509
+ }); });
510
+ it('should not hide hidden attributes', function () { return __awaiter(void 0, void 0, void 0, function () {
511
+ var hiddenAttributes, user, inputs;
512
+ return __generator(this, function (_a) {
513
+ switch (_a.label) {
514
+ case 0:
515
+ hiddenAttributes = { 'entities/uri$$123': ['configuration/relationTypes/HasAddress/attributes/Active'] };
516
+ user = setUp({ hiddenAttributes: hiddenAttributes }).user;
517
+ inputs = screen.getAllByRole('combobox');
518
+ return [4 /*yield*/, user.click(inputs[0])];
519
+ case 1:
520
+ _a.sent();
521
+ expect(screen.getByText('ActiveHiddenAttribute')).toBeInTheDocument();
522
+ return [2 /*return*/];
523
+ }
524
+ });
525
+ }); });
526
+ it('should add sendMasked option if connection entity has attribute with masked value', function () { return __awaiter(void 0, void 0, void 0, function () {
527
+ var props, user, inputs;
528
+ return __generator(this, function (_a) {
529
+ switch (_a.label) {
530
+ case 0:
531
+ props = __assign(__assign({}, defaultProps), { connection: {
532
+ relation: defaultRelation,
533
+ entity: {
534
+ uri: 'entities/uri$$123',
535
+ type: 'configuration/entityTypes/HCP',
536
+ object: {
537
+ uri: 'entities/04B1CqH',
538
+ type: 'configuration/entityTypes/Location',
539
+ attributes: {
540
+ Address: [
541
+ {
542
+ label: 'AcOEvPaVqTfzZCE Josogaf VA',
543
+ relationshipLabel: '',
544
+ value: {
545
+ AddressLine1: [
546
+ {
547
+ type: 'configuration/entityTypes/Location/attributes/AddressLine1',
548
+ ov: true,
549
+ value: 'AcOEvPaVqTfzZCE',
550
+ uri: 'entities/04B1CqH/attributes/Address/03R51aT/AddressLine1/1XFBcmPYm'
551
+ }
552
+ ],
553
+ AddressLine2: [
554
+ {
555
+ type: 'configuration/entityTypes/Location/attributes/AddressLine2',
556
+ ov: true,
557
+ masked: true,
558
+ value: 'KBmiSMlqhElLHMH',
559
+ uri: 'entities/04B1CqH/attributes/Address/03R51aT/AddressLine2/1XFBcmTp2'
560
+ }
561
+ ]
562
+ }
563
+ }
564
+ ]
565
+ }
640
566
  }
641
- ]
642
- },
643
- type: 'configuration/relationTypes/HCPtoHCA',
644
- uri: relationUri
645
- }
646
- },
647
- entity: {
648
- entityUri: 'entities/456'
649
- }
650
- };
651
- component.setProps({
652
- connection: editedConnection
653
- });
654
- applyButton = findApplyButton(component);
655
- expect(applyButton.prop('disabled')).toBe(false);
656
- applyButton.find('button').simulate('click');
657
- expect(mdmActions.errorsSet).toHaveBeenCalledWith([
658
- {
659
- attributeType: {
660
- label: 'Role',
661
- name: 'Role',
662
- type: 'String',
663
- hidden: false,
664
- important: false,
665
- system: false,
666
- required: true,
667
- attributeOrdering: {
668
- orderType: 'ASC',
669
- orderingStrategy: 'LUD'
670
- },
671
- uri: 'configuration/relationTypes/HCPtoHCA/attributes/Role'
672
- },
673
- attributeTypeUri: 'configuration/relationTypes/HCPtoHCA/attributes/Role',
674
- message: 'Attribute is required',
675
- parentUri: relationUri,
676
- type: 'missed',
677
- uri: '',
678
- source: ErrorSource.local,
679
- path: [
567
+ }
568
+ } });
569
+ user = setUp({ props: props }).user;
570
+ inputs = screen.getAllByRole('textbox');
571
+ return [4 /*yield*/, user.click(inputs[0])];
572
+ case 1:
573
+ _a.sent();
574
+ expect(typeAheadSearch).toHaveBeenCalledWith([defaultProps.metadata.entityTypes[1]], '', {
575
+ globalFilter: '',
576
+ max: 20,
577
+ searchOptions: '',
578
+ sendMasked: true
579
+ });
580
+ return [2 /*return*/];
581
+ }
582
+ });
583
+ }); });
584
+ describe('apply button', function () {
585
+ var createRelation = function (value) { return (__assign(__assign({}, defaultProps.connection.relation), { object: __assign(__assign({}, defaultProps.connection.relation.object), { attributes: {
586
+ Name: [
680
587
  {
681
- label: '<No label>, Affiliated with',
682
- type: 'relationConnection',
683
- value: editedConnection,
684
- valueType: relationTypes[2],
685
- viewId: 'relationView2'
588
+ uri: 'relations/uri$$Qgs4qfvmR3Daksyb1697627670006/attributes/Name/uri$$jIo2A6VSD',
589
+ type: 'configuration/relationTypes/HasAddress/attributes/Name',
590
+ value: value
686
591
  }
687
592
  ]
688
- }
689
- ]);
690
- expect(mdmActions.editRelation).not.toHaveBeenCalledWith(config.id, expect.any(Object));
691
- expect(mdmActions.closeRelationEditor).not.toHaveBeenCalledWith(config.id, expect.any(String));
692
- });
693
- it('should evaluate and update connection entity label if modified entity is specified', function () {
694
- getEntityType.mockReturnValue({ dataLabelPattern: '{Name}' });
695
- var expectedLabel = 'new Label!';
696
- var modifiedEntity = {
697
- uri: 'entities/uri$$1',
698
- attributes: { Name: [{ value: expectedLabel, uri: '123' }] }
699
- };
700
- var props = __assign(__assign({}, defaultProps), { config: config, metadata: { relationTypes: relationTypes, entityTypes: [] } });
701
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialModifiedEntity: modifiedEntity, modifiedEntity: modifiedEntity });
702
- var component = setUp({ props: props, mdmValues: mdmValues });
703
- var applyButton = findApplyButton(component);
704
- expect(applyButton.prop('disabled')).toBe(true);
705
- component.setProps({
706
- connection: {
707
- __metadata: {
708
- draft: 'edited'
709
- },
710
- relation: {
711
- relationUri: relationUri,
712
- relationType: '123',
713
- object: {
714
- type: '123'
715
- }
716
- },
717
- entity: {
718
- entityUri: 'entities/uri$$1',
719
- entityType: 'type',
720
- entityLabel: '',
721
- object: {
722
- uri: 'entities/uri$$1',
723
- type: 'type',
724
- label: ''
725
- }
726
- }
593
+ } }) })); };
594
+ var createEntity = function (uri) { return ({
595
+ entityUri: uri,
596
+ entityType: 'configuration/entityTypes/Location',
597
+ entityLabel: 'location entity',
598
+ object: { uri: uri, type: 'configuration/entityTypes/Location', label: 'location entity' }
599
+ }); };
600
+ it('should be disables for new connections with added default values', function () { return __awaiter(void 0, void 0, void 0, function () {
601
+ var connection, props, applyButton;
602
+ return __generator(this, function (_a) {
603
+ switch (_a.label) {
604
+ case 0:
605
+ connection = { relation: createRelation('name value'), entity: {}, isNew: true };
606
+ props = __assign(__assign({}, defaultProps), { connection: connection });
607
+ setUp({ props: props });
608
+ return [4 /*yield*/, screen.findByText('Apply')];
609
+ case 1:
610
+ applyButton = _a.sent();
611
+ expect(applyButton).toBeDisabled();
612
+ return [2 /*return*/];
727
613
  }
728
614
  });
729
- applyButton = findApplyButton(component);
730
- expect(applyButton.prop('disabled')).toBe(false);
731
- applyButton.find('button').simulate('click');
732
- var expectedConnection = {
733
- relation: {
734
- relationUri: relationUri,
735
- relationType: '123',
736
- object: {
737
- type: '123'
738
- }
739
- },
740
- entity: {
741
- entityUri: 'entities/uri$$1',
742
- entityType: 'type',
743
- entityLabel: expectedLabel,
744
- object: {
745
- uri: 'entities/uri$$1',
746
- type: 'type',
747
- label: expectedLabel
748
- }
615
+ }); });
616
+ it('should call addRelation action on Apply button click for new connections', function () { return __awaiter(void 0, void 0, void 0, function () {
617
+ var entity, relation, connection, props, user;
618
+ return __generator(this, function (_a) {
619
+ switch (_a.label) {
620
+ case 0:
621
+ entity = createEntity('entities/0C32GxR');
622
+ relation = createRelation('new name value');
623
+ connection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity, isNew: true });
624
+ props = __assign(__assign({}, defaultProps), { connection: connection });
625
+ user = setUp({ props: props }).user;
626
+ return [4 /*yield*/, user.click(screen.getByText('Apply'))];
627
+ case 1:
628
+ _a.sent();
629
+ expect(mdmActions.addRelation).toHaveBeenCalledWith(props.config.id, connection);
630
+ expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(props.config.id, relation.relationUri);
631
+ return [2 /*return*/];
749
632
  }
750
- };
751
- expect(mdmActions.editRelation).toHaveBeenCalledWith(config.id, expectedConnection);
752
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, expectedConnection.relation.relationUri);
753
- });
754
- it('should not update connection entity label if modified entity is not specified', function () {
755
- getEntityType.mockReturnValue({ dataLabelPattern: '{Name}' });
756
- var props = __assign(__assign({}, defaultProps), { config: config, metadata: { relationTypes: relationTypes, entityTypes: [] } });
757
- var component = setUp({ props: props });
758
- var applyButton = findApplyButton(component);
759
- expect(applyButton.prop('disabled')).toBe(true);
760
- component.setProps({
761
- connection: {
762
- __metadata: {
763
- draft: 'edited'
764
- },
765
- relation: {
766
- relationUri: relationUri,
767
- relationType: '123',
768
- object: {
769
- type: '123'
770
- }
771
- },
772
- entity: {
773
- entityUri: 'entities/uri$$1',
774
- entityType: 'type',
775
- entityLabel: '',
776
- object: {
777
- uri: 'entities/uri$$1',
778
- type: 'type',
779
- label: ''
780
- }
781
- }
633
+ });
634
+ }); });
635
+ it('should not call addRelation action on Apply button if connection has validation errors', function () { return __awaiter(void 0, void 0, void 0, function () {
636
+ var entity, relation, connection, props, user;
637
+ return __generator(this, function (_a) {
638
+ switch (_a.label) {
639
+ case 0:
640
+ entity = createEntity('entities/0C32GxR');
641
+ relation = createRelation('');
642
+ connection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity, isNew: true });
643
+ props = __assign(__assign({}, defaultProps), { connection: connection });
644
+ user = setUp({ props: props }).user;
645
+ return [4 /*yield*/, user.click(screen.getByText('Apply'))];
646
+ case 1:
647
+ _a.sent();
648
+ expect(mdmActions.addRelation).not.toHaveBeenCalled();
649
+ expect(mdmActions.errorsSet).toHaveBeenCalledWith([
650
+ {
651
+ attributeType: props.metadata.relationTypes[0].attributes[1],
652
+ attributeTypeUri: 'configuration/relationTypes/HasAddress/attributes/Name',
653
+ message: 'Attribute is required',
654
+ parentUri: connection.relation.relationUri,
655
+ path: [
656
+ {
657
+ label: 'location entity, has address',
658
+ type: 'relationConnection',
659
+ value: connection,
660
+ valueType: props.metadata.relationTypes[0],
661
+ viewId: props.config.id
662
+ }
663
+ ],
664
+ source: ErrorSource.local,
665
+ type: ErrorType.missed,
666
+ uri: ''
667
+ }
668
+ ]);
669
+ expect(mdmActions.closeRelationEditor).not.toHaveBeenCalled();
670
+ return [2 /*return*/];
782
671
  }
783
672
  });
784
- applyButton = findApplyButton(component);
785
- expect(applyButton.prop('disabled')).toBe(false);
786
- applyButton.find('button').simulate('click');
787
- var expectedConnection = {
788
- relation: {
789
- relationUri: relationUri,
790
- relationType: '123',
791
- object: {
792
- type: '123'
793
- }
794
- },
795
- entity: {
796
- entityUri: 'entities/uri$$1',
797
- entityType: 'type',
798
- entityLabel: '',
799
- object: {
800
- uri: 'entities/uri$$1',
801
- type: 'type',
802
- label: ''
803
- }
673
+ }); });
674
+ it('should call editRelation action on Apply button click for existing connections', function () { return __awaiter(void 0, void 0, void 0, function () {
675
+ var entity, relation, connection, props, user;
676
+ return __generator(this, function (_a) {
677
+ switch (_a.label) {
678
+ case 0:
679
+ entity = createEntity('entities/0C32GxR');
680
+ relation = createRelation('new name value');
681
+ connection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity });
682
+ props = __assign(__assign({}, defaultProps), { connection: connection });
683
+ user = setUp({ props: props }).user;
684
+ return [4 /*yield*/, user.click(screen.getByText('Apply'))];
685
+ case 1:
686
+ _a.sent();
687
+ expect(mdmActions.editRelation).toHaveBeenCalledWith(props.config.id, connection);
688
+ expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(props.config.id, relation.relationUri);
689
+ return [2 /*return*/];
804
690
  }
805
- };
806
- expect(mdmActions.editRelation).toHaveBeenCalledWith(config.id, expectedConnection);
807
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, expectedConnection.relation.relationUri);
808
- });
809
- it('should clean up outdated temp modified entities', function () {
810
- getEntityType.mockReturnValue({});
811
- var connection = {
812
- relation: { relationUri: relationUri },
813
- entity: { entityUri: 'entities/uri$$relationEntity' }
814
- };
815
- var initialAllModifiedEntities = {
816
- 'entities/uri$$relationEntity': {
817
- uri: 'entities/uri$$relationEntity',
818
- attributes: {
819
- Address: [
691
+ });
692
+ }); });
693
+ it('should not call editRelation action on Apply button click if connection has validation errors', function () { return __awaiter(void 0, void 0, void 0, function () {
694
+ var entity, relation, connection, props, user;
695
+ return __generator(this, function (_a) {
696
+ switch (_a.label) {
697
+ case 0:
698
+ entity = createEntity('entities/0C32GxR');
699
+ relation = createRelation('');
700
+ connection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity });
701
+ props = __assign(__assign({}, defaultProps), { connection: connection });
702
+ user = setUp({ props: props }).user;
703
+ return [4 /*yield*/, user.click(screen.getByText('Apply'))];
704
+ case 1:
705
+ _a.sent();
706
+ expect(mdmActions.editRelation).not.toHaveBeenCalled();
707
+ expect(mdmActions.errorsSet).toHaveBeenCalledWith([
820
708
  {
821
- refEntity: [
709
+ attributeType: props.metadata.relationTypes[0].attributes[1],
710
+ attributeTypeUri: 'configuration/relationTypes/HasAddress/attributes/Name',
711
+ message: 'Attribute is required',
712
+ parentUri: connection.relation.relationUri,
713
+ path: [
822
714
  {
823
- objectURI: 'entities/uri$$addressEntity1'
715
+ label: 'location entity, has address',
716
+ type: 'relationConnection',
717
+ value: connection,
718
+ valueType: props.metadata.relationTypes[0],
719
+ viewId: props.config.id
824
720
  }
825
- ]
826
- },
827
- {
828
- refEntity: [
721
+ ],
722
+ source: ErrorSource.local,
723
+ type: ErrorType.missed,
724
+ uri: ''
725
+ }
726
+ ]);
727
+ expect(mdmActions.closeRelationEditor).not.toHaveBeenCalled();
728
+ return [2 /*return*/];
729
+ }
730
+ });
731
+ }); });
732
+ it('should evaluate and update connection entity label if modified entity is specified', function () { return __awaiter(void 0, void 0, void 0, function () {
733
+ var entityUri, entity, relation, connection, modifiedEntity, props, mdmValues, user;
734
+ var _a;
735
+ return __generator(this, function (_b) {
736
+ switch (_b.label) {
737
+ case 0:
738
+ entityUri = 'entities/uri$$kAp2KJM8';
739
+ entity = createEntity(entityUri);
740
+ relation = createRelation('new name value');
741
+ connection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity });
742
+ modifiedEntity = {
743
+ type: 'configuration/entityTypes/Location',
744
+ uri: entityUri,
745
+ attributes: {
746
+ FirstName: [
829
747
  {
830
- objectURI: 'entities/uri$$addressEntity2'
748
+ uri: 'entities/uri$$kAp2KJM8/attributes/FirstName/uri$$wsbN3s0X',
749
+ type: 'configuration/entityTypes/Location/attributes/FirstName',
750
+ value: 'first name value'
831
751
  }
832
752
  ]
833
753
  }
834
- ]
835
- }
836
- },
837
- 'entities/uri$$addressEntity1': {
838
- uri: 'entities/uri$$addressEntity1',
839
- attributes: {
840
- Location: [
841
- {
842
- refEntity: [
754
+ };
755
+ props = __assign(__assign({}, defaultProps), { connection: connection });
756
+ mdmValues = __assign(__assign({}, defaultMdmValues), { modifiedEntities: (_a = {}, _a[entityUri] = modifiedEntity, _a) });
757
+ user = setUp({ mdmValues: mdmValues, props: props }).user;
758
+ return [4 /*yield*/, user.click(screen.getByText('Apply'))];
759
+ case 1:
760
+ _b.sent();
761
+ expect(mdmActions.editRelation).toHaveBeenCalledWith(props.config.id, {
762
+ entity: __assign(__assign({}, entity), { entityLabel: 'first name value', object: __assign(__assign({}, entity.object), { label: 'first name value' }) }),
763
+ relation: relation
764
+ });
765
+ expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(props.config.id, relation.relationUri);
766
+ return [2 /*return*/];
767
+ }
768
+ });
769
+ }); });
770
+ it('should clean up outdated temp modified entities', function () { return __awaiter(void 0, void 0, void 0, function () {
771
+ var entityUri, entity, relation, connection, modifiedEntities, props, mdmValues, _a, user, rerender, updatedModifiedEntities, updatedEntity, updatedConnection;
772
+ var _b;
773
+ return __generator(this, function (_c) {
774
+ switch (_c.label) {
775
+ case 0:
776
+ entityUri = 'entities/uri$$kAp2KJM8';
777
+ entity = createEntity(entityUri);
778
+ relation = createRelation('new name value');
779
+ connection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity });
780
+ modifiedEntities = (_b = {},
781
+ _b[entityUri] = {
782
+ type: 'configuration/entityTypes/Location',
783
+ uri: entityUri,
784
+ attributes: {
785
+ Address: [
786
+ {
787
+ refEntity: [{ objectURI: 'entities/uri$$kLnBs782' }],
788
+ refRelation: null,
789
+ uri: 'entities/uri$$kAp2KJM8/attributes/Address/uri$$nbsAsD',
790
+ value: {},
791
+ relationshipLabel: '',
792
+ startObjectCrosswalks: []
793
+ },
794
+ {
795
+ refEntity: [{ objectURI: 'entities/uri$$bAWp0mnS' }],
796
+ refRelation: null,
797
+ uri: 'entities/uri$$kAp2KJM8/attributes/Address/uri$$nSplKs321',
798
+ value: {},
799
+ relationshipLabel: '',
800
+ startObjectCrosswalks: []
801
+ }
802
+ ]
803
+ }
804
+ },
805
+ _b['entities/uri$$kLnBs782'] = {
806
+ type: 'configuration/entityTypes/Location',
807
+ uri: 'entities/uri$$kLnBs782',
808
+ attributes: {
809
+ Address: [
810
+ {
811
+ refEntity: [
812
+ {
813
+ objectURI: 'entities/uri$$ks0PsMA'
814
+ }
815
+ ],
816
+ refRelation: null,
817
+ uri: 'entities/uri$$kLnBs782/attributes/Address/uri$$o23NbsDA',
818
+ value: {},
819
+ relationshipLabel: '',
820
+ startObjectCrosswalks: []
821
+ }
822
+ ]
823
+ }
824
+ },
825
+ _b['entities/uri$$bAWp0mnS'] = {
826
+ uri: 'entities/uri$$bAWp0mnS',
827
+ type: 'configuration/entityTypes/HCP'
828
+ },
829
+ _b['entities/uri$$ks0PsMA'] = {
830
+ uri: 'entities/uri$$ks0PsMA',
831
+ type: 'configuration/entityTypes/HCP'
832
+ },
833
+ _b['entities/uri$$MsS01sDA'] = {
834
+ uri: 'entities/uri$$MsS01sDA',
835
+ type: 'configuration/entityTypes/HCP'
836
+ },
837
+ _b);
838
+ props = __assign(__assign({}, defaultProps), { connection: connection });
839
+ mdmValues = __assign(__assign({}, defaultMdmValues), { modifiedEntities: modifiedEntities });
840
+ _a = setUp({ mdmValues: mdmValues, props: props }), user = _a.user, rerender = _a.rerender;
841
+ updatedModifiedEntities = __assign(__assign({}, modifiedEntities), { 'entities/uri$$jSdsAA32': {
842
+ uri: 'entities/uri$$jSdsAA32',
843
+ type: 'configuration/entityTypes/Location',
844
+ attributes: {}
845
+ } });
846
+ updatedEntity = createEntity('entities/uri$$jSdsAA32');
847
+ updatedConnection = __assign(__assign({}, connection), { entity: updatedEntity });
848
+ rerender({
849
+ mdmValues: __assign(__assign({}, mdmValues), { modifiedEntities: updatedModifiedEntities }),
850
+ props: __assign(__assign({}, props), { connection: updatedConnection })
851
+ });
852
+ return [4 /*yield*/, user.click(screen.getByText('Apply'))];
853
+ case 1:
854
+ _c.sent();
855
+ expect(mdmActions.editRelation).toHaveBeenCalledWith(props.config.id, __assign(__assign({}, connection), { entity: __assign(__assign({}, updatedEntity), { entityLabel: '', object: __assign(__assign({}, updatedEntity.object), { label: '' }) }) }));
856
+ expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(props.config.id, relation.relationUri);
857
+ expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$kLnBs782');
858
+ expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$bAWp0mnS');
859
+ expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$ks0PsMA');
860
+ expect(mdmActions.entityDeleted).not.toHaveBeenCalledWith('entities/uri$$MsS01sDA');
861
+ return [2 /*return*/];
862
+ }
863
+ });
864
+ }); });
865
+ it('should disable apply button if modified entity and connection was not changed', function () { return __awaiter(void 0, void 0, void 0, function () {
866
+ var entityUri, entity, relation, modifiedEntity, connection, mdmConnection, props, mdmValues, applyButton;
867
+ var _a, _b;
868
+ return __generator(this, function (_c) {
869
+ switch (_c.label) {
870
+ case 0:
871
+ entityUri = 'entities/uri$$kAp2KJM8';
872
+ entity = createEntity(entityUri);
873
+ relation = createRelation('name value');
874
+ modifiedEntity = {
875
+ type: 'configuration/entityTypes/Location',
876
+ uri: entityUri,
877
+ attributes: {
878
+ FirstName: [
843
879
  {
844
- objectURI: 'entities/uri$$locationEntity'
880
+ uri: 'entities/uri$$kAp2KJM8/attributes/FirstName/uri$$wsbN3s0X',
881
+ type: 'configuration/entityTypes/Location/attributes/FirstName',
882
+ value: 'first name value'
845
883
  }
846
884
  ]
847
885
  }
848
- ]
849
- }
850
- },
851
- 'entities/uri$$addressEntity2': {
852
- uri: 'entities/uri$$addressEntity2'
853
- },
854
- 'entities/uri$$locationEntity': {
855
- uri: 'entities/uri$$locationEntity'
856
- },
857
- 'entities/uri$$notRelatedEntity': {
858
- uri: 'entities/uri$$notRelatedEntity'
886
+ };
887
+ connection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity, isNew: true });
888
+ mdmConnection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity, initial: { modifiedEntity: modifiedEntity, connection: connection } });
889
+ props = __assign(__assign({}, defaultProps), { connection: connection });
890
+ mdmValues = __assign(__assign({}, defaultMdmValues), { relations: (_a = {}, _a[props.config.id] = { relationsToEdit: [mdmConnection] }, _a), modifiedEntities: (_b = {}, _b[entityUri] = modifiedEntity, _b) });
891
+ setUp({ props: props, mdmValues: mdmValues });
892
+ return [4 /*yield*/, screen.findByText('Apply')];
893
+ case 1:
894
+ applyButton = _c.sent();
895
+ expect(applyButton).toBeDisabled();
896
+ return [2 /*return*/];
859
897
  }
860
- };
861
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config, metadata: { relationTypes: relationTypes, entityTypes: [{ uri: '456', attributes: [] }] } });
862
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialConnection: connection, modifiedEntity: initialAllModifiedEntities['entities/uri$$relationEntity'], initialModifiedEntity: initialAllModifiedEntities['entities/uri$$relationEntity'], modifiedEntities: initialAllModifiedEntities });
863
- var component = setUp({ props: props, mdmValues: mdmValues });
864
- var applyButton = findApplyButton(component);
865
- expect(applyButton.prop('disabled')).toBe(true);
866
- useMdmModifiedEntity.mockReturnValue({
867
- uri: 'entities/uri$$newRelationEntity',
868
- attributes: {}
869
898
  });
870
- useMdmModifiedEntities.mockReturnValue(__assign(__assign({}, initialAllModifiedEntities), { 'entities/uri$$newRelationEntity': {
871
- uri: 'entities/uri$$newRelationEntity',
872
- type: '456'
873
- } }));
874
- // set new connection entity, so referenced Address and Location entities from old connection entity becomes outdated
875
- component.setProps({
876
- connection: {
877
- relation: {
878
- relationUri: relationUri,
879
- relationType: '123',
880
- object: {
881
- type: '123'
882
- }
883
- },
884
- entity: { entityUri: 'entities/uri$$newRelationEntity' }
899
+ }); });
900
+ it('should enable apply button if modified entity was changed', function () { return __awaiter(void 0, void 0, void 0, function () {
901
+ var createModifiedEntity, entityUri, entity, relation, connection, mdmConnection, props, mdmValues, applyButton;
902
+ var _a, _b;
903
+ return __generator(this, function (_c) {
904
+ switch (_c.label) {
905
+ case 0:
906
+ createModifiedEntity = function (value) { return ({
907
+ type: 'configuration/entityTypes/Location',
908
+ uri: entityUri,
909
+ attributes: {
910
+ FirstName: [
911
+ {
912
+ uri: 'entities/uri$$kAp2KJM8/attributes/FirstName/uri$$wsbN3s0X',
913
+ type: 'configuration/entityTypes/Location/attributes/FirstName',
914
+ value: value
915
+ }
916
+ ]
917
+ }
918
+ }); };
919
+ entityUri = 'entities/uri$$kAp2KJM8';
920
+ entity = createEntity(entityUri);
921
+ relation = createRelation('name value');
922
+ connection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity, isNew: true });
923
+ mdmConnection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity, initial: { modifiedEntity: createModifiedEntity('initial first name'), connection: connection } });
924
+ props = __assign(__assign({}, defaultProps), { connection: connection });
925
+ mdmValues = __assign(__assign({}, defaultMdmValues), { relations: (_a = {}, _a[props.config.id] = { relationsToEdit: [mdmConnection] }, _a), modifiedEntities: (_b = {}, _b[entityUri] = createModifiedEntity('changed first name'), _b) });
926
+ setUp({ props: props, mdmValues: mdmValues });
927
+ return [4 /*yield*/, screen.findByText('Apply')];
928
+ case 1:
929
+ applyButton = _c.sent();
930
+ expect(applyButton).not.toBeDisabled();
931
+ return [2 /*return*/];
885
932
  }
886
933
  });
887
- applyButton = findApplyButton(component);
888
- expect(applyButton.prop('disabled')).toBe(false);
889
- applyButton.find('button').simulate('click');
890
- var clearedConnection = {
891
- relation: {
892
- relationUri: relationUri,
893
- relationType: '123',
894
- object: {
895
- type: '123'
896
- }
897
- },
898
- entity: { entityUri: 'entities/uri$$newRelationEntity' }
899
- };
900
- expect(mdmActions.editRelation).toHaveBeenCalledWith(config.id, clearedConnection);
901
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, clearedConnection.relation.relationUri);
902
- expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$addressEntity1');
903
- expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$addressEntity2');
904
- expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$locationEntity');
905
- expect(mdmActions.entityDeleted).not.toHaveBeenCalledWith('entities/uri$$notRelatedEntity');
906
- });
907
- it('should call validateConnection with correct params', function () {
908
- getEntityType.mockReturnValue({});
909
- var connection = {
910
- relation: { relationUri: relationUri },
911
- entity: { entityUri: 'entities/uri$$relationEntity' }
912
- };
913
- var initialAllModifiedEntities = {};
914
- var metadata = { relationTypes: relationTypes, entityTypes: [{ uri: '456', attributes: [] }] };
915
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config, metadata: metadata });
916
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialConnection: connection, initialModifiedEntity: undefined, modifiedEntity: initialAllModifiedEntities['entities/uri$$relationEntity'], modifiedEntities: initialAllModifiedEntities });
917
- var component = setUp({ props: props, mdmValues: mdmValues });
918
- var applyButton = findApplyButton(component);
919
- expect(applyButton.prop('disabled')).toBe(true);
920
- var updatedAllModifiedEntities = __assign(__assign({}, initialAllModifiedEntities), { 'entities/uri$$newRelationEntity': {
921
- uri: 'entities/uri$$newRelationEntity',
922
- type: '456'
923
- } });
924
- var updatedConnecton = {
925
- relation: {
926
- relationUri: relationUri,
927
- relationType: '123',
928
- object: {
929
- type: '123'
930
- }
931
- },
932
- entity: { entityUri: 'entities/uri$$newRelationEntity' }
933
- };
934
- useMdmModifiedEntities.mockReturnValue(updatedAllModifiedEntities);
935
- component.setProps({ connection: updatedConnecton });
936
- applyButton = findApplyButton(component);
937
- expect(applyButton.prop('disabled')).toBe(false);
938
- applyButton.find('button').simulate('click');
939
- expect(validateConnection).toHaveBeenCalledWith(metadata, updatedAllModifiedEntities, updatedConnecton);
940
- });
941
- it('should enable Apply button if modified entity was changed', function () {
942
- var connection = { relation: { relationUri: relationUri }, entity: { entityUri: 'entities/uri$$123' } };
943
- var props = __assign(__assign({}, defaultProps), { config: config, metadata: { relationTypes: relationTypes, entityTypes: [] }, connection: connection });
944
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialConnection: connection });
945
- var component = setUp({ props: props, mdmValues: mdmValues });
946
- var applyButton = findApplyButton(component);
947
- expect(applyButton.prop('disabled')).toBe(true);
948
- useMdmModifiedEntity.mockReturnValue({
949
- uri: 'entities/$$uri',
950
- attributes: []
951
- });
952
- component.setProps({ test: 1 });
953
- applyButton = findApplyButton(component);
954
- expect(applyButton.prop('disabled')).toBe(false);
955
- });
956
- it('should enable Apply button if some referenced entity related to modified entity was changed', function () {
957
- var connection = {
958
- relation: { relationUri: relationUri },
959
- entity: { entityUri: 'entities/uri$$relationEntity' }
960
- };
961
- var initialAllModifiedEntities = {
962
- 'entities/uri$$relationEntity': {
963
- uri: 'entities/uri$$relationEntity',
964
- attributes: {
965
- Address: [
966
- {
967
- refEntity: [
934
+ }); });
935
+ it('should enable apply button if connection was changed', function () { return __awaiter(void 0, void 0, void 0, function () {
936
+ var entityUri, entity, relation, modifiedEntity, connection, mdmConnection, props, mdmValues, applyButton;
937
+ var _a, _b;
938
+ return __generator(this, function (_c) {
939
+ switch (_c.label) {
940
+ case 0:
941
+ entityUri = 'entities/uri$$kAp2KJM8';
942
+ entity = createEntity(entityUri);
943
+ relation = createRelation('name value');
944
+ modifiedEntity = {
945
+ type: 'configuration/entityTypes/Location',
946
+ uri: entityUri,
947
+ attributes: {
948
+ FirstName: [
968
949
  {
969
- objectURI: 'entities/uri$$addressEntity1'
950
+ uri: 'entities/uri$$kAp2KJM8/attributes/FirstName/uri$$wsbN3s0X',
951
+ type: 'configuration/entityTypes/Location/attributes/FirstName',
952
+ value: 'first name value'
970
953
  }
971
954
  ]
972
955
  }
973
- ]
974
- }
975
- },
976
- 'entities/uri$$addressEntity1': {
977
- uri: 'entities/uri$$addressEntity1',
978
- attributes: {
979
- Location: [
980
- {
981
- refEntity: [
956
+ };
957
+ connection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity, isNew: true });
958
+ mdmConnection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity, initial: { modifiedEntity: modifiedEntity, connection: __assign(__assign({}, connection), { relation: createRelation('changed name value') }) } });
959
+ props = __assign(__assign({}, defaultProps), { connection: connection });
960
+ mdmValues = __assign(__assign({}, defaultMdmValues), { relations: (_a = {}, _a[props.config.id] = { relationsToEdit: [mdmConnection] }, _a), modifiedEntities: (_b = {}, _b[entityUri] = modifiedEntity, _b) });
961
+ setUp({ props: props, mdmValues: mdmValues });
962
+ return [4 /*yield*/, screen.findByText('Apply')];
963
+ case 1:
964
+ applyButton = _c.sent();
965
+ expect(applyButton).not.toBeDisabled();
966
+ return [2 /*return*/];
967
+ }
968
+ });
969
+ }); });
970
+ it('should enable apply button if some referenced entity related to modified entity was changed', function () { return __awaiter(void 0, void 0, void 0, function () {
971
+ var entityUri, entity, relation, modifiedEntity, modifiedEntities, connection, mdmConnection, props, mdmValues, rerender, updatedModifiedEntities, applyButton;
972
+ var _a, _b;
973
+ return __generator(this, function (_c) {
974
+ switch (_c.label) {
975
+ case 0:
976
+ entityUri = 'entities/uri$$kAp2KJM8';
977
+ entity = createEntity(entityUri);
978
+ relation = createRelation('name value');
979
+ modifiedEntity = {
980
+ type: 'configuration/entityTypes/Location',
981
+ uri: entityUri,
982
+ attributes: {
983
+ Address: [
982
984
  {
983
- objectURI: 'entities/uri$$locationEntity'
985
+ refEntity: [{ objectURI: 'entities/uri$$kLnBs782' }],
986
+ refRelation: null,
987
+ uri: 'entities/uri$$kAp2KJM8/attributes/Address/uri$$nbsAsD',
988
+ value: {},
989
+ relationshipLabel: '',
990
+ startObjectCrosswalks: []
984
991
  }
985
992
  ]
986
993
  }
987
- ]
988
- }
989
- },
990
- 'entities/uri$$locationEntity': {
991
- uri: 'entities/uri$$locationEntity'
994
+ };
995
+ modifiedEntities = (_a = {},
996
+ _a[entityUri] = modifiedEntity,
997
+ _a['entities/uri$$kLnBs782'] = {
998
+ uri: 'entities/uri$$MsS01sDA',
999
+ type: 'configuration/entityTypes/Location',
1000
+ attributes: {
1001
+ FirstName: [
1002
+ {
1003
+ uri: 'entities/uri$$MsS01sDA/attributes/FirstName/uri$$jsNs01HO',
1004
+ type: 'configuration/entityTypes/Location/attributes/FirstName',
1005
+ value: 'initial first name value'
1006
+ }
1007
+ ]
1008
+ }
1009
+ },
1010
+ _a);
1011
+ connection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity, isNew: true });
1012
+ mdmConnection = __assign(__assign({}, defaultProps.connection), { relation: relation, entity: entity, initial: { modifiedEntity: modifiedEntity, connection: connection } });
1013
+ props = __assign(__assign({}, defaultProps), { connection: connection });
1014
+ mdmValues = __assign(__assign({}, defaultMdmValues), { relations: (_b = {}, _b[props.config.id] = { relationsToEdit: [mdmConnection] }, _b), modifiedEntities: modifiedEntities });
1015
+ rerender = setUp({ props: props, mdmValues: mdmValues }).rerender;
1016
+ updatedModifiedEntities = __assign(__assign({}, modifiedEntities), { 'entities/uri$$kLnBs782': {
1017
+ uri: 'entities/uri$$MsS01sDA',
1018
+ type: 'configuration/entityTypes/Location',
1019
+ attributes: {
1020
+ FirstName: [
1021
+ {
1022
+ uri: 'entities/uri$$MsS01sDA/attributes/FirstName/uri$$jsNs01HO',
1023
+ type: 'configuration/entityTypes/Location/attributes/FirstName',
1024
+ value: 'changed first name value'
1025
+ }
1026
+ ]
1027
+ }
1028
+ } });
1029
+ rerender({ mdmValues: __assign(__assign({}, mdmValues), { modifiedEntities: updatedModifiedEntities }) });
1030
+ return [4 /*yield*/, screen.findByText('Apply')];
1031
+ case 1:
1032
+ applyButton = _c.sent();
1033
+ expect(applyButton).not.toBeDisabled();
1034
+ return [2 /*return*/];
992
1035
  }
993
- };
994
- var props = __assign(__assign({}, defaultProps), { config: config, metadata: { relationTypes: relationTypes, entityTypes: [] }, connection: connection });
995
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialConnection: connection, modifiedEntity: initialAllModifiedEntities['entities/uri$$relationEntity'], initialModifiedEntity: initialAllModifiedEntities['entities/uri$$relationEntity'], modifiedEntities: initialAllModifiedEntities });
996
- var component = setUp({ props: props, mdmValues: mdmValues });
997
- var applyButton = findApplyButton(component);
998
- expect(applyButton.prop('disabled')).toBe(true);
999
- // change deep referenced entity (modifiedEntity is not changed)
1000
- useMdmModifiedEntities.mockReturnValue(__assign(__assign({}, initialAllModifiedEntities), { 'entities/uri$$locationEntity': {
1001
- uri: 'entities/uri$$locationEntity',
1002
- attributes: {}
1003
- } }));
1004
- component.setProps({ test: 1 });
1005
- applyButton = findApplyButton(component);
1006
- expect(applyButton.prop('disabled')).toBe(false);
1007
- });
1036
+ });
1037
+ }); });
1008
1038
  });
1009
- describe('Cancel button behavior', function () {
1010
- it('should call closeRelationEditor action and remove related errors', function () {
1011
- var modifiedEntity = null;
1012
- var connection = { relation: { relationUri: relationUri }, entity: {} };
1013
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
1014
- var profileErrors = [
1015
- {
1016
- parentUri: 'relations/2',
1017
- uri: '',
1018
- attributeTypeUri: 'configuration/relationTypes/AccountTeam',
1019
- message: 'Entity is required',
1020
- deactivated: true,
1021
- type: 'missed'
1022
- },
1023
- {
1024
- parentUri: connection.relation.relationUri,
1025
- uri: '',
1026
- attributeTypeUri: 'configuration/relationTypes/HasAddress/attributes/BusinessCode',
1027
- message: 'Entity is required',
1028
- type: 'missed'
1029
- },
1030
- {
1031
- parentUri: connection.relation.relationUri,
1032
- uri: '',
1033
- attributeTypeUri: 'configuration/relationTypes/HasAddress/attributes/AddressType',
1034
- message: 'Entity is required',
1035
- type: 'missed'
1036
- }
1037
- ];
1038
- var mdmValues = __assign(__assign({}, defaultMdmValues), { modifiedEntity: modifiedEntity, initialModifiedEntity: modifiedEntity, profileErrors: profileErrors });
1039
- var component = setUp({ props: props, mdmValues: mdmValues });
1040
- findCancelButton(component).find('button').simulate('click');
1041
- expect(mdmActions.errorsSet).toHaveBeenCalledWith([
1042
- {
1043
- parentUri: 'relations/2',
1044
- uri: '',
1045
- attributeTypeUri: 'configuration/relationTypes/AccountTeam',
1046
- message: 'Entity is required',
1047
- deactivated: true,
1048
- type: 'missed'
1049
- }
1050
- ]);
1051
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, connection.relation.relationUri);
1052
- expect(mdmAction).toHaveBeenCalledTimes(2);
1053
- });
1054
- it('should delete modified entity if there was no entity initially but it was set after', function () {
1055
- var connection = { relation: { relationUri: relationUri }, entity: { entityUri: 'entities/uri$$123' } };
1056
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
1057
- var profileErrors = [
1058
- {
1059
- parentUri: connection.relation.relationUri,
1060
- uri: '',
1061
- attributeTypeUri: 'configuration/relationTypes/HasAddress/attributes/BusinessCode',
1062
- message: 'Entity is required',
1063
- type: 'missed'
1039
+ describe('cancel button', function () {
1040
+ it('should call closeRelationEditor action and remove related errors', function () { return __awaiter(void 0, void 0, void 0, function () {
1041
+ var profileErrors, mdmValues, user;
1042
+ return __generator(this, function (_a) {
1043
+ switch (_a.label) {
1044
+ case 0:
1045
+ profileErrors = [
1046
+ {
1047
+ parentUri: 'relations/11',
1048
+ uri: '',
1049
+ attributeTypeUri: defaultRelation.relationType,
1050
+ message: 'Entity is required',
1051
+ deactivated: true,
1052
+ type: ErrorType.missedRefEntity
1053
+ },
1054
+ {
1055
+ parentUri: defaultRelation.relationUri,
1056
+ uri: '',
1057
+ attributeTypeUri: defaultRelation.relationType,
1058
+ message: 'Entity is required - deactivated',
1059
+ deactivated: true,
1060
+ type: ErrorType.missedRefEntity
1061
+ },
1062
+ {
1063
+ parentUri: defaultRelation.relationUri,
1064
+ uri: '',
1065
+ attributeTypeUri: defaultRelation.relationType,
1066
+ message: 'Entity is required',
1067
+ type: ErrorType.missedRefEntity
1068
+ }
1069
+ ];
1070
+ mdmValues = __assign(__assign({}, defaultMdmValues), { profileErrors: profileErrors });
1071
+ user = setUp({ mdmValues: mdmValues }).user;
1072
+ return [4 /*yield*/, user.click(screen.getByText('Cancel'))];
1073
+ case 1:
1074
+ _a.sent();
1075
+ expect(mdmActions.errorsSet).toHaveBeenCalledWith([
1076
+ {
1077
+ attributeTypeUri: defaultRelation.relationType,
1078
+ deactivated: true,
1079
+ message: 'Entity is required',
1080
+ parentUri: 'relations/11',
1081
+ type: ErrorType.missedRefEntity,
1082
+ uri: ''
1083
+ }
1084
+ ]);
1085
+ expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(defaultProps.config.id, defaultProps.connection.relation.relationUri);
1086
+ expect(mdmAction).toHaveBeenCalledTimes(2);
1087
+ return [2 /*return*/];
1064
1088
  }
1065
- ];
1066
- var mdmValues = __assign(__assign({}, defaultMdmValues), { profileErrors: profileErrors });
1067
- var component = setUp({ props: props, mdmValues: mdmValues });
1068
- useMdmModifiedEntity.mockReturnValue({
1069
- uri: 'entities/uri$$123',
1070
- attributes: []
1071
1089
  });
1072
- component.setProps({ test: 1 });
1073
- findCancelButton(component).find('button').simulate('click');
1074
- expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$123');
1075
- expect(mdmActions.errorsSet).toHaveBeenCalledWith([]);
1076
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, connection.relation.relationUri);
1077
- expect(mdmAction).toHaveBeenCalledTimes(3);
1078
- });
1079
- it('should restore modified entity to initial state if there was initial entity and it was changed/cleared', function () {
1080
- var connection = { relation: { relationUri: relationUri }, entity: {} };
1081
- var initialModifiedEntity = {
1082
- uri: 'entities/uri$$initial',
1083
- attributes: []
1084
- };
1085
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
1086
- var profileErrors = [
1087
- {
1088
- parentUri: connection.relation.relationUri,
1089
- uri: '',
1090
- attributeTypeUri: 'configuration/relationTypes/HasAddress/attributes/BusinessCode',
1091
- message: 'Entity is required',
1092
- type: 'missed'
1093
- }
1094
- ];
1095
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialModifiedEntity: initialModifiedEntity, modifiedEntity: initialModifiedEntity, profileErrors: profileErrors });
1096
- var component = setUp({ props: props, mdmValues: mdmValues });
1097
- useMdmModifiedEntity.mockReturnValue({
1098
- uri: 'entities/uri$$initial',
1099
- attributes: {
1100
- Name: [{ value: '123', uri: 'uri' }]
1090
+ }); });
1091
+ it('should delete modified entity if there was no entity initially but it was set after', function () { return __awaiter(void 0, void 0, void 0, function () {
1092
+ var entityUri, connection, modifiedEntity, props, mdmValues, user;
1093
+ var _a, _b;
1094
+ return __generator(this, function (_c) {
1095
+ switch (_c.label) {
1096
+ case 0:
1097
+ entityUri = 'entities/uri$$kAp2KJM8';
1098
+ connection = __assign(__assign({}, defaultProps.connection), { entity: {
1099
+ entityUri: entityUri,
1100
+ entityType: 'configuration/entityTypes/Location',
1101
+ entityLabel: 'location entity',
1102
+ object: { uri: entityUri, type: 'configuration/entityTypes/Location', label: 'location entity' }
1103
+ } });
1104
+ modifiedEntity = { type: 'configuration/entityTypes/Location', uri: entityUri, attributes: {} };
1105
+ props = __assign(__assign({}, defaultProps), { connection: connection });
1106
+ mdmValues = __assign(__assign({}, defaultMdmValues), { relations: (_a = {},
1107
+ _a[props.config.id] = {
1108
+ relationsToEdit: [__assign(__assign({}, defaultProps.connection), { initial: { connection: connection } })]
1109
+ },
1110
+ _a), modifiedEntities: (_b = {},
1111
+ _b[entityUri] = modifiedEntity,
1112
+ _b) });
1113
+ user = setUp({ props: props, mdmValues: mdmValues }).user;
1114
+ mdmAction.mockClear();
1115
+ return [4 /*yield*/, user.click(screen.getByText('Cancel'))];
1116
+ case 1:
1117
+ _c.sent();
1118
+ expect(mdmActions.entityDeleted).toHaveBeenCalledWith(entityUri);
1119
+ expect(mdmActions.errorsSet).toHaveBeenCalledWith([]);
1120
+ expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(props.config.id, connection.relation.relationUri);
1121
+ expect(mdmAction).toHaveBeenCalledTimes(3);
1122
+ return [2 /*return*/];
1101
1123
  }
1102
1124
  });
1103
- component.setProps({ test: 1 });
1104
- findCancelButton(component).find('button').simulate('click');
1105
- expect(mdmActions.entityCreated).toHaveBeenCalledWith(initialModifiedEntity);
1106
- expect(mdmActions.errorsSet).toHaveBeenCalledWith([]);
1107
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, connection.relation.relationUri);
1108
- expect(mdmAction).toHaveBeenCalledTimes(3);
1109
- });
1110
- it('should restore initial modified entity if it was changed to another one (and delete new one)', function () {
1111
- var connection = { relation: { relationUri: relationUri }, entity: { entityUri: 'entities/uri$$initial' } };
1112
- var initialModifiedEntity = {
1113
- uri: 'entities/uri$$initial',
1114
- attributes: []
1115
- };
1116
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
1117
- var profileErrors = [
1118
- {
1119
- parentUri: connection.relation.relationUri,
1120
- uri: '',
1121
- attributeTypeUri: 'configuration/relationTypes/HasAddress/attributes/BusinessCode',
1122
- message: 'Entity is required',
1123
- type: 'missed'
1124
- }
1125
- ];
1126
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialModifiedEntity: initialModifiedEntity, modifiedEntity: initialModifiedEntity, profileErrors: profileErrors });
1127
- var component = setUp({ props: props, mdmValues: mdmValues });
1128
- useMdmModifiedEntity.mockReturnValue({
1129
- uri: 'entities/uri$$newone',
1130
- attributes: {
1131
- Name: [{ value: '123', uri: 'uri' }]
1125
+ }); });
1126
+ it('should restore modified entity to initial state if there was initial entity and it was changed/cleared', function () { return __awaiter(void 0, void 0, void 0, function () {
1127
+ var entityUri, modifiedEntity, relationToEdit, mdmValues, user;
1128
+ var _a;
1129
+ return __generator(this, function (_b) {
1130
+ switch (_b.label) {
1131
+ case 0:
1132
+ entityUri = 'entities/uri$$kAp2KJM8';
1133
+ modifiedEntity = { type: 'configuration/entityTypes/Location', uri: entityUri, attributes: {} };
1134
+ relationToEdit = __assign(__assign({}, defaultProps.connection), { initial: { connection: defaultProps.connection, modifiedEntity: modifiedEntity } });
1135
+ mdmValues = __assign(__assign({}, defaultMdmValues), { relations: (_a = {}, _a[defaultProps.config.id] = { relationsToEdit: [relationToEdit] }, _a), modifiedEntities: {} });
1136
+ user = setUp({ mdmValues: mdmValues }).user;
1137
+ return [4 /*yield*/, user.click(screen.getByText('Cancel'))];
1138
+ case 1:
1139
+ _b.sent();
1140
+ expect(mdmActions.entityCreated).toHaveBeenCalledWith(modifiedEntity);
1141
+ expect(mdmActions.errorsSet).toHaveBeenCalledWith([]);
1142
+ expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(defaultProps.config.id, defaultProps.connection.relation.relationUri);
1143
+ expect(mdmAction).toHaveBeenCalledTimes(3);
1144
+ return [2 /*return*/];
1132
1145
  }
1133
1146
  });
1134
- component.setProps({
1135
- connection: { relation: { relationUri: relationUri }, entity: { entityUri: 'entities/uri$$newone' } }
1147
+ }); });
1148
+ it('should restore initial modified entity if it was changed to another one (and delete new one)', function () { return __awaiter(void 0, void 0, void 0, function () {
1149
+ var entityUri, modifiedEntity, connection, relationToEdit, mdmValues, props, user;
1150
+ var _a;
1151
+ return __generator(this, function (_b) {
1152
+ switch (_b.label) {
1153
+ case 0:
1154
+ entityUri = 'entities/uri$$kAp2KJM8';
1155
+ modifiedEntity = { type: 'configuration/entityTypes/Location', uri: entityUri, attributes: {} };
1156
+ connection = __assign(__assign({}, defaultProps.connection), { entity: { entityUri: 'entities/uri$$7BhsS31L' } });
1157
+ relationToEdit = __assign(__assign({}, connection), { initial: { connection: defaultProps.connection, modifiedEntity: modifiedEntity } });
1158
+ mdmValues = __assign(__assign({}, defaultMdmValues), { relations: (_a = {}, _a[defaultProps.config.id] = { relationsToEdit: [relationToEdit] }, _a), modifiedEntities: { 'entities/uri$$7BhsS31L': __assign(__assign({}, modifiedEntity), { uri: 'entities/uri$$7BhsS31L' }) } });
1159
+ props = __assign(__assign({}, defaultProps), { connection: connection });
1160
+ user = setUp({ mdmValues: mdmValues, props: props }).user;
1161
+ return [4 /*yield*/, user.click(screen.getByText('Cancel'))];
1162
+ case 1:
1163
+ _b.sent();
1164
+ expect(mdmActions.entityCreated).toHaveBeenCalledWith(modifiedEntity);
1165
+ expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$7BhsS31L');
1166
+ expect(mdmActions.errorsSet).toHaveBeenCalledWith([]);
1167
+ expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(props.config.id, connection.relation.relationUri);
1168
+ expect(mdmAction).toHaveBeenCalledTimes(4);
1169
+ return [2 /*return*/];
1170
+ }
1136
1171
  });
1137
- findCancelButton(component).find('button').simulate('click');
1138
- expect(mdmActions.entityCreated).toHaveBeenCalledWith(initialModifiedEntity);
1139
- expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$newone');
1140
- expect(mdmActions.errorsSet).toHaveBeenCalledWith([]);
1141
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, connection.relation.relationUri);
1142
- expect(mdmAction).toHaveBeenCalledTimes(4);
1143
- });
1144
- it('should not call additional actions if modifiedEntity prop was not changed', function () {
1145
- var connection = { relation: { relationUri: relationUri }, entity: { entityUri: 'entities/uri$$123' } };
1146
- var modifiedEntity = {
1147
- uri: 'entities/uri$$123',
1148
- attributes: []
1149
- };
1150
- var profileErrors = [
1151
- {
1152
- parentUri: connection.relation.relationUri,
1153
- uri: '',
1154
- attributeTypeUri: 'configuration/relationTypes/HasAddress/attributes/BusinessCode',
1155
- message: 'Entity is required',
1156
- type: 'missed'
1172
+ }); });
1173
+ it('should not call additional actions if modifiedEntity prop was not changed', function () { return __awaiter(void 0, void 0, void 0, function () {
1174
+ var entityUri, modifiedEntity, connection, relationToEdit, mdmValues, props, user;
1175
+ var _a, _b;
1176
+ return __generator(this, function (_c) {
1177
+ switch (_c.label) {
1178
+ case 0:
1179
+ entityUri = 'entities/uri$$kAp2KJM8';
1180
+ modifiedEntity = { type: 'configuration/entityTypes/Location', uri: entityUri, attributes: {} };
1181
+ connection = __assign(__assign({}, defaultProps.connection), { entity: { entityUri: entityUri } });
1182
+ relationToEdit = __assign(__assign({}, connection), { initial: { connection: defaultProps.connection, modifiedEntity: modifiedEntity } });
1183
+ mdmValues = __assign(__assign({}, defaultMdmValues), { relations: (_a = {}, _a[defaultProps.config.id] = { relationsToEdit: [relationToEdit] }, _a), modifiedEntities: (_b = {}, _b[entityUri] = modifiedEntity, _b) });
1184
+ props = __assign(__assign({}, defaultProps), { connection: connection });
1185
+ user = setUp({ mdmValues: mdmValues, props: props }).user;
1186
+ return [4 /*yield*/, user.click(screen.getByText('Cancel'))];
1187
+ case 1:
1188
+ _c.sent();
1189
+ expect(mdmActions.entityCreated).not.toHaveBeenCalled();
1190
+ expect(mdmActions.errorsSet).toHaveBeenCalledWith([]);
1191
+ expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(props.config.id, connection.relation.relationUri);
1192
+ expect(mdmAction).toHaveBeenCalledTimes(2);
1193
+ return [2 /*return*/];
1157
1194
  }
1158
- ];
1159
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
1160
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialModifiedEntity: modifiedEntity, modifiedEntity: modifiedEntity, profileErrors: profileErrors });
1161
- var component = setUp({ props: props, mdmValues: mdmValues });
1162
- component.setProps({
1163
- connection: {
1164
- relation: {
1165
- relationUri: relationUri,
1166
- relationType: '123'
1167
- },
1168
- entity: {
1169
- entityUri: 'entities/uri$$123'
1170
- }
1195
+ });
1196
+ }); });
1197
+ it('should restore all related referenced entities to their initial state and delete outdated related referenced entities', function () { return __awaiter(void 0, void 0, void 0, function () {
1198
+ var entityUri, connection, modifiedEntities, relationToEdit, mdmValues, props, _a, user, rerender, updatedModifiedEntities;
1199
+ var _b, _c;
1200
+ return __generator(this, function (_d) {
1201
+ switch (_d.label) {
1202
+ case 0:
1203
+ entityUri = 'entities/uri$$kAp2KJM8';
1204
+ connection = __assign(__assign({}, defaultProps.connection), { entity: { entityUri: entityUri } });
1205
+ modifiedEntities = (_b = {},
1206
+ _b[entityUri] = {
1207
+ type: 'configuration/entityTypes/Location',
1208
+ uri: entityUri,
1209
+ attributes: {
1210
+ Address: [
1211
+ {
1212
+ refEntity: [{ objectURI: 'entities/uri$$kLnBs782' }],
1213
+ refRelation: null,
1214
+ uri: 'entities/uri$$kAp2KJM8/attributes/Address/uri$$nbsAsD',
1215
+ value: {},
1216
+ relationshipLabel: '',
1217
+ startObjectCrosswalks: []
1218
+ }
1219
+ ]
1220
+ }
1221
+ },
1222
+ _b['entities/uri$$kLnBs782'] = {
1223
+ type: 'configuration/entityTypes/Location',
1224
+ uri: 'entities/uri$$kLnBs782',
1225
+ attributes: {
1226
+ Address: [
1227
+ {
1228
+ refEntity: [
1229
+ {
1230
+ objectURI: 'entities/uri$$ks0PsMA'
1231
+ }
1232
+ ],
1233
+ refRelation: null,
1234
+ uri: 'entities/uri$$kLnBs782/attributes/Address/uri$$o23NbsDA',
1235
+ value: {},
1236
+ relationshipLabel: '',
1237
+ startObjectCrosswalks: []
1238
+ }
1239
+ ]
1240
+ }
1241
+ },
1242
+ _b['entities/uri$$ks0PsMA'] = {
1243
+ uri: 'entities/uri$$ks0PsMA',
1244
+ type: 'configuration/entityTypes/Location'
1245
+ },
1246
+ _b);
1247
+ relationToEdit = __assign(__assign({}, connection), { initial: { connection: defaultProps.connection, modifiedEntity: modifiedEntities[entityUri] } });
1248
+ mdmValues = __assign(__assign({}, defaultMdmValues), { relations: (_c = {}, _c[defaultProps.config.id] = { relationsToEdit: [relationToEdit] }, _c), modifiedEntities: modifiedEntities });
1249
+ props = __assign(__assign({}, defaultProps), { connection: connection });
1250
+ _a = setUp({ mdmValues: mdmValues, props: props }), user = _a.user, rerender = _a.rerender;
1251
+ updatedModifiedEntities = __assign(__assign({}, modifiedEntities), { 'entities/uri$$ks0PsMA': {
1252
+ type: 'configuration/entityTypes/Location',
1253
+ uri: 'entities/uri$$ks0PsMA',
1254
+ attributes: {
1255
+ Address: [
1256
+ {
1257
+ refEntity: [
1258
+ {
1259
+ objectURI: 'entities/uri$$8jKsBssA3'
1260
+ }
1261
+ ],
1262
+ refRelation: null,
1263
+ uri: 'entities/uri$$ks0PsMA/attributes/Address/uri$$o23NbsDA',
1264
+ value: {},
1265
+ relationshipLabel: '',
1266
+ startObjectCrosswalks: []
1267
+ }
1268
+ ]
1269
+ }
1270
+ }, 'entities/uri$$8jKsBssA3': {
1271
+ uri: 'entities/uri$$8jKsBssA3',
1272
+ type: 'configuration/entityTypes/Location'
1273
+ }, 'entities/uri$$IS2bSa92': {
1274
+ uri: 'entities/uri$$IS2bSa92',
1275
+ type: 'configuration/entityTypes/HCP'
1276
+ } });
1277
+ rerender({ mdmValues: __assign(__assign({}, mdmValues), { modifiedEntities: updatedModifiedEntities }) });
1278
+ return [4 /*yield*/, user.click(screen.getByText('Cancel'))];
1279
+ case 1:
1280
+ _d.sent();
1281
+ expect(mdmActions.entityCreated).toHaveBeenCalledWith(modifiedEntities['entities/uri$$kLnBs782']);
1282
+ expect(mdmActions.entityCreated).toHaveBeenCalledWith(modifiedEntities['entities/uri$$ks0PsMA']);
1283
+ expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$8jKsBssA3');
1284
+ expect(mdmActions.entityDeleted).not.toHaveBeenCalledWith('entities/uri$$IS2bSa92');
1285
+ expect(mdmActions.errorsSet).toHaveBeenCalledWith([]);
1286
+ expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(props.config.id, connection.relation.relationUri);
1287
+ expect(mdmAction).toHaveBeenCalledTimes(5);
1288
+ return [2 /*return*/];
1171
1289
  }
1172
1290
  });
1173
- findCancelButton(component).find('button').simulate('click');
1174
- expect(mdmActions.entityCreated).not.toHaveBeenCalledWith(modifiedEntity);
1175
- expect(mdmActions.errorsSet).toHaveBeenCalledWith([]);
1176
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, connection.relation.relationUri);
1177
- expect(mdmAction).toHaveBeenCalledTimes(2);
1178
- });
1179
- it('should restore all related referenced entities to their initial state and delete outdated related referenced entities', function () {
1180
- var connection = { relation: { relationUri: relationUri }, entity: { entityUri: 'entities/uri$$relationEntity' } };
1181
- var initialAllModifiedEntities = {
1182
- 'entities/uri$$relationEntity': {
1183
- uri: 'entities/uri$$relationEntity',
1184
- attributes: {
1185
- Address: [
1186
- {
1187
- refEntity: [
1188
- {
1189
- objectURI: 'entities/uri$$addressEntity1'
1190
- }
1191
- ]
1192
- }
1193
- ]
1291
+ }); });
1292
+ });
1293
+ describe('entity selector', function () {
1294
+ describe('creating', function () {
1295
+ it('should create new entity and call events for saving it in relation and in modified entities store slice', function () { return __awaiter(void 0, void 0, void 0, function () {
1296
+ var user;
1297
+ return __generator(this, function (_a) {
1298
+ switch (_a.label) {
1299
+ case 0:
1300
+ user = setUp().user;
1301
+ return [4 /*yield*/, user.click(screen.getByTestId('select-dropdown-indicator'))];
1302
+ case 1:
1303
+ _a.sent();
1304
+ return [4 /*yield*/, user.click(screen.getByText('Create new Address'))];
1305
+ case 2:
1306
+ _a.sent();
1307
+ expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(defaultProps.config.id, defaultProps.connection.relation.relationUri, {
1308
+ attributes: {},
1309
+ timestamp: expect.any(Number),
1310
+ type: 'configuration/entityTypes/Location',
1311
+ uri: expect.any(String)
1312
+ });
1313
+ expect(mdmActions.entityCreated).toHaveBeenCalledWith({
1314
+ attributes: {},
1315
+ timestamp: expect.any(Number),
1316
+ type: 'configuration/entityTypes/Location',
1317
+ uri: expect.any(String)
1318
+ });
1319
+ expect(mdmAction).toHaveBeenCalledTimes(2);
1320
+ return [2 /*return*/];
1194
1321
  }
1195
- },
1196
- 'entities/uri$$addressEntity1': {
1197
- uri: 'entities/uri$$addressEntity1',
1198
- attributes: {
1199
- Location: [
1200
- {
1201
- refEntity: [
1202
- {
1203
- objectURI: 'entities/uri$$locationEntity'
1204
- }
1205
- ]
1206
- }
1207
- ]
1322
+ });
1323
+ }); });
1324
+ it('should delete previous temp (modified) entity before creating new one', function () { return __awaiter(void 0, void 0, void 0, function () {
1325
+ var entityUri, modifiedEntity, connection, mdmValues, props, user;
1326
+ var _a;
1327
+ return __generator(this, function (_b) {
1328
+ switch (_b.label) {
1329
+ case 0:
1330
+ entityUri = 'entities/uri$$kAp2KJM8';
1331
+ modifiedEntity = { type: 'configuration/entityTypes/Location', uri: entityUri, attributes: {} };
1332
+ connection = __assign(__assign({}, defaultProps.connection), { entity: { entityUri: entityUri, entityType: 'configuration/entityTypes/Location' } });
1333
+ mdmValues = __assign(__assign({}, defaultMdmValues), { modifiedEntities: (_a = {}, _a[entityUri] = modifiedEntity, _a) });
1334
+ props = __assign(__assign({}, defaultProps), { connection: connection });
1335
+ user = setUp({ mdmValues: mdmValues, props: props }).user;
1336
+ return [4 /*yield*/, user.click(screen.getByTestId('select-dropdown-indicator'))];
1337
+ case 1:
1338
+ _b.sent();
1339
+ return [4 /*yield*/, user.click(screen.getByText('Create new Address'))];
1340
+ case 2:
1341
+ _b.sent();
1342
+ expect(mdmActions.setInitialInfo).toHaveBeenCalledWith(props.config.id, props.connection.relation.relationUri, modifiedEntity);
1343
+ expect(mdmActions.entityDeleted).toHaveBeenCalledWith(entityUri);
1344
+ expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(defaultProps.config.id, defaultProps.connection.relation.relationUri, {
1345
+ attributes: {},
1346
+ timestamp: expect.any(Number),
1347
+ type: 'configuration/entityTypes/Location',
1348
+ uri: expect.any(String)
1349
+ });
1350
+ expect(mdmActions.entityCreated).toHaveBeenCalledWith({
1351
+ attributes: {},
1352
+ timestamp: expect.any(Number),
1353
+ type: 'configuration/entityTypes/Location',
1354
+ uri: expect.any(String)
1355
+ });
1356
+ expect(mdmAction).toHaveBeenCalledTimes(4);
1357
+ return [2 /*return*/];
1208
1358
  }
1209
- },
1210
- 'entities/uri$$locationEntity': {
1211
- uri: 'entities/uri$$locationEntity'
1212
- }
1213
- };
1214
- var initialModifiedEntity = initialAllModifiedEntities['entities/uri$$relationEntity'];
1215
- var profileErrors = [
1216
- {
1217
- parentUri: connection.relation.relationUri,
1218
- uri: '',
1219
- attributeTypeUri: 'configuration/relationTypes/HasAddress/attributes/BusinessCode',
1220
- message: 'Entity is required',
1221
- type: 'missed'
1222
- }
1223
- ];
1224
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
1225
- var mdmValues = __assign(__assign({}, defaultMdmValues), { initialModifiedEntity: initialModifiedEntity, modifiedEntity: initialModifiedEntity, modifiedEntities: initialAllModifiedEntities, profileErrors: profileErrors });
1226
- var component = setUp({ props: props, mdmValues: mdmValues });
1227
- useMdmModifiedEntities.mockReturnValue(__assign(__assign({}, initialAllModifiedEntities), { 'entities/uri$$locationEntity': {
1228
- uri: 'entities/uri$$locationEntity',
1229
- attributes: {
1230
- Ref: [
1231
- {
1232
- refEntity: [
1233
- {
1234
- objectURI: 'entities/uri$$outdatedEntity'
1235
- }
1236
- ]
1237
- }
1238
- ]
1359
+ });
1360
+ }); });
1361
+ it('should create new entity with init value and call events when onCreate prop was called with initValue argument', function () { return __awaiter(void 0, void 0, void 0, function () {
1362
+ var user;
1363
+ return __generator(this, function (_a) {
1364
+ switch (_a.label) {
1365
+ case 0:
1366
+ user = setUp().user;
1367
+ return [4 /*yield*/, user.click(screen.getByTestId('select-dropdown-indicator'))];
1368
+ case 1:
1369
+ _a.sent();
1370
+ return [4 /*yield*/, user.type(screen.getByRole('combobox'), 'init value')];
1371
+ case 2:
1372
+ _a.sent();
1373
+ return [4 /*yield*/, user.click(screen.getByText('Create "init value" as new Address'))];
1374
+ case 3:
1375
+ _a.sent();
1376
+ expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(defaultProps.config.id, defaultProps.connection.relation.relationUri, {
1377
+ attributes: {
1378
+ FirstName: [
1379
+ {
1380
+ type: 'configuration/entityTypes/Location/attributes/FirstName',
1381
+ uri: expect.any(String),
1382
+ value: 'init value'
1383
+ }
1384
+ ]
1385
+ },
1386
+ timestamp: expect.any(Number),
1387
+ type: 'configuration/entityTypes/Location',
1388
+ uri: expect.any(String)
1389
+ });
1390
+ expect(mdmActions.entityCreated).toHaveBeenCalledWith({
1391
+ attributes: {
1392
+ FirstName: [
1393
+ {
1394
+ type: 'configuration/entityTypes/Location/attributes/FirstName',
1395
+ uri: expect.any(String),
1396
+ value: 'init value'
1397
+ }
1398
+ ]
1399
+ },
1400
+ timestamp: expect.any(Number),
1401
+ type: 'configuration/entityTypes/Location',
1402
+ uri: expect.any(String)
1403
+ });
1404
+ expect(mdmAction).toHaveBeenCalledTimes(2);
1405
+ return [2 /*return*/];
1239
1406
  }
1240
- }, 'entities/uri$$outdatedEntity': {
1241
- uri: 'entities/uri$$outdatedEntity',
1242
- attributes: {}
1243
- }, 'entities/uri$$notRelatedEntity': {
1244
- uri: 'entities/uri$$notRelatedEntity',
1245
- attributes: {}
1246
- } }));
1247
- component.setProps({ test: 1 });
1248
- findCancelButton(component).find('button').simulate('click');
1249
- expect(mdmActions.entityCreated).toHaveBeenCalledWith(initialAllModifiedEntities['entities/uri$$addressEntity1']);
1250
- expect(mdmActions.entityCreated).toHaveBeenCalledWith(initialAllModifiedEntities['entities/uri$$locationEntity']);
1251
- expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$outdatedEntity');
1252
- expect(mdmActions.entityDeleted).not.toHaveBeenCalledWith('entities/uri$$notRelatedEntity');
1253
- expect(mdmActions.errorsSet).toHaveBeenCalledWith([]);
1254
- expect(mdmActions.closeRelationEditor).toHaveBeenCalledWith(config.id, connection.relation.relationUri);
1255
- expect(mdmAction).toHaveBeenCalledTimes(5);
1256
- });
1257
- });
1258
- describe('EntitySelector behavior', function () {
1259
- describe('onCreate behavior', function () {
1260
- it('should create new entity and call events for saving it in relation and in modified entities store slice', function () {
1261
- var mockedNewEntity = { uri: 'entities/uri$$1' };
1262
- createTemporaryEntity.mockReturnValue(mockedNewEntity);
1263
- getEntityType.mockReturnValue({ dataLabelPattern: '{Name}' });
1264
- var connection = {
1265
- relation: {
1266
- relationUri: relationUri,
1267
- relationType: 'configuration/relationTypes/AccountTeam'
1268
- },
1269
- entity: {}
1270
- };
1271
- var entityTypeUri = 'configuration/entityTypes/HCP';
1272
- var metadata = { relationTypes: [] };
1273
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config, metadata: metadata });
1274
- var component = setUp({ props: props });
1275
- var entitySelector = component.find(EntitySelector);
1276
- expect(entitySelector.length).toBe(1);
1277
- entitySelector.prop('onCreate')(entityTypeUri);
1278
- expect(getEntityType).toHaveBeenCalledWith(metadata, entityTypeUri);
1279
- expect(createTemporaryEntity).toHaveBeenCalledWith(expect.objectContaining({ entityTypeUri: entityTypeUri }));
1280
- expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(config.id, connection.relation.relationUri, mockedNewEntity);
1281
- expect(mdmActions.entityCreated).toHaveBeenCalledWith(mockedNewEntity);
1282
- expect(mdmAction).toHaveBeenCalledTimes(2);
1283
- });
1284
- it('should delete previous temp (modified) entity before creating new one', function () {
1285
- var mockedNewEntity = { uri: 'entities/uri$$1' };
1286
- createTemporaryEntity.mockReturnValue(mockedNewEntity);
1287
- getEntityType.mockReturnValue({ dataLabelPattern: '{Name}' });
1288
- var connection = {
1289
- relation: {
1290
- relationUri: relationUri,
1291
- relationType: 'configuration/relationTypes/AccountTeam'
1292
- },
1293
- entity: { entityUri: 'entities/uri$$prev' }
1294
- };
1295
- var modifiedEntity = { uri: 'entities/uri$$prev' };
1296
- var entityTypeUri = 'configuration/entityTypes/HCP';
1297
- var metadata = { relationTypes: [] };
1298
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config, metadata: metadata });
1299
- var mdmValues = __assign(__assign({}, defaultMdmValues), { modifiedEntity: modifiedEntity });
1300
- var component = setUp({ props: props, mdmValues: mdmValues });
1301
- var entitySelector = component.find(EntitySelector);
1302
- expect(entitySelector.length).toBe(1);
1303
- entitySelector.prop('onCreate')(entityTypeUri);
1304
- expect(getEntityType).toHaveBeenCalledWith(metadata, entityTypeUri);
1305
- expect(createTemporaryEntity).toHaveBeenCalledWith(expect.objectContaining({ entityTypeUri: entityTypeUri }));
1306
- expect(mdmActions.setInitialInfo).toHaveBeenCalledWith(config.id, relationUri, modifiedEntity);
1307
- expect(mdmActions.entityDeleted).toHaveBeenCalledWith('entities/uri$$prev');
1308
- expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(config.id, connection.relation.relationUri, mockedNewEntity);
1309
- expect(mdmActions.entityCreated).toHaveBeenCalledWith(mockedNewEntity);
1310
- expect(mdmAction).toHaveBeenCalledTimes(4);
1311
- });
1312
- it('should create new entity with init value and call events when onCreate prop was called with initValue argument', function () {
1313
- var connection = {
1314
- relation: {
1315
- relationUri: relationUri,
1316
- relationType: 'configuration/relationTypes/AccountTeam'
1317
- },
1318
- entity: {}
1319
- };
1320
- var entityTypeUri = 'configuration/entityTypes/HCP';
1321
- var entityType = {
1322
- uri: 'configuration/entityTypes/HCP',
1323
- label: 'HCP',
1324
- attributes: [
1325
- {
1326
- name: 'Name',
1327
- type: 'String',
1328
- uri: 'configuration/entityTypes/HCP/attributes/Name',
1329
- access: ['CREATE', 'READ']
1330
- },
1331
- {
1332
- name: 'Int',
1333
- type: 'Int',
1334
- uri: 'configuration/entityTypes/HCP/attributes/Int',
1335
- access: ['CREATE', 'READ']
1336
- },
1337
- {
1338
- name: 'UsedInBusinessCard',
1339
- type: 'String',
1340
- uri: 'configuration/entityTypes/HCP/attributes/UsedInBusinessCard',
1341
- access: ['CREATE', 'READ']
1342
- },
1343
- {
1344
- name: 'DataLabelSimple',
1345
- type: 'String',
1346
- uri: 'configuration/entityTypes/HCP/attributes/DataLabelSimple',
1347
- access: []
1348
- },
1349
- {
1350
- name: 'Required',
1351
- type: 'String',
1352
- required: true,
1353
- uri: 'configuration/entityTypes/HCP/attributes/Required',
1354
- access: []
1355
- }
1356
- ],
1357
- dataLabelPattern: '{DataLabelSimple} {OtherSimple}',
1358
- businessCardAttributeURIs: [
1359
- 'configuration/entityTypes/HCP/attributes/Employment',
1360
- 'configuration/entityTypes/HCP/attributes/FirstName',
1361
- 'configuration/entityTypes/HCP/attributes/UsedInBusinessCard'
1362
- ]
1363
- };
1364
- var mockedNewEntity = { uri: 'entities/uri$$1' };
1365
- var initValue = '123';
1366
- var metadata = { relationTypes: [] };
1367
- getEntityType.mockReturnValue(entityType);
1368
- createTemporaryEntity.mockReturnValue(mockedNewEntity);
1369
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config, metadata: metadata });
1370
- var component = setUp({ props: props });
1371
- var entitySelector = component.find(EntitySelector);
1372
- expect(entitySelector.length).toBe(1);
1373
- entitySelector.prop('onCreate')(entityTypeUri, initValue);
1374
- expect(getEntityType).toHaveBeenCalledWith(metadata, entityTypeUri);
1375
- expect(createTemporaryEntity).toHaveBeenCalledWith({
1376
- entityTypeUri: entityTypeUri,
1377
- initValue: initValue,
1378
- attributeTypes: [
1379
- {
1380
- name: 'UsedInBusinessCard',
1381
- type: 'String',
1382
- uri: 'configuration/entityTypes/HCP/attributes/UsedInBusinessCard',
1383
- access: ['CREATE', 'READ']
1384
- }
1385
- ],
1386
- metadata: metadata,
1387
- mode: 'Editing'
1388
1407
  });
1389
- expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(config.id, connection.relation.relationUri, mockedNewEntity);
1390
- expect(mdmActions.entityCreated).toHaveBeenCalledWith(mockedNewEntity);
1391
- expect(mdmAction).toHaveBeenCalledTimes(2);
1392
- });
1408
+ }); });
1393
1409
  });
1394
- describe('onChange behavior', function () {
1395
- it('should set connection entity', function () {
1396
- var connection = {
1397
- relation: {
1398
- relationUri: relationUri,
1399
- relationType: 'configuration/relationTypes/AccountTeam'
1400
- },
1401
- entity: {}
1402
- };
1403
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
1404
- var component = setUp({ props: props });
1405
- var entitySelector = component.find(EntitySelector);
1406
- expect(entitySelector.length).toBe(1);
1407
- var entity = { uri: 'entities/123' };
1408
- entitySelector.prop('onChange')(entity);
1409
- expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(config.id, connection.relation.relationUri, entity);
1410
- expect(mdmAction).toHaveBeenCalledTimes(1);
1410
+ describe('changing', function () {
1411
+ beforeEach(function () {
1412
+ typeAheadSearch.mockResolvedValue([
1413
+ { type: 'configuration/entityTypes/Location', label: 'location entity 1', uri: 'entities/0C32GxR' },
1414
+ { type: 'configuration/entityTypes/Location', label: 'location entity 2', uri: 'entities/0G49Cnu' }
1415
+ ]);
1411
1416
  });
1412
- it('should deactivate error if it was set', function () {
1413
- var connection = {
1414
- relation: {
1415
- relationUri: relationUri,
1416
- relationType: 'configuration/relationTypes/AccountTeam'
1417
- },
1418
- entity: {}
1419
- };
1420
- var error = {
1421
- uri: 'uri',
1422
- type: 'missedRefEntity',
1423
- message: 'alarm!',
1424
- attributeTypeUri: 'configuration/relationTypes/AccountTeam',
1425
- parentUri: relationUri
1426
- };
1427
- var profileErrors = [error];
1428
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
1429
- var mdmValues = __assign(__assign({}, defaultMdmValues), { profileErrors: profileErrors });
1430
- var component = setUp({ props: props, mdmValues: mdmValues });
1431
- var entitySelector = component.find(EntitySelector);
1432
- expect(entitySelector.length).toBe(1);
1433
- var entity = { uri: 'entities/123' };
1434
- entitySelector.prop('onChange')(entity);
1435
- expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(config.id, connection.relation.relationUri, entity);
1436
- expect(mdmActions.errorDeactivated).toHaveBeenCalledWith("".concat(error.attributeTypeUri, "-").concat(error.uri, "-").concat(error.parentUri));
1437
- expect(mdmAction).toHaveBeenCalledTimes(2);
1438
- });
1439
- it('should clear connection entity and modified entity if it set', function () {
1440
- var connection = {
1441
- relation: {
1442
- relationUri: relationUri,
1443
- relationType: 'configuration/relationTypes/AccountTeam'
1444
- },
1445
- entity: { entityUri: 'entities/uri$$1' }
1446
- };
1447
- var modifiedEntity = { uri: 'entities/uri$$1' };
1448
- var props = __assign(__assign({}, defaultProps), { connection: connection, config: config });
1449
- var mdmValues = __assign(__assign({}, defaultMdmValues), { modifiedEntity: modifiedEntity, initialModifiedEntity: modifiedEntity });
1450
- var component = setUp({ props: props, mdmValues: mdmValues });
1451
- var entitySelector = component.find(EntitySelector);
1452
- expect(entitySelector.length).toBe(1);
1453
- var entity = {};
1454
- entitySelector.prop('onChange')(entity);
1455
- expect(mdmActions.entityDeleted).toHaveBeenCalledWith(modifiedEntity.uri);
1456
- expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(config.id, connection.relation.relationUri, entity);
1457
- expect(mdmAction).toHaveBeenCalledTimes(2);
1417
+ afterEach(function () {
1418
+ jest.clearAllMocks();
1458
1419
  });
1420
+ it('should set connection entity', function () { return __awaiter(void 0, void 0, void 0, function () {
1421
+ var user;
1422
+ return __generator(this, function (_a) {
1423
+ switch (_a.label) {
1424
+ case 0:
1425
+ user = setUp().user;
1426
+ return [4 /*yield*/, user.click(screen.getByTestId('select-dropdown-indicator'))];
1427
+ case 1:
1428
+ _a.sent();
1429
+ return [4 /*yield*/, user.click(screen.getByText('location entity 1'))];
1430
+ case 2:
1431
+ _a.sent();
1432
+ expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(defaultProps.config.id, defaultProps.connection.relation.relationUri, {
1433
+ entityType: defaultProps.metadata.entityTypes[1],
1434
+ label: 'location entity 1',
1435
+ type: 'configuration/entityTypes/Location',
1436
+ uri: 'entities/0C32GxR'
1437
+ });
1438
+ expect(mdmAction).toHaveBeenCalledTimes(1);
1439
+ return [2 /*return*/];
1440
+ }
1441
+ });
1442
+ }); });
1443
+ it('should deactivate error if it was set', function () { return __awaiter(void 0, void 0, void 0, function () {
1444
+ var error, mdmValues, user;
1445
+ return __generator(this, function (_a) {
1446
+ switch (_a.label) {
1447
+ case 0:
1448
+ error = {
1449
+ parentUri: defaultRelation.relationUri,
1450
+ uri: 'uri',
1451
+ attributeTypeUri: defaultRelation.relationType,
1452
+ message: 'Entity is required',
1453
+ type: ErrorType.missedRefEntity
1454
+ };
1455
+ mdmValues = __assign(__assign({}, defaultMdmValues), { profileErrors: [error] });
1456
+ setUp({ mdmValues: mdmValues });
1457
+ user = setUp().user;
1458
+ return [4 /*yield*/, user.click(screen.getAllByTestId('select-dropdown-indicator')[0])];
1459
+ case 1:
1460
+ _a.sent();
1461
+ return [4 /*yield*/, user.click(screen.getByText('location entity 1'))];
1462
+ case 2:
1463
+ _a.sent();
1464
+ expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(defaultProps.config.id, defaultProps.connection.relation.relationUri, {
1465
+ entityType: defaultProps.metadata.entityTypes[1],
1466
+ label: 'location entity 1',
1467
+ type: 'configuration/entityTypes/Location',
1468
+ uri: 'entities/0C32GxR'
1469
+ });
1470
+ expect(mdmActions.errorDeactivated).toHaveBeenCalledWith("".concat(error.attributeTypeUri, "-").concat(error.uri, "-").concat(error.parentUri));
1471
+ expect(mdmAction).toHaveBeenCalledTimes(2);
1472
+ return [2 /*return*/];
1473
+ }
1474
+ });
1475
+ }); });
1476
+ it('should clear connection entity and modified entity if it set', function () { return __awaiter(void 0, void 0, void 0, function () {
1477
+ var entityUri, modifiedEntity, connection, mdmValues, props, user;
1478
+ var _a;
1479
+ return __generator(this, function (_b) {
1480
+ switch (_b.label) {
1481
+ case 0:
1482
+ entityUri = 'entities/uri$$kAp2KJM8';
1483
+ modifiedEntity = { type: 'configuration/entityTypes/Location', uri: entityUri, attributes: {} };
1484
+ connection = __assign(__assign({}, defaultProps.connection), { entity: { entityUri: entityUri, entityType: 'configuration/entityTypes/Location' } });
1485
+ mdmValues = __assign(__assign({}, defaultMdmValues), { modifiedEntities: (_a = {}, _a[entityUri] = modifiedEntity, _a) });
1486
+ props = __assign(__assign({}, defaultProps), { connection: connection });
1487
+ user = setUp({ mdmValues: mdmValues, props: props }).user;
1488
+ mdmAction.mockClear();
1489
+ return [4 /*yield*/, user.click(screen.getByTestId('select-dropdown-indicator'))];
1490
+ case 1:
1491
+ _b.sent();
1492
+ return [4 /*yield*/, user.click(screen.getByText('location entity 1'))];
1493
+ case 2:
1494
+ _b.sent();
1495
+ expect(mdmActions.entityDeleted).toHaveBeenCalledWith(entityUri);
1496
+ expect(mdmActions.setRelationEntity).toHaveBeenCalledWith(defaultProps.config.id, defaultProps.connection.relation.relationUri, {
1497
+ entityType: defaultProps.metadata.entityTypes[1],
1498
+ label: 'location entity 1',
1499
+ type: 'configuration/entityTypes/Location',
1500
+ uri: 'entities/0C32GxR'
1501
+ });
1502
+ expect(mdmAction).toHaveBeenCalledTimes(2);
1503
+ return [2 /*return*/];
1504
+ }
1505
+ });
1506
+ }); });
1459
1507
  });
1460
1508
  });
1461
- describe('useScrollToAttributeError tests', function () {
1509
+ describe('errors highlighting', function () {
1462
1510
  var fullError = {
1463
- type: 'invalid',
1511
+ type: ErrorType.invalid,
1464
1512
  attributeTypeUri: defaultProps.connection.relation.relationType,
1465
1513
  parentUri: defaultProps.connection.relation.relationUri,
1466
1514
  uri: 'someUrl',
1467
- source: 'validationService',
1468
- severity: 'ERROR'
1515
+ source: ErrorSource.validationService,
1516
+ severity: ErrorSeverity.ERROR
1469
1517
  };
1470
- it('should not highlight error if it have uri', function () {
1471
- var component = setUp({ contextError: fullError });
1472
- expect(component.find('RelationEditor').prop('highlightedError')).toBe(null);
1473
- expect(useScrollToAttributeError.mock.calls[0][0]).toMatchObject({
1474
- highlightedError: null,
1475
- isSimple: true
1518
+ it('should not highlight error if it have uri', function () { return __awaiter(void 0, void 0, void 0, function () {
1519
+ return __generator(this, function (_a) {
1520
+ switch (_a.label) {
1521
+ case 0:
1522
+ setUp({ error: fullError });
1523
+ return [4 /*yield*/, screen.findByText('Select Address profile')];
1524
+ case 1:
1525
+ _a.sent();
1526
+ expect(scrollIntoRef).not.toHaveBeenCalledWith();
1527
+ return [2 /*return*/];
1528
+ }
1476
1529
  });
1477
- });
1478
- it('should highlight error if it have same parent uri, empty uri, and attribute type uri', function () {
1479
- var error = __assign(__assign({}, fullError), { uri: '' });
1480
- var component = setUp({ contextError: error });
1481
- var highlightedError = {
1482
- element: error,
1483
- highlightError: highlightErrorSpy,
1484
- scrollIntoRef: scrollIntoRefSpy,
1485
- type: ScrollType.Error
1486
- };
1487
- expect(component.find('RelationEditor').prop('highlightedError')).toMatchObject(highlightedError);
1488
- expect(useScrollToAttributeError.mock.calls[0][0]).toMatchObject({ highlightedError: highlightedError, isSimple: true });
1489
- });
1530
+ }); });
1531
+ it('should highlight error if it have same parent uri, empty uri, and attribute type uri', function () { return __awaiter(void 0, void 0, void 0, function () {
1532
+ var error;
1533
+ return __generator(this, function (_a) {
1534
+ switch (_a.label) {
1535
+ case 0:
1536
+ error = __assign(__assign({}, fullError), { uri: '' });
1537
+ setUp({ error: error });
1538
+ return [4 /*yield*/, screen.findByText('Select Address profile')];
1539
+ case 1:
1540
+ _a.sent();
1541
+ expect(scrollIntoRef).toHaveBeenCalled();
1542
+ return [2 /*return*/];
1543
+ }
1544
+ });
1545
+ }); });
1490
1546
  });
1491
1547
  });