Skip to content

Commit e5bbbeb

Browse files
committed
test(DataGrid): add unit tests for utils
1 parent cfb456c commit e5bbbeb

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

packages/devextreme/js/__internal/grids/grid_core/columns_resizing_reordering/m_columns_resizing_reordering.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ export class DraggingHeaderViewController extends modules.ViewController {
14361436
* @param columns All columns in the given location
14371437
* @param location Location where we move column (headers, group, column chooser, etc.)
14381438
* @param sourceColumn Column that is dragging
1439-
* @param cells collection of draggable cells wrapped into jQuery object
1439+
* @param cells JQuery-wrapped collection of header cell elements
14401440
* @returns whether to filter current point (true - remove point, false - keep it)
14411441
*/
14421442

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { describe, expect, it } from '@jest/globals';
2+
3+
import { getDraggingPanelBoundingRects } from './utils';
4+
5+
const getRandomPoint = (max: number) => Math.floor(Math.random() * max);
6+
7+
const getDraggingPanelMock = () => ({
8+
getBoundingRect: () => ({
9+
top: getRandomPoint(1080),
10+
bottom: getRandomPoint(1080),
11+
left: getRandomPoint(1920),
12+
right: getRandomPoint(1920),
13+
}),
14+
} as any);
15+
16+
describe('m_columns_resizing_reordering/utils.test.ts', () => {
17+
describe('getDraggingPanelBoundingRects', () => {
18+
it('returns equal amount of elements in tuple', () => {
19+
const draggingPanels = [
20+
getDraggingPanelMock(),
21+
getDraggingPanelMock(),
22+
getDraggingPanelMock(),
23+
];
24+
const result = getDraggingPanelBoundingRects(draggingPanels);
25+
26+
expect(result?.length).toBe(draggingPanels.length);
27+
});
28+
29+
it('returns the same dragging panel objects', () => {
30+
const draggingPanels = [
31+
getDraggingPanelMock(),
32+
getDraggingPanelMock(),
33+
getDraggingPanelMock(),
34+
];
35+
const result = getDraggingPanelBoundingRects(draggingPanels);
36+
37+
expect(result).not.toBeNull();
38+
result?.forEach((draggingPanelBoundingRect, index) => {
39+
expect(draggingPanelBoundingRect.draggingPanel).toBe(draggingPanels[index]);
40+
});
41+
});
42+
43+
it('returns filtered tuple without empty objects', () => {
44+
const draggingPanels = [
45+
getDraggingPanelMock(),
46+
undefined,
47+
getDraggingPanelMock(),
48+
null,
49+
];
50+
const result = getDraggingPanelBoundingRects(draggingPanels);
51+
52+
expect(result?.length).toBe(draggingPanels.filter(Boolean).length);
53+
});
54+
55+
it('returns null if the result is empty array', () => {
56+
const draggingPanels = [undefined, null] as any[];
57+
const result = getDraggingPanelBoundingRects(draggingPanels);
58+
59+
expect(result).toBeNull();
60+
});
61+
62+
it('returns null if draggingPanels array is empty', () => {
63+
const draggingPanels = [] as any[];
64+
const result = getDraggingPanelBoundingRects(draggingPanels);
65+
66+
expect(result).toBeNull();
67+
});
68+
69+
it('returns null if draggingPanels is null or undefined', () => {
70+
expect(getDraggingPanelBoundingRects(undefined as any)).toBeNull();
71+
expect(getDraggingPanelBoundingRects(null as any)).toBeNull();
72+
});
73+
});
74+
});

0 commit comments

Comments
 (0)