|
| 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