@centreon/ui 26.12.0 → 26.12.2

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 (57) 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/ExclusiveCheckboxGroup.browser.test.tsx +304 -0
  6. package/src/Form/Inputs/SegmentedButtons.browser.test.tsx +113 -0
  7. package/src/InputField/Number/Number.browser.test.tsx +109 -0
  8. package/src/InputField/Select/Autocomplete/Connected/Multi/MultiConnectedAutocompleteField.browser.test.tsx +250 -0
  9. package/src/Listing/Listing.browser.test.tsx +476 -0
  10. package/src/Module/Module.browser.test.tsx +145 -0
  11. package/src/Pagination/Pagination.browser.test.tsx +184 -0
  12. package/src/Panel/Section/index.test.tsx +1 -1
  13. package/src/RichTextEditor/RichTextEditor.browser.test.tsx +567 -0
  14. package/src/RichTextEditor/plugins/FloatingLinkEditorPlugin.tsx +3 -1
  15. package/src/TimePeriods/ResolutionTimePeriod.browser.test.tsx +143 -0
  16. package/src/TimePeriods/TimePeriods.browser.test.tsx +468 -0
  17. package/src/Typography/FluidTypography/FluidTypography.browser.test.tsx +54 -0
  18. package/src/api/useMutationQuery/useMutationQuery.browser.test.tsx +154 -0
  19. package/src/components/CollapsibleItem/CollapsibleItem.browser.test.tsx +120 -0
  20. package/src/components/CopyCommand/CopyCommand.browser.test.tsx +287 -0
  21. package/src/components/CrudPage/CrudPage.browser.test.tsx +659 -0
  22. package/src/components/DataTable/DataTable.browser.test.tsx +257 -0
  23. package/src/components/Form/AccessRights/AccessRights.browser.test.tsx +527 -0
  24. package/src/components/ItemComposition/ItemComposition.browser.test.tsx +172 -0
  25. package/src/components/Layout/PageLayout.browser.test.tsx +114 -0
  26. package/src/components/Modal/ConfirmationModal/ConfirmationModal.browser.test.tsx +237 -0
  27. package/src/components/SortableEntriesList/SortableEntriesList.browser.test.tsx +981 -0
  28. package/src/components/Tabs/Tabs.browser.test.tsx +115 -0
  29. package/src/utils/useFullscreen/Fullscreen.browser.test.tsx +176 -0
  30. package/src/utils/useLocale/useLocale.browser.test.tsx +49 -0
  31. package/src/utils/useLocaleTimezoneDate/{LocaleTimezoneDate.cypress.spec.tsx → LocaleTimezoneDate.browser.test.tsx} +24 -11
  32. package/src/Dashboard/Dashboard.cypress.spec.tsx +0 -71
  33. package/src/Form/Form.cypress.spec.tsx +0 -306
  34. package/src/Form/Inputs/ExclusiveCheckboxGroup.cypress.spec.tsx +0 -236
  35. package/src/Form/Inputs/SegmentedButtons.cypress.spec.tsx +0 -101
  36. package/src/InputField/Number/Number.cypress.spec.tsx +0 -89
  37. package/src/InputField/Select/Autocomplete/Connected/Multi/MultiConnectedAutocompleteField.cypress.spec.tsx +0 -182
  38. package/src/Listing/Listing.cypress.spec.tsx +0 -349
  39. package/src/Module/Module.cypress.spec.tsx +0 -127
  40. package/src/Pagination/Pagination.cypress.spec.tsx +0 -140
  41. package/src/RichTextEditor/RichTextEditor.cypress.spec.tsx +0 -408
  42. package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +0 -74
  43. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +0 -488
  44. package/src/Typography/FluidTypography/FluidTypography.cypress.spec.tsx +0 -27
  45. package/src/api/useMutationQuery/useMutationQuery.cypress.spec.tsx +0 -93
  46. package/src/components/CollapsibleItem/CollapsibleItem.cypress.spec.tsx +0 -76
  47. package/src/components/CopyCommand/CopyCommand.cypress.spec.tsx +0 -167
  48. package/src/components/CrudPage/CrudPage.cypress.spec.tsx +0 -561
  49. package/src/components/DataTable/DataTable.cypress.spec.tsx +0 -174
  50. package/src/components/Form/AccessRights/AccessRights.cypress.spec.tsx +0 -376
  51. package/src/components/ItemComposition/ItemComposition.cypress.spec.tsx +0 -112
  52. package/src/components/Layout/PageLayout.cypress.spec.tsx +0 -64
  53. package/src/components/Modal/ConfirmationModal/ConfirmationModal.cypress.spec.tsx +0 -171
  54. package/src/components/SortableEntriesList/SortableEntriesList.cypress.spec.tsx +0 -792
  55. package/src/components/Tabs/Tabs.cypress.spec.tsx +0 -69
  56. package/src/utils/useFullscreen/Fullscreen.cypress.spec.tsx +0 -130
  57. package/src/utils/useLocale/useLocale.cypress.spec.tsx +0 -40
