|
| 1 | +import React from 'react'; |
| 2 | +import { mount } from 'enzyme'; |
| 3 | +import { act } from 'react-dom/test-utils'; |
| 4 | +import { spyElementPrototype } from 'rc-util/lib/test/domHook'; |
| 5 | +// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 6 | +import { isStyleSupport } from 'rc-util/lib/Dom/styleChecker'; |
| 7 | +import Table from '../src'; |
| 8 | + |
| 9 | +jest.mock('rc-util/lib/Dom/styleChecker', () => { |
| 10 | + return { |
| 11 | + isStyleSupport: (name, val) => val !== 'sticky', |
| 12 | + }; |
| 13 | +}); |
| 14 | + |
| 15 | +describe('Table.FixedColumn', () => { |
| 16 | + let domSpy; |
| 17 | + |
| 18 | + beforeAll(() => { |
| 19 | + domSpy = spyElementPrototype(HTMLElement, 'offsetParent', { |
| 20 | + get: () => ({}), |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + afterAll(() => { |
| 25 | + domSpy.mockRestore(); |
| 26 | + }); |
| 27 | + |
| 28 | + const columns = [ |
| 29 | + { title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' }, |
| 30 | + { title: 'title2', dataIndex: 'b', key: 'b', width: 100, fixed: 'left' }, |
| 31 | + { title: 'title3', dataIndex: 'c', key: 'c' }, |
| 32 | + { title: 'title4', dataIndex: 'b', key: 'd' }, |
| 33 | + { title: 'title5', dataIndex: 'b', key: 'e' }, |
| 34 | + { title: 'title6', dataIndex: 'b', key: 'f' }, |
| 35 | + { title: 'title7', dataIndex: 'b', key: 'g' }, |
| 36 | + { title: 'title8', dataIndex: 'b', key: 'h' }, |
| 37 | + { title: 'title9', dataIndex: 'b', key: 'i' }, |
| 38 | + { title: 'title10', dataIndex: 'b', key: 'j' }, |
| 39 | + { title: 'title11', dataIndex: 'b', key: 'k' }, |
| 40 | + { title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' }, |
| 41 | + ]; |
| 42 | + const data = [{ a: '123', b: 'xxxxxxxx', d: 3, key: '1' }]; |
| 43 | + |
| 44 | + it('not sticky', async () => { |
| 45 | + jest.useFakeTimers(); |
| 46 | + const wrapper = mount(<Table columns={columns} data={data} scroll={{ x: 1200 }} />); |
| 47 | + |
| 48 | + act(() => { |
| 49 | + wrapper.find('table ResizeObserver').first().props().onResize({ width: 93, offsetWidth: 93 }); |
| 50 | + }); |
| 51 | + |
| 52 | + await act(async () => { |
| 53 | + jest.runAllTimers(); |
| 54 | + await Promise.resolve(); |
| 55 | + wrapper.update(); |
| 56 | + }); |
| 57 | + |
| 58 | + expect(wrapper.exists('.rc-table-cell-fix-left')).toBeFalsy(); |
| 59 | + expect(wrapper.exists('.rc-table-cell-fix-right')).toBeFalsy(); |
| 60 | + }); |
| 61 | +}); |
0 commit comments