2018-04-18 00:15:22 +08:00
|
|
|
import React from 'react';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2022-09-05 19:41:32 +08:00
|
|
|
import type { ListProps } from '..';
|
2018-04-18 00:15:22 +08:00
|
|
|
import List from '..';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
2024-04-08 14:04:08 +08:00
|
|
|
import ConfigProvider from '../../config-provider';
|
2018-04-18 00:15:22 +08:00
|
|
|
|
|
|
|
describe('List', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(List);
|
|
|
|
mountTest(List.Item);
|
|
|
|
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(List);
|
|
|
|
rtlTest(List.Item);
|
|
|
|
|
2018-04-18 00:15:22 +08:00
|
|
|
it('locale not passed to internal div', async () => {
|
|
|
|
const locale = { emptyText: 'Custom text' };
|
2022-11-19 13:47:33 +08:00
|
|
|
const renderItem: ListProps<any>['renderItem'] = (item) => <List.Item>{item}</List.Item>;
|
2022-09-05 19:41:32 +08:00
|
|
|
const dataSource: ListProps<any>['dataSource'] = [];
|
2018-04-18 00:15:22 +08:00
|
|
|
|
2022-06-01 13:45:51 +08:00
|
|
|
const { container } = render(
|
|
|
|
<List renderItem={renderItem} dataSource={dataSource} locale={locale} />,
|
|
|
|
);
|
2022-09-05 19:41:32 +08:00
|
|
|
expect(container.querySelector('div.ant-list')?.getAttribute('locale')).toBe(null);
|
2018-04-18 00:15:22 +08:00
|
|
|
});
|
2023-08-17 17:55:46 +08:00
|
|
|
|
|
|
|
it('should apply the componentSize of ConfigProvider', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<>
|
|
|
|
<ConfigProvider componentSize="small">
|
|
|
|
<List />,
|
|
|
|
</ConfigProvider>
|
|
|
|
<ConfigProvider componentSize="large">
|
|
|
|
<List />,
|
|
|
|
</ConfigProvider>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container.querySelector('.ant-list-sm')).toBeTruthy();
|
|
|
|
expect(container.querySelector('.ant-list-lg')).toBeTruthy();
|
|
|
|
});
|
2024-09-09 22:27:42 +08:00
|
|
|
|
|
|
|
it('ref should be able to get List id passe to internal div', async () => {
|
|
|
|
const renderItem: ListProps<any>['renderItem'] = (item) => <List.Item>{item}</List.Item>;
|
|
|
|
const dataSource: ListProps<any>['dataSource'] = [];
|
|
|
|
const ref = React.createRef<HTMLDivElement>();
|
|
|
|
const id = 'list-1';
|
|
|
|
render(<List ref={ref} id={id} renderItem={renderItem} dataSource={dataSource} />);
|
|
|
|
|
|
|
|
expect(ref.current?.id).toBe(id);
|
|
|
|
});
|
2018-04-18 00:15:22 +08:00
|
|
|
});
|