@@ -0,0 +1,257 @@
1
+ import Delete from '@mui/icons-material/Delete';
2
+ import { Box } from '@mui/material';
3
+
4
+ import { rs } from '@rstest/core';
5
+ import { render } from '@test-setup/render';
6
+ import { screen, within } from '@testing-library/react';
7
+
8
+ import { IconButton } from '../..';
9
+ import { ColumnType, type RowRecord } from '../../Listing/models';
10
+ import { DataTable } from '.';
11
+
12
+ interface Entity {
13
+ description: string;
14
+ id: number;
15
+ title: string;
16
+ }
17
+
18
+ const data: Array<Entity> = Array(5)
19
+ .fill(0)
20
+ .map((_, idx) => ({
21
+ description: `Description ${idx}`,
22
+ id: idx,
23
+ title: `Entity ${idx}`
24
+ }));
25
+
26
+ const CardActions = (): JSX.Element => {
27
+ return (
28
+ <IconButton ariaLabel="Delete" onClick={rs.fn()} title="Delete">
29
+ <Delete fontSize="small" />
30
+ </IconButton>
31
+ );
32
+ };
33
+
34
+ interface InitializeDataTableGridProps {
35
+ hasActions: boolean;
36
+ hasCardAction: boolean;
37
+ }
38
+
39
+ const initializeDataTableGrid = ({
40
+ hasActions,
41
+ hasCardAction
42
+ }: InitializeDataTableGridProps): void => {
43
+ // A 1200px-wide parent: the viewport width is fixed.
44
+ render(
45
+ <div style={{ width: 1200 }}>
46
+ <DataTable variant="grid">
47
+ {data.map(({ title, description }) => (
48
+ <DataTable.Item
49
+ Actions={<CardActions />}
50
+ description={description}
51
+ hasActions={hasActions}
52
+ hasCardAction={hasCardAction}
53
+ key={title}
54
+ title={title}
55
+ />
56
+ ))}
57
+ </DataTable>
58
+ </div>
59
+ );
60
+ };
61
+
62
+ const initializeDataTableEmpty = (canCreate = false): void => {
63
+ render(
64
+ <DataTable isEmpty variant="grid">
65
+ <DataTable.EmptyState
66
+ canCreate={canCreate}
67
+ labels={{
68
+ actions: {
69
+ create: 'Create'
70
+ },
71
+ description: 'Description',
72
+ title: 'Welcome'
73
+ }}
74
+ onCreate={rs.fn()}
75
+ />
76
+ </DataTable>
77
+ );
78
+ };
79
+
80
+ const initializeDataTableListing = (): void => {
81
+ render(
82
+ <Box sx={{ height: '100vh' }}>
83
+ <DataTable variant="listing">
84
+ <DataTable.Listing
85
+ columns={[
86
+ {
87
+ getFormattedString: (row: RowRecord): string =>
88
+ (row as unknown as Entity).title,
89
+ id: 'title',
90
+ label: 'Title',
91
+ type: ColumnType.string
92
+ },
93
+ {
94
+ getFormattedString: (row: RowRecord): string =>
95
+ (row as unknown as Entity).description,
96
+ id: 'description',
97
+ label: 'Description',
98
+ type: ColumnType.string
99
+ }
100
+ ]}
101
+ rows={data}
102
+ />
103
+ </DataTable>
104
+ </Box>
105
+ );
106
+ };
107
+
108
+ const getCards = (): Array<HTMLElement> =>
109
+ Array.from(document.querySelectorAll<HTMLElement>('[data-item-title]'));
110
+
111
+ // The cards in order, each with its title and description, laid out as a grid.
112
+ const expectCardsInOrder = (): void => {
113
+ const cards = getCards();
114
+
115
+ expect(cards.map((card) => card.dataset.itemTitle)).toEqual(
116
+ data.map(({ title }) => title)
117
+ );
118
+ cards.forEach((card, index) => {
119
+ expect(within(card).getByText(data[index].title)).toBeVisible();
120
+ expect(within(card).getByText(data[index].description)).toBeVisible();
121
+ });
122
+
123
+ // A grid: equal cards, several per row, the last ones wrapping onto a
124
+ // second row, in reading order.
125
+ const boxes = cards.map((card) => card.getBoundingClientRect());
126
+ const columns = boxes.filter(({ top }) => top === boxes[0].top).length;
127
+
128
+ expect(columns).toBeGreaterThan(1);
129
+ expect(columns).toBeLessThan(boxes.length);
130
+ boxes.forEach((box, index) => {
131
+ const column = index % columns;
132
+ const row = Math.floor(index / columns);
133
+
134
+ expect(box.width).toBe(boxes[0].width);
135
+ expect(box.left).toBe(boxes[column].left);
136
+ expect(box.top).toBe(boxes[row * columns].top);
137
+ expect(box.top).toBeGreaterThanOrEqual(
138
+ boxes[0].top + row * boxes[0].height
139
+ );
140
+ });
141
+ };
142
+
143
+ describe('DataTable: Grid', () => {
144
+ beforeEach(() => {
145
+ expect.hasAssertions();
146
+ });
147
+
148
+ it('displays items with title and description only', async () => {
149
+ initializeDataTableGrid({
150
+ hasActions: false,
151
+ hasCardAction: false
152
+ });
153
+
154
+ for (const { title, description } of data) {
155
+ expect(await screen.findByText(title)).toBeVisible();
156
+ expect(screen.getByText(description)).toBeVisible();
157
+ }
158
+
159
+ expectCardsInOrder();
160
+ expect(screen.queryByLabelText('Delete')).not.toBeInTheDocument();
161
+ expect(screen.queryByLabelText('view')).not.toBeInTheDocument();
162
+ });
163
+
164
+ it('displays items with actions', async () => {
165
+ initializeDataTableGrid({
166
+ hasActions: true,
167
+ hasCardAction: false
168
+ });
169
+
170
+ expect(await screen.findAllByLabelText('Delete')).toHaveLength(5);
171
+
172
+ expectCardsInOrder();
173
+ getCards().forEach((card) => {
174
+ expect(within(card).getByLabelText('Delete')).toBeVisible();
175
+ });
176
+ expect(screen.queryByLabelText('view')).not.toBeInTheDocument();
177
+ });
178
+
179
+ it('displays items with card action only', async () => {
180
+ initializeDataTableGrid({
181
+ hasActions: false,
182
+ hasCardAction: true
183
+ });
184
+
185
+ expect(await screen.findAllByLabelText('view')).toHaveLength(5);
186
+
187
+ expectCardsInOrder();
188
+ expect(screen.queryByLabelText('Delete')).not.toBeInTheDocument();
189
+ });
190
+
191
+ it('displays items with card action and bottom actions', async () => {
192
+ initializeDataTableGrid({
193
+ hasActions: true,
194
+ hasCardAction: true
195
+ });
196
+
197
+ expect(await screen.findAllByLabelText('view')).toHaveLength(5);
198
+ expect(screen.getAllByLabelText('Delete')).toHaveLength(5);
199
+
200
+ expectCardsInOrder();
201
+ getCards().forEach((card) => {
202
+ expect(within(card).getByLabelText('view')).toBeVisible();
203
+ expect(within(card).getByLabelText('Delete')).toBeVisible();
204
+ });
205
+ });
206
+ });
207
+
208
+ describe('DataTable: Empty', () => {
209
+ beforeEach(() => {
210
+ expect.hasAssertions();
211
+ });
212
+
213
+ it('displays the title', async () => {
214
+ initializeDataTableEmpty();
215
+
216
+ expect(await screen.findByText('Welcome')).toBeVisible();
217
+
218
+ expect(screen.getByText('Description')).toBeVisible();
219
+ expect(screen.queryByText('Create')).not.toBeInTheDocument();
220
+ expect(screen.queryByLabelText('create')).not.toBeInTheDocument();
221
+ });
222
+
223
+ it('displays the title and the action button', async () => {
224
+ initializeDataTableEmpty(true);
225
+
226
+ expect(await screen.findByText('Welcome')).toBeVisible();
227
+ expect(screen.getByText('Create')).toBeVisible();
228
+
229
+ expect(screen.getByText('Description')).toBeVisible();
230
+ expect(screen.getByLabelText('create')).toBeEnabled();
231
+ expect(screen.getByLabelText('create')).toHaveTextContent(/^Create$/);
232
+ });
233
+ });
234
+
235
+ describe('DataTable: Listing', () => {
236
+ beforeEach(() => {
237
+ expect.hasAssertions();
238
+ });
239
+
240
+ it('displays the listing', async () => {
241
+ initializeDataTableListing();
242
+
243
+ for (const { title, description } of data) {
244
+ expect(await screen.findByText(title)).toBeVisible();
245
+ expect(screen.getByText(description)).toBeVisible();
246
+ }
247
+
248
+ expect(screen.getByText('Title')).toBeVisible();
249
+ expect(screen.getByText('Description')).toBeVisible();
250
+ const rows = screen.getAllByRole('row');
251
+
252
+ expect(rows).toHaveLength(data.length + 1);
253
+ data.forEach(({ title, description }, index) => {
254
+ expect(rows[index + 1]).toHaveTextContent(`${title}${description}`);
255
+ });
256
+ });
257
+ });