@centreon/ui 26.10.7 → 26.10.9

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