You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
208 lines
5.6 KiB
208 lines
5.6 KiB
6 years ago
|
import React from 'react';
|
||
|
import List from '..';
|
||
3 years ago
|
import { render } from '../../../tests/utils';
|
||
2 years ago
|
import ConfigProvider from '../../config-provider';
|
||
6 years ago
|
|
||
|
describe('List Item Layout', () => {
|
||
6 years ago
|
const data = [
|
||
|
{
|
||
|
key: 1,
|
||
5 years ago
|
href: 'https://ant.design',
|
||
6 years ago
|
title: `ant design`,
|
||
3 years ago
|
avatar: 'https://joeschmoe.io/api/v1/random',
|
||
6 years ago
|
description:
|
||
|
'Ant Design, a design language for background applications, is refined by Ant UED Team.',
|
||
|
content:
|
||
|
'We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.',
|
||
|
extra: 'extra',
|
||
|
},
|
||
|
];
|
||
6 years ago
|
|
||
|
it('horizontal itemLayout List which contains string nodes should not be flex container', () => {
|
||
3 years ago
|
const { container: wrapper } = render(
|
||
6 years ago
|
<List
|
||
|
dataSource={data}
|
||
|
renderItem={item => (
|
||
|
<List.Item key={item.title}>
|
||
|
I am <span>ant</span> design list item
|
||
|
</List.Item>
|
||
|
)}
|
||
6 years ago
|
/>,
|
||
6 years ago
|
);
|
||
3 years ago
|
expect(
|
||
|
wrapper.querySelectorAll('.ant-list-item')[0].classList.contains('ant-list-item-no-flex'),
|
||
|
).toBe(true);
|
||
6 years ago
|
});
|
||
|
|
||
3 years ago
|
it('horizontal itemLayout List should be flex container by default', () => {
|
||
|
const { container: wrapper } = render(
|
||
6 years ago
|
<List
|
||
|
dataSource={data}
|
||
|
renderItem={item => (
|
||
|
<List.Item key={item.title}>
|
||
|
<List.Item.Meta
|
||
|
title={<a href={item.href}>{item.title}</a>}
|
||
|
description={item.description}
|
||
|
/>
|
||
|
</List.Item>
|
||
|
)}
|
||
6 years ago
|
/>,
|
||
6 years ago
|
);
|
||
3 years ago
|
expect(
|
||
2 years ago
|
wrapper.querySelector('.ant-list-item')?.classList.contains('ant-list-item-no-flex'),
|
||
3 years ago
|
).toBe(false);
|
||
6 years ago
|
});
|
||
|
|
||
|
it('vertical itemLayout List should be flex container when there is extra node', () => {
|
||
3 years ago
|
const { container: wrapper } = render(
|
||
6 years ago
|
<List
|
||
|
itemLayout="vertical"
|
||
|
dataSource={data}
|
||
|
renderItem={item => (
|
||
|
<List.Item key={item.title} extra={item.extra}>
|
||
|
<List.Item.Meta
|
||
|
title={<a href={item.href}>{item.title}</a>}
|
||
|
description={item.description}
|
||
|
/>
|
||
|
</List.Item>
|
||
|
)}
|
||
6 years ago
|
/>,
|
||
6 years ago
|
);
|
||
3 years ago
|
expect(
|
||
|
wrapper.querySelectorAll('.ant-list-item')[0].classList.contains('ant-list-item-no-flex'),
|
||
|
).toBe(false);
|
||
6 years ago
|
});
|
||
|
|
||
|
it('vertical itemLayout List should not be flex container when there is not extra node', () => {
|
||
3 years ago
|
const { container: wrapper } = render(
|
||
6 years ago
|
<List
|
||
|
itemLayout="vertical"
|
||
|
dataSource={data}
|
||
|
renderItem={item => (
|
||
|
<List.Item key={item.title}>
|
||
|
<List.Item.Meta
|
||
|
title={<a href={item.href}>{item.title}</a>}
|
||
|
description={item.description}
|
||
|
/>
|
||
|
</List.Item>
|
||
|
)}
|
||
6 years ago
|
/>,
|
||
6 years ago
|
);
|
||
3 years ago
|
expect(
|
||
|
wrapper.querySelectorAll('.ant-list-item')[0].classList.contains('ant-list-item-no-flex'),
|
||
|
).toBe(true);
|
||
6 years ago
|
});
|
||
|
|
||
|
it('horizontal itemLayout List should accept extra node', () => {
|
||
3 years ago
|
const { container: wrapper } = render(
|
||
6 years ago
|
<List
|
||
|
dataSource={data}
|
||
|
renderItem={item => (
|
||
5 years ago
|
<List.Item
|
||
|
key={item.title}
|
||
|
actions={[<a key="action">Action</a>]}
|
||
|
extra={<span>{item.extra}</span>}
|
||
|
>
|
||
6 years ago
|
<List.Item.Meta
|
||
|
title={<a href={item.href}>{item.title}</a>}
|
||
|
description={item.description}
|
||
|
/>
|
||
|
</List.Item>
|
||
|
)}
|
||
6 years ago
|
/>,
|
||
6 years ago
|
);
|
||
3 years ago
|
expect(wrapper.firstChild).toMatchSnapshot();
|
||
6 years ago
|
});
|
||
5 years ago
|
|
||
|
it('should render in RTL direction', () => {
|
||
3 years ago
|
const { container: wrapper } = render(
|
||
5 years ago
|
<ConfigProvider direction="rtl">
|
||
|
<List
|
||
|
dataSource={data}
|
||
|
renderItem={item => (
|
||
|
<List.Item
|
||
|
key={item.title}
|
||
|
actions={[<a key="action">Action</a>]}
|
||
|
extra={<span>{item.extra}</span>}
|
||
|
>
|
||
|
<List.Item.Meta
|
||
|
title={<a href={item.href}>{item.title}</a>}
|
||
|
description={item.description}
|
||
|
/>
|
||
|
</List.Item>
|
||
|
)}
|
||
|
/>
|
||
|
</ConfigProvider>,
|
||
|
);
|
||
3 years ago
|
expect(wrapper.firstChild).toMatchSnapshot();
|
||
5 years ago
|
});
|
||
5 years ago
|
|
||
|
it('rowKey could be string', () => {
|
||
|
const dataWithId = [
|
||
|
{
|
||
|
id: 1,
|
||
|
title: `ant design`,
|
||
|
},
|
||
|
{
|
||
|
id: 2,
|
||
|
title: `ant design`,
|
||
|
},
|
||
|
{
|
||
|
id: 3,
|
||
|
title: `ant design`,
|
||
|
},
|
||
|
];
|
||
3 years ago
|
const { container: wrapper } = render(
|
||
5 years ago
|
<List
|
||
|
dataSource={dataWithId}
|
||
|
rowKey="id"
|
||
|
renderItem={item => <List.Item>{item.title}</List.Item>}
|
||
|
/>,
|
||
|
);
|
||
3 years ago
|
expect(wrapper.firstChild).toMatchSnapshot();
|
||
5 years ago
|
});
|
||
|
|
||
|
it('rowKey could be function', () => {
|
||
|
const dataWithId = [
|
||
|
{
|
||
|
id: 1,
|
||
|
title: `ant design`,
|
||
|
},
|
||
|
{
|
||
|
id: 2,
|
||
|
title: `ant design`,
|
||
|
},
|
||
|
{
|
||
|
id: 3,
|
||
|
title: `ant design`,
|
||
|
},
|
||
|
];
|
||
3 years ago
|
const { container: wrapper } = render(
|
||
5 years ago
|
<List
|
||
|
dataSource={dataWithId}
|
||
|
rowKey={item => item.id}
|
||
|
renderItem={item => <List.Item>{item.title}</List.Item>}
|
||
|
/>,
|
||
|
);
|
||
3 years ago
|
expect(wrapper.firstChild).toMatchSnapshot();
|
||
5 years ago
|
});
|
||
3 years ago
|
|
||
|
it('should ref', () => {
|
||
2 years ago
|
const ref = React.createRef<HTMLElement>();
|
||
3 years ago
|
|
||
|
render(<List.Item ref={ref}>Item</List.Item>);
|
||
|
expect(ref.current).toHaveClass('ant-list-item');
|
||
|
});
|
||
|
|
||
|
it('should grid ref', () => {
|
||
2 years ago
|
const ref = React.createRef<HTMLElement>();
|
||
3 years ago
|
|
||
|
render(
|
||
2 years ago
|
<List grid={{}}>
|
||
3 years ago
|
<List.Item ref={ref}>Item</List.Item>,
|
||
|
</List>,
|
||
|
);
|
||
|
expect(ref.current).toHaveClass('ant-col');
|
||
|
});
|
||
6 years ago
|
});
|