|
| 1 | +import React from 'react'; |
| 2 | +import { render, act } from '@testing-library/react'; |
| 3 | +import Table from '../src'; |
| 4 | +// 保留 spyElementPrototype 的相关逻辑 |
| 5 | +import { spyElementPrototype } from '@rc-component/util/lib/test/domHook'; |
| 6 | +import RcResizeObserver from '@rc-component/resize-observer'; |
| 7 | + |
| 8 | +vi.mock('@rc-component/util/lib/Dom/styleChecker', () => { |
| 9 | + return { |
| 10 | + isStyleSupport: (name, val) => val !== 'sticky', |
| 11 | + }; |
| 12 | +}); |
| 13 | + |
| 14 | +describe('Table.FixedColumn', () => { |
| 15 | + let domSpy; |
| 16 | + |
| 17 | + beforeAll(() => { |
| 18 | + domSpy = spyElementPrototype(HTMLElement, 'offsetParent', { |
| 19 | + get: () => ({}), |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + afterAll(() => { |
| 24 | + domSpy.mockRestore(); |
| 25 | + }); |
| 26 | + |
| 27 | + const columns = [ |
| 28 | + { title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' }, |
| 29 | + { title: 'title2', dataIndex: 'b', key: 'b', width: 100, fixed: 'left' }, |
| 30 | + { title: 'title3', dataIndex: 'c', key: 'c' }, |
| 31 | + { title: 'title4', dataIndex: 'b', key: 'd' }, |
| 32 | + { title: 'title5', dataIndex: 'b', key: 'e' }, |
| 33 | + { title: 'title6', dataIndex: 'b', key: 'f' }, |
| 34 | + { title: 'title7', dataIndex: 'b', key: 'g' }, |
| 35 | + { title: 'title8', dataIndex: 'b', key: 'h' }, |
| 36 | + { title: 'title9', dataIndex: 'b', key: 'i' }, |
| 37 | + { title: 'title10', dataIndex: 'b', key: 'j' }, |
| 38 | + { title: 'title11', dataIndex: 'b', key: 'k' }, |
| 39 | + { title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' }, |
| 40 | + ]; |
| 41 | + const data = [{ a: '123', b: 'xxxxxxxx', d: 3, key: '1' }]; |
| 42 | + |
| 43 | + it('not sticky', async () => { |
| 44 | + vi.useFakeTimers(); |
| 45 | + const { container } = render(<Table columns={columns} data={data} scroll={{ x: 1200 }} />); |
| 46 | + |
| 47 | + // 模拟时间流逝,触发 Table 内部的更新逻辑 |
| 48 | + await act(async () => { |
| 49 | + vi.runAllTimers(); |
| 50 | + await Promise.resolve(); |
| 51 | + }); |
| 52 | + |
| 53 | + expect(container.querySelector('.rc-table-cell-fix-left')).toBeNull(); |
| 54 | + expect(container.querySelector('.rc-table-cell-fix-right')).toBeNull(); |
| 55 | + }); |
| 56 | +}); |
0 commit comments