@centreon/ui 24.4.1-sync-release-34022.1 → 24.4.1-test-code-coverage.1

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 (220) hide show
  1. package/package.json +48 -40
  2. package/src/ActionsList/ActionsList.styles.ts +40 -71
  3. package/src/Button/Icon/index.stories.tsx +1 -1
  4. package/src/Button/Icon/index.tsx +1 -1
  5. package/src/Dashboard/Dashboard.styles.ts +6 -5
  6. package/src/Dialog/Confirm/index.tsx +10 -2
  7. package/src/Dialog/UnsavedChanges/index.tsx +21 -20
  8. package/src/Dialog/UnsavedChanges/translatedLabels.ts +4 -6
  9. package/src/Dialog/index.tsx +8 -1
  10. package/src/Form/Inputs/CheckboxGroup.tsx +4 -1
  11. package/src/Form/Inputs/Text.tsx +3 -1
  12. package/src/Form/Inputs/models.ts +1 -0
  13. package/src/Graph/BarStack/BarStack.cypress.spec.tsx +139 -0
  14. package/src/Graph/BarStack/BarStack.stories.tsx +123 -0
  15. package/src/Graph/BarStack/BarStack.styles.ts +37 -0
  16. package/src/Graph/BarStack/BarStack.tsx +14 -0
  17. package/src/Graph/BarStack/ResponsiveBarStack.tsx +209 -0
  18. package/src/Graph/BarStack/index.ts +1 -0
  19. package/src/Graph/BarStack/models.ts +19 -0
  20. package/src/Graph/BarStack/useResponsiveBarStack.ts +131 -0
  21. package/src/Graph/Gauge/Gauge.cypress.spec.tsx +102 -0
  22. package/src/Graph/Gauge/Gauge.tsx +1 -1
  23. package/src/Graph/HeatMap/HeatMap.cypress.spec.tsx +145 -0
  24. package/src/Graph/HeatMap/HeatMap.stories.tsx +0 -25
  25. package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +8 -2
  26. package/src/Graph/Legend/Legend.tsx +21 -0
  27. package/src/Graph/Legend/index.ts +1 -0
  28. package/src/Graph/Legend/models.ts +11 -0
  29. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/index.tsx +4 -5
  30. package/src/Graph/LineChart/BasicComponents/ThresholdLine.tsx +3 -1
  31. package/src/Graph/LineChart/Header/index.tsx +3 -31
  32. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/useTickGraph.ts +9 -11
  33. package/src/Graph/LineChart/InteractiveComponents/Annotations/Annotation/index.tsx +3 -2
  34. package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/GraphValueTooltip.tsx +68 -0
  35. package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/useGraphValueTooltip.ts +27 -0
  36. package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/useGraphValueTooltipStyles.ts +31 -0
  37. package/src/Graph/LineChart/InteractiveComponents/index.tsx +132 -17
  38. package/src/Graph/LineChart/InteractiveComponents/interactionWithGraphAtoms.ts +7 -27
  39. package/src/Graph/LineChart/Legend/Legend.styles.ts +5 -9
  40. package/src/Graph/LineChart/Legend/LegendHeader.tsx +10 -22
  41. package/src/Graph/LineChart/Legend/index.tsx +17 -55
  42. package/src/Graph/LineChart/LineChart.cypress.spec.tsx +91 -0
  43. package/src/Graph/LineChart/LineChart.styles.ts +8 -0
  44. package/src/Graph/LineChart/LineChart.tsx +106 -116
  45. package/src/Graph/LineChart/LoadingSkeleton.tsx +2 -2
  46. package/src/Graph/LineChart/index.tsx +6 -7
  47. package/src/Graph/LineChart/mockedData/lastDayWithIncompleteValues.json +1320 -0
  48. package/src/Graph/LineChart/mockedData/lastDayWithNullValues.json +1314 -0
  49. package/src/Graph/LineChart/models.ts +12 -1
  50. package/src/Graph/PieChart/PieChart.cypress.spec.tsx +154 -0
  51. package/src/Graph/PieChart/PieChart.stories.tsx +194 -0
  52. package/src/Graph/PieChart/PieChart.styles.ts +39 -0
  53. package/src/Graph/PieChart/PieChart.tsx +14 -0
  54. package/src/Graph/PieChart/ResponsivePie.tsx +243 -0
  55. package/src/Graph/PieChart/index.ts +1 -0
  56. package/src/Graph/PieChart/models.ts +19 -0
  57. package/src/Graph/PieChart/useResponsivePie.ts +81 -0
  58. package/src/Graph/SingleBar/SingleBar.cypress.spec.tsx +121 -0
  59. package/src/Graph/Text/Text.cypress.spec.tsx +101 -0
  60. package/src/Graph/Text/Text.styles.ts +12 -1
  61. package/src/Graph/Text/Text.tsx +17 -12
  62. package/src/Graph/Tree/DescendantNodes.tsx +89 -0
  63. package/src/Graph/Tree/Links.tsx +77 -0
  64. package/src/Graph/Tree/StandaloneTree.tsx +32 -0
  65. package/src/Graph/Tree/Tree.cypress.spec.tsx +195 -0
  66. package/src/Graph/Tree/Tree.stories.tsx +160 -0
  67. package/src/Graph/Tree/Tree.tsx +116 -0
  68. package/src/Graph/Tree/constants.ts +2 -0
  69. package/src/Graph/Tree/index.ts +4 -0
  70. package/src/Graph/Tree/models.ts +55 -0
  71. package/src/Graph/Tree/stories/contents.tsx +164 -0
  72. package/src/Graph/Tree/stories/datas.ts +305 -0
  73. package/src/Graph/Tree/utils.ts +49 -0
  74. package/src/Graph/common/testUtils.ts +71 -0
  75. package/src/Graph/common/timeSeries/index.ts +50 -12
  76. package/src/Graph/common/utils.ts +19 -0
  77. package/src/Graph/index.ts +4 -0
  78. package/src/InputField/Number/Number.cypress.spec.tsx +85 -0
  79. package/src/InputField/Number/Number.stories.tsx +66 -0
  80. package/src/InputField/Number/Number.tsx +74 -0
  81. package/src/InputField/Search/index.tsx +2 -2
  82. package/src/InputField/Select/Autocomplete/Multi/index.tsx +4 -2
  83. package/src/InputField/Select/Autocomplete/index.tsx +10 -3
  84. package/src/InputField/Select/IconPopover/index.tsx +1 -1
  85. package/src/InputField/Select/index.tsx +14 -1
  86. package/src/InputField/Text/index.tsx +38 -38
  87. package/src/Listing/ActionBar/index.tsx +10 -10
  88. package/src/Listing/Cell/DataCell.styles.ts +3 -0
  89. package/src/Listing/Cell/DataCell.tsx +8 -4
  90. package/src/Listing/Listing.cypress.spec.tsx +217 -33
  91. package/src/Listing/Listing.styles.ts +3 -5
  92. package/src/Listing/Row/Row.tsx +7 -3
  93. package/src/Listing/index.stories.tsx +25 -2
  94. package/src/Listing/index.test.tsx +1 -1
  95. package/src/Listing/index.tsx +202 -143
  96. package/src/Listing/models.ts +1 -0
  97. package/src/Listing/useStyleTable.ts +1 -0
  98. package/src/Panel/index.tsx +1 -1
  99. package/src/PopoverMenu/index.tsx +6 -5
  100. package/src/ThemeProvider/index.tsx +3 -0
  101. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +6 -7
  102. package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +12 -9
  103. package/src/Typography/FluidTypography/FluidTypography.cypress.spec.tsx +27 -0
  104. package/src/Typography/FluidTypography/index.stories.tsx +2 -2
  105. package/src/Typography/FluidTypography/index.tsx +21 -28
  106. package/src/api/index.ts +3 -3
  107. package/src/api/useGraphQuery/index.ts +26 -5
  108. package/src/api/useGraphQuery/models.ts +5 -0
  109. package/src/api/useMutationQuery/index.test.ts +4 -4
  110. package/src/api/useMutationQuery/index.ts +24 -13
  111. package/src/components/CollapsibleItem/CollapsibleItem.cypress.spec.tsx +76 -0
  112. package/src/components/CollapsibleItem/CollapsibleItem.stories.tsx +26 -0
  113. package/src/components/CollapsibleItem/CollapsibleItem.tsx +43 -14
  114. package/src/components/CollapsibleItem/useCollapsibleItemStyles.ts +24 -1
  115. package/src/components/DataTable/DataTable.cypress.spec.tsx +14 -33
  116. package/src/components/DataTable/Item/DataTableItem.tsx +4 -60
  117. package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.cypress.spec.tsx +36 -13
  118. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ContactSwitch.tsx +11 -3
  119. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ShareInput.styles.ts +8 -0
  120. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ShareInput.tsx +1 -0
  121. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/useShareInput.tsx +4 -0
  122. package/src/components/Form/{AccessRightsV2 → AccessRights}/models.ts +1 -0
  123. package/src/components/Form/{AccessRightsV2 → AccessRights}/storiesData.ts +23 -22
  124. package/src/components/Form/Dashboard/DashboardDuplicationForm.tsx +85 -0
  125. package/src/components/Form/Dashboard/index.ts +1 -0
  126. package/src/components/Form/FormActions.tsx +7 -2
  127. package/src/components/Form/index.ts +2 -2
  128. package/src/components/ItemComposition/Item.tsx +1 -1
  129. package/src/components/ItemComposition/ItemComposition.cypress.spec.tsx +113 -0
  130. package/src/components/ItemComposition/ItemComposition.stories.tsx +14 -0
  131. package/src/components/ItemComposition/ItemComposition.styles.ts +36 -3
  132. package/src/components/ItemComposition/ItemComposition.tsx +41 -17
  133. package/src/components/List/Item/ListItem.tsx +3 -3
  134. package/src/components/Modal/ConfirmationModal/ConfirmationModal.cypress.spec.tsx +168 -0
  135. package/src/components/Modal/ConfirmationModal/ConfirmationModal.stories.tsx +62 -0
  136. package/src/components/Modal/ConfirmationModal/ConfirmationModal.tsx +87 -0
  137. package/src/components/Modal/Modal.styles.ts +8 -3
  138. package/src/components/Modal/index.ts +2 -0
  139. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.stories.tsx +3 -3
  140. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.tsx +1 -1
  141. package/src/components/Tooltip/ConfirmationTooltip/models.ts +1 -1
  142. package/src/components/Zoom/Minimap.tsx +129 -0
  143. package/src/components/Zoom/Zoom.cypress.spec.tsx +246 -0
  144. package/src/components/Zoom/Zoom.stories.tsx +115 -0
  145. package/src/components/Zoom/Zoom.styles.tsx +68 -0
  146. package/src/components/Zoom/Zoom.tsx +64 -0
  147. package/src/components/Zoom/ZoomContent.tsx +170 -0
  148. package/src/components/Zoom/constants.ts +2 -0
  149. package/src/components/Zoom/localPoint.ts +51 -0
  150. package/src/components/Zoom/models.ts +25 -0
  151. package/src/components/Zoom/useMinimap.ts +156 -0
  152. package/src/components/Zoom/useZoom.ts +70 -0
  153. package/src/components/Zoom/utils.ts +55 -0
  154. package/src/components/index.ts +1 -0
  155. package/src/index.ts +1 -0
  156. package/src/utils/index.ts +3 -0
  157. package/src/utils/resourcesStatusURL.ts +166 -0
  158. package/src/utils/useFullscreen/Fullscreen.cypress.spec.tsx +130 -0
  159. package/src/utils/useFullscreen/atoms.ts +3 -0
  160. package/src/utils/useFullscreen/index.ts +2 -0
  161. package/src/utils/useFullscreen/translatedLabels.ts +1 -0
  162. package/src/utils/useFullscreen/useFullscreen.ts +73 -0
  163. package/src/utils/useFullscreen/useFullscreenListener.ts +62 -0
  164. package/src/utils/useInfiniteScrollListing.ts +4 -1
  165. package/src/Graph/LineChart/BasicComponents/LoadingProgress.tsx +0 -46
  166. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/TooltipAnchorPoint.tsx +0 -96
  167. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/useTooltipAnchorPoint.ts +0 -107
  168. package/src/Graph/LineChart/Legend/InteractiveValue.tsx +0 -22
  169. package/src/Graph/LineChart/Legend/useInteractiveValues.ts +0 -99
  170. package/src/Typography/FluidTypography/useFluidResizeObserver.ts +0 -56
  171. package/src/components/Form/AccessRights/AccessRights.resource.ts +0 -45
  172. package/src/components/Form/AccessRights/AccessRightsForm.stories.tsx +0 -59
  173. package/src/components/Form/AccessRights/AccessRightsForm.styles.ts +0 -21
  174. package/src/components/Form/AccessRights/AccessRightsForm.tsx +0 -67
  175. package/src/components/Form/AccessRights/AccessRightsFormActions.tsx +0 -80
  176. package/src/components/Form/AccessRights/Input/AddAction.tsx +0 -31
  177. package/src/components/Form/AccessRights/Input/ContactAccessRightInput.stories.tsx +0 -54
  178. package/src/components/Form/AccessRights/Input/ContactAccessRightInput.tsx +0 -72
  179. package/src/components/Form/AccessRights/Input/ContactAccessRightsInput.styles.ts +0 -22
  180. package/src/components/Form/AccessRights/Input/ContactInputField.tsx +0 -105
  181. package/src/components/Form/AccessRights/Input/RoleInputField.tsx +0 -29
  182. package/src/components/Form/AccessRights/List/ContactAccessRightsList.stories.tsx +0 -97
  183. package/src/components/Form/AccessRights/List/ContactAccessRightsList.styles.ts +0 -71
  184. package/src/components/Form/AccessRights/List/ContactAccessRightsList.tsx +0 -51
  185. package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.stories.tsx +0 -116
  186. package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.tsx +0 -118
  187. package/src/components/Form/AccessRights/List/ContactAccessRightsListItemSkeleton.tsx +0 -26
  188. package/src/components/Form/AccessRights/List/ContactAccessRightsListSkeleton.tsx +0 -28
  189. package/src/components/Form/AccessRights/Stats/AccessRightsStats.styles.ts +0 -18
  190. package/src/components/Form/AccessRights/Stats/AccessRightsStats.tsx +0 -41
  191. package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +0 -54
  192. package/src/components/Form/AccessRights/common/GroupLabel.styles.ts +0 -18
  193. package/src/components/Form/AccessRights/common/GroupLabel.tsx +0 -15
  194. package/src/components/Form/AccessRights/common/Input.styles.ts +0 -48
  195. package/src/components/Form/AccessRights/common/RoleInputSelect.styles.ts +0 -11
  196. package/src/components/Form/AccessRights/common/RoleInputSelect.tsx +0 -57
  197. package/src/components/Form/AccessRights/index.ts +0 -3
  198. package/src/components/Form/AccessRights/useAccessRightsForm.test.tsx +0 -531
  199. package/src/components/Form/AccessRights/useAccessRightsForm.tsx +0 -282
  200. package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +0 -41
  201. /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.stories.tsx +0 -0
  202. /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.styles.ts +0 -0
  203. /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.tsx +0 -0
  204. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/Actions.styles.ts +0 -0
  205. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/Actions.tsx +0 -0
  206. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/useActions.ts +0 -0
  207. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/Item.tsx +0 -0
  208. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/List.styles.tsx +0 -0
  209. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/List.tsx +0 -0
  210. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/ListItemSkeleton.tsx +0 -0
  211. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/ListSkeleton.tsx +0 -0
  212. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/RemoveAccessRight.tsx +0 -0
  213. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/StateChip.tsx +0 -0
  214. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/useItem.ts +0 -0
  215. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Provider.tsx +0 -0
  216. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Stats/Stats.tsx +0 -0
  217. /package/src/components/Form/{AccessRightsV2 → AccessRights}/atoms.ts +0 -0
  218. /package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.styles.tsx +0 -0
  219. /package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.tsx +0 -0
  220. /package/src/components/Form/{AccessRightsV2 → AccessRights}/useAccessRightsInitValues.ts +0 -0
