@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,306 +0,0 @@
1
- import { Typography } from '@mui/material';
2
-
3
- import { faker } from '@faker-js/faker';
4
- import { useFormikContext } from 'formik';
5
- import { object } from 'yup';
6
-
7
- import { Button } from '../components';
8
- import { Form } from './Form';
9
- import { InputType } from './Inputs/models';
10
-
11
- faker.seed(42);
12
-
13
- const AddItem = ({ addItem }: { addItem: (item) => void }): JSX.Element => {
14
- const { values } = useFormikContext();
15
- const add = (): void => {
16
- addItem({
17
- alias: faker.company.name(),
18
- id: values.list.length,
19
- name: faker.person.firstName()
20
- });
21
- };
22
-
23
- return (
24
- <Button onClick={add} variant="ghost">
25
- Add item
26
- </Button>
27
- );
28
- };
29
-
30
- const SortContent = ({
31
- name,
32
- alias
33
- }: {
34
- alias: string;
35
- name: string;
36
- }): JSX.Element => (
37
- <Typography>
38
- {name} ({alias})
39
- </Typography>
40
- );
41
-
42
- const initializeFormList = (): void => {
43
- cy.mount({
44
- Component: (
45
- <Form
46
- initialValues={{
47
- list: []
48
- }}
49
- inputs={[
50
- {
51
- fieldName: 'list',
52
- group: '',
53
- label: '',
54
- list: {
55
- AddItem,
56
- addItemLabel: 'Add an item to the list',
57
- itemProps: ['id', 'name', 'alias'],
58
- SortContent,
59
- sortLabel: 'Sort items'
60
- },
61
- type: InputType.List
62
- }
63
- ]}
64
- submit={cy.stub()}
65
- validationSchema={object()}
66
- />
67
- )
68
- });
69
- };
70
-
71
- describe('Form list', () => {
72
- beforeEach(initializeFormList);
73
-
74
- it('adds an element to the list', () => {
75
- cy.contains('Add an item to the list').should('be.visible');
76
- cy.contains('Sort items').should('be.visible');
77
-
78
- cy.contains('Add item').click();
79
-
80
- cy.findByLabelText('sort-0').should('be.visible');
81
- cy.findByLabelText('delete-0').should('be.visible');
82
- cy.contains('Lavinia (Wiegand LLC)').should('be.visible');
83
-
84
- cy.makeSnapshot();
85
- });
86
-
87
- it('sorts elements in the list', () => {
88
- cy.contains('Add an item to the list').should('be.visible');
89
- cy.contains('Sort items').should('be.visible');
90
-
91
- cy.contains('Add item').click();
92
- cy.contains('Add item').click();
93
-
94
- cy.findByLabelText('sort-0').should('be.visible');
95
- cy.findByLabelText('delete-0').should('be.visible');
96
- cy.contains('Sammie (Crist - Beer)').should('be.visible');
97
- cy.findByLabelText('sort-1').should('be.visible');
98
- cy.findByLabelText('delete-1').should('be.visible');
99
- cy.contains('Waino (Quigley Group)').should('be.visible');
100
-
101
- cy.moveSortableElementUsingAriaLabel({
102
- ariaLabel: 'sort-0',
103
- direction: 'down'
104
- });
105
-
106
- cy.contains('Waino (Quigley Group)').should('be.visible');
107
- cy.contains('Sammie (Crist - Beer)').should('be.visible');
108
-
109
- cy.makeSnapshot();
110
- });
111
-
112
- it('removes an element from the list', () => {
113
- cy.contains('Add an item to the list').should('be.visible');
114
- cy.contains('Sort items').should('be.visible');
115
-
116
- cy.contains('Add item').click();
117
- cy.contains('Add item').click();
118
-
119
- cy.findByLabelText('sort-0').should('be.visible');
120
- cy.findByLabelText('delete-0').should('be.visible');
121
- cy.contains('Elliott (Effertz, Deckow and Deckow)').should('be.visible');
122
- cy.findByLabelText('sort-1').should('be.visible');
123
- cy.findByLabelText('delete-1').should('be.visible');
124
- cy.contains('Leopoldo (Kemmer Inc)').should('be.visible');
125
-
126
- cy.findByLabelText('delete-0').click();
127
-
128
- cy.contains('Elliott (Effertz, Deckow and Deckow)').should('not.exist');
129
-
130
- cy.makeSnapshot();
131
- });
132
- });
133
-
134
- const initializeFormWithSections = (): void => {
135
- cy.mount({
136
- Component: (
137
- <Form
138
- groups={[
139
- {
140
- name: 'First group',
141
- order: 1
142
- },
143
- {
144
- name: 'Third group',
145
- order: 3
146
- },
147
- {
148
- name: 'Second group',
149
- order: 2
150
- },
151
- {
152
- name: 'Fourth group',
153
- order: 4
154
- }
155
- ]}
156
- initialValues={{
157
- list: []
158
- }}
159
- inputs={[
160
- {
161
- fieldName: 'First name',
162
- group: 'First group',
163
- label: 'Name',
164
- type: InputType.Text
165
- },
166
- {
167
- fieldName: 'Divider',
168
- group: 'First group',
169
- label: 'Divider',
170
- type: InputType.Divider
171
- },
172
- {
173
- fieldName: 'Second name',
174
- group: 'First group',
175
- label: 'Name',
176
- type: InputType.Text
177
- },
178
- {
179
- fieldName: 'Third name',
180
- group: 'First group',
181
- label: 'Name',
182
- type: InputType.Text
183
- },
184
- {
185
- fieldName: 'Fourth name',
186
- group: 'First group',
187
- label: 'Name',
188
- type: InputType.Text
189
- },
190
- {
191
- fieldName: 'Fifth name',
192
- group: 'First group',
193
- label: 'Name',
194
- type: InputType.Text
195
- },
196
- {
197
- fieldName: 'Sixth name',
198
- group: 'First group',
199
- label: 'Name',
200
- type: InputType.Text
201
- },
202
- {
203
- fieldName: 'Seventh name',
204
- group: 'First group',
205
- label: 'Name',
206
- type: InputType.Text
207
- },
208
- {
209
- fieldName: 'Eighth name',
210
- group: 'First group',
211
- label: 'Name',
212
- type: InputType.Text
213
- },
214
- {
215
- fieldName: 'Ninth name',
216
- group: 'First group',
217
- label: 'Name',
218
- type: InputType.Text
219
- },
220
- {
221
- fieldName: 'First second group name',
222
- group: 'Second group',
223
- label: 'Name',
224
- type: InputType.Text
225
- },
226
- {
227
- fieldName: 'First third group name',
228
- group: 'Third group',
229
- label: 'Name',
230
- type: InputType.Text
231
- },
232
- {
233
- fieldName: 'First fourth group name',
234
- group: 'Fourth group',
235
- label: 'Name',
236
- type: InputType.Text
237
- }
238
- ]}
239
- isCollapsible
240
- submit={cy.stub()}
241
- validationSchema={object()}
242
- />
243
- )
244
- });
245
- };
246
-
247
- const initializeFile = () => {
248
- cy.mount({
249
- Component: (
250
- <Form
251
- initialValues={{
252
- list: []
253
- }}
254
- inputs={[
255
- {
256
- fieldName: 'list',
257
- file: {
258
- accept: '.json'
259
- },
260
- group: '',
261
- label: 'json',
262
- type: InputType.File
263
- }
264
- ]}
265
- submit={cy.stub()}
266
- validationSchema={object()}
267
- />
268
- )
269
- });
270
- };
271
-
272
- describe('File', () => {
273
- it('uploads a file when a file is selected', () => {
274
- initializeFile();
275
-
276
- cy.contains('Drop or select a file').should('be.visible');
277
- cy.findByLabelText('select a file').selectFile('package.json', {
278
- force: true
279
- });
280
- cy.contains('package.json').should('be.visible');
281
-
282
- cy.makeSnapshot();
283
- });
284
- });
285
-
286
- describe('Form with sections', () => {
287
- beforeEach(initializeFormWithSections);
288
- it('displays sections when correct amount of sections', () => {
289
- cy.contains('First group').should('be.visible');
290
- cy.contains('Second group').should('be.visible');
291
- cy.contains('Third group').should('be.visible');
292
- cy.contains('Fourth group').should('be.visible');
293
- cy.makeSnapshot();
294
- });
295
-
296
- it('scrolls correctly to section', () => {
297
- cy.window().then((win) => {
298
- const initialScrollY = win.scrollY;
299
- cy.contains('Third group').click();
300
- cy.window().its('scrollY').should('be.greaterThan', initialScrollY);
301
- });
302
-
303
- cy.wait(500); // Wait for the scroll animation to complete
304
- cy.makeSnapshot();
305
- });
306
- });
@@ -1,174 +0,0 @@
1
- import { Typography } from '@mui/material';
2
-
3
- import { useFormikContext } from 'formik';
4
- import { object } from 'yup';
5
-
6
- import { Form } from '../Form';
7
- import { InputType } from './models';
8
-
9
- const options = ['Down', 'Unreachable', 'Recovery', 'None'];
10
-
11
- const ValueDisplay = (): JSX.Element => {
12
- const { values } = useFormikContext<{
13
- notificationOptions: Array<string> | null;
14
- }>();
15
-
16
- return (
17
- <Typography data-testid="value">
18
- {JSON.stringify(values.notificationOptions)}
19
- </Typography>
20
- );
21
- };
22
-
23
- const initialize = ({
24
- notificationOptions = [],
25
- disabled = false
26
- }: {
27
- disabled?: boolean;
28
- notificationOptions?: Array<string> | null;
29
- } = {}): void => {
30
- cy.mount({
31
- Component: (
32
- <Form
33
- initialValues={{ notificationOptions }}
34
- inputs={[
35
- {
36
- dataTestId: 'notification-options',
37
- exclusiveCheckboxGroup: {
38
- direction: 'horizontal',
39
- exclusiveLabel: 'No notifications',
40
- exclusiveOption: 'None',
41
- options
42
- },
43
- fieldName: 'notificationOptions',
44
- getDisabled: () => disabled,
45
- group: '',
46
- label: 'Notification options',
47
- type: InputType.ExclusiveCheckboxGroup
48
- },
49
- {
50
- custom: { Component: ValueDisplay },
51
- fieldName: 'value',
52
- group: '',
53
- label: 'value',
54
- type: InputType.Custom
55
- }
56
- ]}
57
- submit={cy.stub()}
58
- validationSchema={object()}
59
- />
60
- )
61
- });
62
- };
63
-
64
- const toggle = (): Cypress.Chainable => cy.findByLabelText('No notifications');
65
-
66
- const expectValue = (value: Array<string> | null): void => {
67
- cy.findByTestId('value').should('have.text', JSON.stringify(value));
68
- };
69
-
70
- describe('Exclusive checkbox group', () => {
71
- it('displays the toggle and every option except the exclusive one', () => {
72
- initialize();
73
-
74
- toggle().should('not.be.checked');
75
- cy.findByLabelText('Down').should('exist');
76
- cy.findByLabelText('Unreachable').should('exist');
77
- cy.findByLabelText('Recovery').should('exist');
78
- cy.findByLabelText('None').should('not.exist');
79
-
80
- cy.makeSnapshot();
81
- });
82
-
83
- it('keeps the inherited state when nothing is selected', () => {
84
- initialize();
85
-
86
- toggle().should('not.be.checked');
87
- cy.findByLabelText('Down').should('not.be.checked').and('be.enabled');
88
- expectValue([]);
89
- });
90
-
91
- it('treats a null value as the inherited state', () => {
92
- initialize({ notificationOptions: null });
93
-
94
- toggle().should('not.be.checked');
95
- cy.findByLabelText('Down').should('not.be.checked').and('be.enabled');
96
- });
97
-
98
- it('displays the exclusive state from the initial value', () => {
99
- initialize({ notificationOptions: ['None'] });
100
-
101
- toggle().should('be.checked');
102
- cy.findByLabelText('Down').should('not.be.checked').and('be.disabled');
103
- expectValue(['None']);
104
-
105
- cy.makeSnapshot();
106
- });
107
-
108
- it('displays a selection from the initial value', () => {
109
- initialize({ notificationOptions: ['Down', 'Recovery'] });
110
-
111
- toggle().should('not.be.checked');
112
- cy.findByLabelText('Down').should('be.checked');
113
- cy.findByLabelText('Unreachable').should('not.be.checked');
114
- cy.findByLabelText('Recovery').should('be.checked');
115
- expectValue(['Down', 'Recovery']);
116
- });
117
-
118
- it('goes from the inherited state to a selection and back', () => {
119
- initialize();
120
-
121
- cy.findByLabelText('Down').click();
122
- cy.findByLabelText('Recovery').click();
123
- expectValue(['Down', 'Recovery']);
124
-
125
- cy.findByLabelText('Down').click();
126
- cy.findByLabelText('Recovery').click();
127
- expectValue([]);
128
- toggle().should('not.be.checked');
129
- });
130
-
131
- it('goes from the inherited state to the exclusive state and back', () => {
132
- initialize();
133
-
134
- toggle().click();
135
- toggle().should('be.checked');
136
- expectValue(['None']);
137
-
138
- toggle().click();
139
- toggle().should('not.be.checked');
140
- expectValue([]);
141
- });
142
-
143
- it('clears the selection when the toggle is turned on and leaves it empty when turned off', () => {
144
- initialize({ notificationOptions: ['Down', 'Recovery'] });
145
-
146
- toggle().click();
147
- expectValue(['None']);
148
- cy.findByLabelText('Down').should('not.be.checked').and('be.disabled');
149
- cy.findByLabelText('Recovery').should('not.be.checked').and('be.disabled');
150
-
151
- toggle().click();
152
- expectValue([]);
153
- cy.findByLabelText('Down').should('not.be.checked').and('be.enabled');
154
-
155
- cy.findByLabelText('Unreachable').click();
156
- expectValue(['Unreachable']);
157
- });
158
-
159
- it('prevents ticking a box while the toggle is on', () => {
160
- initialize({ notificationOptions: ['None'] });
161
-
162
- cy.findByLabelText('Down').click({ force: true });
163
- cy.findByLabelText('Down').should('not.be.checked');
164
- expectValue(['None']);
165
- });
166
-
167
- it('disables both the toggle and the checkboxes when the input is disabled', () => {
168
- initialize({ disabled: true, notificationOptions: ['Down'] });
169
-
170
- toggle().should('be.disabled');
171
- cy.findByLabelText('Down').should('be.checked').and('be.disabled');
172
- expectValue(['Down']);
173
- });
174
- });
@@ -1,89 +0,0 @@
1
- import NumberField, { type NumberProps } from './Number';
2
-
3
- const initialize = (props: NumberProps): void => {
4
- cy.mount({
5
- Component: <NumberField {...props} />
6
- });
7
- };
8
-
9
- describe('Number field', () => {
10
- it('displays the placeholder when the field has no default or fallback values', () => {
11
- initialize({ dataTestId: 'test', onChange: cy.stub() });
12
-
13
- cy.get('input').should('have.value', '');
14
- cy.get('input').should('have.attr', 'placeholder', '0');
15
-
16
- cy.makeSnapshot();
17
- });
18
-
19
- it('displays the fallback value as placeholder when the field as no default value', () => {
20
- initialize({ dataTestId: 'test', fallbackValue: 25, onChange: cy.stub() });
21
-
22
- cy.get('input').should('have.value', '');
23
- cy.get('input').should('have.attr', 'placeholder', '25');
24
-
25
- cy.makeSnapshot();
26
- });
27
-
28
- it('displays the default value as placeholder when the field as default value', () => {
29
- initialize({ dataTestId: 'test', defaultValue: 25, onChange: cy.stub() });
30
-
31
- cy.get('input').should('have.value', '25');
32
-
33
- cy.makeSnapshot();
34
- });
35
-
36
- it('displays the fallback value when the field is cleared out', () => {
37
- initialize({
38
- dataTestId: 'test',
39
- defaultValue: 25,
40
- fallbackValue: 10,
41
- onChange: cy.stub()
42
- });
43
-
44
- cy.get('input').should('have.value', '25');
45
- cy.get('input').clear();
46
- cy.get('input').should('have.value', '');
47
- cy.get('input').should('have.attr', 'placeholder', '10');
48
-
49
- cy.makeSnapshot();
50
- });
51
-
52
- it('displays the field using auto size', () => {
53
- initialize({
54
- autoSize: true,
55
- dataTestId: 'test',
56
- defaultValue: 25,
57
- onChange: cy.stub()
58
- });
59
-
60
- cy.get('input').should('have.value', '25');
61
-
62
- cy.get('input').type('0');
63
-
64
- cy.makeSnapshot();
65
- });
66
-
67
- it('sets the value to the minimum value configured when a value less than the minimum value is typed in the field', () => {
68
- initialize({
69
- dataTestId: 'test',
70
- defaultValue: 25,
71
- onChange: cy.stub(),
72
- textFieldSlotsAndSlotProps: {
73
- slotProps: {
74
- htmlInput: {
75
- min: 2
76
- }
77
- }
78
- }
79
- });
80
-
81
- cy.get('input').should('have.value', '25');
82
-
83
- cy.get('input').clear().type('-1');
84
-
85
- cy.get('input').should('have.value', '2');
86
-
87
- cy.makeSnapshot();
88
- });
89
- });