test: add test cases to increase coverage (#26559)

* test:  add test cases to increase coverage

* chore: remove console
This commit is contained in:
偏右 2020-09-03 13:36:23 +08:00 committed by GitHub
parent e5fe9b90df
commit a409f3126f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 164 additions and 2 deletions

View File

@ -13,7 +13,6 @@ interface ScrollToOptions {
export default function scrollTo(y: number, options: ScrollToOptions = {}) {
const { getContainer = () => window, callback, duration = 450 } = options;
const container = getContainer();
const scrollTop = getScroll(container, true);
const startTime = Date.now();

View File

@ -697,6 +697,22 @@ describe('Table.filter', () => {
expect(wrapper.render()).toMatchSnapshot();
});
it('renders custom filter icon as ReactNode', () => {
const filterIcon = <span className="customize-icon" />;
const wrapper = mount(
createTable({
columns: [
{
...column,
filterIcon,
},
],
}),
);
expect(wrapper.render()).toMatchSnapshot();
expect(wrapper.find('span.customize-icon').length).toBe(1);
});
// https://github.com/ant-design/ant-design/issues/13028
it('reset dropdown filter correctly', () => {
class Demo extends React.Component {
@ -1205,4 +1221,32 @@ describe('Table.filter', () => {
.first();
expect(checkbox.props().checked).toEqual(false);
});
it('should not trigger onChange when filter is empty', () => {
const onChange = jest.fn();
const Test = ({ filters }) => (
<Table
onChange={onChange}
rowKey="name"
columns={[
{
title: 'Name',
dataIndex: 'name',
filters,
},
]}
dataSource={[
{
name: 'Jack',
},
]}
/>
);
const wrapper = mount(<Test filters={[]} />);
wrapper.find('.ant-dropdown-trigger').first().simulate('click');
wrapper.find('.ant-table-filter-dropdown-btns .ant-btn-primary').simulate('click');
expect(onChange).not.toHaveBeenCalled();
onChange.mockReset();
wrapper.unmount();
});
});

View File

@ -103,6 +103,17 @@ describe('Table.pagination', () => {
expect(scrollTo).toHaveBeenCalledTimes(2);
});
it('should scroll inside .ant-table-body', () => {
scrollTo.mockImplementationOnce((top, { getContainer }) => {
expect(top).toBe(0);
expect(getContainer().className).toBe('ant-table-body');
});
const wrapper = mount(
createTable({ scroll: { y: 20 }, pagination: { showSizeChanger: true, pageSize: 2 } }),
);
wrapper.find('Pager').last().simulate('click');
});
it('fires change event', () => {
const handleChange = jest.fn();
const handlePaginationChange = jest.fn();

View File

@ -86,7 +86,7 @@ describe('Table.rowSelection', () => {
const radios = wrapper.find('input');
expect(radios.length).toBe(4);
radios.first().simulate('click');
radios.first().simulate('change', { target: { checked: true } });
expect(getSelections(wrapper)).toEqual([0]);

View File

@ -50,6 +50,114 @@ exports[`Table.filter renders custom content correctly 1`] = `
</div>
`;
exports[`Table.filter renders custom filter icon as ReactNode 1`] = `
<div
class="ant-table-wrapper"
>
<div
class="ant-spin-nested-loading"
>
<div
class="ant-spin-container"
>
<div
class="ant-table"
>
<div
class="ant-table-container"
>
<div
class="ant-table-content"
>
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="ant-table-thead"
>
<tr>
<th
class="ant-table-cell"
>
<div
class="ant-table-filter-column"
>
<span
class="ant-table-filter-column-title"
>
Name
</span>
<span
class="ant-table-filter-trigger-container"
>
<span
class="ant-table-filter-trigger ant-dropdown-trigger"
role="button"
tabindex="-1"
>
<span
class="customize-icon"
/>
</span>
</span>
</div>
</th>
</tr>
</thead>
<tbody
class="ant-table-tbody"
>
<tr
class="ant-table-row ant-table-row-level-0"
data-row-key="0"
>
<td
class="ant-table-cell"
>
Jack
</td>
</tr>
<tr
class="ant-table-row ant-table-row-level-0"
data-row-key="1"
>
<td
class="ant-table-cell"
>
Lucy
</td>
</tr>
<tr
class="ant-table-row ant-table-row-level-0"
data-row-key="2"
>
<td
class="ant-table-cell"
>
Tom
</td>
</tr>
<tr
class="ant-table-row ant-table-row-level-0"
data-row-key="3"
>
<td
class="ant-table-cell"
>
Jerry
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
`;
exports[`Table.filter renders custom filter icon as string correctly 1`] = `
<div
class="ant-table-wrapper"