@@ -1,531 +0,0 @@
1
- import { ReactElement } from 'react';
2
-
3
- import { renderHook } from '@testing-library/react-hooks';
4
- import { act } from '@testing-library/react';
5
-
6
- import {
7
- AccessRightsFormProvider,
8
- AccessRightsFormProviderProps,
9
- useAccessRightsForm
10
- } from './useAccessRightsForm';
11
- import {
12
- contactAccessRightsMock,
13
- contactsMock,
14
- rolesMock
15
- } from './__fixtures__/contactAccessRight.mock';
16
-
17
- const contextWrapper = (
18
- contextProps: AccessRightsFormProviderProps
19
- ): ReactElement => <AccessRightsFormProvider {...contextProps} />;
20
-
21
- describe('useAccessRightsForm', () => {
22
- const baseContextProps: AccessRightsFormProviderProps = {
23
- children: null,
24
- options: {
25
- contacts: contactsMock(25),
26
- roles: rolesMock()
27
- }
28
- };
29
-
30
- const initialValues: AccessRightsFormProviderProps['initialValues'] =
31
- contactAccessRightsMock(30);
32
-
33
- it('should render the hook', () => {
34
- const contextProps = { ...baseContextProps };
35
-
36
- const { result } = renderHook(() => useAccessRightsForm(), {
37
- initialProps: contextProps,
38
- wrapper: contextWrapper
39
- });
40
-
41
- expect(result.current).toBeDefined();
42
- });
43
-
44
- describe('Provider', () => {
45
- it('should persist the `options`', () => {
46
- const contextProps = { ...baseContextProps };
47
-
48
- const { result } = renderHook(() => useAccessRightsForm(), {
49
- initialProps: contextProps,
50
- wrapper: contextWrapper
51
- });
52
-
53
- expect(result.current.options).toBeDefined();
54
- expect(result.current.options).toEqual(contextProps.options);
55
- });
56
-
57
- it('should persist the `initialValues` as `contactAccessRights`', () => {
58
- const contextProps = { ...baseContextProps, initialValues };
59
-
60
- const { result } = renderHook(() => useAccessRightsForm(), {
61
- initialProps: contextProps,
62
- wrapper: contextWrapper
63
- });
64
-
65
- expect(result.current.contactAccessRights).toBeDefined();
66
- expect(result.current.contactAccessRights).toHaveLength(
67
- initialValues.length
68
- );
69
- initialValues.forEach((initialValue) => {
70
- expect(
71
- result.current.contactAccessRights.find(
72
- ({ contactAccessRight: { contact } }) =>
73
- contact?.id === initialValue.contact?.id
74
- )
75
- ).toBeDefined();
76
- });
77
- });
78
- });
79
-
80
- describe('addContactAccessRight', () => {
81
- it('should add a contact access right', () => {
82
- const contextProps = { ...baseContextProps };
83
-
84
- const { result } = renderHook(() => useAccessRightsForm(), {
85
- initialProps: contextProps,
86
- wrapper: contextWrapper
87
- });
88
-
89
- const contactAccessRight = contactAccessRightsMock(1)[0];
90
- act(() => result.current.addContactAccessRight(contactAccessRight));
91
-
92
- expect(result.current.contactAccessRights).toHaveLength(1);
93
- expect(
94
- result.current.contactAccessRights.find(
95
- ({ contactAccessRight: { contact } }) =>
96
- contact?.id === contactAccessRight.contact?.id
97
- )
98
- ).toBeDefined();
99
- });
100
- it('should not add a contact access right if it already exists', () => {
101
- const contextProps = { ...baseContextProps, initialValues };
102
-
103
- const { result } = renderHook(() => useAccessRightsForm(), {
104
- initialProps: contextProps,
105
- wrapper: contextWrapper
106
- });
107
-
108
- const { contactAccessRight } = result.current.contactAccessRights[0];
109
- act(() => result.current.addContactAccessRight(contactAccessRight));
110
-
111
- expect(result.current.contactAccessRights).toHaveLength(
112
- initialValues.length
113
- );
114
- });
115
- });
116
-
117
- describe('removeContactAccessRight', () => {
118
- it('should remove a contact access right of a pre-existing', () => {
119
- const contextProps = { ...baseContextProps, initialValues };
120
-
121
- const { result } = renderHook(() => useAccessRightsForm(), {
122
- initialProps: contextProps,
123
- wrapper: contextWrapper
124
- });
125
-
126
- const { contactAccessRight } = result.current.contactAccessRights[0];
127
- act(() => result.current.removeContactAccessRight(contactAccessRight));
128
-
129
- expect(result.current.contactAccessRights).toHaveLength(
130
- initialValues.length
131
- );
132
-
133
- expect(
134
- result.current.contactAccessRights.find(
135
- ({ contactAccessRight: { contact }, state }) =>
136
- contact?.id === contactAccessRight.contact?.id &&
137
- state === 'removed'
138
- )
139
- ).toBeDefined();
140
- });
141
- it('should restore a contact access right if it was pre-existing', () => {
142
- const contextProps = { ...baseContextProps, initialValues };
143
-
144
- const { result } = renderHook(() => useAccessRightsForm(), {
145
- initialProps: contextProps,
146
- wrapper: contextWrapper
147
- });
148
-
149
- const { contactAccessRight } = result.current.contactAccessRights[0];
150
- act(() => result.current.removeContactAccessRight(contactAccessRight));
151
- act(() =>
152
- result.current.removeContactAccessRight(contactAccessRight, true)
153
- );
154
-
155
- expect(
156
- result.current.contactAccessRights.find(
157
- ({ contactAccessRight: { contact }, state }) =>
158
- contact?.id === contactAccessRight.contact?.id &&
159
- state === 'unchanged'
160
- )
161
- ).toBeDefined();
162
- });
163
- it('should completely remove a contact access right if it was newly added', () => {
164
- const contextProps = { ...baseContextProps };
165
-
166
- const { result } = renderHook(() => useAccessRightsForm(), {
167
- initialProps: contextProps,
168
- wrapper: contextWrapper
169
- });
170
-
171
- const contactAccessRight = contactAccessRightsMock(1)[0];
172
- act(() => result.current.addContactAccessRight(contactAccessRight));
173
- act(() => result.current.removeContactAccessRight(contactAccessRight));
174
-
175
- expect(result.current.contactAccessRights).toHaveLength(0);
176
- });
177
- it('should restore a contact access right to it previous state', () => {
178
- const contextProps = { ...baseContextProps, initialValues };
179
-
180
- const { result } = renderHook(() => useAccessRightsForm(), {
181
- initialProps: contextProps,
182
- wrapper: contextWrapper
183
- });
184
-
185
- const { contactAccessRight } = result.current.contactAccessRights[0];
186
- const updatedContactAccessRight = {
187
- ...contactAccessRight,
188
- role:
189
- contactAccessRight.role === rolesMock()[0].role
190
- ? rolesMock()[1].role
191
- : rolesMock()[0].role
192
- };
193
-
194
- act(() =>
195
- result.current.updateContactAccessRight(updatedContactAccessRight)
196
- );
197
- act(() =>
198
- result.current.removeContactAccessRight(updatedContactAccessRight)
199
- );
200
- act(() =>
201
- result.current.removeContactAccessRight(updatedContactAccessRight, true)
202
- );
203
-
204
- const updatedContactAccessRightState =
205
- result.current.contactAccessRights.find(
206
- ({ contactAccessRight: { contact } }) =>
207
- contact?.id === updatedContactAccessRight.contact?.id
208
- );
209
-
210
- expect(updatedContactAccessRightState).toBeDefined();
211
- expect(updatedContactAccessRightState?.state).toEqual('updated');
212
- });
213
- });
214
-
215
- describe('updateContactAccessRight', () => {
216
- it('should update a contact access right', () => {
217
- const contextProps = { ...baseContextProps, initialValues };
218
-
219
- const { result } = renderHook(() => useAccessRightsForm(), {
220
- initialProps: contextProps,
221
- wrapper: contextWrapper
222
- });
223
-
224
- const { contactAccessRight } = result.current.contactAccessRights[0];
225
- const updatedContactAccessRight = {
226
- ...contactAccessRight,
227
- role:
228
- contactAccessRight.role === rolesMock()[0].role
229
- ? rolesMock()[1].role
230
- : rolesMock()[0].role
231
- };
232
-
233
- act(() =>
234
- result.current.updateContactAccessRight(updatedContactAccessRight)
235
- );
236
-
237
- const updatedContactAccessRightState =
238
- result.current.contactAccessRights.find(
239
- ({ contactAccessRight: { contact } }) =>
240
- contact?.id === updatedContactAccessRight.contact?.id
241
- );
242
-
243
- expect(updatedContactAccessRightState).toBeDefined();
244
-
245
- expect(updatedContactAccessRightState?.state).toEqual('updated');
246
-
247
- expect(
248
- updatedContactAccessRightState?.contactAccessRight.role ===
249
- updatedContactAccessRight.role
250
- ).toBeTruthy();
251
- });
252
-
253
- it('should update a contact access right to its previous state', () => {
254
- const contextProps = {
255
- ...baseContextProps,
256
- initialValues
257
- };
258
-
259
- const { result } = renderHook(() => useAccessRightsForm(), {
260
- initialProps: contextProps,
261
- wrapper: contextWrapper
262
- });
263
-
264
- const { contactAccessRight } = result.current.contactAccessRights[0];
265
- const updatedContactAccessRight = {
266
- ...contactAccessRight,
267
- role:
268
- contactAccessRight.role === rolesMock()[0].role
269
- ? rolesMock()[1].role
270
- : rolesMock()[0].role
271
- };
272
-
273
- act(() =>
274
- result.current.updateContactAccessRight(updatedContactAccessRight)
275
- );
276
-
277
- updatedContactAccessRight.role =
278
- updatedContactAccessRight.role === rolesMock()[0].role
279
- ? rolesMock()[1].role
280
- : rolesMock()[0].role;
281
-
282
- act(() =>
283
- result.current.updateContactAccessRight(updatedContactAccessRight)
284
- );
285
-
286
- const updatedContactAccessRightState =
287
- result.current.contactAccessRights.find(
288
- ({ contactAccessRight: { contact } }) =>
289
- contact?.id === updatedContactAccessRight.contact?.id
290
- );
291
-
292
- expect(updatedContactAccessRightState).toBeDefined();
293
- expect(updatedContactAccessRightState?.state).toEqual('unchanged');
294
- });
295
-
296
- it('should update a contact access right to `unchanged` state if it is updated to its original value', () => {
297
- const contextProps = { ...baseContextProps, initialValues };
298
-
299
- const { result } = renderHook(() => useAccessRightsForm(), {
300
- initialProps: contextProps,
301
- wrapper: contextWrapper
302
- });
303
-
304
- const { contactAccessRight } = result.current.contactAccessRights[0];
305
- const updatedContactAccessRight = {
306
- ...contactAccessRight,
307
- role:
308
- contactAccessRight.role === rolesMock()[0].role
309
- ? rolesMock()[1].role
310
- : rolesMock()[0].role
311
- };
312
-
313
- act(() =>
314
- result.current.updateContactAccessRight(updatedContactAccessRight)
315
- );
316
- act(() =>
317
- result.current.removeContactAccessRight(updatedContactAccessRight)
318
- );
319
- act(() =>
320
- result.current.removeContactAccessRight(updatedContactAccessRight, true)
321
- );
322
-
323
- updatedContactAccessRight.role =
324
- updatedContactAccessRight.role === rolesMock()[0].role
325
- ? rolesMock()[1].role
326
- : rolesMock()[0].role;
327
-
328
- act(() =>
329
- result.current.updateContactAccessRight(updatedContactAccessRight)
330
- );
331
-
332
- const updatedContactAccessRightState =
333
- result.current.contactAccessRights.find(
334
- ({ contactAccessRight: { contact } }) =>
335
- contact?.id === updatedContactAccessRight.contact?.id
336
- );
337
-
338
- expect(updatedContactAccessRightState).toBeDefined();
339
- expect(updatedContactAccessRightState?.state).toEqual('unchanged');
340
- });
341
-
342
- it('should update a contact access right to `updated` state if it is updated subsequently', () => {
343
- const contextProps = { ...baseContextProps, initialValues };
344
-
345
- const { result } = renderHook(() => useAccessRightsForm(), {
346
- initialProps: contextProps,
347
- wrapper: contextWrapper
348
- });
349
-
350
- const { contactAccessRight } = result.current.contactAccessRights[0];
351
- const updatedContactAccessRight = {
352
- ...contactAccessRight,
353
- role:
354
- contactAccessRight.role === rolesMock()[0].role
355
- ? rolesMock()[1].role
356
- : rolesMock()[0].role
357
- };
358
-
359
- act(() =>
360
- result.current.updateContactAccessRight(updatedContactAccessRight)
361
- );
362
- act(() => result.current.updateContactAccessRight(contactAccessRight));
363
- act(() =>
364
- result.current.updateContactAccessRight(updatedContactAccessRight)
365
- );
366
-
367
- const updatedContactAccessRightState =
368
- result.current.contactAccessRights.find(
369
- ({ contactAccessRight: { contact } }) =>
370
- contact?.id === updatedContactAccessRight.contact?.id
371
- );
372
-
373
- expect(updatedContactAccessRightState).toBeDefined();
374
- expect(updatedContactAccessRightState?.state).toEqual('updated');
375
- });
376
-
377
- it('should keep a new contact access right in `added` state if it is updated', () => {
378
- const contextProps = { ...baseContextProps };
379
-
380
- const { result } = renderHook(() => useAccessRightsForm(), {
381
- initialProps: contextProps,
382
- wrapper: contextWrapper
383
- });
384
-
385
- const contactAccessRight = contactAccessRightsMock(1)[0];
386
- act(() => result.current.addContactAccessRight(contactAccessRight));
387
-
388
- const updatedContactAccessRight = {
389
- ...contactAccessRight,
390
- role:
391
- contactAccessRight.role === rolesMock()[0].role
392
- ? rolesMock()[1].role
393
- : rolesMock()[0].role
394
- };
395
-
396
- act(() =>
397
- result.current.updateContactAccessRight(updatedContactAccessRight)
398
- );
399
-
400
- const updatedContactAccessRightState =
401
- result.current.contactAccessRights.find(
402
- ({ contactAccessRight: { contact } }) =>
403
- contact?.id === updatedContactAccessRight.contact?.id
404
- );
405
-
406
- expect(updatedContactAccessRightState).toBeDefined();
407
- expect(updatedContactAccessRightState?.state).toEqual('added');
408
- });
409
- });
410
-
411
- describe('onSubmit', () => {
412
- it('should call the `onSubmit` callback with the correct payload', () => {
413
- const contextProps = { ...baseContextProps, initialValues };
414
- const onSubmit = jest.fn();
415
-
416
- const { result } = renderHook(() => useAccessRightsForm(), {
417
- initialProps: { ...contextProps, onSubmit },
418
- wrapper: contextWrapper
419
- });
420
-
421
- act(() => result.current.submit());
422
-
423
- expect(onSubmit).toHaveBeenCalledWith(result.current.contactAccessRights);
424
- });
425
- });
426
-
427
- describe('state', () => {
428
- it('should have `isDirty` flag set on changes', () => {
429
- const contextProps = { ...baseContextProps, initialValues };
430
-
431
- const { result } = renderHook(() => useAccessRightsForm(), {
432
- initialProps: contextProps,
433
- wrapper: contextWrapper
434
- });
435
-
436
- const { contactAccessRight } = result.current.contactAccessRights[0];
437
- const updatedContactAccessRight = {
438
- ...contactAccessRight,
439
- role:
440
- contactAccessRight.role === rolesMock()[0].role
441
- ? rolesMock()[1].role
442
- : rolesMock()[0].role
443
- };
444
-
445
- expect(result.current.isDirty).toBeFalsy();
446
-
447
- act(() =>
448
- result.current.updateContactAccessRight(updatedContactAccessRight)
449
- );
450
-
451
- expect(result.current.isDirty).toBeTruthy();
452
- });
453
-
454
- it('should have `isDirty` flag cleared on reverted changes', () => {
455
- const contextProps = { ...baseContextProps, initialValues };
456
-
457
- const { result } = renderHook(() => useAccessRightsForm(), {
458
- initialProps: contextProps,
459
- wrapper: contextWrapper
460
- });
461
-
462
- const { contactAccessRight } = result.current.contactAccessRights[0];
463
- act(() => result.current.removeContactAccessRight(contactAccessRight));
464
- act(() =>
465
- result.current.removeContactAccessRight(contactAccessRight, true)
466
- );
467
-
468
- expect(result.current.isDirty).toBeFalsy();
469
- });
470
-
471
- it('should have stats updated on changes', () => {
472
- const contextProps = { ...baseContextProps, initialValues };
473
-
474
- const { result } = renderHook(() => useAccessRightsForm(), {
475
- initialProps: contextProps,
476
- wrapper: contextWrapper
477
- });
478
-
479
- expect(result.current.stats).toEqual({
480
- added: 0,
481
- removed: 0,
482
- updated: 0
483
- });
484
-
485
- // update contact access right
486
- const { contactAccessRight: contactAccessRightToUpdate } =
487
- result.current.contactAccessRights[1];
488
- const updatedContactAccessRight = {
489
- ...contactAccessRightToUpdate,
490
- role:
491
- contactAccessRightToUpdate.role === rolesMock()[0].role
492
- ? rolesMock()[1].role
493
- : rolesMock()[0].role
494
- };
495
-
496
- act(() =>
497
- result.current.updateContactAccessRight(updatedContactAccessRight)
498
- );
499
-
500
- expect(result.current.stats).toEqual({
501
- added: 0,
502
- removed: 0,
503
- updated: 1
504
- });
505
-
506
- // remove contact access right
507
- const { contactAccessRight: contactAccessRightToRemove } =
508
- result.current.contactAccessRights[2];
509
-
510
- act(() =>
511
- result.current.removeContactAccessRight(contactAccessRightToRemove)
512
- );
513
-
514
- expect(result.current.stats).toEqual({
515
- added: 0,
516
- removed: 1,
517
- updated: 1
518
- });
519
-
520
- // add contact access right
521
- const contactAccessRight = contactAccessRightsMock(1)[0];
522
- act(() => result.current.addContactAccessRight(contactAccessRight));
523
-
524
- expect(result.current.stats).toEqual({
525
- added: 1,
526
- removed: 1,
527
- updated: 1
528
- });
529
- });
530
- });
531
- });