@axinom/mosaic-ui 0.35.0-rc.6 → 0.35.0-rc.8
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/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/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/styles/variables.scss +0 -5
- package/src/components/DynamicDataList/DynamicDataList.reposition.spec.tsx +0 -816
|
@@ -1,816 +0,0 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { act } from 'react-dom/test-utils';
|
|
4
|
-
import {
|
|
5
|
-
calculateNewList,
|
|
6
|
-
DynamicDataList,
|
|
7
|
-
DynamicDataListProps,
|
|
8
|
-
removeItemFromList,
|
|
9
|
-
} from './DynamicDataList';
|
|
10
|
-
import { DynamicListColumn } from './DynamicDataList.model';
|
|
11
|
-
import { DynamicListRow } from './DynamicListRow/DynamicListRow';
|
|
12
|
-
|
|
13
|
-
interface DynamicListTestData {
|
|
14
|
-
id: number;
|
|
15
|
-
title: string;
|
|
16
|
-
position?: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const defaultData: DynamicListTestData[] = [
|
|
20
|
-
{
|
|
21
|
-
id: 1,
|
|
22
|
-
title: 'fses',
|
|
23
|
-
position: 1,
|
|
24
|
-
},
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
const defaultColumns: DynamicListColumn<DynamicListTestData>[] = [
|
|
28
|
-
{
|
|
29
|
-
propertyName: 'id',
|
|
30
|
-
label: 'Id',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
propertyName: 'title',
|
|
34
|
-
label: 'Title',
|
|
35
|
-
},
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
const defaultProps: DynamicDataListProps<DynamicListTestData> = {
|
|
39
|
-
value: defaultData,
|
|
40
|
-
columns: defaultColumns,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const mockPos1 = 1;
|
|
44
|
-
const mockPos2 = 2;
|
|
45
|
-
const mockPos3 = 3;
|
|
46
|
-
|
|
47
|
-
const dataWithPositions: DynamicListTestData[] = [
|
|
48
|
-
{ id: 0, title: 'title-0', position: mockPos1 },
|
|
49
|
-
{ id: 1, title: 'title-1', position: mockPos2 },
|
|
50
|
-
{ id: 2, title: 'title-2', position: mockPos3 },
|
|
51
|
-
];
|
|
52
|
-
const [mockRow1, mockRow2, mockRow3] = dataWithPositions;
|
|
53
|
-
|
|
54
|
-
describe('DynamicDataList', () => {
|
|
55
|
-
describe('row dragging', () => {
|
|
56
|
-
it(`doesn't reorder the list if a dragged row's position is the same as the target row's position`, () => {
|
|
57
|
-
const wrapper = shallow(
|
|
58
|
-
<DynamicDataList
|
|
59
|
-
{...defaultProps}
|
|
60
|
-
columns={defaultColumns}
|
|
61
|
-
value={dataWithPositions}
|
|
62
|
-
allowReordering={true}
|
|
63
|
-
allowRowDragging={true}
|
|
64
|
-
/>,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
let rows = wrapper.find(DynamicListRow);
|
|
68
|
-
|
|
69
|
-
expect(rows.at(0).prop('data')).toBe(mockRow1);
|
|
70
|
-
expect(rows.at(1).prop('data')).toBe(mockRow2);
|
|
71
|
-
expect(rows.at(2).prop('data')).toBe(mockRow3);
|
|
72
|
-
|
|
73
|
-
act(() => {
|
|
74
|
-
// @ts-expect-error not full event args object
|
|
75
|
-
rows.last().prop('onDragStart')?.({}, mockRow2);
|
|
76
|
-
});
|
|
77
|
-
wrapper.update();
|
|
78
|
-
|
|
79
|
-
rows = wrapper.find(DynamicListRow);
|
|
80
|
-
|
|
81
|
-
act(() => {
|
|
82
|
-
// @ts-expect-error not full event args object
|
|
83
|
-
rows.first().prop('onDrop')?.({}, mockRow2, 'above');
|
|
84
|
-
});
|
|
85
|
-
wrapper.update();
|
|
86
|
-
|
|
87
|
-
rows = wrapper.find(DynamicListRow);
|
|
88
|
-
|
|
89
|
-
expect(rows.at(0).prop('data')).toBe(mockRow1);
|
|
90
|
-
expect(rows.at(1).prop('data')).toBe(mockRow2);
|
|
91
|
-
expect(rows.at(2).prop('data')).toBe(mockRow3);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it(`emits 'onChange' when the list is reordered`, () => {
|
|
95
|
-
const onChangeSpy = jest.fn();
|
|
96
|
-
const wrapper = shallow(
|
|
97
|
-
<DynamicDataList
|
|
98
|
-
{...defaultProps}
|
|
99
|
-
columns={defaultColumns}
|
|
100
|
-
value={dataWithPositions}
|
|
101
|
-
positionPropertyName={'position'}
|
|
102
|
-
allowReordering={true}
|
|
103
|
-
allowRowDragging={true}
|
|
104
|
-
onChange={onChangeSpy}
|
|
105
|
-
/>,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
let rows = wrapper.find(DynamicListRow);
|
|
109
|
-
|
|
110
|
-
act(() => {
|
|
111
|
-
// @ts-expect-error not full event args object
|
|
112
|
-
rows.last().prop('onDragStart')?.({}, mockPos3);
|
|
113
|
-
});
|
|
114
|
-
wrapper.update();
|
|
115
|
-
|
|
116
|
-
rows = wrapper.find(DynamicListRow);
|
|
117
|
-
|
|
118
|
-
act(() => {
|
|
119
|
-
// @ts-expect-error not full event args object
|
|
120
|
-
rows.first().prop('onDrop')?.({}, mockPos1, 'above');
|
|
121
|
-
});
|
|
122
|
-
wrapper.update();
|
|
123
|
-
|
|
124
|
-
expect(onChangeSpy).toHaveBeenCalledTimes(1);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe('dragging a row upwards', () => {
|
|
128
|
-
it(`replaces target row with dragged row if dragged on the top half of the target row and current row is dragged up`, () => {
|
|
129
|
-
const onChangeSpy = jest.fn();
|
|
130
|
-
const wrapper = shallow(
|
|
131
|
-
<DynamicDataList
|
|
132
|
-
{...defaultProps}
|
|
133
|
-
columns={defaultColumns}
|
|
134
|
-
value={dataWithPositions}
|
|
135
|
-
positionPropertyName={'position'}
|
|
136
|
-
allowReordering={true}
|
|
137
|
-
allowRowDragging={true}
|
|
138
|
-
onChange={onChangeSpy}
|
|
139
|
-
/>,
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
let rows = wrapper.find(DynamicListRow);
|
|
143
|
-
|
|
144
|
-
expect(rows.at(0).prop('data')).toBe(mockRow1);
|
|
145
|
-
expect(rows.at(1).prop('data')).toBe(mockRow2);
|
|
146
|
-
expect(rows.at(2).prop('data')).toBe(mockRow3);
|
|
147
|
-
|
|
148
|
-
act(() => {
|
|
149
|
-
// @ts-expect-error not full event args object
|
|
150
|
-
rows.last().prop('onDragStart')?.({}, mockPos3);
|
|
151
|
-
});
|
|
152
|
-
wrapper.update();
|
|
153
|
-
|
|
154
|
-
rows = wrapper.find(DynamicListRow);
|
|
155
|
-
|
|
156
|
-
act(() => {
|
|
157
|
-
// @ts-expect-error not full event args object
|
|
158
|
-
rows.first().prop('onDrop')?.({}, mockPos1, 'above');
|
|
159
|
-
});
|
|
160
|
-
wrapper.update();
|
|
161
|
-
|
|
162
|
-
rows = wrapper.find(DynamicListRow);
|
|
163
|
-
|
|
164
|
-
expect(rows.at(0).prop('data')).toEqual({
|
|
165
|
-
...mockRow3,
|
|
166
|
-
position: mockPos1,
|
|
167
|
-
});
|
|
168
|
-
expect(rows.at(1).prop('data')).toEqual({
|
|
169
|
-
...mockRow1,
|
|
170
|
-
position: mockPos2,
|
|
171
|
-
});
|
|
172
|
-
expect(rows.at(2).prop('data')).toEqual({
|
|
173
|
-
...mockRow2,
|
|
174
|
-
position: mockPos3,
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
expect(onChangeSpy).toHaveBeenCalledTimes(1);
|
|
178
|
-
expect(onChangeSpy).toHaveBeenCalledWith([
|
|
179
|
-
{ id: 2, position: 1, title: 'title-2' },
|
|
180
|
-
{ id: 0, position: 2, title: 'title-0' },
|
|
181
|
-
{ id: 1, position: 3, title: 'title-1' },
|
|
182
|
-
]);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it(`places dragged row below target row if dragged on the bottom half of the target row and current row is dragged up`, () => {
|
|
186
|
-
const onChangeSpy = jest.fn();
|
|
187
|
-
const wrapper = shallow(
|
|
188
|
-
<DynamicDataList
|
|
189
|
-
{...defaultProps}
|
|
190
|
-
columns={defaultColumns}
|
|
191
|
-
value={dataWithPositions}
|
|
192
|
-
positionPropertyName={'position'}
|
|
193
|
-
allowReordering={true}
|
|
194
|
-
allowRowDragging={true}
|
|
195
|
-
onChange={onChangeSpy}
|
|
196
|
-
/>,
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
let rows = wrapper.find(DynamicListRow);
|
|
200
|
-
|
|
201
|
-
expect(rows.at(0).prop('data')).toBe(mockRow1);
|
|
202
|
-
expect(rows.at(1).prop('data')).toBe(mockRow2);
|
|
203
|
-
expect(rows.at(2).prop('data')).toBe(mockRow3);
|
|
204
|
-
|
|
205
|
-
act(() => {
|
|
206
|
-
// @ts-expect-error not full event args object
|
|
207
|
-
rows.last().prop('onDragStart')?.({}, mockPos3);
|
|
208
|
-
});
|
|
209
|
-
wrapper.update();
|
|
210
|
-
|
|
211
|
-
rows = wrapper.find(DynamicListRow);
|
|
212
|
-
|
|
213
|
-
act(() => {
|
|
214
|
-
// @ts-expect-error not full event args object
|
|
215
|
-
rows.first().prop('onDrop')?.({}, mockPos1, 'below');
|
|
216
|
-
});
|
|
217
|
-
wrapper.update();
|
|
218
|
-
|
|
219
|
-
rows = wrapper.find(DynamicListRow);
|
|
220
|
-
|
|
221
|
-
expect(rows.at(0).prop('data')).toBe(mockRow1);
|
|
222
|
-
expect(rows.at(1).prop('data')).toEqual({
|
|
223
|
-
...mockRow3,
|
|
224
|
-
position: mockPos2,
|
|
225
|
-
});
|
|
226
|
-
expect(rows.at(2).prop('data')).toEqual({
|
|
227
|
-
...mockRow2,
|
|
228
|
-
position: mockPos3,
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
expect(onChangeSpy).toHaveBeenCalledTimes(1);
|
|
232
|
-
expect(onChangeSpy).toHaveBeenCalledWith([
|
|
233
|
-
{ id: 0, position: 1, title: 'title-0' },
|
|
234
|
-
{ id: 2, position: 2, title: 'title-2' },
|
|
235
|
-
{ id: 1, position: 3, title: 'title-1' },
|
|
236
|
-
]);
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
describe('dragging a row downwards', () => {
|
|
241
|
-
it(`places dragged row above target row if dragged on the top half of the target row and current row is dragged down`, () => {
|
|
242
|
-
const onChangeSpy = jest.fn();
|
|
243
|
-
const wrapper = shallow(
|
|
244
|
-
<DynamicDataList
|
|
245
|
-
{...defaultProps}
|
|
246
|
-
columns={defaultColumns}
|
|
247
|
-
value={dataWithPositions}
|
|
248
|
-
positionPropertyName={'position'}
|
|
249
|
-
allowReordering={true}
|
|
250
|
-
allowRowDragging={true}
|
|
251
|
-
onChange={onChangeSpy}
|
|
252
|
-
/>,
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
let rows = wrapper.find(DynamicListRow);
|
|
256
|
-
|
|
257
|
-
expect(rows.at(0).prop('data')).toBe(mockRow1);
|
|
258
|
-
expect(rows.at(1).prop('data')).toBe(mockRow2);
|
|
259
|
-
expect(rows.at(2).prop('data')).toBe(mockRow3);
|
|
260
|
-
|
|
261
|
-
act(() => {
|
|
262
|
-
// @ts-expect-error not full event args object
|
|
263
|
-
rows.first().prop('onDragStart')?.({}, mockPos1);
|
|
264
|
-
});
|
|
265
|
-
wrapper.update();
|
|
266
|
-
|
|
267
|
-
rows = wrapper.find(DynamicListRow);
|
|
268
|
-
|
|
269
|
-
act(() => {
|
|
270
|
-
// @ts-expect-error not full event args object
|
|
271
|
-
rows.last().prop('onDrop')?.({}, mockPos3, 'above');
|
|
272
|
-
});
|
|
273
|
-
wrapper.update();
|
|
274
|
-
|
|
275
|
-
rows = wrapper.find(DynamicListRow);
|
|
276
|
-
|
|
277
|
-
expect(rows.at(0).prop('data')).toEqual({
|
|
278
|
-
...mockRow2,
|
|
279
|
-
position: mockPos1,
|
|
280
|
-
});
|
|
281
|
-
expect(rows.at(1).prop('data')).toEqual({
|
|
282
|
-
...mockRow1,
|
|
283
|
-
position: mockPos2,
|
|
284
|
-
});
|
|
285
|
-
expect(rows.at(2).prop('data')).toEqual({
|
|
286
|
-
...mockRow3,
|
|
287
|
-
position: mockPos3,
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
expect(onChangeSpy).toHaveBeenCalledTimes(1);
|
|
291
|
-
expect(onChangeSpy).toHaveBeenCalledWith([
|
|
292
|
-
{ id: 1, position: 1, title: 'title-1' },
|
|
293
|
-
{ id: 0, position: 2, title: 'title-0' },
|
|
294
|
-
{ id: 2, position: 3, title: 'title-2' },
|
|
295
|
-
]);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it(`replaces target row if dragged on the bottom half of the target row and current row is dragged down`, () => {
|
|
299
|
-
const onChangeSpy = jest.fn();
|
|
300
|
-
const wrapper = shallow(
|
|
301
|
-
<DynamicDataList
|
|
302
|
-
{...defaultProps}
|
|
303
|
-
columns={defaultColumns}
|
|
304
|
-
value={dataWithPositions}
|
|
305
|
-
positionPropertyName={'position'}
|
|
306
|
-
allowReordering={true}
|
|
307
|
-
allowRowDragging={true}
|
|
308
|
-
onChange={onChangeSpy}
|
|
309
|
-
/>,
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
let rows = wrapper.find(DynamicListRow);
|
|
313
|
-
|
|
314
|
-
expect(rows.at(0).prop('data')).toBe(mockRow1);
|
|
315
|
-
expect(rows.at(1).prop('data')).toBe(mockRow2);
|
|
316
|
-
expect(rows.at(2).prop('data')).toBe(mockRow3);
|
|
317
|
-
|
|
318
|
-
act(() => {
|
|
319
|
-
// @ts-expect-error not full event args object
|
|
320
|
-
rows.first().prop('onDragStart')?.({}, mockPos1);
|
|
321
|
-
});
|
|
322
|
-
wrapper.update();
|
|
323
|
-
|
|
324
|
-
rows = wrapper.find(DynamicListRow);
|
|
325
|
-
|
|
326
|
-
act(() => {
|
|
327
|
-
// @ts-expect-error not full event args object
|
|
328
|
-
rows.last().prop('onDrop')?.({}, mockPos3, 'below');
|
|
329
|
-
});
|
|
330
|
-
wrapper.update();
|
|
331
|
-
|
|
332
|
-
rows = wrapper.find(DynamicListRow);
|
|
333
|
-
|
|
334
|
-
expect(rows.at(0).prop('data')).toEqual({
|
|
335
|
-
...mockRow2,
|
|
336
|
-
position: mockPos1,
|
|
337
|
-
});
|
|
338
|
-
expect(rows.at(1).prop('data')).toEqual({
|
|
339
|
-
...mockRow3,
|
|
340
|
-
position: mockPos2,
|
|
341
|
-
});
|
|
342
|
-
expect(rows.at(2).prop('data')).toEqual({
|
|
343
|
-
...mockRow1,
|
|
344
|
-
position: mockPos3,
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
expect(onChangeSpy).toHaveBeenCalledTimes(1);
|
|
348
|
-
expect(onChangeSpy).toHaveBeenCalledWith([
|
|
349
|
-
{ id: 1, position: 1, title: 'title-1' },
|
|
350
|
-
{ id: 2, position: 2, title: 'title-2' },
|
|
351
|
-
{ id: 0, position: 3, title: 'title-0' },
|
|
352
|
-
]);
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
describe('caclulateNewList', () => {
|
|
358
|
-
describe('item is moved up', () => {
|
|
359
|
-
it(`when rows are sequential
|
|
360
|
-
all items before the new position and all items after the current row should not be affected.
|
|
361
|
-
the item in the new position, and the items in between should have their positions incremented.
|
|
362
|
-
the item being moved should have the calculated position.`, () => {
|
|
363
|
-
const result = calculateNewList(
|
|
364
|
-
[
|
|
365
|
-
{ id: 1, pos: 1 },
|
|
366
|
-
{ id: 2, pos: 2 },
|
|
367
|
-
{ id: 3, pos: 3 },
|
|
368
|
-
{ id: 4, pos: 4 },
|
|
369
|
-
{ id: 5, pos: 5 },
|
|
370
|
-
],
|
|
371
|
-
'pos',
|
|
372
|
-
4,
|
|
373
|
-
2,
|
|
374
|
-
'drag',
|
|
375
|
-
'above',
|
|
376
|
-
);
|
|
377
|
-
|
|
378
|
-
expect(result).toEqual([
|
|
379
|
-
{ id: 1, pos: 1 },
|
|
380
|
-
{ id: 4, pos: 2 },
|
|
381
|
-
{ id: 2, pos: 3 },
|
|
382
|
-
{ id: 3, pos: 4 },
|
|
383
|
-
{ id: 5, pos: 5 },
|
|
384
|
-
]);
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it(`when rows are not sequential
|
|
388
|
-
all items before the new position and all items after the current row should not be affected.
|
|
389
|
-
only increment positions until the gap is reached.
|
|
390
|
-
the item being moved should have the calculated position.`, () => {
|
|
391
|
-
const result = calculateNewList(
|
|
392
|
-
[
|
|
393
|
-
{ id: 1, pos: 1 },
|
|
394
|
-
{ id: 2, pos: 2 },
|
|
395
|
-
{ id: 7, pos: 7 },
|
|
396
|
-
{ id: 8, pos: 8 },
|
|
397
|
-
{ id: 20, pos: 20 },
|
|
398
|
-
{ id: 100, pos: 100 },
|
|
399
|
-
],
|
|
400
|
-
'pos',
|
|
401
|
-
20,
|
|
402
|
-
2,
|
|
403
|
-
'drag',
|
|
404
|
-
'above',
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
expect(result).toEqual([
|
|
408
|
-
{ id: 1, pos: 1 },
|
|
409
|
-
{ id: 20, pos: 2 },
|
|
410
|
-
{ id: 2, pos: 3 },
|
|
411
|
-
{ id: 7, pos: 7 },
|
|
412
|
-
{ id: 8, pos: 8 },
|
|
413
|
-
{ id: 100, pos: 100 },
|
|
414
|
-
]);
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
it(`when a row is placed between two rows with a gap and dragged below the top item
|
|
418
|
-
all items before the new position and all items after the current row should not be affected.
|
|
419
|
-
only increment positions until the gap is reached.
|
|
420
|
-
the item being moved should be placed after the row above it.`, () => {
|
|
421
|
-
const result = calculateNewList(
|
|
422
|
-
[
|
|
423
|
-
{ id: 1, pos: 1 },
|
|
424
|
-
{ id: 2, pos: 2 },
|
|
425
|
-
{ id: 7, pos: 7 },
|
|
426
|
-
{ id: 8, pos: 8 },
|
|
427
|
-
{ id: 20, pos: 20 },
|
|
428
|
-
{ id: 100, pos: 100 },
|
|
429
|
-
],
|
|
430
|
-
'pos',
|
|
431
|
-
20,
|
|
432
|
-
2,
|
|
433
|
-
'drag',
|
|
434
|
-
'below',
|
|
435
|
-
);
|
|
436
|
-
|
|
437
|
-
expect(result).toEqual([
|
|
438
|
-
{ id: 1, pos: 1 },
|
|
439
|
-
{ id: 2, pos: 2 },
|
|
440
|
-
{ id: 20, pos: 3 },
|
|
441
|
-
{ id: 7, pos: 7 },
|
|
442
|
-
{ id: 8, pos: 8 },
|
|
443
|
-
{ id: 100, pos: 100 },
|
|
444
|
-
]);
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
it(`when a row is placed between two rows with a gap and dragged above the bottom item
|
|
448
|
-
all items before the new position and all items after the current row should not be affected.
|
|
449
|
-
only increment positions until the gap is reached.
|
|
450
|
-
the item being moved should be placed after the row above it.`, () => {
|
|
451
|
-
const result = calculateNewList(
|
|
452
|
-
[
|
|
453
|
-
{ id: 1, pos: 1 },
|
|
454
|
-
{ id: 2, pos: 2 },
|
|
455
|
-
{ id: 7, pos: 7 },
|
|
456
|
-
{ id: 8, pos: 8 },
|
|
457
|
-
{ id: 20, pos: 20 },
|
|
458
|
-
{ id: 100, pos: 100 },
|
|
459
|
-
],
|
|
460
|
-
'pos',
|
|
461
|
-
20,
|
|
462
|
-
7,
|
|
463
|
-
'drag',
|
|
464
|
-
'above',
|
|
465
|
-
);
|
|
466
|
-
|
|
467
|
-
expect(result).toEqual([
|
|
468
|
-
{ id: 1, pos: 1 },
|
|
469
|
-
{ id: 2, pos: 2 },
|
|
470
|
-
{ id: 20, pos: 3 },
|
|
471
|
-
{ id: 7, pos: 7 },
|
|
472
|
-
{ id: 8, pos: 8 },
|
|
473
|
-
{ id: 100, pos: 100 },
|
|
474
|
-
]);
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
it(`when rows are sequential
|
|
478
|
-
item should take position 1 if set via input and new value is 0 or less.
|
|
479
|
-
all items inbetween the current row and new position should be incremented.`, () => {
|
|
480
|
-
const result = calculateNewList(
|
|
481
|
-
[
|
|
482
|
-
{ id: 1, pos: 1 },
|
|
483
|
-
{ id: 2, pos: 2 },
|
|
484
|
-
{ id: 3, pos: 3 },
|
|
485
|
-
{ id: 4, pos: 4 },
|
|
486
|
-
{ id: 5, pos: 5 },
|
|
487
|
-
],
|
|
488
|
-
'pos',
|
|
489
|
-
4,
|
|
490
|
-
0,
|
|
491
|
-
'input',
|
|
492
|
-
);
|
|
493
|
-
|
|
494
|
-
expect(result).toEqual([
|
|
495
|
-
{ id: 4, pos: 1 },
|
|
496
|
-
{ id: 1, pos: 2 },
|
|
497
|
-
{ id: 2, pos: 3 },
|
|
498
|
-
{ id: 3, pos: 4 },
|
|
499
|
-
{ id: 5, pos: 5 },
|
|
500
|
-
]);
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
it(`when rows are sequential
|
|
504
|
-
item should replace target row.
|
|
505
|
-
all items inbetween the current row and new position should be incremented.`, () => {
|
|
506
|
-
const result = calculateNewList(
|
|
507
|
-
[
|
|
508
|
-
{ id: 1, pos: 1 },
|
|
509
|
-
{ id: 2, pos: 2 },
|
|
510
|
-
{ id: 3, pos: 3 },
|
|
511
|
-
{ id: 4, pos: 4 },
|
|
512
|
-
{ id: 5, pos: 5 },
|
|
513
|
-
],
|
|
514
|
-
'pos',
|
|
515
|
-
4,
|
|
516
|
-
2,
|
|
517
|
-
'input',
|
|
518
|
-
);
|
|
519
|
-
|
|
520
|
-
expect(result).toEqual([
|
|
521
|
-
{ id: 1, pos: 1 },
|
|
522
|
-
{ id: 4, pos: 2 },
|
|
523
|
-
{ id: 2, pos: 3 },
|
|
524
|
-
{ id: 3, pos: 4 },
|
|
525
|
-
{ id: 5, pos: 5 },
|
|
526
|
-
]);
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
it(`when rows are not sequential and current row is moved into an empty position
|
|
530
|
-
current row should take up the empty poisition
|
|
531
|
-
no other row should be affected.`, () => {
|
|
532
|
-
const result = calculateNewList(
|
|
533
|
-
[
|
|
534
|
-
{ id: 1, pos: 1 },
|
|
535
|
-
{ id: 2, pos: 2 },
|
|
536
|
-
{ id: 7, pos: 7 },
|
|
537
|
-
{ id: 8, pos: 8 },
|
|
538
|
-
{ id: 20, pos: 20 },
|
|
539
|
-
{ id: 100, pos: 100 },
|
|
540
|
-
],
|
|
541
|
-
'pos',
|
|
542
|
-
100,
|
|
543
|
-
10,
|
|
544
|
-
'input',
|
|
545
|
-
);
|
|
546
|
-
|
|
547
|
-
expect(result).toEqual([
|
|
548
|
-
{ id: 1, pos: 1 },
|
|
549
|
-
{ id: 2, pos: 2 },
|
|
550
|
-
{ id: 7, pos: 7 },
|
|
551
|
-
{ id: 8, pos: 8 },
|
|
552
|
-
{ id: 100, pos: 10 },
|
|
553
|
-
{ id: 20, pos: 20 },
|
|
554
|
-
]);
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
it(`when rows are not sequential and current row is moved between 2 rows
|
|
558
|
-
current row should be placed after the row above it.
|
|
559
|
-
all rows after the new position should be incremented until a gap is reached.`, () => {
|
|
560
|
-
const result = calculateNewList(
|
|
561
|
-
[
|
|
562
|
-
{ id: 1, pos: 1 },
|
|
563
|
-
{ id: 2, pos: 2 },
|
|
564
|
-
{ id: 7, pos: 7 },
|
|
565
|
-
{ id: 8, pos: 8 },
|
|
566
|
-
{ id: 20, pos: 20 },
|
|
567
|
-
{ id: 100, pos: 100 },
|
|
568
|
-
],
|
|
569
|
-
'pos',
|
|
570
|
-
20,
|
|
571
|
-
2,
|
|
572
|
-
'input',
|
|
573
|
-
);
|
|
574
|
-
|
|
575
|
-
expect(result).toEqual([
|
|
576
|
-
{ id: 1, pos: 1 },
|
|
577
|
-
{ id: 20, pos: 2 },
|
|
578
|
-
{ id: 2, pos: 3 },
|
|
579
|
-
{ id: 7, pos: 7 },
|
|
580
|
-
{ id: 8, pos: 8 },
|
|
581
|
-
{ id: 100, pos: 100 },
|
|
582
|
-
]);
|
|
583
|
-
});
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
describe('item is moved down', () => {
|
|
587
|
-
it(`when rows are sequential
|
|
588
|
-
all items before the new position and all items after the current row should not be affected.
|
|
589
|
-
the item in the new position, and the items in between should have their positions decremented.
|
|
590
|
-
the item being moved should have the calculated position.`, () => {
|
|
591
|
-
const result = calculateNewList(
|
|
592
|
-
[
|
|
593
|
-
{ id: 1, pos: 1 },
|
|
594
|
-
{ id: 2, pos: 2 },
|
|
595
|
-
{ id: 3, pos: 3 },
|
|
596
|
-
{ id: 4, pos: 4 },
|
|
597
|
-
{ id: 5, pos: 5 },
|
|
598
|
-
],
|
|
599
|
-
'pos',
|
|
600
|
-
4,
|
|
601
|
-
2,
|
|
602
|
-
'drag',
|
|
603
|
-
'above',
|
|
604
|
-
);
|
|
605
|
-
|
|
606
|
-
expect(result).toEqual([
|
|
607
|
-
{ id: 1, pos: 1 },
|
|
608
|
-
{ id: 4, pos: 2 },
|
|
609
|
-
{ id: 2, pos: 3 },
|
|
610
|
-
{ id: 3, pos: 4 },
|
|
611
|
-
{ id: 5, pos: 5 },
|
|
612
|
-
]);
|
|
613
|
-
});
|
|
614
|
-
|
|
615
|
-
it(`when rows are not sequential
|
|
616
|
-
all items before the new position and all items after the current row should not be affected.
|
|
617
|
-
only decrement positions until the gap is reached.
|
|
618
|
-
the item being moved should have the calculated position.`, () => {
|
|
619
|
-
const result = calculateNewList(
|
|
620
|
-
[
|
|
621
|
-
{ id: 1, pos: 1 },
|
|
622
|
-
{ id: 2, pos: 2 },
|
|
623
|
-
{ id: 7, pos: 7 },
|
|
624
|
-
{ id: 8, pos: 8 },
|
|
625
|
-
{ id: 20, pos: 20 },
|
|
626
|
-
{ id: 100, pos: 100 },
|
|
627
|
-
],
|
|
628
|
-
'pos',
|
|
629
|
-
1,
|
|
630
|
-
20,
|
|
631
|
-
'drag',
|
|
632
|
-
'below',
|
|
633
|
-
);
|
|
634
|
-
|
|
635
|
-
expect(result).toEqual([
|
|
636
|
-
{ id: 2, pos: 2 },
|
|
637
|
-
{ id: 7, pos: 7 },
|
|
638
|
-
{ id: 8, pos: 8 },
|
|
639
|
-
{ id: 20, pos: 19 },
|
|
640
|
-
{ id: 1, pos: 20 },
|
|
641
|
-
{ id: 100, pos: 100 },
|
|
642
|
-
]);
|
|
643
|
-
});
|
|
644
|
-
|
|
645
|
-
it(`when a row is placed between two rows with a gap and dragged above the bottom item
|
|
646
|
-
all items before the new position and all items after the current row should not be affected.
|
|
647
|
-
only decrement positions until the gap is reached.
|
|
648
|
-
the item being moved should replace the row above it.`, () => {
|
|
649
|
-
const result = calculateNewList(
|
|
650
|
-
[
|
|
651
|
-
{ id: 1, pos: 1 },
|
|
652
|
-
{ id: 2, pos: 2 },
|
|
653
|
-
{ id: 7, pos: 7 },
|
|
654
|
-
{ id: 8, pos: 8 },
|
|
655
|
-
{ id: 20, pos: 20 },
|
|
656
|
-
{ id: 100, pos: 100 },
|
|
657
|
-
],
|
|
658
|
-
'pos',
|
|
659
|
-
1,
|
|
660
|
-
20,
|
|
661
|
-
'drag',
|
|
662
|
-
'above',
|
|
663
|
-
);
|
|
664
|
-
|
|
665
|
-
expect(result).toEqual([
|
|
666
|
-
{ id: 2, pos: 2 },
|
|
667
|
-
{ id: 7, pos: 6 },
|
|
668
|
-
{ id: 8, pos: 7 },
|
|
669
|
-
{ id: 1, pos: 8 },
|
|
670
|
-
{ id: 20, pos: 20 },
|
|
671
|
-
{ id: 100, pos: 100 },
|
|
672
|
-
]);
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
it(`when a row is placed between two rows with a gap and dragged below the top item
|
|
676
|
-
all items before the new position and all items after the current row should not be affected.
|
|
677
|
-
only decrement positions until the gap is reached.
|
|
678
|
-
the item being moved should replace the row above it.`, () => {
|
|
679
|
-
const result = calculateNewList(
|
|
680
|
-
[
|
|
681
|
-
{ id: 1, pos: 1 },
|
|
682
|
-
{ id: 2, pos: 2 },
|
|
683
|
-
{ id: 7, pos: 7 },
|
|
684
|
-
{ id: 8, pos: 8 },
|
|
685
|
-
{ id: 20, pos: 20 },
|
|
686
|
-
{ id: 100, pos: 100 },
|
|
687
|
-
],
|
|
688
|
-
'pos',
|
|
689
|
-
1,
|
|
690
|
-
8,
|
|
691
|
-
'drag',
|
|
692
|
-
'below',
|
|
693
|
-
);
|
|
694
|
-
|
|
695
|
-
expect(result).toEqual([
|
|
696
|
-
{ id: 2, pos: 2 },
|
|
697
|
-
{ id: 7, pos: 6 },
|
|
698
|
-
{ id: 8, pos: 7 },
|
|
699
|
-
{ id: 1, pos: 8 },
|
|
700
|
-
{ id: 20, pos: 20 },
|
|
701
|
-
{ id: 100, pos: 100 },
|
|
702
|
-
]);
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
it(`when rows are sequential
|
|
706
|
-
all items before the current and all items after the new position should not be affected.
|
|
707
|
-
the item in the new position, and the items in between should have their positions decremented.
|
|
708
|
-
the item being moved should have the calculated position.`, () => {
|
|
709
|
-
const result = calculateNewList(
|
|
710
|
-
[
|
|
711
|
-
{ id: 1, pos: 1 },
|
|
712
|
-
{ id: 2, pos: 2 },
|
|
713
|
-
{ id: 3, pos: 3 },
|
|
714
|
-
{ id: 4, pos: 4 },
|
|
715
|
-
{ id: 5, pos: 5 },
|
|
716
|
-
],
|
|
717
|
-
'pos',
|
|
718
|
-
2,
|
|
719
|
-
4,
|
|
720
|
-
'input',
|
|
721
|
-
);
|
|
722
|
-
|
|
723
|
-
expect(result).toEqual([
|
|
724
|
-
{ id: 1, pos: 1 },
|
|
725
|
-
{ id: 3, pos: 2 },
|
|
726
|
-
{ id: 4, pos: 3 },
|
|
727
|
-
{ id: 2, pos: 4 },
|
|
728
|
-
{ id: 5, pos: 5 },
|
|
729
|
-
]);
|
|
730
|
-
});
|
|
731
|
-
|
|
732
|
-
it(`when rows are not sequential
|
|
733
|
-
all items before the current and all items after the new position should not be affected.
|
|
734
|
-
the item in the new position, and the items in between should have their positions decremented until a gap is reached
|
|
735
|
-
the item being moved should have the calculated position.`, () => {
|
|
736
|
-
const result = calculateNewList(
|
|
737
|
-
[
|
|
738
|
-
{ id: 1, pos: 1 },
|
|
739
|
-
{ id: 2, pos: 2 },
|
|
740
|
-
{ id: 7, pos: 7 },
|
|
741
|
-
{ id: 8, pos: 8 },
|
|
742
|
-
{ id: 20, pos: 20 },
|
|
743
|
-
{ id: 100, pos: 100 },
|
|
744
|
-
],
|
|
745
|
-
'pos',
|
|
746
|
-
1,
|
|
747
|
-
20,
|
|
748
|
-
'input',
|
|
749
|
-
);
|
|
750
|
-
|
|
751
|
-
expect(result).toEqual([
|
|
752
|
-
{ id: 2, pos: 2 },
|
|
753
|
-
{ id: 7, pos: 7 },
|
|
754
|
-
{ id: 8, pos: 8 },
|
|
755
|
-
{ id: 20, pos: 19 },
|
|
756
|
-
{ id: 1, pos: 20 },
|
|
757
|
-
{ id: 100, pos: 100 },
|
|
758
|
-
]);
|
|
759
|
-
});
|
|
760
|
-
});
|
|
761
|
-
});
|
|
762
|
-
|
|
763
|
-
describe('removeItemFromList', () => {
|
|
764
|
-
it(`when all rows are sequential
|
|
765
|
-
all items before the deleted item should not be affected.
|
|
766
|
-
removes the item being deleted.
|
|
767
|
-
decrements all subsequent item positions`, () => {
|
|
768
|
-
const result = removeItemFromList(
|
|
769
|
-
[
|
|
770
|
-
{ id: 1, pos: 1 },
|
|
771
|
-
{ id: 2, pos: 2 },
|
|
772
|
-
{ id: 3, pos: 3 },
|
|
773
|
-
{ id: 4, pos: 4 },
|
|
774
|
-
{ id: 5, pos: 5 },
|
|
775
|
-
],
|
|
776
|
-
'pos',
|
|
777
|
-
2,
|
|
778
|
-
);
|
|
779
|
-
|
|
780
|
-
expect(result).toEqual([
|
|
781
|
-
{ id: 1, pos: 1 },
|
|
782
|
-
{ id: 2, pos: 2 },
|
|
783
|
-
{ id: 4, pos: 3 },
|
|
784
|
-
{ id: 5, pos: 4 },
|
|
785
|
-
]);
|
|
786
|
-
});
|
|
787
|
-
|
|
788
|
-
it(`when rows are not sequential
|
|
789
|
-
all items before the deleted item should not be affected.
|
|
790
|
-
removes the item being deleted.
|
|
791
|
-
decrements all subsequent item positions until a gap is reached`, () => {
|
|
792
|
-
const result = removeItemFromList(
|
|
793
|
-
[
|
|
794
|
-
{ id: 1, pos: 1 },
|
|
795
|
-
{ id: 2, pos: 2 },
|
|
796
|
-
{ id: 3, pos: 3 },
|
|
797
|
-
{ id: 7, pos: 7 },
|
|
798
|
-
{ id: 8, pos: 8 },
|
|
799
|
-
{ id: 20, pos: 20 },
|
|
800
|
-
{ id: 100, pos: 100 },
|
|
801
|
-
],
|
|
802
|
-
'pos',
|
|
803
|
-
1,
|
|
804
|
-
);
|
|
805
|
-
|
|
806
|
-
expect(result).toEqual([
|
|
807
|
-
{ id: 1, pos: 1 },
|
|
808
|
-
{ id: 3, pos: 2 },
|
|
809
|
-
{ id: 7, pos: 7 },
|
|
810
|
-
{ id: 8, pos: 8 },
|
|
811
|
-
{ id: 20, pos: 20 },
|
|
812
|
-
{ id: 100, pos: 100 },
|
|
813
|
-
]);
|
|
814
|
-
});
|
|
815
|
-
});
|
|
816
|
-
});
|