@reltio/sources 1.4.1585 → 1.4.1586-mui5

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 (94) hide show
  1. package/index.ts +1 -0
  2. package/package.json +38 -21
  3. package/public/bundle.js +205 -0
  4. package/public/bundle.js.LICENSE.txt +79 -0
  5. package/public/package.json +22 -0
  6. package/scripts/build/index.js +20 -0
  7. package/src/components/CrosswalkTreeView/CrosswalkTreeView.tsx +47 -0
  8. package/src/components/CrosswalkTreeView/__tests__/CrosswalkTreeView.spec.tsx +72 -0
  9. package/src/components/CrosswalkTreeView/__tests__/helpers.spec.ts +961 -0
  10. package/src/components/CrosswalkTreeView/helpers.ts +91 -0
  11. package/src/components/CrosswalkTreeView/styles.ts +10 -0
  12. package/src/components/EmptyState/EmptyState.tsx +20 -0
  13. package/src/components/EmptyState/__tests__/EmptyState.test.tsx +13 -0
  14. package/src/components/EmptyState/icons/EmptySources.svg +43 -0
  15. package/src/components/EmptyState/styles.ts +19 -0
  16. package/src/components/LegendTable/LegendTable.tsx +124 -0
  17. package/src/components/LegendTable/LegendTableRow/ContributorRow/ContributorRow.tsx +46 -0
  18. package/src/components/LegendTable/LegendTableRow/ContributorRow/__tests__/ContributorRow.test.tsx +103 -0
  19. package/src/components/LegendTable/LegendTableRow/ContributorRow/styles.ts +31 -0
  20. package/src/components/LegendTable/LegendTableRow/LegendTableRow.tsx +179 -0
  21. package/src/components/LegendTable/LegendTableRow/__tests__/LegendTableRow.test.tsx +371 -0
  22. package/src/components/LegendTable/LegendTableRow/styles.ts +31 -0
  23. package/src/components/LegendTable/__tests__/LegendTable.test.tsx +273 -0
  24. package/src/components/LegendTable/__tests__/helpers.test.ts +541 -0
  25. package/src/components/LegendTable/helpers.ts +64 -0
  26. package/src/components/LegendTable/styles.ts +17 -0
  27. package/src/components/LegendView/LegendView.tsx +201 -0
  28. package/src/components/LegendView/__tests__/LegendView.test.tsx +307 -0
  29. package/src/components/LegendView/styles.ts +51 -0
  30. package/src/components/RightSidePanel/RightSidePanel.tsx +25 -0
  31. package/src/components/RightSidePanel/__tests__/RightSidePanel.test.tsx +28 -0
  32. package/src/components/RightSidePanel/styles.ts +14 -0
  33. package/src/components/RulesestsSelector/RulesestsSelector.tsx +31 -0
  34. package/src/components/RulesestsSelector/RulesetOption/RulesetOption.tsx +25 -0
  35. package/src/components/RulesestsSelector/RulesetOption/__tests__/RulesetOption.test.tsx +25 -0
  36. package/src/components/RulesestsSelector/RulesetOption/styles.ts +27 -0
  37. package/src/components/RulesestsSelector/RulesetsMenuList/RulesetsMenuList.tsx +14 -0
  38. package/src/components/RulesestsSelector/__tests__/RulesetsSelector.test.tsx +91 -0
  39. package/src/components/RulesestsSelector/styles.ts +7 -0
  40. package/src/components/SankeyChart/Link.tsx +31 -0
  41. package/src/components/SankeyChart/MergeTooltip.tsx +37 -0
  42. package/src/components/SankeyChart/Node.tsx +137 -0
  43. package/src/components/SankeyChart/SankeyChart.tsx +103 -0
  44. package/src/components/SankeyChart/__tests__/Link.spec.tsx +127 -0
  45. package/src/components/SankeyChart/__tests__/MergeTooltip.spec.tsx +22 -0
  46. package/src/components/SankeyChart/__tests__/Node.spec.tsx +248 -0
  47. package/src/components/SankeyChart/__tests__/SankeyChart.spec.tsx +161 -0
  48. package/src/components/SankeyChart/__tests__/__snapshots__/SankeyChart.spec.tsx.snap +183 -0
  49. package/src/components/SankeyChart/sankey.ts +322 -0
  50. package/src/components/SankeyChart/styles.ts +41 -0
  51. package/src/components/SankeyChart/useSankey.tsx +44 -0
  52. package/src/components/SelectableTree/SelectableTree.tsx +46 -0
  53. package/src/components/SelectableTree/__tests__/SelectableTree.test.tsx +28 -0
  54. package/src/components/SelectableTree/__tests__/__snapshots__/SelectableTree.test.tsx.snap +59 -0
  55. package/src/components/SelectableTree/styles.ts +42 -0
  56. package/src/components/SourcesView/SourcesView.tsx +318 -0
  57. package/src/components/SourcesView/__tests__/IntegrationSourcesView.spec.tsx +199 -0
  58. package/src/components/SourcesView/__tests__/SourcesView.spec.tsx +903 -0
  59. package/src/components/SourcesView/__tests__/data/metadata.data.ts +27 -0
  60. package/src/components/SourcesView/__tests__/data/store.data.ts +65 -0
  61. package/src/components/SourcesView/icons/LegendIcon.svg +8 -0
  62. package/src/components/SourcesView/index.tsx +57 -0
  63. package/src/components/SourcesView/styles.ts +44 -0
  64. package/src/components/TreeActionSnackbar/TreeActionSnackbar.tsx +38 -0
  65. package/src/components/TreeActionSnackbar/__tests__/TreeActionSnackbar.test.tsx +38 -0
  66. package/src/components/TreeActionSnackbar/styles.ts +11 -0
  67. package/src/components/UnmergeDialog/UnmergeDialog.tsx +78 -0
  68. package/src/components/UnmergeDialog/__tests__/UnmergeDialog.test.tsx +124 -0
  69. package/src/components/UnmergeDialog/__tests__/testData.data.ts +271 -0
  70. package/src/components/UnmergeDialog/styles.ts +34 -0
  71. package/src/components/UnsubscribeDialog/UnsubscribeDialog.tsx +64 -0
  72. package/src/components/UnsubscribeDialog/__tests__/UnsubscribeDialog.test.tsx +59 -0
  73. package/src/components/UnsubscribeDialog/styles.ts +31 -0
  74. package/src/hooks/__tests__/useCrosswalkTree.specs.tsx +68 -0
  75. package/src/hooks/__tests__/useCrosswalkTreeActions.specs.ts +110 -0
  76. package/src/hooks/__tests__/useCrosswalksDisplay.specs.tsx +213 -0
  77. package/src/hooks/__tests__/useEntityWithSurvivorshipGroups.specs.ts +160 -0
  78. package/src/hooks/useCrosswalkTree.ts +38 -0
  79. package/src/hooks/useCrosswalkTreeActions.ts +83 -0
  80. package/src/hooks/useCrosswalksDisplay.ts +110 -0
  81. package/src/hooks/useEntityWithSurvivorshipGroups.tsx +51 -0
  82. package/src/icons/notMatch.svg +14 -0
  83. package/src/index.ts +1 -0
  84. package/src/services/errors.ts +11 -0
  85. package/src/types/LegendMode.ts +5 -0
  86. package/src/types/SankeyChartData.ts +31 -0
  87. package/src/types/SourcesSavedState.ts +3 -0
  88. package/src/types/UnmergeContributorEvent.ts +7 -0
  89. package/src/types/UnsubscribeContributorEvent.ts +6 -0
  90. package/src/types/index.ts +4 -0
  91. package/tsconfig.json +4 -0
  92. package/webpack.config.js +10 -0
  93. package/bundle.js +0 -2
  94. package/bundle.js.LICENSE.txt +0 -42
