@centreon/ui 26.12.1 → 26.12.3
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.
- package/package.json +6 -3
- package/public/mockServiceWorker.js +31 -8
- package/src/Dashboard/Dashboard.browser.test.tsx +107 -0
- package/src/Form/CollapsibleGroup.tsx +6 -33
- package/src/Form/Form.browser.test.tsx +553 -0
- package/src/Form/Inputs/ExclusiveCheckboxGroup.browser.test.tsx +304 -0
- package/src/Form/Inputs/Grid.tsx +1 -2
- package/src/Form/Inputs/SegmentedButtons.browser.test.tsx +113 -0
- package/src/Form/Inputs/index.tsx +10 -52
- package/src/InputField/Number/Number.browser.test.tsx +109 -0
- package/src/InputField/Select/Autocomplete/Connected/Multi/MultiConnectedAutocompleteField.browser.test.tsx +250 -0
- package/src/Listing/Listing.browser.test.tsx +476 -0
- package/src/Module/Module.browser.test.tsx +145 -0
- package/src/Pagination/Pagination.browser.test.tsx +184 -0
- package/src/RichTextEditor/RichTextEditor.browser.test.tsx +567 -0
- package/src/RichTextEditor/plugins/FloatingLinkEditorPlugin.tsx +3 -1
- package/src/TimePeriods/ResolutionTimePeriod.browser.test.tsx +143 -0
- package/src/TimePeriods/TimePeriods.browser.test.tsx +468 -0
- package/src/Typography/FluidTypography/FluidTypography.browser.test.tsx +54 -0
- package/src/api/useMutationQuery/useMutationQuery.browser.test.tsx +154 -0
- package/src/components/CollapsibleItem/CollapsibleItem.browser.test.tsx +120 -0
- package/src/components/CopyCommand/CopyCommand.browser.test.tsx +287 -0
- package/src/components/CrudPage/CrudPage.browser.test.tsx +659 -0
- package/src/components/DataTable/DataTable.browser.test.tsx +257 -0
- package/src/components/Form/AccessRights/AccessRights.browser.test.tsx +527 -0
- package/src/components/ItemComposition/ItemComposition.browser.test.tsx +172 -0
- package/src/components/Layout/PageLayout.browser.test.tsx +114 -0
- package/src/components/Modal/ConfirmationModal/ConfirmationModal.browser.test.tsx +237 -0
- package/src/components/SortableEntriesList/SortableEntriesList.browser.test.tsx +981 -0
- package/src/components/Tabs/Tabs.browser.test.tsx +115 -0
- package/src/utils/useFullscreen/Fullscreen.browser.test.tsx +176 -0
- package/src/utils/useLocale/useLocale.browser.test.tsx +49 -0
- package/src/utils/useLocaleTimezoneDate/{LocaleTimezoneDate.cypress.spec.tsx → LocaleTimezoneDate.browser.test.tsx} +24 -11
- package/src/Dashboard/Dashboard.cypress.spec.tsx +0 -71
- package/src/Form/Form.cypress.spec.tsx +0 -306
- package/src/Form/Inputs/ExclusiveCheckboxGroup.cypress.spec.tsx +0 -236
- package/src/Form/Inputs/SegmentedButtons.cypress.spec.tsx +0 -101
- package/src/InputField/Number/Number.cypress.spec.tsx +0 -89
- package/src/InputField/Select/Autocomplete/Connected/Multi/MultiConnectedAutocompleteField.cypress.spec.tsx +0 -182
- package/src/Listing/Listing.cypress.spec.tsx +0 -349
- package/src/Module/Module.cypress.spec.tsx +0 -127
- package/src/Pagination/Pagination.cypress.spec.tsx +0 -140
- package/src/RichTextEditor/RichTextEditor.cypress.spec.tsx +0 -408
- package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +0 -74
- package/src/TimePeriods/TimePeriods.cypress.spec.tsx +0 -488
- package/src/Typography/FluidTypography/FluidTypography.cypress.spec.tsx +0 -27
- package/src/api/useMutationQuery/useMutationQuery.cypress.spec.tsx +0 -93
- package/src/components/CollapsibleItem/CollapsibleItem.cypress.spec.tsx +0 -76
- package/src/components/CopyCommand/CopyCommand.cypress.spec.tsx +0 -167
- package/src/components/CrudPage/CrudPage.cypress.spec.tsx +0 -561
- package/src/components/DataTable/DataTable.cypress.spec.tsx +0 -174
- package/src/components/Form/AccessRights/AccessRights.cypress.spec.tsx +0 -376
- package/src/components/ItemComposition/ItemComposition.cypress.spec.tsx +0 -112
- package/src/components/Layout/PageLayout.cypress.spec.tsx +0 -64
- package/src/components/Modal/ConfirmationModal/ConfirmationModal.cypress.spec.tsx +0 -171
- package/src/components/SortableEntriesList/SortableEntriesList.cypress.spec.tsx +0 -792
- package/src/components/Tabs/Tabs.cypress.spec.tsx +0 -69
- package/src/utils/useFullscreen/Fullscreen.cypress.spec.tsx +0 -130
- 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,236 +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
|
-
variant
|
|
27
|
-
}: {
|
|
28
|
-
disabled?: boolean;
|
|
29
|
-
notificationOptions?: Array<string> | null;
|
|
30
|
-
variant?: 'checkboxes' | 'chips';
|
|
31
|
-
} = {}): void => {
|
|
32
|
-
cy.mount({
|
|
33
|
-
Component: (
|
|
34
|
-
<Form
|
|
35
|
-
initialValues={{ notificationOptions }}
|
|
36
|
-
inputs={[
|
|
37
|
-
{
|
|
38
|
-
dataTestId: 'notification-options',
|
|
39
|
-
exclusiveCheckboxGroup: {
|
|
40
|
-
direction: 'horizontal',
|
|
41
|
-
exclusiveLabel: 'No notifications',
|
|
42
|
-
exclusiveOption: 'None',
|
|
43
|
-
options,
|
|
44
|
-
variant
|
|
45
|
-
},
|
|
46
|
-
fieldName: 'notificationOptions',
|
|
47
|
-
getDisabled: () => disabled,
|
|
48
|
-
group: '',
|
|
49
|
-
label: 'Notification options',
|
|
50
|
-
type: InputType.ExclusiveCheckboxGroup
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
custom: { Component: ValueDisplay },
|
|
54
|
-
fieldName: 'value',
|
|
55
|
-
group: '',
|
|
56
|
-
label: 'value',
|
|
57
|
-
type: InputType.Custom
|
|
58
|
-
}
|
|
59
|
-
]}
|
|
60
|
-
submit={cy.stub()}
|
|
61
|
-
validationSchema={object()}
|
|
62
|
-
/>
|
|
63
|
-
)
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const toggle = (): Cypress.Chainable => cy.findByLabelText('No notifications');
|
|
68
|
-
|
|
69
|
-
const expectValue = (value: Array<string> | null): void => {
|
|
70
|
-
cy.findByTestId('value').should('have.text', JSON.stringify(value));
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
describe('Exclusive checkbox group', () => {
|
|
74
|
-
it('displays the toggle and every option except the exclusive one', () => {
|
|
75
|
-
initialize();
|
|
76
|
-
|
|
77
|
-
toggle().should('not.be.checked');
|
|
78
|
-
cy.findByLabelText('Down').should('exist');
|
|
79
|
-
cy.findByLabelText('Unreachable').should('exist');
|
|
80
|
-
cy.findByLabelText('Recovery').should('exist');
|
|
81
|
-
cy.findByLabelText('None').should('not.exist');
|
|
82
|
-
|
|
83
|
-
cy.makeSnapshot();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('keeps the inherited state when nothing is selected', () => {
|
|
87
|
-
initialize();
|
|
88
|
-
|
|
89
|
-
toggle().should('not.be.checked');
|
|
90
|
-
cy.findByLabelText('Down').should('not.be.checked').and('be.enabled');
|
|
91
|
-
expectValue([]);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('treats a null value as the inherited state', () => {
|
|
95
|
-
initialize({ notificationOptions: null });
|
|
96
|
-
|
|
97
|
-
toggle().should('not.be.checked');
|
|
98
|
-
cy.findByLabelText('Down').should('not.be.checked').and('be.enabled');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('displays the exclusive state from the initial value', () => {
|
|
102
|
-
initialize({ notificationOptions: ['None'] });
|
|
103
|
-
|
|
104
|
-
toggle().should('be.checked');
|
|
105
|
-
cy.findByLabelText('Down').should('not.be.checked').and('be.disabled');
|
|
106
|
-
expectValue(['None']);
|
|
107
|
-
|
|
108
|
-
cy.makeSnapshot();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('displays a selection from the initial value', () => {
|
|
112
|
-
initialize({ notificationOptions: ['Down', 'Recovery'] });
|
|
113
|
-
|
|
114
|
-
toggle().should('not.be.checked');
|
|
115
|
-
cy.findByLabelText('Down').should('be.checked');
|
|
116
|
-
cy.findByLabelText('Unreachable').should('not.be.checked');
|
|
117
|
-
cy.findByLabelText('Recovery').should('be.checked');
|
|
118
|
-
expectValue(['Down', 'Recovery']);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('goes from the inherited state to a selection and back', () => {
|
|
122
|
-
initialize();
|
|
123
|
-
|
|
124
|
-
cy.findByLabelText('Down').click();
|
|
125
|
-
cy.findByLabelText('Recovery').click();
|
|
126
|
-
expectValue(['Down', 'Recovery']);
|
|
127
|
-
|
|
128
|
-
cy.findByLabelText('Down').click();
|
|
129
|
-
cy.findByLabelText('Recovery').click();
|
|
130
|
-
expectValue([]);
|
|
131
|
-
toggle().should('not.be.checked');
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('goes from the inherited state to the exclusive state and back', () => {
|
|
135
|
-
initialize();
|
|
136
|
-
|
|
137
|
-
toggle().click();
|
|
138
|
-
toggle().should('be.checked');
|
|
139
|
-
expectValue(['None']);
|
|
140
|
-
|
|
141
|
-
toggle().click();
|
|
142
|
-
toggle().should('not.be.checked');
|
|
143
|
-
expectValue([]);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('clears the selection when the toggle is turned on and leaves it empty when turned off', () => {
|
|
147
|
-
initialize({ notificationOptions: ['Down', 'Recovery'] });
|
|
148
|
-
|
|
149
|
-
toggle().click();
|
|
150
|
-
expectValue(['None']);
|
|
151
|
-
cy.findByLabelText('Down').should('not.be.checked').and('be.disabled');
|
|
152
|
-
cy.findByLabelText('Recovery').should('not.be.checked').and('be.disabled');
|
|
153
|
-
|
|
154
|
-
toggle().click();
|
|
155
|
-
expectValue([]);
|
|
156
|
-
cy.findByLabelText('Down').should('not.be.checked').and('be.enabled');
|
|
157
|
-
|
|
158
|
-
cy.findByLabelText('Unreachable').click();
|
|
159
|
-
expectValue(['Unreachable']);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('prevents ticking a box while the toggle is on', () => {
|
|
163
|
-
initialize({ notificationOptions: ['None'] });
|
|
164
|
-
|
|
165
|
-
cy.findByLabelText('Down').click({ force: true });
|
|
166
|
-
cy.findByLabelText('Down').should('not.be.checked');
|
|
167
|
-
expectValue(['None']);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('disables both the toggle and the checkboxes when the input is disabled', () => {
|
|
171
|
-
initialize({ disabled: true, notificationOptions: ['Down'] });
|
|
172
|
-
|
|
173
|
-
toggle().should('be.disabled');
|
|
174
|
-
cy.findByLabelText('Down').should('be.checked').and('be.disabled');
|
|
175
|
-
expectValue(['Down']);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe('Exclusive checkbox group, as chips', () => {
|
|
180
|
-
const chip = (option: string): Cypress.Chainable =>
|
|
181
|
-
cy.findByTestId(`notification-options-${option}`);
|
|
182
|
-
|
|
183
|
-
it('displays the options as chips and the exclusive one as the toggle', () => {
|
|
184
|
-
initialize({ variant: 'chips' });
|
|
185
|
-
|
|
186
|
-
['Down', 'Unreachable', 'Recovery'].forEach((option) => {
|
|
187
|
-
chip(option).should('have.attr', 'aria-pressed', 'false');
|
|
188
|
-
});
|
|
189
|
-
chip('None').should('not.exist');
|
|
190
|
-
toggle().should('not.be.checked');
|
|
191
|
-
cy.findByRole('checkbox', { name: 'Down' }).should('not.exist');
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('toggles a chip on and off', () => {
|
|
195
|
-
initialize({ variant: 'chips' });
|
|
196
|
-
|
|
197
|
-
chip('Down').click();
|
|
198
|
-
chip('Recovery').click();
|
|
199
|
-
|
|
200
|
-
expectValue(['Down', 'Recovery']);
|
|
201
|
-
chip('Down').should('have.attr', 'aria-pressed', 'true');
|
|
202
|
-
|
|
203
|
-
chip('Down').click();
|
|
204
|
-
|
|
205
|
-
expectValue(['Recovery']);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('clears and disables the chips while the toggle is on', () => {
|
|
209
|
-
initialize({ notificationOptions: ['Down', 'Recovery'], variant: 'chips' });
|
|
210
|
-
|
|
211
|
-
toggle().click();
|
|
212
|
-
|
|
213
|
-
expectValue(['None']);
|
|
214
|
-
chip('Down')
|
|
215
|
-
.should('have.attr', 'aria-pressed', 'false')
|
|
216
|
-
.and('have.attr', 'aria-disabled', 'true');
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('leaves the chips empty and usable once the toggle is off', () => {
|
|
220
|
-
initialize({ notificationOptions: ['None'], variant: 'chips' });
|
|
221
|
-
|
|
222
|
-
toggle().click();
|
|
223
|
-
|
|
224
|
-
expectValue([]);
|
|
225
|
-
chip('Unreachable').click();
|
|
226
|
-
|
|
227
|
-
expectValue(['Unreachable']);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('disables the chips and the toggle when the input is disabled', () => {
|
|
231
|
-
initialize({ disabled: true, variant: 'chips' });
|
|
232
|
-
|
|
233
|
-
chip('Down').should('have.attr', 'aria-disabled', 'true');
|
|
234
|
-
toggle().should('be.disabled');
|
|
235
|
-
});
|
|
236
|
-
});
|
|
@@ -1,101 +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 = [
|
|
10
|
-
{ label: 'Yes', value: 'true' },
|
|
11
|
-
{ label: 'No', value: 'false' },
|
|
12
|
-
{ label: 'Default', value: 'use_default' }
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
const ValueDisplay = (): JSX.Element => {
|
|
16
|
-
const { values } = useFormikContext<{ enabled: string }>();
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<Typography data-testid="value">
|
|
20
|
-
{JSON.stringify(values.enabled)}
|
|
21
|
-
</Typography>
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const initialize = ({
|
|
26
|
-
enabled = 'use_default',
|
|
27
|
-
disabled = false
|
|
28
|
-
}: {
|
|
29
|
-
disabled?: boolean;
|
|
30
|
-
enabled?: string;
|
|
31
|
-
} = {}): void => {
|
|
32
|
-
cy.mount({
|
|
33
|
-
Component: (
|
|
34
|
-
<Form
|
|
35
|
-
initialValues={{ enabled }}
|
|
36
|
-
inputs={[
|
|
37
|
-
{
|
|
38
|
-
dataTestId: 'enabled',
|
|
39
|
-
fieldName: 'enabled',
|
|
40
|
-
getDisabled: () => disabled,
|
|
41
|
-
group: '',
|
|
42
|
-
label: 'Notification Enabled',
|
|
43
|
-
segmentedButtons: { options },
|
|
44
|
-
type: InputType.SegmentedButtons
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
custom: { Component: ValueDisplay },
|
|
48
|
-
fieldName: 'value',
|
|
49
|
-
group: '',
|
|
50
|
-
label: 'value',
|
|
51
|
-
type: InputType.Custom
|
|
52
|
-
}
|
|
53
|
-
]}
|
|
54
|
-
submit={cy.stub()}
|
|
55
|
-
validationSchema={object()}
|
|
56
|
-
/>
|
|
57
|
-
)
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const button = (label: string): Cypress.Chainable =>
|
|
62
|
-
cy.findByRole('button', { name: label });
|
|
63
|
-
|
|
64
|
-
describe('Segmented buttons', () => {
|
|
65
|
-
it('displays every option and marks the current one', () => {
|
|
66
|
-
initialize();
|
|
67
|
-
|
|
68
|
-
cy.contains('Notification Enabled').should('be.visible');
|
|
69
|
-
button('Yes').should('have.attr', 'aria-pressed', 'false');
|
|
70
|
-
button('No').should('have.attr', 'aria-pressed', 'false');
|
|
71
|
-
button('Default').should('have.attr', 'aria-pressed', 'true');
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('stores the value of the clicked option as given', () => {
|
|
75
|
-
initialize();
|
|
76
|
-
|
|
77
|
-
button('Yes').click();
|
|
78
|
-
|
|
79
|
-
// A string, not the boolean the radio would store.
|
|
80
|
-
cy.findByTestId('value').should('have.text', '"true"');
|
|
81
|
-
button('Yes').should('have.attr', 'aria-pressed', 'true');
|
|
82
|
-
button('Default').should('have.attr', 'aria-pressed', 'false');
|
|
83
|
-
|
|
84
|
-
button('No').click();
|
|
85
|
-
|
|
86
|
-
cy.findByTestId('value').should('have.text', '"false"');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('starts on the initial value', () => {
|
|
90
|
-
initialize({ enabled: 'false' });
|
|
91
|
-
|
|
92
|
-
button('No').should('have.attr', 'aria-pressed', 'true');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('does not change when disabled', () => {
|
|
96
|
-
initialize({ disabled: true });
|
|
97
|
-
|
|
98
|
-
button('Yes').should('be.disabled');
|
|
99
|
-
cy.findByTestId('value').should('have.text', '"use_default"');
|
|
100
|
-
});
|
|
101
|
-
});
|