Skip to content

Commit b34469b

Browse files
committed
feat: add test case
1 parent 17bed24 commit b34469b

File tree

6 files changed

+6455
-1
lines changed

6 files changed

+6455
-1
lines changed

docs/examples/shadow.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,27 @@ const columns2: ColumnsType<User> = [
138138
title: 'Name0',
139139
fixed: 'left',
140140
dataIndex: 'name0',
141+
width: 100,
141142
},
142143
{
143144
key: 'name1',
144145
title: 'Name1',
145146
fixed: 'left',
146147
dataIndex: 'name1',
148+
width: 100,
147149
},
148150
{
149151
key: 'name2',
150152
title: 'Name2',
151153
dataIndex: 'name2',
154+
width: 500,
152155
},
153156
{
154157
key: 'name3',
155158
title: 'Name3',
156159
fixed: 'right',
157160
dataIndex: 'name3',
161+
width: 100,
158162
},
159163
],
160164
},

tests/FixedColumn.spec.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
66
import { act } from 'react-dom/test-utils';
77
import Table, { type ColumnsType } from '../src';
88
import { safeAct } from './utils';
9+
import { RowColSpanWithFixed, RowColSpanWithFixed2 } from './__mocks__/shadowTest';
910

1011
function triggerResize(ele: HTMLElement) {
1112
_rs([{ target: ele }] as any);
@@ -298,4 +299,14 @@ describe('Table.FixedColumn', () => {
298299
expect(container.querySelector('.healer-table')).toBeTruthy();
299300
});
300301
});
302+
it('shadow should display correctly', async () => {
303+
const { container, rerender } = render(<RowColSpanWithFixed />);
304+
expect(container.querySelectorAll('.rc-table-cell-fix-left-last').length).toBe(104);
305+
expect(container.querySelectorAll('.rc-table-cell-fix-right-first').length).toBe(101);
306+
expect(container).toMatchSnapshot();
307+
rerender(<RowColSpanWithFixed2 />);
308+
expect(container.querySelectorAll('.rc-table-cell-fix-left-last').length).toBe(4);
309+
expect(container.querySelectorAll('.rc-table-cell-fix-right-first').length).toBe(4);
310+
expect(container).toMatchSnapshot();
311+
});
301312
});

tests/__mocks__/shadowTest.tsx

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import React from 'react';
2+
import Table from '../../src';
3+
import '../../assets/index.less';
4+
import type { ColumnsType } from '../../src';
5+
6+
interface DataType {
7+
key: React.Key;
8+
name: string;
9+
age: number;
10+
street: string;
11+
building: string;
12+
number: number;
13+
companyAddress: string;
14+
companyName: string;
15+
gender: string;
16+
}
17+
18+
const columns: ColumnsType<DataType> = [
19+
{
20+
title: 'Other',
21+
fixed: 'left',
22+
ellipsis: true,
23+
children: [
24+
{
25+
title: 'Age',
26+
dataIndex: 'age',
27+
key: 'age',
28+
width: 150,
29+
fixed: 'left',
30+
ellipsis: true,
31+
},
32+
{
33+
title: 'Address',
34+
children: [
35+
{
36+
title: 'Street',
37+
dataIndex: 'street',
38+
key: 'street',
39+
width: 150,
40+
fixed: 'left',
41+
ellipsis: true,
42+
},
43+
{
44+
title: 'Block',
45+
children: [
46+
{
47+
title: 'Door No.',
48+
dataIndex: 'number',
49+
key: 'number',
50+
width: 100,
51+
fixed: 'left',
52+
ellipsis: true,
53+
},
54+
{
55+
title: 'Building',
56+
dataIndex: 'building',
57+
key: 'building',
58+
width: 100,
59+
fixed: 'left',
60+
ellipsis: true,
61+
},
62+
],
63+
},
64+
],
65+
},
66+
],
67+
},
68+
{
69+
title: 'Name',
70+
dataIndex: 'name',
71+
key: 'name',
72+
width: 100,
73+
},
74+
{
75+
title: 'Company',
76+
children: [
77+
{
78+
title: 'Company Address',
79+
dataIndex: 'companyAddress',
80+
key: 'companyAddress',
81+
width: 200,
82+
},
83+
{
84+
title: 'Company Name',
85+
dataIndex: 'companyName',
86+
key: 'companyName',
87+
},
88+
],
89+
},
90+
{
91+
title: 'Gender',
92+
dataIndex: 'gender',
93+
key: 'gender',
94+
width: 80,
95+
fixed: 'right',
96+
},
97+
];
98+
99+
const data: DataType[] = [];
100+
for (let i = 0; i < 100; i++) {
101+
data.push({
102+
key: i,
103+
name: 'John Brown',
104+
age: i + 1,
105+
street: 'Lake Park',
106+
building: 'C',
107+
number: 2035,
108+
companyAddress: 'Lake Street 42',
109+
companyName: 'SoftLake Co',
110+
gender: 'M',
111+
});
112+
}
113+
114+
interface User {
115+
key: number;
116+
name: string;
117+
}
118+
119+
const columns2: ColumnsType<User> = [
120+
{
121+
title: '父表头右侧的阴影导致整个表格最右侧有空隙',
122+
key: 'title',
123+
children: [
124+
{
125+
key: 'name0',
126+
title: 'Name0',
127+
fixed: 'left',
128+
dataIndex: 'name0',
129+
width: 100,
130+
},
131+
{
132+
key: 'name1',
133+
title: 'Name1',
134+
fixed: 'left',
135+
dataIndex: 'name1',
136+
width: 100,
137+
},
138+
{
139+
key: 'name2',
140+
title: 'Name2',
141+
dataIndex: 'name2',
142+
width: 500,
143+
},
144+
{
145+
key: 'name3',
146+
title: 'Name3',
147+
fixed: 'right',
148+
dataIndex: 'name3',
149+
width: 100,
150+
},
151+
],
152+
},
153+
];
154+
155+
const data2: User[] = [
156+
{
157+
key: 0,
158+
name: 'Jack',
159+
},
160+
{
161+
key: 1,
162+
name: 'Jack1',
163+
},
164+
{
165+
key: 2,
166+
name: 'Jack1',
167+
},
168+
];
169+
170+
export const RowColSpanWithFixed = () => (
171+
<Table columns={columns} data={data} className="table1" scroll={{ x: 1500, y: 500 }} />
172+
);
173+
export const RowColSpanWithFixed2 = () => (
174+
<Table columns={columns2} data={data2} className="table2" scroll={{ x: 1500, y: 500 }} />
175+
);
176+
177+
export default {
178+
RowColSpanWithFixed,
179+
RowColSpanWithFixed2,
180+
};

0 commit comments

Comments
 (0)