|
| 1 | +import { |
| 2 | + describe, |
| 3 | + expect, |
| 4 | + it, |
| 5 | +} from '@jest/globals'; |
| 6 | +import type { dxElementWrapper } from '@js/core/renderer'; |
| 7 | +import $ from '@js/core/renderer'; |
| 8 | + |
| 9 | +import { GridCoreStickyColumnsDom } from '../dom'; |
| 10 | + |
| 11 | +const addWidgetPrefix = (className: string): string => `dx-datagrid-${className}`; |
| 12 | + |
| 13 | +const createElement = ( |
| 14 | + rect: { left: number; right: number }, |
| 15 | + className = '', |
| 16 | + style: { left?: string; right?: string } = {}, |
| 17 | +): dxElementWrapper => { |
| 18 | + const element = document.createElement('td'); |
| 19 | + |
| 20 | + element.className = className; |
| 21 | + Object.assign(element.style, style); |
| 22 | + element.getBoundingClientRect = (): DOMRect => ({ |
| 23 | + ...rect, |
| 24 | + width: rect.right - rect.left, |
| 25 | + }) as DOMRect; |
| 26 | + |
| 27 | + return $(element); |
| 28 | +}; |
| 29 | + |
| 30 | +const $container = createElement({ left: 0, right: 600 }); |
| 31 | + |
| 32 | +describe('GridCoreStickyColumnsDom.isFixedCellPinnedToLeft', () => { |
| 33 | + describe('when the cell is fixed to the left', () => { |
| 34 | + it('should return true', () => { |
| 35 | + const $cell = createElement({ left: 0, right: 100 }, 'dx-datagrid-sticky-column-left'); |
| 36 | + |
| 37 | + expect(GridCoreStickyColumnsDom.isFixedCellPinnedToLeft($cell, $container, addWidgetPrefix)) |
| 38 | + .toBe(true); |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + describe('when the sticky cell is pinned to the left', () => { |
| 43 | + it('should return true', () => { |
| 44 | + const $cell = createElement({ left: 0, right: 100 }, 'dx-datagrid-sticky-column', { left: '0px' }); |
| 45 | + |
| 46 | + expect(GridCoreStickyColumnsDom.isFixedCellPinnedToLeft($cell, $container, addWidgetPrefix)) |
| 47 | + .toBe(true); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe('when the sticky cell is not pinned', () => { |
| 52 | + it('should return false', () => { |
| 53 | + const $cell = createElement({ left: 200, right: 300 }, 'dx-datagrid-sticky-column', { left: '0px' }); |
| 54 | + |
| 55 | + expect(GridCoreStickyColumnsDom.isFixedCellPinnedToLeft($cell, $container, addWidgetPrefix)) |
| 56 | + .toBe(false); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('when the cell is fixed to the right', () => { |
| 61 | + it('should return false', () => { |
| 62 | + const $cell = createElement({ left: 500, right: 600 }, 'dx-datagrid-sticky-column-right'); |
| 63 | + |
| 64 | + expect(GridCoreStickyColumnsDom.isFixedCellPinnedToLeft($cell, $container, addWidgetPrefix)) |
| 65 | + .toBe(false); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + describe('when the cell is not fixed', () => { |
| 70 | + it('should return false', () => { |
| 71 | + const $cell = createElement({ left: 0, right: 100 }); |
| 72 | + |
| 73 | + expect(GridCoreStickyColumnsDom.isFixedCellPinnedToLeft($cell, $container, addWidgetPrefix)) |
| 74 | + .toBe(false); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
| 78 | + |
| 79 | +describe('GridCoreStickyColumnsDom.isFixedCellPinnedToRight', () => { |
| 80 | + describe('when the cell is fixed to the right', () => { |
| 81 | + it('should return true', () => { |
| 82 | + const $cell = createElement({ left: 500, right: 600 }, 'dx-datagrid-sticky-column-right'); |
| 83 | + |
| 84 | + expect(GridCoreStickyColumnsDom.isFixedCellPinnedToRight($cell, $container, addWidgetPrefix)) |
| 85 | + .toBe(true); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + describe('when the sticky cell is pinned to the right', () => { |
| 90 | + it('should return true', () => { |
| 91 | + const $cell = createElement({ left: 500, right: 600 }, 'dx-datagrid-sticky-column', { right: '0px' }); |
| 92 | + |
| 93 | + expect(GridCoreStickyColumnsDom.isFixedCellPinnedToRight($cell, $container, addWidgetPrefix)) |
| 94 | + .toBe(true); |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + describe('when the sticky cell is not pinned', () => { |
| 99 | + it('should return false', () => { |
| 100 | + const $cell = createElement({ left: 200, right: 300 }, 'dx-datagrid-sticky-column', { right: '0px' }); |
| 101 | + |
| 102 | + expect(GridCoreStickyColumnsDom.isFixedCellPinnedToRight($cell, $container, addWidgetPrefix)) |
| 103 | + .toBe(false); |
| 104 | + }); |
| 105 | + }); |
| 106 | + |
| 107 | + describe('when the cell is fixed to the left', () => { |
| 108 | + it('should return false', () => { |
| 109 | + const $cell = createElement({ left: 0, right: 100 }, 'dx-datagrid-sticky-column-left'); |
| 110 | + |
| 111 | + expect(GridCoreStickyColumnsDom.isFixedCellPinnedToRight($cell, $container, addWidgetPrefix)) |
| 112 | + .toBe(false); |
| 113 | + }); |
| 114 | + }); |
| 115 | +}); |
0 commit comments