11/* eslint-disable no-undef, react/no-multi-comp, no-console */
22import React from 'react' ;
3- import { mount } from 'enzyme ' ;
3+ import { render , fireEvent , act } from '@testing-library/react ' ;
44import { resetWarned } from '@rc-component/util/lib/warning' ;
55import TreeSelect , { TreeNode as SelectNode } from '../src' ;
6+ import { selectNode , triggerOpen , expectOpen } from './util' ;
7+ import { mount } from 'enzyme' ;
68
79describe ( 'TreeSelect.tree' , ( ) => {
810 const createSelect = props => (
@@ -71,7 +73,7 @@ describe('TreeSelect.tree', () => {
7173 it ( 'warning if node key are not same as value' , ( ) => {
7274 resetWarned ( ) ;
7375 const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
74- mount ( < TreeSelect treeData = { [ { title : 'little' , value : 'ttt' , key : 'little' } ] } /> ) ;
76+ render ( < TreeSelect treeData = { [ { title : 'little' , value : 'ttt' , key : 'little' } ] } /> ) ;
7577 expect ( spy ) . toHaveBeenCalledWith (
7678 'Warning: `key` or `value` with TreeNode must be the same or you can remove one of them. key: little, value: ttt.' ,
7779 ) ;
@@ -81,15 +83,15 @@ describe('TreeSelect.tree', () => {
8183 it ( 'warning if node undefined value' , ( ) => {
8284 resetWarned ( ) ;
8385 const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
84- mount ( < TreeSelect treeData = { [ { title : 'little' } ] } /> ) ;
86+ render ( < TreeSelect treeData = { [ { title : 'little' } ] } /> ) ;
8587 expect ( spy ) . toHaveBeenCalledWith ( 'Warning: TreeNode `value` is invalidate: undefined' ) ;
8688 spy . mockRestore ( ) ;
8789 } ) ;
8890
8991 it ( 'warning if node has same value' , ( ) => {
9092 resetWarned ( ) ;
9193 const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
92- mount (
94+ render (
9395 < TreeSelect
9496 treeData = { [
9597 { title : 'little' , value : 'ttt' } ,
@@ -103,13 +105,14 @@ describe('TreeSelect.tree', () => {
103105
104106 // https://github.com/ant-design/ant-design/issues/14597
105107 it ( 'empty string is also a value' , ( ) => {
106- const wrapper = mount (
108+ const { container } = render (
107109 < TreeSelect placeholder = "Please select" value = "" >
108110 < SelectNode key = "" value = "" title = "empty string" />
109111 </ TreeSelect > ,
110112 ) ;
111113
112- expect ( wrapper . getSelection ( 0 ) . text ( ) ) . toEqual ( 'empty string' ) ;
114+ const selectionContent = container . querySelector ( '.rc-tree-select-content-value' ) ;
115+ expect ( selectionContent ?. textContent ) . toEqual ( 'empty string' ) ;
113116 } ) ;
114117
115118 describe ( 'treeNodeLabelProp' , ( ) => {
@@ -121,7 +124,7 @@ describe('TreeSelect.tree', () => {
121124 } ,
122125 ] . forEach ( ( { name, ...restProps } ) => {
123126 it ( name , ( ) => {
124- const wrapper = mount (
127+ const { container } = render (
125128 < TreeSelect
126129 open
127130 treeDefaultExpandAll
@@ -131,31 +134,35 @@ describe('TreeSelect.tree', () => {
131134 /> ,
132135 ) ;
133136
134- expect ( wrapper . find ( '.rc-tree-select-tree-title' ) . text ( ) ) . toEqual ( 'a light' ) ;
135- expect ( wrapper . find ( '.rc-tree-select-selection-item' ) . text ( ) ) . toEqual ( 'Light' ) ;
137+ expect ( container . querySelector ( '.rc-tree-select-tree-title' ) ?. textContent ) . toEqual (
138+ 'a light' ,
139+ ) ;
140+ expect ( container . querySelector ( '.rc-tree-select-content-value' ) ?. textContent ) . toEqual (
141+ 'Light' ,
142+ ) ;
136143 } ) ;
137144 } ) ;
138145 } ) ;
139146
140147 it ( 'Node icon' , ( ) => {
141- const wrapper = mount (
148+ const { container } = render (
142149 < TreeSelect open >
143150 < SelectNode value = "little" title = "Little" icon = { < span className = "bamboo-light" /> } />
144151 </ TreeSelect > ,
145152 ) ;
146153
147- expect ( wrapper . exists ( '.bamboo-light' ) ) . toBeTruthy ( ) ;
154+ expect ( container . querySelector ( '.bamboo-light' ) ) . toBeTruthy ( ) ;
148155 } ) ;
149156
150157 it ( 'dynamic with filter should not show expand icon' , ( ) => {
151- const wrapper = mount (
158+ const { container } = render (
152159 < TreeSelect
153160 open
154161 treeData = { [ { label : 'Bamboo' , value : 'bamboo' , isLeaf : false } ] }
155162 searchValue = "boo"
156163 /> ,
157164 ) ;
158165
159- expect ( wrapper . exists ( '.rc-tree-select-tree-icon__open' ) ) . toBeFalsy ( ) ;
166+ expect ( container . querySelector ( '.rc-tree-select-tree-icon__open' ) ) . toBeFalsy ( ) ;
160167 } ) ;
161168} ) ;
0 commit comments