@@ -0,0 +1,271 @@
1
+ import {Contributor, CrosswalkTree} from '@reltio/mdm-sdk';
2
+
3
+ export const contributors: Contributor[] = [
4
+ {
5
+ uri: 'entities/j8K1vc9',
6
+ crosswalks: [
7
+ {
8
+ uri: 'entities/j8K1vc9/crosswalks/1kQ5cap2n',
9
+ type: 'configuration/sources/Reltio',
10
+ ownerType: 'entity',
11
+ value: 'j8K1vc9'
12
+ },
13
+ {
14
+ uri: 'relations/fwqqZcE/crosswalks/3CQl2KAH8',
15
+ type: 'configuration/sources/Reltio',
16
+ ownerType: 'relation',
17
+ value: 'fwqqZcE'
18
+ }
19
+ ],
20
+ merges: [
21
+ {
22
+ losers: [
23
+ {
24
+ crosswalks: [
25
+ {
26
+ ownerType: 'entity',
27
+ type: 'configuration/sources/MDS',
28
+ uri: 'entities/j8K1vc9/crosswalks/3dPCbiK7u',
29
+ value: 'mds_202108061617'
30
+ }
31
+ ],
32
+ phantomEntity: true,
33
+ uri: 'entities/1N1mfYja'
34
+ }
35
+ ],
36
+ mergeReason: 'Merge on the fly',
37
+ mergeRules: '',
38
+ time: 1628248691969,
39
+ user: 'marat'
40
+ },
41
+ {
42
+ losers: [
43
+ {
44
+ merges: [
45
+ {
46
+ losers: [
47
+ {
48
+ crosswalks: [
49
+ {
50
+ ownerType: 'entity',
51
+ type: 'configuration/sources/DEA',
52
+ uri: 'entities/j8K1vc9/crosswalks/1CwTipUbG',
53
+ value: 'DEA'
54
+ }
55
+ ],
56
+ phantomEntity: true,
57
+ uri: 'entities/hBEvFzQ'
58
+ }
59
+ ],
60
+ mergeReason: 'Move phantoms from gDAOTUO due to S_1543928071633_0001GJf',
61
+ mergeRules: '',
62
+ time: 1543928071655,
63
+ user: 'alexander.kirsanov'
64
+ }
65
+ ],
66
+ uri: 'entities/p6u3cIz'
67
+ }
68
+ ],
69
+ mergeReason: 'Merge by hand',
70
+ mergeRules: '',
71
+ time: 1543928125863,
72
+ user: 'alexander.kirsanov'
73
+ },
74
+ {
75
+ losers: [
76
+ {
77
+ crosswalks: [
78
+ {
79
+ ownerType: 'entity',
80
+ type: 'configuration/sources/AHA',
81
+ uri: 'entities/j8K1vc9/crosswalks/1vLQ8LtYf',
82
+ value: 'AHA1'
83
+ },
84
+ {
85
+ ownerType: 'entity',
86
+ type: 'configuration/sources/Veeva',
87
+ uri: 'entities/j8K1vc9/crosswalks/1vLQ8MVuz',
88
+ value: 'Veeva1'
89
+ },
90
+ {
91
+ ownerType: 'entity',
92
+ type: 'configuration/sources/AOA',
93
+ uri: 'entities/j8K1vc9/crosswalks/1vLQ8Mihl',
94
+ value: 'AOA'
95
+ },
96
+ {
97
+ ownerType: 'entity',
98
+ type: 'configuration/sources/Reltio',
99
+ uri: 'entities/j8K1vc9/crosswalks/1vLQ8NL45',
100
+ value: 'gDAOTUO'
101
+ },
102
+ {
103
+ ownerType: 'relation',
104
+ type: 'configuration/sources/Reltio',
105
+ uri: 'relations/YduMTVk/crosswalks/1WY5HTvm8',
106
+ value: 'YduMTVk'
107
+ }
108
+ ],
109
+ uri: 'entities/gDAOTUO'
110
+ }
111
+ ],
112
+ mergeReason: 'Merge by hand',
113
+ mergeRules: '',
114
+ time: 1543928117165,
115
+ user: 'alexander.kirsanov'
116
+ }
117
+ ]
118
+ },
119
+ {
120
+ uri: 'entities/1N1mfYja',
121
+ crosswalks: [
122
+ {
123
+ uri: 'entities/j8K1vc9/crosswalks/3dPCbiK7u',
124
+ type: 'configuration/sources/MDS',
125
+ ownerType: 'entity',
126
+ value: 'mds_202108061617'
127
+ }
128
+ ]
129
+ },
130
+ {
131
+ crosswalks: undefined,
132
+ uri: 'entities/p6u3cIz',
133
+ merges: [
134
+ {
135
+ losers: [
136
+ {
137
+ crosswalks: [
138
+ {
139
+ ownerType: 'entity',
140
+ type: 'configuration/sources/DEA',
141
+ uri: 'entities/j8K1vc9/crosswalks/1CwTipUbG',
142
+ value: 'DEA'
143
+ }
144
+ ],
145
+ phantomEntity: true,
146
+ uri: 'entities/hBEvFzQ'
147
+ }
148
+ ],
149
+ mergeReason: 'Move phantoms from gDAOTUO due to S_1543928071633_0001GJf',
150
+ mergeRules: '',
151
+ time: 1543928071655,
152
+ user: 'alexander.kirsanov'
153
+ }
154
+ ]
155
+ }
156
+ ];
157
+ export const crosswalkTree: CrosswalkTree = {
158
+ merges: [
159
+ {
160
+ time: 1628248691969,
161
+ mergeReason: 'Merge on the fly',
162
+ mergeRules: '',
163
+ user: 'marat',
164
+ losers: [
165
+ {
166
+ uri: 'entities/1N1mfYja',
167
+ crosswalks: [
168
+ {
169
+ uri: 'entities/j8K1vc9/crosswalks/3dPCbiK7u',
170
+ type: 'configuration/sources/MDS',
171
+ ownerType: 'entity',
172
+ value: 'mds_202108061617'
173
+ }
174
+ ],
175
+ phantomEntity: true
176
+ }
177
+ ]
178
+ },
179
+ {
180
+ time: 1543928125863,
181
+ mergeReason: 'Merge by hand',
182
+ mergeRules: '',
183
+ user: 'alexander.kirsanov',
184
+ losers: [
185
+ {
186
+ merges: [
187
+ {
188
+ time: 1543928071655,
189
+ mergeReason: 'Move phantoms from gDAOTUO due to S_1543928071633_0001GJf',
190
+ mergeRules: '',
191
+ user: 'alexander.kirsanov',
192
+ losers: [
193
+ {
194
+ uri: 'entities/hBEvFzQ',
195
+ crosswalks: [
196
+ {
197
+ uri: 'entities/j8K1vc9/crosswalks/1CwTipUbG',
198
+ type: 'configuration/sources/DEA',
199
+ ownerType: 'entity',
200
+ value: 'DEA'
201
+ }
202
+ ],
203
+ phantomEntity: true
204
+ }
205
+ ]
206
+ }
207
+ ],
208
+ uri: 'entities/p6u3cIz'
209
+ }
210
+ ]
211
+ },
212
+ {
213
+ time: 1543928117165,
214
+ mergeReason: 'Merge by hand',
215
+ mergeRules: '',
216
+ user: 'alexander.kirsanov',
217
+ losers: [
218
+ {
219
+ uri: 'entities/gDAOTUO',
220
+ crosswalks: [
221
+ {
222
+ uri: 'entities/j8K1vc9/crosswalks/1vLQ8LtYf',
223
+ type: 'configuration/sources/AHA',
224
+ ownerType: 'entity',
225
+ value: 'AHA1'
226
+ },
227
+ {
228
+ uri: 'entities/j8K1vc9/crosswalks/1vLQ8MVuz',
229
+ type: 'configuration/sources/Veeva',
230
+ ownerType: 'entity',
231
+ value: 'Veeva1'
232
+ },
233
+ {
234
+ uri: 'entities/j8K1vc9/crosswalks/1vLQ8Mihl',
235
+ type: 'configuration/sources/AOA',
236
+ ownerType: 'entity',
237
+ value: 'AOA'
238
+ },
239
+ {
240
+ uri: 'entities/j8K1vc9/crosswalks/1vLQ8NL45',
241
+ type: 'configuration/sources/Reltio',
242
+ ownerType: 'entity',
243
+ value: 'gDAOTUO'
244
+ },
245
+ {
246
+ uri: 'relations/YduMTVk/crosswalks/1WY5HTvm8',
247
+ type: 'configuration/sources/Reltio',
248
+ ownerType: 'relation',
249
+ value: 'YduMTVk'
250
+ }
251
+ ]
252
+ }
253
+ ]
254
+ }
255
+ ],
256
+ uri: 'entities/j8K1vc9',
257
+ crosswalks: [
258
+ {
259
+ uri: 'entities/j8K1vc9/crosswalks/1kQ5cap2n',
260
+ type: 'configuration/sources/Reltio',
261
+ ownerType: 'entity',
262
+ value: 'j8K1vc9'
263
+ },
264
+ {
265
+ uri: 'relations/fwqqZcE/crosswalks/3CQl2KAH8',
266
+ type: 'configuration/sources/Reltio',
267
+ ownerType: 'relation',
268
+ value: 'fwqqZcE'
269
+ }
270
+ ]
271
+ };
@@ -0,0 +1,34 @@
1
+ import {makeStyles} from '@mui/styles';
2
+
3
+ export const useStyles = makeStyles((theme) => ({
4
+ dialogContainer: {
5
+ maxWidth: 'unset'
6
+ },
7
+ dialogTitle: {
8
+ padding: '13px 16px 0 16px',
9
+ fontWeight: 500,
10
+ fontSize: '20px',
11
+ lineHeight: '23px',
12
+ letterSpacing: '0.25px'
13
+ },
14
+ dialogContent: {
15
+ display: 'flex',
16
+ flexDirection: 'column',
17
+ padding: '13px 16px 0 16px'
18
+ },
19
+ trees: {
20
+ display: 'flex'
21
+ },
22
+ uri: {
23
+ fontSize: '13px',
24
+ lineHeight: '15px',
25
+ color: theme.palette.text.primary,
26
+ marginBottom: '15px'
27
+ },
28
+ title: {
29
+ fontSize: '13px',
30
+ lineHeight: '15px',
31
+ color: theme.palette.text.secondary,
32
+ paddingRight: '2px'
33
+ }
34
+ }));
@@ -0,0 +1,64 @@
1
+ import React, {useMemo} from 'react';
2
+ import i18n from 'ui-i18n';
3
+ import Button from '@mui/material/Button';
4
+ import Dialog from '@mui/material/Dialog';
5
+ import DialogActions from '@mui/material/DialogActions';
6
+ import DialogContent from '@mui/material/DialogContent';
7
+ import DialogTitle from '@mui/material/DialogTitle';
8
+ import Typography from '@mui/material/Typography';
9
+ import {SelectableTree} from '../SelectableTree/SelectableTree';
10
+ import {collectCrosswalksFromContributor, Contributor, CrosswalkTree, getLastUriPart} from '@reltio/mdm-sdk';
11
+
12
+ import {useStyles} from './styles';
13
+
14
+ type Props = {
15
+ contributor: Contributor;
16
+ crosswalkTree: CrosswalkTree;
17
+ canUnsubscribe?: boolean;
18
+ onClose: () => void;
19
+ onUnsubscribeContributor: () => void;
20
+ };
21
+
22
+ export const UnsubscribeDialog = ({
23
+ canUnsubscribe,
24
+ contributor,
25
+ crosswalkTree,
26
+ onClose,
27
+ onUnsubscribeContributor
28
+ }: Props) => {
29
+ const styles = useStyles();
30
+
31
+ const coloredCrosswalks = useMemo(
32
+ () => collectCrosswalksFromContributor(contributor, true).map(({uri}) => uri),
33
+ [contributor]
34
+ );
35
+
36
+ const unsubscribeContributor = () => {
37
+ onUnsubscribeContributor();
38
+ onClose();
39
+ };
40
+
41
+ return (
42
+ <Dialog open={true} onClose={onClose} classes={{paper: styles.dialogContainer}}>
43
+ <DialogTitle classes={{root: styles.dialogTitle}}>{i18n.text('Unsubscribe')}</DialogTitle>
44
+ <DialogContent classes={{root: styles.dialogContent}}>
45
+ <Typography variant={'body2'} className={styles.uri}>
46
+ <span className={styles.title}>{i18n.text('Entity URI:')}</span>
47
+ {getLastUriPart(contributor.uri).toUpperCase()}
48
+ </Typography>
49
+ <SelectableTree
50
+ selected
51
+ title={i18n.text('Unsubscribe')}
52
+ crosswalkTree={crosswalkTree}
53
+ coloredCrosswalks={coloredCrosswalks}
54
+ />
55
+ </DialogContent>
56
+ <DialogActions>
57
+ <Button onClick={onClose}>{i18n.text('Cancel')}</Button>
58
+ <Button disabled={!canUnsubscribe} onClick={unsubscribeContributor} color="primary">
59
+ {i18n.text('Unsubscribe')}
60
+ </Button>
61
+ </DialogActions>
62
+ </Dialog>
63
+ );
64
+ };
@@ -0,0 +1,59 @@
1
+ import React from 'react';
2
+ import {shallow} from 'enzyme';
3
+ import Button from '@mui/material/Button';
4
+ import {SelectableTree} from '../../SelectableTree/SelectableTree';
5
+ import {contributors, crosswalkTree} from '../../UnmergeDialog/__tests__/testData.data';
6
+ import {UnsubscribeDialog} from '../UnsubscribeDialog';
7
+ import Typography from '@mui/material/Typography';
8
+
9
+ describe('UnsubscribeDialog tests', () => {
10
+ const contributorUri = 'entities/p6u3cIz';
11
+ const props = {
12
+ contributor: contributors.find(({uri}) => uri === contributorUri),
13
+ crosswalkTree,
14
+ canUnsubscribe: true,
15
+ onClose: jest.fn(),
16
+ onUnsubscribeContributor: jest.fn()
17
+ };
18
+
19
+ it('should render correctly', () => {
20
+ const component = shallow(<UnsubscribeDialog {...props} />);
21
+ const selectableTree = component.find(SelectableTree);
22
+
23
+ expect(component.find(Typography).text()).toBe('Entity URI:P6U3CIZ');
24
+ expect(selectableTree.prop('selected')).toBe(true);
25
+ expect(selectableTree.prop('crosswalkTree')).toEqual(props.crosswalkTree);
26
+ expect(selectableTree.prop('coloredCrosswalks')).toEqual([]);
27
+ expect(selectableTree.prop('title')).toBe('Unsubscribe');
28
+ const unsubscribeButton = component.find(Button).filterWhere((button) => button.text() === 'Unsubscribe');
29
+ expect(unsubscribeButton.prop('disabled')).toBeFalsy();
30
+ });
31
+
32
+ it('should call onUnsubscribeContributor and onClose on Unsubscribe Button click', () => {
33
+ const component = shallow(<UnsubscribeDialog {...props} />);
34
+ const unsubscribeContributor = component
35
+ .find(Button)
36
+ .filterWhere((button) => button.text() === 'Unsubscribe')
37
+ .prop('onClick') as () => void;
38
+ unsubscribeContributor();
39
+ expect(props.onUnsubscribeContributor).toHaveBeenCalled();
40
+ expect(props.onClose).toHaveBeenCalled();
41
+ });
42
+
43
+ it('should call onClose on Cancel Button click', () => {
44
+ const component = shallow(<UnsubscribeDialog {...props} />);
45
+ const closeDialog = component
46
+ .find(Button)
47
+ .filterWhere((button) => button.text() === 'Cancel')
48
+ .prop('onClick') as () => void;
49
+ closeDialog();
50
+ expect(props.onClose).toHaveBeenCalled();
51
+ });
52
+
53
+ it('should disable unsubscribe button if canUnsubscribe === false', () => {
54
+ const component = shallow(<UnsubscribeDialog {...props} canUnsubscribe={false} />);
55
+
56
+ const unsubscribeButton = component.find(Button).filterWhere((button) => button.text() === 'Unsubscribe');
57
+ expect(unsubscribeButton.prop('disabled')).toBeTruthy();
58
+ });
59
+ });
@@ -0,0 +1,31 @@
1
+ import {makeStyles} from '@mui/styles';
2
+
3
+ export const useStyles = makeStyles((theme) => ({
4
+ dialogContainer: {
5
+ maxWidth: 'unset'
6
+ },
7
+ dialogTitle: {
8
+ padding: '13px 16px 0 16px',
9
+ fontWeight: 500,
10
+ fontSize: '20px',
11
+ lineHeight: '23px',
12
+ letterSpacing: '0.25px'
13
+ },
14
+ dialogContent: {
15
+ display: 'flex',
16
+ flexDirection: 'column',
17
+ padding: '13px 16px 0 16px'
18
+ },
19
+ uri: {
20
+ fontSize: '13px',
21
+ lineHeight: '15px',
22
+ color: theme.palette.text.primary,
23
+ marginBottom: '15px'
24
+ },
25
+ title: {
26
+ fontSize: '13px',
27
+ lineHeight: '15px',
28
+ color: theme.palette.text.secondary,
29
+ paddingRight: '2px'
30
+ }
31
+ }));
@@ -0,0 +1,68 @@
1
+ import React from 'react';
2
+ import {mount} from 'enzyme';
3
+ import {act} from 'react-dom/test-utils';
4
+ import * as mdmSdk from '@reltio/mdm-sdk';
5
+ import {useCrosswalkTree} from '../useCrosswalkTree';
6
+ import {noop} from '@reltio/components';
7
+
8
+ jest.mock('@reltio/mdm-sdk', () => ({
9
+ ...jest.requireActual<Record<string, unknown>>('@reltio/mdm-sdk'),
10
+ getCrosswalkTree: jest.fn()
11
+ }));
12
+
13
+ type Props = {
14
+ entity?: {uri: string};
15
+ onSuccess?: () => void;
16
+ };
17
+
18
+ describe('useCrosswalkTree behaviour', () => {
19
+ const getCrosswalkTreeSpy = jest.spyOn(mdmSdk, 'getCrosswalkTree');
20
+ const TestComponent = ({entity, onSuccess = noop}: Props) => {
21
+ const {crosswalkTree, reload} = useCrosswalkTree({onSuccess, entityUri: entity?.uri});
22
+ return <div data-test={{crosswalkTree}} onClick={reload} />;
23
+ };
24
+
25
+ beforeAll(() => {
26
+ getCrosswalkTreeSpy.mockImplementation(() => Promise.resolve({uri: 'testUri'}));
27
+ });
28
+
29
+ afterEach(() => {
30
+ jest.clearAllMocks();
31
+ });
32
+
33
+ it('should call getCrosswalkTree', async () => {
34
+ await act(async () => {
35
+ mount(<TestComponent entity={{uri: '123'}} />);
36
+ });
37
+ expect(getCrosswalkTreeSpy).toBeCalledWith({
38
+ entityUri: '123'
39
+ });
40
+ });
41
+
42
+ it('should not call getCrosswalkTree if entity is Nil', async () => {
43
+ await act(async () => {
44
+ mount(<TestComponent entity={null} />);
45
+ });
46
+ expect(getCrosswalkTreeSpy).not.toHaveBeenCalled();
47
+ });
48
+
49
+ it('should call getCrosswalkTree if reload is called', async () => {
50
+ let wrapper;
51
+ await act(async () => {
52
+ wrapper = mount(<TestComponent entity={{uri: '123'}} />);
53
+ });
54
+ const event = {} as React.MouseEvent<Document>;
55
+ await act(async () => {
56
+ wrapper.find('div').prop('onClick')(event);
57
+ });
58
+ expect(getCrosswalkTreeSpy).toHaveBeenCalledTimes(2);
59
+ });
60
+
61
+ it('should call onRequestFinished', async () => {
62
+ const onSuccess = jest.fn();
63
+ await act(async () => {
64
+ mount(<TestComponent entity={{uri: '123'}} onSuccess={onSuccess} />);
65
+ });
66
+ expect(onSuccess).toBeCalled();
67
+ });
68
+ });
@@ -0,0 +1,110 @@
1
+ import {useCrosswalkTreeActions} from '../useCrosswalkTreeActions';
2
+ import {act} from 'react-dom/test-utils';
3
+ import * as reactRedux from 'react-redux';
4
+ import mdmModule from '@reltio/mdm-module';
5
+ import {renderHook} from '@testing-library/react-hooks';
6
+ import * as mdmSdk from '@reltio/mdm-sdk';
7
+ import {UnmergeOperation} from '@reltio/mdm-sdk';
8
+
9
+ jest.mock('@reltio/mdm-sdk', () => ({
10
+ ...jest.requireActual<Record<string, unknown>>('@reltio/mdm-sdk'),
11
+ unmergeContributor: jest.fn(),
12
+ unsubscribeEntityFromDataTenantEntity: jest.fn()
13
+ }));
14
+
15
+ describe('useCrosswalkTreeActions', () => {
16
+ beforeAll(() => {
17
+ jest.spyOn(reactRedux, 'useSelector').mockImplementation((selector) => selector({}));
18
+ jest.spyOn(mdmModule.selectors, 'getDtssPath').mockReturnValue('dtssPath/');
19
+ jest.spyOn(mdmModule.selectors, 'getTenant').mockReturnValue('test');
20
+ });
21
+ const initialProps = {
22
+ onSuccess: jest.fn(),
23
+ onError: jest.fn(),
24
+ onShowMessage: jest.fn()
25
+ };
26
+ const getActions = () => {
27
+ return renderHook(useCrosswalkTreeActions, {initialProps}).result.current;
28
+ };
29
+ let resolveSuccess, resolveError;
30
+
31
+ const entity = {
32
+ uri: 'entities/123',
33
+ type: 'configuration/entityTypes/HCP'
34
+ };
35
+
36
+ const unmergeResponse = {a: entity, b: entity};
37
+ const unmergeContributorMock = jest.spyOn(mdmSdk, 'unmergeContributor').mockImplementation(() => {
38
+ return new Promise((_resolve, _reject) => {
39
+ resolveSuccess = () => _resolve(unmergeResponse);
40
+ resolveError = () => _reject({});
41
+ });
42
+ });
43
+
44
+ const unsubscribeContributorMock = jest
45
+ .spyOn(mdmSdk, 'unsubscribeEntityFromDataTenantEntity')
46
+ .mockImplementation(() => {
47
+ return new Promise((_resolve, _reject) => {
48
+ resolveSuccess = () => _resolve({index: 0, object: {status: 'success'}, successful: true});
49
+ resolveError = () => _reject({error: 'Operation failed with error', successful: false});
50
+ });
51
+ });
52
+
53
+ it('should return correct unmergeContributor action and show message', async () => {
54
+ jest.clearAllMocks();
55
+ const {unmergeContributor} = getActions();
56
+ const unmergeEvent = {
57
+ contributorUri: '541',
58
+ entityUri: '123',
59
+ operationType: UnmergeOperation.TreeUnmerge
60
+ };
61
+ unmergeContributor(unmergeEvent);
62
+ expect(unmergeContributorMock).toBeCalledWith(unmergeEvent);
63
+ await act(async () => {
64
+ resolveSuccess();
65
+ });
66
+ expect(initialProps.onShowMessage).toBeCalledWith('has been unmerged', unmergeResponse.b);
67
+ expect(initialProps.onSuccess).toBeCalled();
68
+
69
+ unmergeContributor(unmergeEvent);
70
+ expect(unmergeContributorMock).toBeCalledWith(unmergeEvent);
71
+ await act(async () => {
72
+ resolveError();
73
+ });
74
+ expect(initialProps.onError).toBeCalledWith({});
75
+ });
76
+
77
+ it('should return correct unsubscribe Contributor action', async () => {
78
+ const {unsubscribeContributor} = getActions();
79
+ const unsubscribeEvent = {
80
+ dataTenant: {id: '1111123', label: '2222', name: '111'},
81
+ crosswalk: {uri: '370iIXrRf', type: '1231', value: '12312'}
82
+ };
83
+ unsubscribeContributor(unsubscribeEvent);
84
+
85
+ expect(unsubscribeContributorMock).toBeCalledWith({
86
+ customerTenant: 'test',
87
+ dataTenant: '1111123',
88
+ dtssPath: 'dtssPath/',
89
+ type: '1231',
90
+ value: '12312'
91
+ });
92
+ await act(async () => {
93
+ resolveSuccess();
94
+ });
95
+ expect(initialProps.onSuccess).toBeCalled();
96
+
97
+ unsubscribeContributor(unsubscribeEvent);
98
+ expect(unsubscribeContributorMock).toBeCalledWith({
99
+ customerTenant: 'test',
100
+ dataTenant: '1111123',
101
+ dtssPath: 'dtssPath/',
102
+ type: '1231',
103
+ value: '12312'
104
+ });
105
+ await act(async () => {
106
+ resolveError();
107
+ });
108
+ expect(initialProps.onError).toBeCalledWith({error: 'Operation failed with error', successful: false});
109
+ });
110
+ });