mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
fix: Table loading compatibility (#22739)
* 🐛 Fix Table loading not working when no spinning field close #22733 * ✅ improve table test case
This commit is contained in:
parent
24ae9ebd1e
commit
faa71fd7bd
@ -398,20 +398,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// compatible
|
||||
switch (mergedPagination.position) {
|
||||
case 'top':
|
||||
topPaginationNode = renderPagination();
|
||||
break;
|
||||
|
||||
case 'both':
|
||||
topPaginationNode = renderPagination();
|
||||
bottomPaginationNode = renderPagination();
|
||||
break;
|
||||
|
||||
default:
|
||||
bottomPaginationNode = renderPagination();
|
||||
}
|
||||
bottomPaginationNode = renderPagination();
|
||||
}
|
||||
}
|
||||
|
||||
@ -421,8 +408,11 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
|
||||
spinProps = {
|
||||
spinning: loading,
|
||||
};
|
||||
} else {
|
||||
spinProps = loading;
|
||||
} else if (typeof loading === 'object') {
|
||||
spinProps = {
|
||||
spinning: true,
|
||||
...loading,
|
||||
};
|
||||
}
|
||||
|
||||
const wrapperClassNames = classNames(`${prefixCls}-wrapper`, className, {
|
||||
|
@ -340,12 +340,9 @@ describe('Table.filter', () => {
|
||||
it('fires change event', () => {
|
||||
const handleChange = jest.fn();
|
||||
const wrapper = mount(createTable({ onChange: handleChange }));
|
||||
|
||||
wrapper.find('.ant-dropdown-trigger').first().simulate('click');
|
||||
|
||||
wrapper.find('FilterDropdown').find('MenuItem').first().simulate('click');
|
||||
wrapper.find('FilterDropdown').find('.ant-table-filter-dropdown-btns .ant-btn-primary').simulate('click');
|
||||
|
||||
expect(handleChange).toHaveBeenCalledWith(
|
||||
{},
|
||||
{ name: ['boy'] },
|
||||
@ -356,6 +353,16 @@ describe('Table.filter', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('fires pagination change event', () => {
|
||||
const onPaginationChange = jest.fn();
|
||||
const wrapper = mount(createTable({ pagination: { onChange: onPaginationChange } }));
|
||||
wrapper.find('.ant-dropdown-trigger').first().simulate('click');
|
||||
wrapper.find('FilterDropdown').find('MenuItem').first().simulate('click');
|
||||
wrapper.find('FilterDropdown').find('.ant-table-filter-dropdown-btns .ant-btn-primary').simulate('click');
|
||||
|
||||
expect(onPaginationChange).toHaveBeenCalledWith(1, 10);
|
||||
});
|
||||
|
||||
it('should not fire change event on close filterDropdown without changing anything', () => {
|
||||
const handleChange = jest.fn();
|
||||
const wrapper = mount(createTable({ onChange: handleChange }));
|
||||
|
@ -186,7 +186,6 @@ describe('Table.pagination', () => {
|
||||
it('specify the position of pagination', () => {
|
||||
const wrapper = mount(createTable({ pagination: { position: ['topLeft'] } }));
|
||||
expect(wrapper.find('.ant-spin-container').children()).toHaveLength(2);
|
||||
|
||||
expect(wrapper.find('.ant-spin-container').childAt(0).find('.ant-pagination')).toHaveLength(1);
|
||||
wrapper.setProps({ pagination: { position: ['bottomRight'] } });
|
||||
expect(wrapper.find('.ant-spin-container').children()).toHaveLength(2);
|
||||
@ -195,6 +194,8 @@ describe('Table.pagination', () => {
|
||||
expect(wrapper.find('.ant-spin-container').children()).toHaveLength(3);
|
||||
expect(wrapper.find('.ant-spin-container').childAt(0).find('.ant-pagination')).toHaveLength(1);
|
||||
expect(wrapper.find('.ant-spin-container').childAt(2).find('.ant-pagination')).toHaveLength(1);
|
||||
wrapper.setProps({ pagination: { position: ['invalid'] } });
|
||||
expect(wrapper.find('.ant-pagination')).toHaveLength(1);
|
||||
});
|
||||
|
||||
/**
|
||||
@ -209,12 +210,14 @@ describe('Table.pagination', () => {
|
||||
|
||||
it('ajax render should keep display by the dataSource', () => {
|
||||
const onChange = jest.fn();
|
||||
const onPaginationChange = jest.fn();
|
||||
|
||||
const wrapper = mount(
|
||||
createTable({
|
||||
onChange,
|
||||
pagination: {
|
||||
total: 200,
|
||||
onChange: onPaginationChange,
|
||||
},
|
||||
}),
|
||||
);
|
||||
@ -223,6 +226,8 @@ describe('Table.pagination', () => {
|
||||
|
||||
wrapper.find('.ant-pagination .ant-pagination-item-2').simulate('click');
|
||||
expect(onChange.mock.calls[0][0].current).toBe(2);
|
||||
expect(onChange).toHaveBeenCalledWith({"current": 2, "pageSize": 10, "total": 200}, {}, {}, {"currentDataSource": [{"key": 0, "name": "Jack"}, {"key": 1, "name": "Lucy"}, {"key": 2, "name": "Tom"}, {"key": 3, "name": "Jerry"}]});
|
||||
expect(onPaginationChange).toHaveBeenCalledWith(2, 10);
|
||||
|
||||
expect(wrapper.find('.ant-table-tbody tr.ant-table-row')).toHaveLength(data.length);
|
||||
});
|
||||
|
@ -3,6 +3,7 @@ import { mount } from 'enzyme';
|
||||
import Table from '..';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
import rtlTest from '../../../tests/shared/rtlTest';
|
||||
import { sleep } from '../../../tests/utils';
|
||||
|
||||
const { Column, ColumnGroup } = Table;
|
||||
|
||||
@ -85,8 +86,15 @@ describe('Table', () => {
|
||||
loading.spinning = true;
|
||||
wrapper.setProps({ loading });
|
||||
expect(wrapper.find('.ant-spin')).toHaveLength(0);
|
||||
await sleep(500);
|
||||
wrapper.update();
|
||||
expect(wrapper.find('.ant-spin')).toHaveLength(1);
|
||||
});
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
// https://github.com/ant-design/ant-design/issues/22733
|
||||
it('support loading tip', async () => {
|
||||
const wrapper = mount(<Table loading={{ tip: 'loading...' }} />);
|
||||
await sleep(500);
|
||||
wrapper.update();
|
||||
expect(wrapper.find('.ant-spin')).toHaveLength(1);
|
||||
});
|
||||
@ -156,4 +164,19 @@ describe('Table', () => {
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
it('prevent touch event', () => {
|
||||
const wrapper = mount(
|
||||
<Table
|
||||
columns={[
|
||||
{
|
||||
dataIndex: 'name',
|
||||
children: undefined,
|
||||
},
|
||||
]}
|
||||
dataSource={[]}
|
||||
/>,
|
||||
);
|
||||
wrapper.simulate('touchmove');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user