2019-03-11 23:34:05 +08:00
import React from 'react' ;
2020-01-02 19:10:16 +08:00
import { render , mount } from 'enzyme' ;
2019-03-11 23:34:05 +08:00
import List from '..' ;
2020-01-02 19:10:16 +08:00
import ConfigProvider from '../../config-provider' ;
2019-03-11 23:34:05 +08:00
describe ( 'List Item Layout' , ( ) => {
2019-03-18 10:46:17 +08:00
const data = [
{
key : 1 ,
2020-05-15 17:18:55 +08:00
href : 'https://ant.design' ,
2019-03-18 10:46:17 +08:00
title : ` ant design ` ,
avatar : 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png' ,
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' ,
} ,
] ;
2019-03-11 23:34:05 +08:00
it ( 'horizontal itemLayout List which contains string nodes should not be flex container' , ( ) => {
const wrapper = mount (
< List
dataSource = { data }
renderItem = { item => (
< List . Item key = { item . title } >
I am < span > ant < / s p a n > d e s i g n l i s t i t e m
< / L i s t . I t e m >
) }
2019-03-18 10:46:17 +08:00
/ > ,
2019-03-11 23:34:05 +08:00
) ;
2020-05-15 17:18:55 +08:00
expect ( wrapper . find ( '.ant-list-item' ) . at ( 0 ) . hasClass ( 'ant-list-item-no-flex' ) ) . toBe ( true ) ;
2019-03-11 23:34:05 +08:00
} ) ;
it ( 'horizontal itemLayout List should be flex container defaultly' , ( ) => {
const wrapper = mount (
< List
dataSource = { data }
renderItem = { item => (
< List . Item key = { item . title } >
< List . Item . Meta
title = { < a href = { item . href } > { item . title } < / a > }
description = { item . description }
/ >
< / L i s t . I t e m >
) }
2019-03-18 10:46:17 +08:00
/ > ,
2019-03-11 23:34:05 +08:00
) ;
2020-05-15 17:18:55 +08:00
expect ( wrapper . find ( '.ant-list-item' ) . at ( 0 ) . hasClass ( 'ant-list-item-no-flex' ) ) . toBe ( false ) ;
2019-03-11 23:34:05 +08:00
} ) ;
it ( 'vertical itemLayout List should be flex container when there is extra node' , ( ) => {
const wrapper = mount (
< 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 }
/ >
< / L i s t . I t e m >
) }
2019-03-18 10:46:17 +08:00
/ > ,
2019-03-11 23:34:05 +08:00
) ;
2020-05-15 17:18:55 +08:00
expect ( wrapper . find ( '.ant-list-item' ) . at ( 0 ) . hasClass ( 'ant-list-item-no-flex' ) ) . toBe ( false ) ;
2019-03-11 23:34:05 +08:00
} ) ;
it ( 'vertical itemLayout List should not be flex container when there is not extra node' , ( ) => {
const wrapper = mount (
< 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 }
/ >
< / L i s t . I t e m >
) }
2019-03-18 10:46:17 +08:00
/ > ,
2019-03-11 23:34:05 +08:00
) ;
2020-05-15 17:18:55 +08:00
expect ( wrapper . find ( '.ant-list-item' ) . at ( 0 ) . hasClass ( 'ant-list-item-no-flex' ) ) . toBe ( true ) ;
2019-03-11 23:34:05 +08:00
} ) ;
it ( 'horizontal itemLayout List should accept extra node' , ( ) => {
const wrapper = mount (
< List
dataSource = { data }
renderItem = { item => (
2019-08-02 17:59:42 +08:00
< List . Item
key = { item . title }
actions = { [ < a key = "action" > Action < / a > ] }
extra = { < span > { item . extra } < / s p a n > }
>
2019-03-11 23:34:05 +08:00
< List . Item . Meta
title = { < a href = { item . href } > { item . title } < / a > }
description = { item . description }
/ >
< / L i s t . I t e m >
) }
2019-03-18 10:46:17 +08:00
/ > ,
2019-03-11 23:34:05 +08:00
) ;
expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
} ) ;
2020-01-02 19:10:16 +08:00
it ( 'should render in RTL direction' , ( ) => {
const wrapper = mount (
< ConfigProvider direction = "rtl" >
< List
dataSource = { data }
renderItem = { item => (
< List . Item
key = { item . title }
actions = { [ < a key = "action" > Action < / a > ] }
extra = { < span > { item . extra } < / s p a n > }
>
< List . Item . Meta
title = { < a href = { item . href } > { item . title } < / a > }
description = { item . description }
/ >
< / L i s t . I t e m >
) }
/ >
< / C o n f i g P r o v i d e r > ,
) ;
expect ( render ( wrapper ) ) . toMatchSnapshot ( ) ;
} ) ;
2020-05-27 22:16:35 +08:00
it ( 'rowKey could be string' , ( ) => {
const dataWithId = [
{
id : 1 ,
title : ` ant design ` ,
} ,
{
id : 2 ,
title : ` ant design ` ,
} ,
{
id : 3 ,
title : ` ant design ` ,
} ,
] ;
const wrapper = mount (
< List
dataSource = { dataWithId }
rowKey = "id"
renderItem = { item => < List . Item > { item . title } < / L i s t . I t e m > }
/ > ,
) ;
expect ( wrapper ) . toMatchSnapshot ( ) ;
} ) ;
it ( 'rowKey could be function' , ( ) => {
const dataWithId = [
{
id : 1 ,
title : ` ant design ` ,
} ,
{
id : 2 ,
title : ` ant design ` ,
} ,
{
id : 3 ,
title : ` ant design ` ,
} ,
] ;
const wrapper = mount (
< List
dataSource = { dataWithId }
rowKey = { item => item . id }
renderItem = { item => < List . Item > { item . title } < / L i s t . I t e m > }
/ > ,
) ;
expect ( wrapper ) . toMatchSnapshot ( ) ;
} ) ;
2019-03-11 23:34:05 +08:00
} ) ;