@centreon/ui 24.10.12 → 24.10.13

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 (153) hide show
  1. package/package.json +3 -2
  2. package/public/mockServiceWorker.js +1 -1
  3. package/src/Button/Icon/index.tsx +3 -1
  4. package/src/Dashboard/Dashboard.styles.ts +3 -4
  5. package/src/Dashboard/DashboardLayout.stories.tsx +1 -1
  6. package/src/Dashboard/Grid.tsx +11 -17
  7. package/src/Dashboard/Layout.tsx +27 -56
  8. package/src/Dialog/UnsavedChanges/index.tsx +15 -13
  9. package/src/Dialog/UnsavedChanges/translatedLabels.ts +15 -13
  10. package/src/Form/Form.tsx +0 -1
  11. package/src/Form/Inputs/Autocomplete.tsx +1 -1
  12. package/src/Form/Inputs/ConnectedAutocomplete.tsx +5 -2
  13. package/src/Form/Inputs/Grid.tsx +7 -1
  14. package/src/Form/Inputs/Radio.tsx +1 -1
  15. package/src/Form/Inputs/Switch.tsx +1 -1
  16. package/src/Form/Inputs/Text.tsx +1 -1
  17. package/src/Form/Inputs/index.tsx +25 -24
  18. package/src/Form/Inputs/models.ts +2 -0
  19. package/src/Graph/BarChart/BarChart.cypress.spec.tsx +3 -3
  20. package/src/Graph/BarChart/BarChart.tsx +24 -31
  21. package/src/Graph/BarChart/BarGroup.tsx +32 -59
  22. package/src/Graph/BarChart/BarStack.tsx +64 -13
  23. package/src/Graph/BarChart/MemoizedGroup.tsx +123 -0
  24. package/src/Graph/BarChart/ResponsiveBarChart.tsx +21 -7
  25. package/src/Graph/BarStack/BarStack.cypress.spec.tsx +87 -9
  26. package/src/Graph/BarStack/BarStack.stories.tsx +13 -4
  27. package/src/Graph/BarStack/BarStack.styles.ts +57 -33
  28. package/src/Graph/BarStack/Graph.tsx +173 -0
  29. package/src/Graph/BarStack/GraphAndLegend.tsx +117 -0
  30. package/src/Graph/BarStack/ResponsiveBarStack.tsx +61 -168
  31. package/src/Graph/BarStack/constants.ts +5 -0
  32. package/src/Graph/BarStack/models.ts +0 -1
  33. package/src/Graph/BarStack/useGraphAndLegend.ts +84 -0
  34. package/src/Graph/BarStack/useResponsiveBarStack.ts +73 -97
  35. package/src/Graph/Chart/Chart.cypress.spec.tsx +14 -26
  36. package/src/Graph/Chart/Chart.stories.tsx +1 -1
  37. package/src/Graph/Chart/Chart.tsx +53 -37
  38. package/src/Graph/Chart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +3 -3
  39. package/src/Graph/Chart/InteractiveComponents/AnchorPoint/useTickGraph.ts +19 -6
  40. package/src/Graph/Chart/Legend/Legend.styles.ts +25 -11
  41. package/src/Graph/Chart/Legend/index.tsx +6 -24
  42. package/src/Graph/Chart/index.tsx +34 -43
  43. package/src/Graph/Chart/models.ts +0 -1
  44. package/src/Graph/Chart/useChartData.ts +19 -1
  45. package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +20 -2
  46. package/src/Graph/HeatMap/model.ts +6 -2
  47. package/src/Graph/Legend/Legend.styles.ts +10 -0
  48. package/src/Graph/Legend/Legend.tsx +6 -1
  49. package/src/Graph/SingleBar/ResponsiveSingleBar.tsx +9 -10
  50. package/src/Graph/SingleBar/ThresholdLine.tsx +6 -6
  51. package/src/Graph/Text/Text.styles.ts +2 -2
  52. package/src/Graph/Text/Text.tsx +23 -10
  53. package/src/Graph/Timeline/ResponsiveTimeline.tsx +152 -0
  54. package/src/Graph/Timeline/Timeline.cypress.spec.tsx +148 -0
  55. package/src/Graph/Timeline/Timeline.stories.tsx +91 -0
  56. package/src/Graph/Timeline/Timeline.tsx +28 -0
  57. package/src/Graph/Timeline/index.ts +1 -0
  58. package/src/Graph/Timeline/models.ts +20 -0
  59. package/src/Graph/Timeline/timeline.styles.ts +11 -0
  60. package/src/Graph/Timeline/translatedLabel.ts +6 -0
  61. package/src/Graph/Timeline/useTimeline.ts +90 -0
  62. package/src/Graph/Tree/Links.tsx +2 -2
  63. package/src/Graph/Tree/Tree.tsx +2 -2
  64. package/src/Graph/Tree/constants.ts +1 -1
  65. package/src/Graph/common/Axes/index.tsx +1 -1
  66. package/src/Graph/common/Axes/useAxisY.ts +8 -4
  67. package/src/Graph/common/BaseChart/BaseChart.tsx +3 -12
  68. package/src/Graph/common/BaseChart/ChartSvgWrapper.tsx +12 -4
  69. package/src/Graph/common/BaseChart/Header/index.tsx +3 -1
  70. package/src/Graph/common/BaseChart/useComputeBaseChartDimensions.ts +23 -11
  71. package/src/Graph/common/BaseChart/useComputeYAxisMaxCharacters.ts +92 -0
  72. package/src/Graph/common/models.ts +7 -8
  73. package/src/Graph/common/timeSeries/index.test.ts +1 -1
  74. package/src/Graph/common/timeSeries/index.ts +56 -29
  75. package/src/Graph/common/timeSeries/models.ts +2 -0
  76. package/src/Graph/common/utils.ts +51 -3
  77. package/src/Graph/index.ts +4 -1
  78. package/src/Graph/mockedData/lastDayWithNullValues.json +6 -6
  79. package/src/Graph/mockedData/pingServiceLinesBars.json +47 -47
  80. package/src/Icon/DowntimeIcon.tsx +8 -1
  81. package/src/Icon/FlappingIcon.tsx +22 -0
  82. package/src/Icon/index.ts +1 -0
  83. package/src/InputField/Select/Autocomplete/Connected/Multi/index.test.tsx +21 -1
  84. package/src/InputField/Select/Autocomplete/Connected/index.test.tsx +2 -2
  85. package/src/InputField/Select/Autocomplete/Connected/index.tsx +52 -15
  86. package/src/InputField/Select/Autocomplete/Multi/index.stories.tsx +19 -0
  87. package/src/InputField/Select/Autocomplete/Multi/index.tsx +8 -5
  88. package/src/InputField/Select/Autocomplete/index.tsx +79 -54
  89. package/src/InputField/Text/index.tsx +6 -4
  90. package/src/InputField/translatedLabels.ts +2 -0
  91. package/src/Listing/ActionBar/index.tsx +1 -1
  92. package/src/Listing/Listing.styles.ts +3 -3
  93. package/src/Listing/index.tsx +40 -37
  94. package/src/Listing/models.ts +0 -8
  95. package/src/Listing/useStyleTable.ts +58 -32
  96. package/src/MultiSelectEntries/index.tsx +2 -0
  97. package/src/PopoverMenu/index.tsx +2 -9
  98. package/src/SortableItems/index.tsx +0 -1
  99. package/src/ThemeProvider/index.tsx +1 -1
  100. package/src/ThemeProvider/palettes.ts +6 -0
  101. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +2 -3
  102. package/src/TimePeriods/DateTimePickerInput.tsx +3 -1
  103. package/src/api/buildListingEndpoint/getSearchQueryParameterValue.ts +7 -1
  104. package/src/api/buildListingEndpoint/models.ts +1 -0
  105. package/src/api/customFetch.ts +4 -1
  106. package/src/api/models.ts +9 -0
  107. package/src/api/useGraphQuery/index.ts +117 -20
  108. package/src/api/useGraphQuery/models.ts +1 -0
  109. package/src/api/useMutationQuery/index.ts +1 -1
  110. package/src/components/DataTable/DataTable.styles.ts +1 -1
  111. package/src/components/DataTable/EmptyState/DataTableEmptyState.styles.ts +2 -1
  112. package/src/components/DataTable/EmptyState/DataTableEmptyState.tsx +4 -1
  113. package/src/components/DataTable/Item/DataTableItem.styles.ts +28 -2
  114. package/src/components/DataTable/Item/DataTableItem.tsx +19 -4
  115. package/src/components/Form/FormActions.tsx +21 -12
  116. package/src/components/Layout/AreaIndicator.tsx +1 -1
  117. package/src/components/Layout/PageLayout/PageLayout.styles.ts +2 -7
  118. package/src/components/Layout/PageLayout/PageLayoutBody.tsx +0 -1
  119. package/src/components/Zoom/Zoom.tsx +9 -2
  120. package/src/components/Zoom/ZoomContent.tsx +143 -136
  121. package/src/components/Zoom/models.ts +18 -15
  122. package/src/components/Zoom/useMinimap.ts +5 -8
  123. package/src/components/Zoom/useZoom.ts +3 -3
  124. package/src/index.ts +2 -0
  125. package/src/utils/index.ts +1 -0
  126. package/src/utils/useLocale/index.ts +9 -0
  127. package/src/utils/useLocale/useLocale.cypress.spec.tsx +38 -0
  128. package/src/utils/useLocaleDateTimeFormat/index.ts +4 -2
  129. package/src/utils/usePluralizedTranslation.ts +2 -3
  130. package/src/Graph/common/timeSeries/index.test.ts-E +0 -622
  131. package/src/components/CrudPage/Actions/Actions.styles.ts +0 -16
  132. package/src/components/CrudPage/Actions/Actions.tsx +0 -24
  133. package/src/components/CrudPage/Actions/AddButton.tsx +0 -23
  134. package/src/components/CrudPage/Actions/Filters.tsx +0 -25
  135. package/src/components/CrudPage/Actions/Search.tsx +0 -31
  136. package/src/components/CrudPage/Actions/useSearch.tsx +0 -24
  137. package/src/components/CrudPage/Columns/Actions.tsx +0 -88
  138. package/src/components/CrudPage/CrudPage.cypress.spec.tsx +0 -559
  139. package/src/components/CrudPage/CrudPage.stories.tsx +0 -278
  140. package/src/components/CrudPage/CrudPageRoot.tsx +0 -142
  141. package/src/components/CrudPage/DeleteModal.tsx +0 -77
  142. package/src/components/CrudPage/Form/AddModal.tsx +0 -35
  143. package/src/components/CrudPage/Form/Buttons.tsx +0 -98
  144. package/src/components/CrudPage/Form/UpdateModal.tsx +0 -60
  145. package/src/components/CrudPage/Listing.tsx +0 -63
  146. package/src/components/CrudPage/atoms.ts +0 -30
  147. package/src/components/CrudPage/hooks/useDeleteItem.ts +0 -53
  148. package/src/components/CrudPage/hooks/useGetItem.ts +0 -36
  149. package/src/components/CrudPage/hooks/useGetItems.ts +0 -67
  150. package/src/components/CrudPage/hooks/useListingQueryKey.ts +0 -31
  151. package/src/components/CrudPage/index.tsx +0 -7
  152. package/src/components/CrudPage/models.ts +0 -118
  153. package/src/components/CrudPage/utils.ts +0 -4
