Skip to content

Commit

Permalink
test: Fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Mar 11, 2021
1 parent 0c5f7d0 commit 084ce41
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 62 deletions.
58 changes: 37 additions & 21 deletions tests/FixedColumn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,45 @@ describe('Table.FixedColumn', () => {
{ scrollName: 'scrollX', scroll: { x: 1200 } },
{ scrollName: 'scrollXY', scroll: { x: 1200, y: 100 } },
].forEach(({ scrollName, scroll }) => {
[{ name: 'with data', data }, { name: 'without data', data: [] }].forEach(
({ name, data: testData }) => {
it(`${scrollName} - ${name}`, async () => {
jest.useFakeTimers();
const wrapper = mount(<Table columns={columns} data={testData} scroll={scroll} />);

act(() => {
wrapper
.find('table ResizeObserver')
.first()
.props()
.onResize({ width: 93, offsetWidth: 93 });
});
await act(async () => {
jest.runAllTimers();
await Promise.resolve();
wrapper.update();
});
expect(wrapper.render()).toMatchSnapshot();
jest.useRealTimers();
[
{ name: 'with data', data },
{ name: 'without data', data: [] },
].forEach(({ name, data: testData }) => {
it(`${scrollName} - ${name}`, async () => {
jest.useFakeTimers();
const wrapper = mount(<Table columns={columns} data={testData} scroll={scroll} />);

act(() => {
wrapper
.find('table ResizeObserver')
.first()
.props()
.onResize({ width: 93, offsetWidth: 93 });
});
},
await act(async () => {
jest.runAllTimers();
await Promise.resolve();
wrapper.update();
});
expect(wrapper.render()).toMatchSnapshot();
jest.useRealTimers();
});
});
});

it('all column has width should use it', () => {
const wrapper = mount(
<Table
columns={[
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100 },
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
]}
data={[]}
scroll={{ x: 'max-content' }}
/>,
);

expect(wrapper.find('colgroup').render()).toMatchSnapshot();
});
});

Expand Down
52 changes: 11 additions & 41 deletions tests/__snapshots__/FixedColumn.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,17 @@ exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = `
</div>
`;

exports[`Table.FixedColumn renders correctly all column has width should use it 1`] = `
<colgroup>
<col
style="width: 100px; min-width: 100px;"
/>
<col
style="width: 100px; min-width: 100px;"
/>
</colgroup>
`;

exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
<div
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
Expand Down Expand Up @@ -2395,47 +2406,6 @@ exports[`Table.FixedColumn renders correctly scrollXY - without data 1`] = `
<table
style="table-layout: fixed;"
>
<colgroup>
<col
style="width: 93px; min-width: 93px;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 15px; min-width: 15px;"
/>
</colgroup>
<thead
class="rc-table-thead"
>
Expand Down

0 comments on commit 084ce41

Please sign in to comment.