Skip to content

Commit 138d528

Browse files
committed
test: add case
1 parent 07afed4 commit 138d528

File tree

2 files changed

+78
-17
lines changed

2 files changed

+78
-17
lines changed

Diff for: docs/examples/virtual.tsx

+30-16
Original file line numberDiff line numberDiff line change
@@ -218,28 +218,42 @@ const Demo = () => {
218218

219219
<VirtualTable
220220
virtual={{ x: true }}
221-
columns={columns}
221+
columns={[
222+
{
223+
dataIndex: 'a',
224+
width: 100,
225+
className: 'a',
226+
},
227+
{
228+
dataIndex: 'b',
229+
width: 200,
230+
},
231+
{
232+
dataIndex: 'c',
233+
width: 300,
234+
},
235+
{
236+
dataIndex: 'd',
237+
width: 400,
238+
},
239+
]}
222240
// expandedRowRender={({ b, c }) => b || c}
223-
scroll={{ x: 1300, y: 200 }}
241+
scroll={{
242+
x: 1000,
243+
y: 200,
244+
}}
245+
style={{ width: 200 }}
224246
data={data}
225247
// data={[]}
226248
rowKey="indexKey"
227-
expandable={{
228-
expandedRowRender: () => 2333,
229-
columnWidth: 60,
230-
expandedRowClassName: () => 'good-one',
231-
}}
249+
// expandable={{
250+
// expandedRowRender: () => 2333,
251+
// columnWidth: 60,
252+
// expandedRowClassName: () => 'good-one',
253+
// }}
232254
// onRow={() => ({ className: 'rowed' })}
233255
rowClassName="nice-try"
234-
getContainerWidth={(ele, width) => {
235-
// Minus border
236-
const borderWidth = getComputedStyle(
237-
ele.querySelector('.rc-table-tbody'),
238-
).borderInlineStartWidth;
239-
const mergedWidth = width - parseInt(borderWidth, 10);
240-
241-
return mergedWidth;
242-
}}
256+
getContainerWidth={(ele, width) => 200}
243257
ref={tblRef}
244258
/>
245259
</div>

Diff for: tests/Virtual.spec.tsx

+48-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Table.Virtual', () => {
4141
scrollLeft: {
4242
get: () => {
4343
scrollLeftCalled = true;
44-
return 100;
44+
return 0;
4545
},
4646
set: () => {},
4747
},
@@ -443,4 +443,51 @@ describe('Table.Virtual', () => {
443443
fireEvent.scroll(container.querySelector('.rc-table-tbody-virtual-holder')!);
444444
expect(onScroll).toHaveBeenCalled();
445445
});
446+
447+
it('horizontal virtual', async () => {
448+
const { container } = getTable({
449+
virtual: { x: true },
450+
columns: [
451+
{
452+
width: 100,
453+
className: 'a',
454+
},
455+
{
456+
width: 50,
457+
className: 'b',
458+
},
459+
{
460+
width: 100,
461+
className: 'c',
462+
},
463+
{
464+
width: 50,
465+
className: 'd',
466+
},
467+
],
468+
scroll: {
469+
x: 300,
470+
y: 10,
471+
},
472+
getContainerWidth: () => 200,
473+
data: [{}],
474+
});
475+
476+
resize(container.querySelector('.rc-table'));
477+
478+
await waitFakeTimer();
479+
480+
expect(container.querySelector('.rc-table-row').children.length).toBe(3);
481+
expect(container.querySelector('.rc-table-row').children[0].classList).toContain('a');
482+
expect(container.querySelector('.rc-table-row').children[1].classList).toContain('b');
483+
expect(container.querySelector('.rc-table-row').children[2].classList).toContain('c');
484+
485+
fireEvent.wheel(container.querySelector('.rc-table-tbody-virtual-holder')!, {
486+
deltaX: 100,
487+
});
488+
expect(container.querySelector('.rc-table-row').children.length).toBe(3);
489+
expect(container.querySelector('.rc-table-row').children[0].classList).toContain('b');
490+
expect(container.querySelector('.rc-table-row').children[1].classList).toContain('c');
491+
expect(container.querySelector('.rc-table-row').children[2].classList).toContain('d');
492+
});
446493
});

0 commit comments

Comments
 (0)