( render: any, rerender: any, Table: any, ControlledTable: any, resizeCol: any, resizeTable: any )
| 37 | } |
| 38 | |
| 39 | export let resizingTests = ( |
| 40 | render: any, |
| 41 | rerender: any, |
| 42 | Table: any, |
| 43 | ControlledTable: any, |
| 44 | resizeCol: any, |
| 45 | resizeTable: any |
| 46 | ): void => { |
| 47 | // assumption with all these tests |
| 48 | // 1. the controlling values we pass in aren't actually controlling |
| 49 | // the sizes, they are instead more like the default values that the controlling logic uses |
| 50 | // 2. defaultWidth function and minDefaultWidth passed must be the same in any implementation using |
| 51 | // these tests, or the values will be wrong, if those functions were exposed we could generalize, but seems like a lot just for testing |
| 52 | describe('Resizing', () => { |
| 53 | installPointerEvent(); |
| 54 | let clientWidth, clientHeight; |
| 55 | let onResize; |
| 56 | |
| 57 | beforeEach(function () { |
| 58 | clientWidth = jest |
| 59 | .spyOn(window.HTMLElement.prototype, 'clientWidth', 'get') |
| 60 | .mockImplementation(() => 900); |
| 61 | clientHeight = jest |
| 62 | .spyOn(window.HTMLElement.prototype, 'clientHeight', 'get') |
| 63 | .mockImplementation(() => 1000); |
| 64 | jest.useFakeTimers(); |
| 65 | onResize = jest.fn(); |
| 66 | }); |
| 67 | |
| 68 | afterEach(function () { |
| 69 | act(() => { |
| 70 | jest.runAllTimers(); |
| 71 | }); |
| 72 | clientWidth.mockReset(); |
| 73 | clientHeight.mockReset(); |
| 74 | onResize.mockReset(); |
| 75 | onResize = null; |
| 76 | }); |
| 77 | |
| 78 | describe.each` |
| 79 | allowsResizing |
| 80 | ${undefined} |
| 81 | ${true} |
| 82 | `('initial column sizes allowsResizing=$allowsResizing', ({allowsResizing}) => { |
| 83 | it('should handle no value if table was written with default widths', () => { |
| 84 | let columns = [ |
| 85 | {name: 'Name', id: 'name', allowsResizing}, |
| 86 | {name: 'Type', id: 'type', allowsResizing}, |
| 87 | {name: 'Level', id: 'level', allowsResizing} |
| 88 | ]; |
| 89 | let tree = render(<Table columns={columns} rows={rows} />); |
| 90 | expect(getColumnWidths(tree)).toStrictEqual([300, 300, 300]); |
| 91 | }); |
| 92 | it('should handle default pixel widths', () => { |
| 93 | let columns = [ |
| 94 | {name: 'Name', id: 'name', defaultWidth: 100, allowsResizing}, |
| 95 | {name: 'Type', id: 'type', defaultWidth: 100, allowsResizing}, |
| 96 | {name: 'Level', id: 'level', defaultWidth: 400, allowsResizing} |
no test coverage detected