Skip to content

Commit

Permalink
full test
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Oct 30, 2019
1 parent c63b39c commit 5f8c8ae
Show file tree
Hide file tree
Showing 8 changed files with 944 additions and 42 deletions.
1 change: 0 additions & 1 deletion src/Header/FixedHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function FixedHeader<RecordType>({
onHeaderCell: () => ({
className: `${prefixCls}-cell-scrollbar`,
}),
render: () => null,
};

const columnsWithScrollbar = React.useMemo<ColumnsType<RecordType>>(
Expand Down
66 changes: 65 additions & 1 deletion tests/ExpandRow.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { resetWarned } from 'rc-util/lib/warning';
import Table from '../src';

Expand Down Expand Up @@ -62,8 +63,21 @@ describe('Table.Expand', () => {
{ key: 1, name: 'Jack', age: 28, gender: 'M' },
];
const wrapper = mount(
createTable({ columns, data, expandable: { expandedRowRender, defaultExpandAllRows: true } }),
createTable({
columns,
data,
scroll: { x: 903 },
expandable: { expandedRowRender, defaultExpandAllRows: true },
}),
);
act(() => {
wrapper
.find('ResizeObserver')
.first()
.props()
.onResize({ width: 1128 });
});
wrapper.update();
expect(wrapper.render()).toMatchSnapshot();
});

Expand Down Expand Up @@ -240,4 +254,54 @@ describe('Table.Expand', () => {

expect(wrapper.find('.should-display').length).toBeTruthy();
});

it('expandRowByClick', () => {
const onExpand = jest.fn();
const wrapper = mount(
createTable({
expandable: {
expandedRowRender,
expandRowByClick: true,
onExpand,
},
}),
);
wrapper
.find('tbody tr')
.first()
.simulate('click');
expect(onExpand).toHaveBeenCalledWith(true, sampleData[0]);

wrapper
.find('tbody tr')
.first()
.simulate('click');
expect(onExpand).toHaveBeenCalledWith(false, sampleData[0]);
});

it('some row should not expandable', () => {
const wrapper = mount(
createTable({
expandable: {
expandedRowRender,
rowExpandable: ({ key }) => key === 1,
},
}),
);

expect(
wrapper
.find('tbody tr')
.first()
.find('.rc-table-row-expand-icon')
.hasClass('rc-table-row-spaced'),
).toBeTruthy();
expect(
wrapper
.find('tbody tr')
.last()
.find('.rc-table-row-expand-icon')
.hasClass('rc-table-row-collapsed'),
).toBeTruthy();
});
});
45 changes: 25 additions & 20 deletions tests/FixedColumn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,33 @@ describe('Table.FixedColumn', () => {
];

describe('renders correctly', () => {
[{ name: 'with data', data }, { name: 'without data', data: [] }].forEach(
({ name, data: testData }) => {
it(name, () => {
jest.useFakeTimers();
const wrapper = mount(<Table columns={columns} data={testData} scroll={{ x: 1200 }} />);
[
{ 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}`, () => {
jest.useFakeTimers();
const wrapper = mount(<Table columns={columns} data={testData} scroll={scroll} />);

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

it('has correct scroll classNames when table resize', () => {
Expand Down
31 changes: 31 additions & 0 deletions tests/GroupingColumns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,35 @@ describe('Table with grouping columns', () => {
const titleB = wrapper.find('th.title-b');
expect(titleB.prop('rowSpan')).toBe(2);
});

it('strange layout', () => {
/**
* +-------+
* | | B |
* | +---+
* | A | C |
* + +---+
* | | |
* +---+---+
*/
const columns = [
{
title: 'A',
rowSpan: 3,
className: 'title-a',
},
{
title: 'B',
children: [
{
title: 'C',
},
],
},
];

const wrapper = mount(<Table columns={columns} data={[]} />);
const titleA = wrapper.find('th.title-a');
expect(titleA.prop('rowSpan')).toBe(3);
});
});
33 changes: 26 additions & 7 deletions tests/Table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ describe('Table.Basic', () => {
).toEqual('footer');
});

it('render summary correctly', () => {
const wrapper = mount(
createTable({
summary: () => (
<tr className="summary">
<td>Good</td>
</tr>
),
}),
);

expect(wrapper.find('tfoot').text()).toEqual('Good');
});

it('renders with id correctly', () => {
const testId = 'test-identifier';
const wrapper = mount(createTable({ id: testId }));
Expand Down Expand Up @@ -137,13 +151,18 @@ describe('Table.Basic', () => {
});

it('renders ellipsis', () => {
const wrapper = mount(createTable({ columns: [{ title: 'title', ellipsis: true }] }));
expect(
wrapper
.find('td')
.first()
.hasClass('rc-table-cell-ellipsis'),
).toBeTruthy();
const wrapper = mount(
createTable({
columns: [
{ title: 'title', ellipsis: true },
{ title: 'node title', ellipsis: true, render: () => <h1>233</h1> },
],
}),
);

wrapper.find('td').forEach(td => {
expect(td.hasClass('rc-table-cell-ellipsis')).toBeTruthy();
});
});

it('renders column correctly', () => {
Expand Down
27 changes: 19 additions & 8 deletions tests/__snapshots__/ExpandRow.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

exports[`Table.Expand renders fixed column correctly 1`] = `
<div
class="rc-table"
class="rc-table rc-table-fixed-column"
>
<div
class="rc-table-content"
style="overflow-x: scroll;"
>
<table
style="table-layout: auto;"
style="width: 903px; min-width: 100%; table-layout: fixed;"
>
<colgroup>
<col
Expand Down Expand Up @@ -88,9 +89,14 @@ exports[`Table.Expand renders fixed column correctly 1`] = `
class="rc-table-cell"
colspan="4"
>
<p>
extra data
</p>
<div
class="rc-table-expanded-row-fixed"
style="width: 1128px; position: sticky; left: 0px; overflow: hidden;"
>
<p>
extra data
</p>
</div>
</td>
</tr>
<tr
Expand Down Expand Up @@ -129,9 +135,14 @@ exports[`Table.Expand renders fixed column correctly 1`] = `
class="rc-table-cell"
colspan="4"
>
<p>
extra data
</p>
<div
class="rc-table-expanded-row-fixed"
style="width: 1128px; position: sticky; left: 0px; overflow: hidden;"
>
<p>
extra data
</p>
</div>
</td>
</tr>
</tbody>
Expand Down
Loading

0 comments on commit 5f8c8ae

Please sign in to comment.