@@ -7,12 +7,17 @@ import {
77 getBodyCellText ,
88 getBodyCellContent ,
99 GRID_CONNECTOR_PARENT_REQUEST_DELAY ,
10- getHeaderCellContent
10+ getHeaderCellContent ,
11+ collapseItems
1112} from './shared.js' ;
1213import sinon from 'sinon' ;
1314import type { FlowGrid } from './shared.js' ;
1415import type { GridColumn } from '@vaadin/grid' ;
1516
17+ function isGridInLoadingState ( grid : FlowGrid ) {
18+ return ( grid as any ) . _cache . isLoading ( ) ;
19+ }
20+
1621describe ( 'grid connector - tree' , ( ) => {
1722 let grid : FlowGrid ;
1823
@@ -200,4 +205,40 @@ describe('grid connector - tree', () => {
200205 // root item is outside the DOM so no requests should have been sent
201206 expect ( grid . $server . setParentRequestedRanges ) . to . not . be . called ;
202207 } ) ;
208+
209+ it ( 'should not request items for expanded and immediately collapsed parent' , async ( ) => {
210+ // Add expandable root item
211+ const rootItem = { key : '0' , name : 'foo' , children : true } ;
212+ setRootItems ( grid . $connector , [ rootItem ] ) ;
213+
214+ // Expand the root item
215+ expandItems ( grid . $connector , [ rootItem ] ) ;
216+ expect ( isGridInLoadingState ( grid ) ) . to . be . true ;
217+ // Immediately collapse the root item
218+ collapseItems ( grid . $connector , [ rootItem ] ) ;
219+ await nextFrame ( ) ;
220+
221+ await aTimeout ( GRID_CONNECTOR_PARENT_REQUEST_DELAY ) ;
222+
223+ expect ( isGridInLoadingState ( grid ) ) . to . be . false ;
224+ expect ( grid . $server . setParentRequestedRanges ) . to . not . be . called ;
225+ } ) ;
226+
227+ it ( 'should not request items for expanded and shortly collapsed parent' , async ( ) => {
228+ // Add expandable root item
229+ const rootItem = { key : '0' , name : 'foo' , children : true } ;
230+ setRootItems ( grid . $connector , [ rootItem ] ) ;
231+
232+ // Expand the root item
233+ expandItems ( grid . $connector , [ rootItem ] ) ;
234+ expect ( isGridInLoadingState ( grid ) ) . to . be . true ;
235+ // Collapse the root item after a short delay
236+ await nextFrame ( ) ;
237+ collapseItems ( grid . $connector , [ rootItem ] ) ;
238+
239+ await aTimeout ( GRID_CONNECTOR_PARENT_REQUEST_DELAY ) ;
240+
241+ expect ( isGridInLoadingState ( grid ) ) . to . be . false ;
242+ expect ( grid . $server . setParentRequestedRanges ) . to . not . be . called ;
243+ } ) ;
203244} ) ;
0 commit comments