@axinom/mosaic-ui 0.35.0-rc.0 → 0.35.0-rc.10
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/dist/components/DynamicDataList/DynamicDataList.d.ts +5 -14
- package/dist/components/DynamicDataList/DynamicDataList.d.ts.map +1 -1
- package/dist/components/DynamicDataList/DynamicListDataEntry/DynamicListDataEntry.d.ts +3 -1
- package/dist/components/DynamicDataList/DynamicListDataEntry/DynamicListDataEntry.d.ts.map +1 -1
- package/dist/components/DynamicDataList/DynamicListHeader/DynamicListHeader.d.ts +5 -1
- package/dist/components/DynamicDataList/DynamicListHeader/DynamicListHeader.d.ts.map +1 -1
- package/dist/components/DynamicDataList/DynamicListRow/DynamicListRow.d.ts +9 -10
- package/dist/components/DynamicDataList/DynamicListRow/DynamicListRow.d.ts.map +1 -1
- package/dist/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.actions.d.ts +5 -0
- package/dist/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.actions.d.ts.map +1 -0
- package/dist/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.d.ts +4 -0
- package/dist/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.d.ts.map +1 -0
- package/dist/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.init.d.ts +4 -0
- package/dist/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.init.d.ts.map +1 -0
- package/dist/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.types.d.ts +38 -0
- package/dist/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.types.d.ts.map +1 -0
- package/dist/components/DynamicDataList/helpers/DynamicListReducer/index.d.ts +4 -0
- package/dist/components/DynamicDataList/helpers/DynamicListReducer/index.d.ts.map +1 -0
- package/dist/components/DynamicDataList/helpers/generateId.d.ts +6 -0
- package/dist/components/DynamicDataList/helpers/generateId.d.ts.map +1 -0
- package/dist/components/DynamicDataList/helpers/useColumnDefs.d.ts +14 -0
- package/dist/components/DynamicDataList/helpers/useColumnDefs.d.ts.map +1 -0
- package/dist/components/DynamicDataList/helpers/useDataHandler.d.ts +9 -0
- package/dist/components/DynamicDataList/helpers/useDataHandler.d.ts.map +1 -0
- package/dist/components/DynamicDataList/helpers/useRowAnimation.d.ts +12 -0
- package/dist/components/DynamicDataList/helpers/useRowAnimation.d.ts.map +1 -0
- package/dist/components/DynamicDataList/index.d.ts +1 -1
- package/dist/components/DynamicDataList/index.d.ts.map +1 -1
- package/dist/components/List/ListRow/ListRow.d.ts.map +1 -1
- package/dist/components/List/useColumnsSize.d.ts +1 -0
- package/dist/components/List/useColumnsSize.d.ts.map +1 -1
- package/dist/index.es.js +11 -3
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/src/components/DynamicDataList/DynamicDataList.scss +0 -61
- package/src/components/DynamicDataList/DynamicDataList.spec.tsx +126 -393
- package/src/components/DynamicDataList/DynamicDataList.stories.tsx +0 -5
- package/src/components/DynamicDataList/DynamicDataList.tsx +133 -600
- package/src/components/DynamicDataList/DynamicListDataEntry/DynamicListDataEntry.scss +4 -2
- package/src/components/DynamicDataList/DynamicListDataEntry/DynamicListDataEntry.spec.tsx +17 -44
- package/src/components/DynamicDataList/DynamicListDataEntry/DynamicListDataEntry.tsx +15 -22
- package/src/components/DynamicDataList/DynamicListHeader/DynamicListHeader.scss +15 -10
- package/src/components/DynamicDataList/DynamicListHeader/DynamicListHeader.spec.tsx +4 -1
- package/src/components/DynamicDataList/DynamicListHeader/DynamicListHeader.tsx +16 -14
- package/src/components/DynamicDataList/DynamicListRow/DynamicListRow.scss +16 -24
- package/src/components/DynamicDataList/DynamicListRow/DynamicListRow.spec.tsx +26 -253
- package/src/components/DynamicDataList/DynamicListRow/DynamicListRow.tsx +45 -139
- package/src/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.actions.spec.ts +276 -0
- package/src/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.actions.ts +86 -0
- package/src/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.init.spec.ts +118 -0
- package/src/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.init.ts +40 -0
- package/src/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.spec.ts +89 -0
- package/src/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.ts +42 -0
- package/src/components/DynamicDataList/helpers/DynamicListReducer/DynamicListReducer.types.ts +46 -0
- package/src/components/DynamicDataList/helpers/DynamicListReducer/index.ts +3 -0
- package/src/components/DynamicDataList/helpers/generateId.ts +10 -0
- package/src/components/DynamicDataList/helpers/useColumnDefs.ts +56 -0
- package/src/components/DynamicDataList/helpers/useDataHandler.ts +77 -0
- package/src/components/DynamicDataList/helpers/useRowAnimation.tsx +38 -0
- package/src/components/DynamicDataList/index.ts +2 -2
- package/src/components/FormElements/BooleanView/BooleanViewField.scss +2 -2
- package/src/components/FormStation/FormStation.scss +4 -0
- package/src/components/FormStation/FormStation.tsx +2 -2
- package/src/components/List/List.tsx +1 -1
- package/src/components/List/ListRow/ListRow.tsx +56 -50
- package/src/components/List/ListRow/Renderers/BooleanDotRenderer/BooleanDotRenderer.scss +6 -9
- package/src/components/List/ListRow/Renderers/BooleanDotRenderer/BooleanDotRenderer.spec.tsx +2 -2
- package/src/components/List/ListRow/Renderers/BooleanDotRenderer/BooleanDotRenderer.tsx +1 -1
- package/src/components/List/useColumnsSize.ts +20 -3
- package/src/styles/variables.scss +0 -5
- package/src/components/DynamicDataList/DynamicDataList.reposition.spec.tsx +0 -816
|
@@ -1,13 +1,53 @@
|
|
|
1
1
|
import { mount, shallow } from 'enzyme';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { act } from 'react-dom/test-utils';
|
|
4
|
-
import { config } from 'react-transition-group';
|
|
5
|
-
import { Button } from '../Buttons';
|
|
6
4
|
import { DynamicDataList, DynamicDataListProps } from './DynamicDataList';
|
|
7
5
|
import { DynamicListColumn } from './DynamicDataList.model';
|
|
8
6
|
import { DynamicListDataEntry } from './DynamicListDataEntry/DynamicListDataEntry';
|
|
9
7
|
import { DynamicListHeader } from './DynamicListHeader/DynamicListHeader';
|
|
10
8
|
import { DynamicListRow } from './DynamicListRow/DynamicListRow';
|
|
9
|
+
import { useDataHandler } from './helpers/useDataHandler';
|
|
10
|
+
|
|
11
|
+
jest.mock('./helpers/useDataHandler');
|
|
12
|
+
jest.mock('./helpers/generateId', () => ({
|
|
13
|
+
uuid: jest.fn().mockReturnValue('test-uuid'),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
const mockUseDataHandler = useDataHandler as jest.MockedFunction<
|
|
17
|
+
typeof useDataHandler
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
jest.mock('react-beautiful-dnd', () => ({
|
|
21
|
+
Droppable: ({
|
|
22
|
+
children,
|
|
23
|
+
}: {
|
|
24
|
+
children: (provided: any, snapshot: any) => React.ReactNode;
|
|
25
|
+
}) =>
|
|
26
|
+
children(
|
|
27
|
+
{
|
|
28
|
+
draggableProps: {
|
|
29
|
+
style: {},
|
|
30
|
+
},
|
|
31
|
+
innerRef: jest.fn(),
|
|
32
|
+
},
|
|
33
|
+
{},
|
|
34
|
+
),
|
|
35
|
+
Draggable: ({
|
|
36
|
+
children,
|
|
37
|
+
}: {
|
|
38
|
+
children: (provided: any, snapshot: any) => React.ReactNode;
|
|
39
|
+
}) =>
|
|
40
|
+
children(
|
|
41
|
+
{
|
|
42
|
+
draggableProps: {
|
|
43
|
+
style: {},
|
|
44
|
+
},
|
|
45
|
+
innerRef: jest.fn(),
|
|
46
|
+
},
|
|
47
|
+
{},
|
|
48
|
+
),
|
|
49
|
+
DragDropContext: ({ children }: { children: React.ReactNode }) => children,
|
|
50
|
+
}));
|
|
11
51
|
|
|
12
52
|
interface DynamicListTestData {
|
|
13
53
|
id: number;
|
|
@@ -37,11 +77,17 @@ const defaultColumns: DynamicListColumn<DynamicListTestData>[] = [
|
|
|
37
77
|
const defaultProps: DynamicDataListProps<DynamicListTestData> = {
|
|
38
78
|
value: defaultData,
|
|
39
79
|
columns: defaultColumns,
|
|
80
|
+
positionPropertyName: 'position',
|
|
40
81
|
};
|
|
41
82
|
|
|
42
83
|
describe('DynamicDataList', () => {
|
|
43
|
-
|
|
44
|
-
|
|
84
|
+
mockUseDataHandler.mockReturnValue({
|
|
85
|
+
removeItem: jest.fn(),
|
|
86
|
+
addItem: jest.fn(),
|
|
87
|
+
canAddItems: false,
|
|
88
|
+
items: defaultData,
|
|
89
|
+
nextPosition: 2,
|
|
90
|
+
});
|
|
45
91
|
|
|
46
92
|
it('renders the component without crashing', () => {
|
|
47
93
|
const wrapper = shallow(<DynamicDataList {...defaultProps} />);
|
|
@@ -69,10 +115,10 @@ describe('DynamicDataList', () => {
|
|
|
69
115
|
expect(header.prop('positionLabel')).toBe(mockLabel);
|
|
70
116
|
});
|
|
71
117
|
|
|
72
|
-
it(`creates a position column
|
|
73
|
-
const mockColumns = '100px 1fr 1fr
|
|
118
|
+
it(`creates a position column and columns for each property`, () => {
|
|
119
|
+
const mockColumns = '100px 1fr 1fr';
|
|
74
120
|
|
|
75
|
-
const wrapper =
|
|
121
|
+
const wrapper = mount(<DynamicDataList {...defaultProps} />);
|
|
76
122
|
|
|
77
123
|
const header = wrapper.find(DynamicListHeader);
|
|
78
124
|
const row = wrapper.find(DynamicListRow);
|
|
@@ -82,7 +128,7 @@ describe('DynamicDataList', () => {
|
|
|
82
128
|
});
|
|
83
129
|
|
|
84
130
|
it(`does not create a column for position if prop 'allowReordering' is false`, () => {
|
|
85
|
-
const mockColumns = '1fr 1fr
|
|
131
|
+
const mockColumns = '1fr 1fr';
|
|
86
132
|
|
|
87
133
|
const wrapper = shallow(
|
|
88
134
|
<DynamicDataList {...defaultProps} allowReordering={false} />,
|
|
@@ -96,9 +142,9 @@ describe('DynamicDataList', () => {
|
|
|
96
142
|
});
|
|
97
143
|
|
|
98
144
|
it(`create a smaller position column if 'allowDragging' is false`, () => {
|
|
99
|
-
const mockColumns = '
|
|
145
|
+
const mockColumns = '50px 1fr 1fr';
|
|
100
146
|
|
|
101
|
-
const wrapper =
|
|
147
|
+
const wrapper = mount(
|
|
102
148
|
<DynamicDataList
|
|
103
149
|
{...defaultProps}
|
|
104
150
|
allowReordering={true}
|
|
@@ -113,20 +159,6 @@ describe('DynamicDataList', () => {
|
|
|
113
159
|
expect(row.prop('columnSizes')).toBe(mockColumns);
|
|
114
160
|
});
|
|
115
161
|
|
|
116
|
-
it(`does not create a column for the action button if prop 'allowAddAndRemove' is false`, () => {
|
|
117
|
-
const mockColumns = '100px 1fr 1fr';
|
|
118
|
-
|
|
119
|
-
const wrapper = shallow(
|
|
120
|
-
<DynamicDataList {...defaultProps} allowAddAndRemove={false} />,
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
const header = wrapper.find(DynamicListHeader);
|
|
124
|
-
const row = wrapper.find(DynamicListRow);
|
|
125
|
-
|
|
126
|
-
expect(header.prop('columnSizes')).toBe(mockColumns);
|
|
127
|
-
expect(row.prop('columnSizes')).toBe(mockColumns);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
162
|
it(`each button element should have type of 'button'`, () => {
|
|
131
163
|
const wrapper = mount(
|
|
132
164
|
<DynamicDataList {...defaultProps} allowNewData={true} />,
|
|
@@ -170,7 +202,7 @@ describe('DynamicDataList', () => {
|
|
|
170
202
|
position: 3,
|
|
171
203
|
};
|
|
172
204
|
|
|
173
|
-
const wrapper =
|
|
205
|
+
const wrapper = mount(
|
|
174
206
|
<DynamicDataList
|
|
175
207
|
{...defaultProps}
|
|
176
208
|
columns={defaultColumns}
|
|
@@ -184,26 +216,6 @@ describe('DynamicDataList', () => {
|
|
|
184
216
|
expect(row.prop('positionKey')).toBe(mockKey);
|
|
185
217
|
});
|
|
186
218
|
|
|
187
|
-
it(`sets 'allowReordering' prop for DynamicListHeader to false if 'positionKey' prop is undefined`, () => {
|
|
188
|
-
const dataWithPosition: DynamicListTestData = {
|
|
189
|
-
id: 0,
|
|
190
|
-
title: 'fses',
|
|
191
|
-
position: 3,
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const wrapper = shallow(
|
|
195
|
-
<DynamicDataList
|
|
196
|
-
{...defaultProps}
|
|
197
|
-
columns={defaultColumns}
|
|
198
|
-
value={[dataWithPosition]}
|
|
199
|
-
/>,
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
const header = wrapper.find(DynamicListHeader);
|
|
203
|
-
|
|
204
|
-
expect(header.prop('allowReordering')).toBe(false);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
219
|
it(`sets 'allowReordering' prop for DynamicListHeader to true if 'positionPropertyName' prop is set and 'allowReordering' is true`, () => {
|
|
208
220
|
const mockKey = 'position';
|
|
209
221
|
|
|
@@ -249,407 +261,128 @@ describe('DynamicDataList', () => {
|
|
|
249
261
|
expect(header.prop('allowReordering')).toBe(false);
|
|
250
262
|
});
|
|
251
263
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
position
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
const wrapper = shallow(
|
|
260
|
-
<DynamicDataList
|
|
261
|
-
{...defaultProps}
|
|
262
|
-
columns={defaultColumns}
|
|
263
|
-
value={[dataWithPosition]}
|
|
264
|
-
allowReordering={true}
|
|
265
|
-
/>,
|
|
266
|
-
);
|
|
267
|
-
|
|
268
|
-
let row = wrapper.find(DynamicListRow);
|
|
269
|
-
|
|
270
|
-
expect(row.prop('dragging')).toBe(false);
|
|
271
|
-
|
|
272
|
-
// @ts-expect-error not full event args object
|
|
273
|
-
row.prop('onDragStart')?.({}, dataWithPosition.position);
|
|
274
|
-
|
|
275
|
-
wrapper.update();
|
|
276
|
-
|
|
277
|
-
row = wrapper.find(DynamicListRow);
|
|
278
|
-
|
|
279
|
-
expect(row.prop('dragging')).toBe(true);
|
|
280
|
-
|
|
281
|
-
// @ts-expect-error not full event args object
|
|
282
|
-
row.prop('onDragEnd')?.({}, dataWithPosition);
|
|
283
|
-
|
|
284
|
-
wrapper.update();
|
|
285
|
-
|
|
286
|
-
row = wrapper.find(DynamicListRow);
|
|
287
|
-
|
|
288
|
-
expect(row.prop('dragging')).toBe(false);
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
describe('Data entry', () => {
|
|
292
|
-
const mockPos1 = 1;
|
|
293
|
-
const mockPos2 = 2;
|
|
294
|
-
const mockPos3 = 3;
|
|
295
|
-
|
|
296
|
-
const dataWithPositions: DynamicListTestData[] = [
|
|
297
|
-
{ id: 0, title: 'title-0', position: mockPos1 },
|
|
298
|
-
{ id: 1, title: 'title-1', position: mockPos2 },
|
|
299
|
-
{ id: 2, title: 'title-2', position: mockPos3 },
|
|
300
|
-
];
|
|
301
|
-
|
|
302
|
-
it('disables new data entry by default', () => {
|
|
303
|
-
const wrapper = shallow(<DynamicDataList {...defaultProps} />);
|
|
304
|
-
|
|
305
|
-
const dataEntryRow = wrapper.find(DynamicListDataEntry);
|
|
306
|
-
|
|
307
|
-
expect(dataEntryRow.exists()).toBe(false);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it(`allows new data entry if 'allowNewData' is true, 'allowAddAndRemove' prop is set to 'true'(default), and maxItemLimit is not set(default)`, () => {
|
|
311
|
-
const wrapper = shallow(
|
|
312
|
-
<DynamicDataList {...defaultProps} allowNewData={true} />,
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
const dataEntryRow = wrapper.find(DynamicListDataEntry);
|
|
316
|
-
|
|
317
|
-
expect(dataEntryRow.exists()).toBe(true);
|
|
318
|
-
});
|
|
264
|
+
describe('useDataHandler', () => {
|
|
265
|
+
it(`calls the 'useDataHandler' hook with the correct arguments`, () => {
|
|
266
|
+
const changeSpy = jest.fn();
|
|
267
|
+
const addTransformSpy = jest.fn();
|
|
268
|
+
const mockPositionKey = 'position';
|
|
319
269
|
|
|
320
|
-
|
|
321
|
-
const wrapper = shallow(
|
|
270
|
+
mount(
|
|
322
271
|
<DynamicDataList
|
|
323
272
|
{...defaultProps}
|
|
273
|
+
positionPropertyName={mockPositionKey}
|
|
274
|
+
maxItemLimit={10}
|
|
324
275
|
allowNewData={true}
|
|
325
|
-
|
|
276
|
+
onChange={changeSpy}
|
|
277
|
+
onAddTransformData={addTransformSpy}
|
|
326
278
|
/>,
|
|
327
279
|
);
|
|
328
280
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const wrapper = shallow(
|
|
337
|
-
<DynamicDataList
|
|
338
|
-
{...defaultProps}
|
|
339
|
-
allowNewData={true}
|
|
340
|
-
maxItemLimit={0}
|
|
341
|
-
/>,
|
|
281
|
+
expect(useDataHandler).toHaveBeenCalledWith(
|
|
282
|
+
defaultData,
|
|
283
|
+
mockPositionKey,
|
|
284
|
+
10,
|
|
285
|
+
true,
|
|
286
|
+
changeSpy,
|
|
287
|
+
addTransformSpy,
|
|
342
288
|
);
|
|
343
|
-
|
|
344
|
-
const dataEntryRow = wrapper.find(DynamicListDataEntry);
|
|
345
|
-
|
|
346
|
-
expect(currentItemSize).toBe(1);
|
|
347
|
-
expect(dataEntryRow.exists()).toBe(false);
|
|
348
289
|
});
|
|
349
290
|
|
|
350
|
-
it(`
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
<DynamicDataList
|
|
354
|
-
{...defaultProps}
|
|
355
|
-
allowNewData={true}
|
|
356
|
-
maxItemLimit={1}
|
|
357
|
-
/>,
|
|
291
|
+
it(`doesn't show new data entry row if 'canAddItems' is false`, () => {
|
|
292
|
+
const wrapper = mount(
|
|
293
|
+
<DynamicDataList {...defaultProps} allowNewData={true} />,
|
|
358
294
|
);
|
|
359
295
|
|
|
360
296
|
const dataEntryRow = wrapper.find(DynamicListDataEntry);
|
|
361
297
|
|
|
362
|
-
expect(currentItemSize).toBe(1);
|
|
363
298
|
expect(dataEntryRow.exists()).toBe(false);
|
|
364
299
|
});
|
|
365
300
|
|
|
366
|
-
it(`
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
301
|
+
it(`shows new data entry row if 'canAddItems' is true`, () => {
|
|
302
|
+
mockUseDataHandler.mockReturnValue({
|
|
303
|
+
removeItem: jest.fn(),
|
|
304
|
+
addItem: jest.fn(),
|
|
305
|
+
canAddItems: true,
|
|
306
|
+
items: defaultData,
|
|
307
|
+
nextPosition: 2,
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
const wrapper = mount(
|
|
311
|
+
<DynamicDataList {...defaultProps} allowNewData={true} />,
|
|
374
312
|
);
|
|
375
313
|
|
|
376
314
|
const dataEntryRow = wrapper.find(DynamicListDataEntry);
|
|
377
315
|
|
|
378
|
-
expect(currentItemSize).toBe(1);
|
|
379
316
|
expect(dataEntryRow.exists()).toBe(true);
|
|
380
317
|
});
|
|
381
318
|
|
|
382
|
-
it(`
|
|
383
|
-
const
|
|
319
|
+
it(`sets 'newDataPosition' prop for DynamicListDataEntry`, () => {
|
|
320
|
+
const mockLimit = 10;
|
|
384
321
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
positionPropertyName={'position'}
|
|
393
|
-
/>,
|
|
394
|
-
);
|
|
395
|
-
|
|
396
|
-
const dataEntryRow = wrapper.find(DynamicListDataEntry);
|
|
397
|
-
|
|
398
|
-
expect(dataEntryRow.prop('newDataPosition')).toBe(
|
|
399
|
-
(lastDataRow.position ?? 0) + 1,
|
|
400
|
-
);
|
|
401
|
-
});
|
|
322
|
+
mockUseDataHandler.mockReturnValue({
|
|
323
|
+
removeItem: jest.fn(),
|
|
324
|
+
addItem: jest.fn(),
|
|
325
|
+
canAddItems: true,
|
|
326
|
+
items: defaultData,
|
|
327
|
+
nextPosition: mockLimit,
|
|
328
|
+
});
|
|
402
329
|
|
|
403
|
-
|
|
404
|
-
const wrapper = shallow(
|
|
405
|
-
<DynamicDataList
|
|
406
|
-
{...defaultProps}
|
|
407
|
-
allowNewData={true}
|
|
408
|
-
columns={defaultColumns}
|
|
409
|
-
value={[]}
|
|
410
|
-
allowReordering={true}
|
|
411
|
-
/>,
|
|
412
|
-
);
|
|
330
|
+
const wrapper = mount(<DynamicDataList {...defaultProps} />);
|
|
413
331
|
|
|
414
332
|
const dataEntryRow = wrapper.find(DynamicListDataEntry);
|
|
415
333
|
|
|
416
|
-
expect(dataEntryRow.prop('newDataPosition')).toBe(
|
|
334
|
+
expect(dataEntryRow.prop('newDataPosition')).toBe(mockLimit);
|
|
417
335
|
});
|
|
418
336
|
|
|
419
|
-
it('
|
|
420
|
-
const
|
|
421
|
-
const mockNewItem: DynamicListTestData = {
|
|
422
|
-
id: 3,
|
|
423
|
-
title: 'title-3',
|
|
424
|
-
};
|
|
425
|
-
const wrapper = shallow(
|
|
426
|
-
<DynamicDataList
|
|
427
|
-
{...defaultProps}
|
|
428
|
-
allowNewData={true}
|
|
429
|
-
columns={defaultColumns}
|
|
430
|
-
value={dataWithPositions}
|
|
431
|
-
allowReordering={true}
|
|
432
|
-
onChange={addSpy}
|
|
433
|
-
/>,
|
|
434
|
-
);
|
|
435
|
-
|
|
436
|
-
let rows = wrapper.find(DynamicListRow);
|
|
337
|
+
it('calls the addItem function when the add button is clicked', () => {
|
|
338
|
+
const addItemSpy = jest.fn();
|
|
437
339
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
340
|
+
mockUseDataHandler.mockReturnValue({
|
|
341
|
+
removeItem: jest.fn(),
|
|
342
|
+
addItem: addItemSpy,
|
|
343
|
+
canAddItems: true,
|
|
344
|
+
items: defaultData,
|
|
345
|
+
nextPosition: 2,
|
|
444
346
|
});
|
|
445
|
-
wrapper.update();
|
|
446
347
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
expect(addSpy).toHaveBeenCalledTimes(1);
|
|
451
|
-
expect(addSpy).toHaveBeenCalledWith([...dataWithPositions, mockNewItem]);
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
it(`transform new data if 'onAddTransformData' is set`, () => {
|
|
455
|
-
const mockNewItem: DynamicListTestData = {
|
|
456
|
-
id: 3,
|
|
457
|
-
title: 'title-3',
|
|
348
|
+
const mockItem = {
|
|
349
|
+
id: 2,
|
|
350
|
+
title: 'test',
|
|
458
351
|
};
|
|
459
|
-
const mockTransformedItem: DynamicListTestData = {
|
|
460
|
-
id: 3,
|
|
461
|
-
title: 'transformed-title-3',
|
|
462
|
-
};
|
|
463
|
-
const addSpy = jest.fn();
|
|
464
|
-
const transformSpy = jest.fn().mockReturnValueOnce(mockTransformedItem);
|
|
465
|
-
|
|
466
|
-
const wrapper = shallow(
|
|
467
|
-
<DynamicDataList
|
|
468
|
-
{...defaultProps}
|
|
469
|
-
allowNewData={true}
|
|
470
|
-
columns={defaultColumns}
|
|
471
|
-
value={dataWithPositions}
|
|
472
|
-
allowReordering={true}
|
|
473
|
-
onChange={addSpy}
|
|
474
|
-
onAddTransformData={transformSpy}
|
|
475
|
-
/>,
|
|
476
|
-
);
|
|
477
|
-
|
|
478
|
-
let rows = wrapper.find(DynamicListRow);
|
|
479
|
-
|
|
480
|
-
expect(rows).toHaveLength(3);
|
|
481
|
-
|
|
482
|
-
const entryRow = wrapper.find(DynamicListDataEntry);
|
|
483
|
-
|
|
484
|
-
act(() => {
|
|
485
|
-
entryRow.prop('onActionClicked')?.(mockNewItem);
|
|
486
|
-
});
|
|
487
|
-
wrapper.update();
|
|
488
|
-
|
|
489
|
-
rows = wrapper.find(DynamicListRow);
|
|
490
|
-
|
|
491
|
-
expect(rows).toHaveLength(4);
|
|
492
|
-
expect(transformSpy).toHaveBeenCalledTimes(1);
|
|
493
|
-
expect(transformSpy).toHaveBeenCalledWith(mockNewItem);
|
|
494
|
-
expect(addSpy).toHaveBeenCalledWith([
|
|
495
|
-
...dataWithPositions,
|
|
496
|
-
mockTransformedItem,
|
|
497
|
-
]);
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
it('sorts the data using the position parameter', () => {
|
|
501
|
-
const dataWithPositions: DynamicListTestData[] = [
|
|
502
|
-
{ id: 0, title: 'title-0', position: 2 },
|
|
503
|
-
{ id: 1, title: 'title-1', position: 3 },
|
|
504
|
-
{ id: 2, title: 'title-2', position: 1 },
|
|
505
|
-
];
|
|
506
352
|
|
|
507
353
|
const wrapper = mount(
|
|
508
|
-
<DynamicDataList
|
|
509
|
-
{...defaultProps}
|
|
510
|
-
allowNewData={true}
|
|
511
|
-
columns={defaultColumns}
|
|
512
|
-
value={dataWithPositions}
|
|
513
|
-
allowRowDragging={false}
|
|
514
|
-
allowReordering={false}
|
|
515
|
-
positionPropertyName="position"
|
|
516
|
-
/>,
|
|
517
|
-
);
|
|
518
|
-
|
|
519
|
-
const rows = wrapper.find(DynamicListRow);
|
|
520
|
-
|
|
521
|
-
expect(rows).toHaveLength(3);
|
|
522
|
-
|
|
523
|
-
const data = rows.map((row) => row.prop('data'));
|
|
524
|
-
|
|
525
|
-
expect(data).toMatchObject([
|
|
526
|
-
{ id: 2, title: 'title-2', position: 1 },
|
|
527
|
-
{ id: 0, title: 'title-0', position: 2 },
|
|
528
|
-
{ id: 1, title: 'title-1', position: 3 },
|
|
529
|
-
]);
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
describe('deleting items', () => {
|
|
534
|
-
const mockPos1 = 1;
|
|
535
|
-
const mockPos2 = 2;
|
|
536
|
-
const mockPos3 = 3;
|
|
537
|
-
|
|
538
|
-
const dataWithPositions: DynamicListTestData[] = [
|
|
539
|
-
{ id: 0, title: 'title-0', position: mockPos1 },
|
|
540
|
-
{ id: 1, title: 'title-1', position: mockPos2 },
|
|
541
|
-
{ id: 2, title: 'title-2', position: mockPos3 },
|
|
542
|
-
];
|
|
543
|
-
|
|
544
|
-
it('deletes a row when the delete action button is clicked and repositioning is not allowed', () => {
|
|
545
|
-
const deleteSpy = jest.fn();
|
|
546
|
-
const mockEvent = {
|
|
547
|
-
e: 'event',
|
|
548
|
-
};
|
|
549
|
-
const [, mockRow2, mockRow3] = dataWithPositions;
|
|
550
|
-
const wrapper = mount(
|
|
551
|
-
<DynamicDataList
|
|
552
|
-
{...defaultProps}
|
|
553
|
-
allowNewData={true}
|
|
554
|
-
columns={defaultColumns}
|
|
555
|
-
value={dataWithPositions}
|
|
556
|
-
allowRowDragging={false}
|
|
557
|
-
allowReordering={false}
|
|
558
|
-
onChange={deleteSpy}
|
|
559
|
-
/>,
|
|
354
|
+
<DynamicDataList {...defaultProps} allowNewData={true} />,
|
|
560
355
|
);
|
|
561
356
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
expect(rows).toHaveLength(3);
|
|
565
|
-
|
|
566
|
-
const deleteActions = wrapper.find(Button);
|
|
357
|
+
const dataEntryRow = wrapper.find(DynamicListDataEntry);
|
|
567
358
|
|
|
568
359
|
act(() => {
|
|
569
|
-
|
|
570
|
-
deleteActions.at(1).prop('onButtonClicked')?.(mockEvent);
|
|
360
|
+
dataEntryRow.prop('onActionClicked')?.(mockItem);
|
|
571
361
|
});
|
|
572
|
-
wrapper.update();
|
|
573
|
-
|
|
574
|
-
rows = wrapper.find(DynamicListRow);
|
|
575
362
|
|
|
576
|
-
expect(
|
|
577
|
-
expect(deleteSpy).toHaveBeenCalledTimes(1);
|
|
578
|
-
expect(deleteSpy).toHaveBeenCalledWith([mockRow2, mockRow3]);
|
|
363
|
+
expect(addItemSpy).toHaveBeenCalledWith(mockItem);
|
|
579
364
|
});
|
|
580
365
|
|
|
581
|
-
it('
|
|
582
|
-
const
|
|
583
|
-
e: 'event',
|
|
584
|
-
};
|
|
585
|
-
const deleteSpy = jest.fn();
|
|
586
|
-
const [, mockRow2, mockRow3] = dataWithPositions;
|
|
587
|
-
const wrapper = mount(
|
|
588
|
-
<DynamicDataList
|
|
589
|
-
{...defaultProps}
|
|
590
|
-
allowNewData={true}
|
|
591
|
-
columns={defaultColumns}
|
|
592
|
-
value={dataWithPositions}
|
|
593
|
-
positionPropertyName={'position'}
|
|
594
|
-
allowRowDragging={true}
|
|
595
|
-
allowReordering={true}
|
|
596
|
-
onChange={deleteSpy}
|
|
597
|
-
/>,
|
|
598
|
-
);
|
|
366
|
+
it('calls the removeItem function when the delete button is clicked', () => {
|
|
367
|
+
const removeItemSpy = jest.fn();
|
|
599
368
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
act(() => {
|
|
607
|
-
// @ts-expect-error not full event args object
|
|
608
|
-
deleteActions.at(1).prop('onButtonClicked')?.(mockEvent);
|
|
369
|
+
mockUseDataHandler.mockReturnValue({
|
|
370
|
+
removeItem: removeItemSpy,
|
|
371
|
+
addItem: jest.fn(),
|
|
372
|
+
canAddItems: true,
|
|
373
|
+
items: defaultData,
|
|
374
|
+
nextPosition: 2,
|
|
609
375
|
});
|
|
610
|
-
wrapper.update();
|
|
611
376
|
|
|
612
|
-
|
|
377
|
+
const wrapper = mount(<DynamicDataList {...defaultProps} />);
|
|
613
378
|
|
|
614
|
-
|
|
615
|
-
expect(deleteSpy).toHaveBeenCalledTimes(1);
|
|
616
|
-
expect(deleteSpy).toHaveBeenCalledWith([
|
|
617
|
-
{ ...mockRow2, position: mockPos1 },
|
|
618
|
-
{ ...mockRow3, position: mockPos2 },
|
|
619
|
-
]);
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
it(`data entry row's position should always be after the new last item's position after deleting the previous last item`, () => {
|
|
623
|
-
const mockEvent = {
|
|
624
|
-
e: 'event',
|
|
625
|
-
};
|
|
626
|
-
|
|
627
|
-
const wrapper = mount(
|
|
628
|
-
<DynamicDataList
|
|
629
|
-
{...defaultProps}
|
|
630
|
-
allowNewData={true}
|
|
631
|
-
columns={defaultColumns}
|
|
632
|
-
value={dataWithPositions}
|
|
633
|
-
positionPropertyName={'position'}
|
|
634
|
-
allowReordering={true}
|
|
635
|
-
/>,
|
|
636
|
-
);
|
|
637
|
-
|
|
638
|
-
const deleteActions = wrapper.find(Button);
|
|
639
|
-
|
|
640
|
-
let dataEntryRow = wrapper.find(DynamicListDataEntry);
|
|
641
|
-
|
|
642
|
-
expect(dataEntryRow.prop('newDataPosition')).toBe(mockPos3 + 1);
|
|
379
|
+
const row = wrapper.find(DynamicListRow);
|
|
643
380
|
|
|
644
381
|
act(() => {
|
|
645
|
-
|
|
646
|
-
deleteActions.at(2).prop('onButtonClicked')?.(mockEvent);
|
|
382
|
+
row.prop('onActionClicked')?.(defaultData[0]);
|
|
647
383
|
});
|
|
648
|
-
wrapper.update();
|
|
649
|
-
|
|
650
|
-
dataEntryRow = wrapper.find(DynamicListDataEntry);
|
|
651
384
|
|
|
652
|
-
expect(
|
|
385
|
+
expect(removeItemSpy).toHaveBeenCalledWith(defaultData[0]);
|
|
653
386
|
});
|
|
654
387
|
});
|
|
655
388
|
});
|