@centreon/ui 24.11.2 → 24.11.4
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 +2 -3
- package/src/Dashboard/Dashboard.styles.ts +4 -3
- package/src/Dashboard/DashboardLayout.stories.tsx +1 -1
- package/src/Dashboard/Grid.tsx +17 -11
- package/src/Dashboard/Layout.tsx +56 -27
- package/src/FileDropZone/index.tsx +21 -23
- package/src/Form/CollapsibleGroup.tsx +3 -2
- package/src/Form/Form.cypress.spec.tsx +39 -0
- package/src/Form/Form.tsx +1 -0
- package/src/Form/Inputs/Autocomplete.tsx +27 -4
- package/src/Form/Inputs/ConnectedAutocomplete.tsx +20 -10
- package/src/Form/Inputs/File.tsx +69 -0
- package/src/Form/Inputs/Grid.tsx +30 -2
- package/src/Form/Inputs/Radio.tsx +12 -4
- package/src/Form/Inputs/Switch.tsx +10 -2
- package/src/Form/Inputs/Text.tsx +13 -4
- package/src/Form/Inputs/index.tsx +5 -2
- package/src/Form/Inputs/models.ts +18 -2
- package/src/Form/storiesData.tsx +15 -3
- package/src/Form/translatedLabels.ts +1 -0
- package/src/Graph/BarChart/BarChart.tsx +4 -1
- package/src/Graph/BarChart/ResponsiveBarChart.tsx +3 -2
- package/src/Graph/Chart/Chart.tsx +9 -2
- package/src/Graph/Chart/InteractiveComponents/AnchorPoint/useTickGraph.ts +2 -2
- package/src/Graph/Chart/InteractiveComponents/index.tsx +10 -2
- package/src/Graph/Chart/helpers/index.ts +5 -5
- package/src/Graph/Chart/index.tsx +7 -0
- package/src/Graph/Chart/models.ts +1 -0
- package/src/Graph/common/timeSeries/index.ts +15 -8
- package/src/InputField/Text/index.tsx +1 -1
- package/src/Listing/index.tsx +39 -27
- package/src/Listing/models.ts +8 -0
- package/src/MultiSelectEntries/index.tsx +0 -2
- package/src/PopoverMenu/index.tsx +9 -2
- package/src/SortableItems/index.tsx +1 -0
- package/src/ThemeProvider/index.tsx +1 -1
- package/src/ThemeProvider/palettes.ts +4 -4
- package/src/api/customFetch.ts +4 -1
- package/src/components/CrudPage/Actions/Actions.styles.ts +16 -0
- package/src/components/CrudPage/Actions/Actions.tsx +24 -0
- package/src/components/CrudPage/Actions/AddButton.tsx +23 -0
- package/src/components/CrudPage/Actions/Filters.tsx +25 -0
- package/src/components/CrudPage/Actions/Search.tsx +31 -0
- package/src/components/CrudPage/Actions/useSearch.tsx +24 -0
- package/src/components/CrudPage/Columns/Actions.tsx +88 -0
- package/src/components/CrudPage/CrudPage.cypress.spec.tsx +559 -0
- package/src/components/CrudPage/CrudPage.stories.tsx +278 -0
- package/src/components/CrudPage/CrudPageRoot.tsx +142 -0
- package/src/components/CrudPage/DeleteModal.tsx +77 -0
- package/src/components/CrudPage/Form/AddModal.tsx +35 -0
- package/src/components/CrudPage/Form/Buttons.tsx +98 -0
- package/src/components/CrudPage/Form/UpdateModal.tsx +60 -0
- package/src/components/CrudPage/Listing.tsx +63 -0
- package/src/components/CrudPage/atoms.ts +30 -0
- package/src/components/CrudPage/hooks/useDeleteItem.ts +53 -0
- package/src/components/CrudPage/hooks/useGetItem.ts +36 -0
- package/src/components/CrudPage/hooks/useGetItems.ts +67 -0
- package/src/components/CrudPage/hooks/useListingQueryKey.ts +31 -0
- package/src/components/CrudPage/index.tsx +7 -0
- package/src/components/CrudPage/models.ts +118 -0
- package/src/components/CrudPage/utils.ts +4 -0
- package/src/components/DataTable/DataTable.cypress.spec.tsx +2 -1
- package/src/components/DataTable/DataTable.stories.tsx +17 -0
- package/src/components/DataTable/DataTable.styles.ts +1 -1
- package/src/components/DataTable/EmptyState/DataTableEmptyState.styles.ts +3 -1
- package/src/components/DataTable/EmptyState/DataTableEmptyState.tsx +6 -0
- package/src/components/DataTable/Item/DataTableItem.styles.ts +28 -2
- package/src/components/DataTable/Item/DataTableItem.tsx +19 -4
- package/src/components/Layout/AreaIndicator.tsx +1 -1
- package/src/components/Layout/PageLayout/PageLayout.styles.ts +7 -2
- package/src/components/Layout/PageLayout/PageLayoutBody.tsx +1 -0
- package/src/components/Modal/Modal.styles.ts +1 -1
- package/src/components/Zoom/Zoom.tsx +2 -2
- package/src/components/Zoom/ZoomContent.tsx +2 -2
- package/src/components/index.ts +1 -0
|
@@ -0,0 +1,559 @@
|
|
|
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
|
+
});
|