@@ -1,559 +0,0 @@
1
- import { FormControlLabel, Switch, Typography } from '@mui/material';
2
- import { Provider, atom, createStore, useAtom, useSetAtom } from 'jotai';
3
- import { identity, isNil, prop } from 'ramda';
4
- import { ChangeEvent, useEffect } from 'react';
5
- import { CrudPage } from '.';
6
- import {
7
- Column,
8
- ColumnType,
9
- Method,
10
- SnackbarProvider,
11
- TestQueryProvider
12
- } from '../..';
13
- import { CrudPageRoot } from './CrudPageRoot';
14
- import { CrudPageRootProps } from './models';
15
-
16
- interface Item {
17
- id: number;
18
- name: string;
19
- description: string;
20
- subItems: Array<{ id: number; name: string }>;
21
- }
22
-
23
- interface Filters {
24
- hasDescription: boolean;
25
- isEven: boolean;
26
- }
27
-
28
- const generateItems = (count: number) =>
29
- Array(count)
30
- .fill(0)
31
- .map((_, idx) => ({
32
- id: idx,
33
- name: `Item ${idx}`,
34
- description: `Description ${idx}`,
35
- subItems: [{ id: 1, name: 'SubItem' }]
36
- }));
37
-
38
- const filtersAtom = atom<Filters>({
39
- hasDescription: true,
40
- isEven: false
41
- });
42
-
43
- const Filters = () => {
44
- const [filters, setFilters] = useAtom(filtersAtom);
45
-
46
- const change =
47
- (property: string) => (event: ChangeEvent<HTMLInputElement>) => {
48
- setFilters((current) => ({
49
- ...current,
50
- [property]: event.target.checked
51
- }));
52
- };
53
-
54
- return (
55
- <>
56
- <FormControlLabel
57
- control={
58
- <Switch
59
- checked={filters.hasDescription}
60
- onChange={change('hasDescription')}
61
- />
62
- }
63
- label="Has description"
64
- />
65
- <FormControlLabel
66
- control={
67
- <Switch checked={filters.isEven} onChange={change('isEven')} />
68
- }
69
- label="Is even"
70
- />
71
- </>
72
- );
73
- };
74
-
75
- const getSearchParameters = ({ filters }) => ({
76
- conditions: [
77
- {
78
- field: 'hasDescription',
79
- values: {
80
- $in: filters.hasDescription
81
- }
82
- },
83
- {
84
- field: 'isEven',
85
- values: {
86
- $in: filters.isEven
87
- }
88
- }
89
- ]
90
- });
91
-
92
- const labels = {
93
- title: 'Items',
94
- welcome: {
95
- title: 'Welcome to the items page',
96
- description: 'This page handles item'
97
- },
98
- actions: {
99
- create: 'Create item'
100
- },
101
- listing: {
102
- search: 'Search'
103
- }
104
- };
105
-
106
- const columns: Array<Column> = [
107
- {
108
- type: ColumnType.string,
109
- id: 'name',
110
- label: 'Name',
111
- getFormattedString: prop('name'),
112
- displaySubItemsCaret: true
113
- },
114
- {
115
- type: ColumnType.string,
116
- id: 'description',
117
- label: 'Description',
118
- getFormattedString: prop('description')
119
- }
120
- ];
121
-
122
- const defaultProps: CrudPageRootProps<Item, Filters, Item, Item> = {
123
- baseEndpoint: '/listing',
124
- queryKeyName: 'listing',
125
- filtersAtom,
126
- getSearchParameters,
127
- labels,
128
- columns,
129
- filters: <Filters />,
130
- form: {
131
- getItem: {
132
- baseEndpoint: (id) => `/item/${id}`,
133
- adapter: identity,
134
- itemQueryKey: 'item'
135
- },
136
- Form: ({ initialValues }) => {
137
- const [askBeforeCloseForm, setAskBeforeCloseFormModal] = useAtom(
138
- CrudPage.askBeforeCloseFormModalAtom
139
- );
140
- const setOpenFormModal = useSetAtom(CrudPage.openFormModalAtom);
141
-
142
- useEffect(() => {
143
- if (!askBeforeCloseForm) {
144
- return;
145
- }
146
-
147
- setOpenFormModal(null);
148
- setAskBeforeCloseFormModal(false);
149
- }, [askBeforeCloseForm]);
150
-
151
- return (
152
- <Typography>
153
- This is a placeholder for the form
154
- <br />
155
- Initial values: {JSON.stringify(initialValues)}
156
- </Typography>
157
- );
158
- },
159
- labels: {
160
- add: {
161
- title: 'Add item',
162
- cancel: 'Cancel',
163
- confirm: 'Add'
164
- },
165
- update: {
166
- title: 'Update item',
167
- cancel: 'Cancel',
168
- confirm: 'Update'
169
- }
170
- }
171
- },
172
- deleteItem: {
173
- deleteEndpoint: (item) =>
174
- !isNil(item?.parent)
175
- ? `/listing/${item?.parent?.id}/subItems/${item?.id}`
176
- : `/listing/${item?.id}`,
177
- labels: {
178
- successMessage: (item) =>
179
- !isNil(item?.parent) ? 'Sub item deleted' : 'Item deleted',
180
- confirm: 'Delete',
181
- cancel: 'Cancel',
182
- title: (item) =>
183
- !isNil(item?.parent) ? 'Delete sub item' : 'Delete item',
184
- description: (item) =>
185
- !isNil(item?.parent) ? (
186
- <Typography>
187
- The sub item <strong>{item?.name}</strong> from the item{' '}
188
- <strong>{item?.parent?.name}</strong> will be deleted
189
- </Typography>
190
- ) : (
191
- <Typography>
192
- The item <strong>{item?.name}</strong> will be deleted
193
- </Typography>
194
- )
195
- }
196
- }
197
- };
198
-
199
- const listing = {
200
- result: generateItems(30),
201
- meta: {
202
- page: 1,
203
- total: 60,
204
- limit: 30
205
- }
206
- };
207
-
208
- const emptyListing = {
209
- result: [],
210
- meta: {
211
- page: 1,
212
- total: 0,
213
- limit: 30
214
- }
215
- };
216
-
217
- const initialize = (props: CrudPageRootProps<Item, Filters, Item, Item>) => {
218
- cy.interceptAPIRequest({
219
- alias: 'getEmptyListing',
220
- method: Method.GET,
221
- path: '**/empty-listing**',
222
- response: emptyListing
223
- });
224
-
225
- cy.interceptAPIRequest({
226
- alias: 'getListing',
227
- method: Method.GET,
228
- path: '**/listing**',
229
- response: listing
230
- });
231
-
232
- cy.interceptAPIRequest({
233
- alias: 'getListing',
234
- method: Method.GET,
235
- path: '**/listing**',
236
- response: listing
237
- });
238
-
239
- cy.interceptAPIRequest({
240
- alias: 'deleteItem',
241
- method: Method.DELETE,
242
- path: '**/listing/1',
243
- response: {}
244
- });
245
-
246
- cy.interceptAPIRequest({
247
- alias: 'deleteSubItem',
248
- method: Method.DELETE,
249
- path: '**/listing/0/subItems/1',
250
- response: {}
251
- });
252
-
253
- cy.interceptAPIRequest({
254
- alias: 'getItem',
255
- method: Method.GET,
256
- path: '**/item/0',
257
- response: generateItems(1)[0]
258
- });
259
-
260
- const store = createStore();
261
-
262
- cy.mount({
263
- Component: (
264
- <div style={{ height: '95vh' }}>
265
- <Provider store={store}>
266
- <SnackbarProvider>
267
- <TestQueryProvider>
268
- <CrudPageRoot {...props} />
269
- </TestQueryProvider>
270
- </SnackbarProvider>
271
- </Provider>
272
- </div>
273
- )
274
- });
275
- };
276
-
277
- describe('CrudPage', () => {
278
- it('displays a welcome message when no data are retrieved', () => {
279
- initialize({
280
- ...defaultProps,
281
- queryKeyName: 'empty-listing',
282
- baseEndpoint: '/empty-listing'
283
- });
284
-
285
- cy.waitForRequest('@getEmptyListing');
286
-
287
- cy.contains('Welcome to the items page').should('be.visible');
288
- cy.contains('This page handles item').should('be.visible');
289
- cy.contains('Items').should('be.visible');
290
- cy.get('button').contains('Create item').should('be.visible');
291
-
292
- cy.makeSnapshot();
293
- });
294
-
295
- it('opens the form modal when no data are retrieved and the corresponding button is clicked', () => {
296
- initialize({
297
- ...defaultProps,
298
- queryKeyName: 'empty-listing',
299
- baseEndpoint: '/empty-listing'
300
- });
301
-
302
- cy.waitForRequest('@getEmptyListing');
303
-
304
- cy.contains('Welcome to the items page').should('be.visible');
305
- cy.contains('This page handles item').should('be.visible');
306
- cy.contains('Items').should('be.visible');
307
- cy.get('button').contains('Create item').click();
308
-
309
- cy.contains('Add item').should('be.visible');
310
- cy.contains('This is a placeholder for the form').should('be.visible');
311
- cy.contains('Initial values:').should('be.visible');
312
-
313
- cy.makeSnapshot();
314
- });
315
-
316
- it('displays items when items are retrieved', () => {
317
- initialize(defaultProps);
318
-
319
- cy.waitForRequest('@getListing').then(({ request }) => {
320
- const { searchParams } = request.url;
321
-
322
- expect(searchParams.get('page')).equal('1');
323
- expect(searchParams.get('limit')).equal('10');
324
- expect(searchParams.get('sort_by')).equal('{"name":"asc"}');
325
- expect(searchParams.get('search')).equal(
326
- '{"$and":[{"$or":[{"name":{"$rg":""}}]},{"$and":[{"$or":[{"hasDescription":{"$in":true}}]},{"$or":[{"isEven":{"$in":false}}]}]}]}'
327
- );
328
- });
329
-
330
- cy.contains('Items').should('be.visible');
331
- cy.get('button').contains('Create item').should('be.visible');
332
- cy.contains('Item 0').should('be.visible');
333
- cy.contains('Description 0').should('be.visible');
334
-
335
- cy.makeSnapshot();
336
- });
337
-
338
- it('sends a request when filters and search are updated', () => {
339
- initialize(defaultProps);
340
-
341
- cy.findAllByTestId('Search').eq(1).type('simple search');
342
- cy.findByLabelText('filters').click();
343
- cy.findByLabelText('Has description').click();
344
- cy.findByLabelText('Is even').click();
345
-
346
- cy.findAllByTestId('Search').eq(1).should('have.value', 'simple search');
347
-
348
- cy.findByLabelText('filters').click();
349
-
350
- cy.findByLabelText('Has description').should('not.exist');
351
-
352
- cy.wait(500);
353
-
354
- cy.waitForRequest('@getListing').then(({ request }) => {
355
- const { searchParams } = request.url;
356
-
357
- expect(searchParams.get('search')).equal(
358
- '{"$and":[{"$or":[{"name":{"$rg":"simple search"}}]},{"$and":[{"$or":[{"hasDescription":{"$in":false}}]},{"$or":[{"isEven":{"$in":true}}]}]}]}'
359
- );
360
- });
361
-
362
- cy.makeSnapshot();
363
- });
364
-
365
- it('displays the add modal when data are retrieved and the corresponding is clicked', () => {
366
- initialize(defaultProps);
367
-
368
- cy.waitForRequest('@getListing');
369
-
370
- cy.contains('Create item').click();
371
-
372
- cy.contains('Add item').should('be.visible');
373
- cy.contains('This is a placeholder for the form').should('be.visible');
374
- cy.contains('Initial values:').should('be.visible');
375
-
376
- cy.makeSnapshot();
377
- });
378
-
379
- describe('Delete with advanced labels', () => {
380
- it('deletes an item when items are retrieved and the corresponding button is clicked', () => {
381
- initialize(defaultProps);
382
-
383
- cy.findByTestId('delete-1').click();
384
-
385
- cy.contains('Delete item').should('be.visible');
386
- cy.contains('The item Item 1 will be deleted').should('be.visible');
387
-
388
- cy.get('button').contains('Delete').click();
389
-
390
- cy.waitForRequest('@deleteItem');
391
-
392
- cy.contains('Item deleted').should('be.visible');
393
-
394
- cy.makeSnapshot();
395
- });
396
-
397
- it('deletes a sub-item when items are retrieved and the corresponding button is clicked', () => {
398
- initialize({
399
- ...defaultProps,
400
- subItems: {
401
- canCheckSubItems: false,
402
- enable: true,
403
- getRowProperty: () => 'subItems',
404
- labelExpand: 'Expand',
405
- labelCollapse: 'Collapse'
406
- }
407
- });
408
-
409
- cy.findByTestId('Expand 0').click();
410
- cy.findByTestId('delete-0-1').click();
411
-
412
- cy.contains('Delete sub item').should('be.visible');
413
- cy.contains(
414
- 'The sub item SubItem from the item Item 0 will be deleted'
415
- ).should('be.visible');
416
-
417
- cy.get('button').contains('Delete').click();
418
-
419
- cy.waitForRequest('@deleteSubItem');
420
-
421
- cy.contains('Sub item deleted').should('be.visible');
422
-
423
- cy.makeSnapshot();
424
- });
425
- });
426
-
427
- describe('Delete with basic labels', () => {
428
- it('deletes an item when items are retrieved and the corresponding button is clicked', () => {
429
- initialize({
430
- ...defaultProps,
431
- deleteItem: {
432
- ...defaultProps.deleteItem,
433
- labels: {
434
- title: 'Title',
435
- successMessage: 'This is a success',
436
- description: 'A small description',
437
- cancel: 'Cancel',
438
- confirm: 'Delete'
439
- }
440
- }
441
- });
442
-
443
- cy.findByTestId('delete-1').click();
444
-
445
- cy.contains('Title').should('be.visible');
446
- cy.contains('A small description').should('be.visible');
447
-
448
- cy.get('button').contains('Delete').click();
449
-
450
- cy.waitForRequest('@deleteItem');
451
-
452
- cy.contains('This is a success').should('be.visible');
453
-
454
- cy.makeSnapshot();
455
- });
456
-
457
- it('deletes a sub-item when items are retrieved and the corresponding button is clicked', () => {
458
- initialize({
459
- ...defaultProps,
460
- subItems: {
461
- canCheckSubItems: false,
462
- enable: true,
463
- getRowProperty: () => 'subItems',
464
- labelExpand: 'Expand',
465
- labelCollapse: 'Collapse'
466
- },
467
- deleteItem: {
468
- ...defaultProps.deleteItem,
469
- labels: {
470
- title: 'Title',
471
- successMessage: 'This is a success',
472
- description: 'A small description',
473
- cancel: 'Cancel',
474
- confirm: 'Delete'
475
- }
476
- }
477
- });
478
-
479
- cy.findByTestId('Expand 0').click();
480
- cy.findByTestId('delete-0-1').click();
481
-
482
- cy.contains('Title').should('be.visible');
483
- cy.contains('A small description').should('be.visible');
484
-
485
- cy.get('button').contains('Delete').click();
486
-
487
- cy.waitForRequest('@deleteSubItem');
488
-
489
- cy.contains('This is a success').should('be.visible');
490
-
491
- cy.makeSnapshot();
492
- });
493
- });
494
-
495
- it('cannot delete a sub-item when items are retrieved and the corresponding button is clicked', () => {
496
- initialize({
497
- ...defaultProps,
498
- subItems: {
499
- canDeleteSubItems: false,
500
- canCheckSubItems: false,
501
- enable: true,
502
- getRowProperty: () => 'subItems',
503
- labelExpand: 'Expand',
504
- labelCollapse: 'Collapse'
505
- },
506
- deleteItem: {
507
- ...defaultProps.deleteItem,
508
- labels: {
509
- title: 'Title',
510
- successMessage: 'This is a success',
511
- description: 'A small description',
512
- cancel: 'Cancel',
513
- confirm: 'Delete'
514
- }
515
- }
516
- });
517
-
518
- cy.findByTestId('Expand 0').click();
519
- cy.findByTestId('delete-0-1').should('not.exist');
520
-
521
- cy.makeSnapshot();
522
- });
523
-
524
- it('opens the update form when the corresponding button is clicked', () => {
525
- initialize(defaultProps);
526
-
527
- cy.findByTestId('edit-0').click();
528
-
529
- cy.waitForRequest('@getItem');
530
-
531
- cy.contains('Update item').should('be.visible');
532
- cy.contains('This is a placeholder for the form').should('be.visible');
533
- cy.contains(
534
- 'Initial values: {"id":0,"name":"Item 0","description":"Description 0","subItems":[{"id":1,"name":"SubItem"}]}'
535
- ).should('be.visible');
536
-
537
- cy.makeSnapshot();
538
- });
539
-
540
- it('closes the update form when the update ubtton is clicked and the corresponding button is clicked', () => {
541
- initialize(defaultProps);
542
-
543
- cy.findByTestId('edit-0').click();
544
-
545
- cy.waitForRequest('@getItem');
546
-
547
- cy.contains('Update item').should('be.visible');
548
- cy.contains('This is a placeholder for the form').should('be.visible');
549
- cy.contains(
550
- 'Initial values: {"id":0,"name":"Item 0","description":"Description 0","subItems":[{"id":1,"name":"SubItem"}]}'
551
- ).should('be.visible');
552
-
553
- cy.findByLabelText('close').click();
554
-
555
- cy.contains('Update item').should('not.exist');
556
-
557
- cy.makeSnapshot();
558
- });
559
- });