2022-06-22 14:57:09 +08:00
import React from 'react' ;
2024-04-08 14:04:08 +08:00
2019-09-23 18:49:13 +08:00
import TreeSelect , { TreeNode } from '..' ;
2024-04-08 14:04:08 +08:00
import { resetWarned } from '../../_util/warning' ;
2017-11-19 01:41:40 +08:00
import focusTest from '../../../tests/shared/focusTest' ;
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' ;
2023-04-04 17:17:36 +08:00
import { render } from '../../../tests/utils' ;
2017-11-19 01:41:40 +08:00
describe ( 'TreeSelect' , ( ) = > {
2020-11-08 15:27:30 +08:00
focusTest ( TreeSelect , { refFocus : true } ) ;
2019-08-26 22:53:20 +08:00
mountTest ( TreeSelect ) ;
2020-01-02 19:10:16 +08:00
rtlTest ( TreeSelect ) ;
2019-05-06 12:04:39 +08:00
2019-09-23 18:49:13 +08:00
describe ( 'TreeSelect Custom Icons' , ( ) = > {
it ( 'should support customized icons' , ( ) = > {
2022-08-23 11:57:50 +08:00
const { container } = render (
2019-09-23 18:49:13 +08:00
< TreeSelect
showSearch
clearIcon = { < span > clear < / span > }
removeIcon = { < span > remove < / span > }
value = { [ 'leaf1' , 'leaf2' ] }
placeholder = "Please select"
multiple
allowClear
treeDefaultExpandAll
>
< TreeNode value = "parent 1" title = "parent 1" key = "0-1" >
< TreeNode value = "parent 1-0" title = "parent 1-0" key = "0-1-1" >
< TreeNode value = "leaf1" title = "my leaf" key = "random" / >
< TreeNode value = "leaf2" title = "your leaf" key = "random1" / >
< / TreeNode >
< / TreeNode >
< / TreeSelect > ,
) ;
2022-08-23 11:57:50 +08:00
expect ( container . firstChild ) . toMatchSnapshot ( ) ;
2019-09-23 18:49:13 +08:00
} ) ;
2020-03-20 16:03:13 +08:00
it ( 'should `treeIcon` work' , ( ) = > {
2022-08-23 11:57:50 +08:00
const { container } = render (
2020-03-20 16:03:13 +08:00
< TreeSelect treeIcon open >
< TreeNode value = "parent 1" title = "parent 1" icon = { < span > Bamboo < / span > } / >
< / TreeSelect > ,
) ;
2022-08-23 11:57:50 +08:00
expect ( container . firstChild ) . toMatchSnapshot ( ) ;
2020-03-20 16:03:13 +08:00
} ) ;
2019-09-23 18:49:13 +08:00
} ) ;
2020-08-26 16:42:47 +08:00
it ( 'should support notFoundContent' , ( ) = > {
2022-08-23 11:57:50 +08:00
const content = 'notFoundContent' ;
const { container } = render ( < TreeSelect treeIcon open notFoundContent = { content } / > ) ;
expect ( container . querySelector ( '.ant-select-empty' ) ? . innerHTML ) . toBe ( content ) ;
2020-08-26 16:42:47 +08:00
} ) ;
2022-09-08 14:33:11 +08:00
it ( 'legacy dropdownClassName' , ( ) = > {
resetWarned ( ) ;
2023-06-07 21:59:21 +08:00
const errSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) = > { } ) ;
2022-09-08 14:33:11 +08:00
const { container } = render ( < TreeSelect dropdownClassName = "legacy" open / > ) ;
expect ( errSpy ) . toHaveBeenCalledWith (
'Warning: [antd: TreeSelect] `dropdownClassName` is deprecated. Please use `popupClassName` instead.' ,
) ;
expect ( container . querySelector ( '.legacy' ) ) . toBeTruthy ( ) ;
errSpy . mockRestore ( ) ;
} ) ;
2023-04-04 17:17:36 +08:00
it ( 'warning for legacy dropdownMatchSelectWidth' , ( ) = > {
resetWarned ( ) ;
2023-06-07 21:59:21 +08:00
const errSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) = > { } ) ;
2023-04-04 17:17:36 +08:00
render ( < TreeSelect dropdownMatchSelectWidth open / > ) ;
expect ( errSpy ) . toHaveBeenCalledWith (
2023-09-13 22:07:33 +08:00
'Warning: [antd: TreeSelect] `dropdownMatchSelectWidth` is deprecated. Please use `popupMatchSelectWidth` instead.' ,
2023-04-04 17:17:36 +08:00
) ;
errSpy . mockRestore ( ) ;
} ) ;
2023-04-27 10:16:07 +08:00
2023-04-25 15:27:00 +08:00
it ( 'support aria-*' , async ( ) = > {
const { container } = render (
< TreeSelect
open
treeData = { [ { value : 'parent 1' , title : 'parnet 1' , 'aria-label' : 'label' } ] }
/ > ,
) ;
expect (
container . querySelector ( '.ant-select-tree-treenode-leaf-last' ) ? . getAttribute ( 'aria-label' ) ,
) . toBe ( 'label' ) ;
} ) ;
2023-07-19 20:27:09 +08:00
it ( 'deprecate showArrow' , ( ) = > {
resetWarned ( ) ;
const errSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) = > { } ) ;
const { container } = render ( < TreeSelect showArrow / > ) ;
expect ( errSpy ) . toHaveBeenCalledWith (
'Warning: [antd: TreeSelect] `showArrow` is deprecated which will be removed in next major version. It will be a default behavior, you can hide it by setting `suffixIcon` to null.' ,
) ;
expect ( container . querySelector ( '.ant-select-show-arrow' ) ) . toBeTruthy ( ) ;
errSpy . mockRestore ( ) ;
} ) ;
2017-11-19 01:41:40 +08:00
} ) ;