@@ -162,6 +162,81 @@ describe('Table.Expand', () => {
162162 expect ( container . firstChild ) . toMatchSnapshot ( ) ;
163163 } ) ;
164164
165+ it ( 'honors rowExpandable for tree data' , ( ) => {
166+ const onExpand = vi . fn ( ) ;
167+ const data = [
168+ {
169+ key : 'allowed' ,
170+ name : 'Allowed parent' ,
171+ children : [ { key : 'allowed-child' , name : 'Allowed child' } ] ,
172+ } ,
173+ {
174+ key : 'blocked' ,
175+ name : 'Blocked parent' ,
176+ children : [ { key : 'blocked-child' , name : 'Blocked child' } ] ,
177+ } ,
178+ { key : 'empty' , name : 'Empty parent' , children : [ ] } ,
179+ ] ;
180+ const { container } = render (
181+ createTable ( {
182+ data,
183+ expandable : {
184+ expandedRowKeys : [ 'allowed' , 'blocked' , 'empty' ] ,
185+ expandRowByClick : true ,
186+ onExpand,
187+ rowExpandable : record => record . key === 'allowed' ,
188+ } ,
189+ } ) ,
190+ ) ;
191+
192+ expect ( container . querySelector ( '[data-row-key="allowed-child"]' ) ) . toBeTruthy ( ) ;
193+ expect ( container . querySelector ( '[data-row-key="blocked-child"]' ) ) . toBeFalsy ( ) ;
194+
195+ const allowedIcon = container . querySelector (
196+ '[data-row-key="allowed"] .rc-table-row-expand-icon' ,
197+ ) ;
198+ const blockedIcon = container . querySelector (
199+ '[data-row-key="blocked"] .rc-table-row-expand-icon' ,
200+ ) ;
201+ const emptyIcon = container . querySelector ( '[data-row-key="empty"] .rc-table-row-expand-icon' ) ;
202+ expect ( allowedIcon ) . toHaveClass ( 'rc-table-row-expanded' ) ;
203+ expect ( blockedIcon ) . toHaveClass ( 'rc-table-row-spaced' ) ;
204+ expect ( emptyIcon ) . toHaveClass ( 'rc-table-row-spaced' ) ;
205+
206+ fireEvent . click ( container . querySelector ( '[data-row-key="blocked"]' ) ) ;
207+ expect ( onExpand ) . not . toHaveBeenCalled ( ) ;
208+ } ) ;
209+
210+ it ( 'honors rowExpandable when expanding all tree rows by default' , ( ) => {
211+ const data = [
212+ {
213+ key : 'allowed' ,
214+ name : 'Allowed parent' ,
215+ children : [ { key : 'allowed-child' , name : 'Allowed child' } ] ,
216+ } ,
217+ {
218+ key : 'blocked' ,
219+ name : 'Blocked parent' ,
220+ children : [ { key : 'blocked-child' , name : 'Blocked child' } ] ,
221+ } ,
222+ ] ;
223+ const { container } = render (
224+ createTable ( {
225+ data,
226+ expandable : {
227+ defaultExpandAllRows : true ,
228+ rowExpandable : record => record . key === 'allowed' ,
229+ } ,
230+ } ) ,
231+ ) ;
232+
233+ expect ( container . querySelector ( '[data-row-key="allowed-child"]' ) ) . toBeTruthy ( ) ;
234+ expect ( container . querySelector ( '[data-row-key="blocked-child"]' ) ) . toBeFalsy ( ) ;
235+ expect (
236+ container . querySelector ( '[data-row-key="blocked"] .rc-table-row-expand-icon' ) ,
237+ ) . toHaveClass ( 'rc-table-row-spaced' ) ;
238+ } ) ;
239+
165240 it ( 'not use nest when children is invalidate' , ( ) => {
166241 const data = [
167242 { key : 2 , name : 'Jack' , age : 28 , children : null } ,
0 commit comments