mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 11:10:01 +08:00
test: ✅ add test cases to increase coverage (#26559)
* test: ✅ add test cases to increase coverage
* chore: remove console
This commit is contained in:
parent
e5fe9b90df
commit
a409f3126f
@ -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();
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
@ -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();
|
||||
|
@ -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]);
|
||||
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user