@@ -464,6 +464,40 @@ describe("db manager", () => {
464464 expandedItems ! [ 0 ] as VariantAnalysisUserDefinedListExpandedDbItem ;
465465 expect ( expandedItem . listName ) . toEqual ( "new-list-name" ) ;
466466 } ) ;
467+
468+ it ( "should remove non existent items in expanded state when item is expanded" , async ( ) => {
469+ // We remove items from the expanded state if they are not in the config
470+
471+ // Populate expanded state with non existent item
472+ const listName = "my-list-4" ;
473+ const variantAnalysisList = {
474+ kind : ExpandedDbItemKind . RemoteUserDefinedList ,
475+ listName,
476+ } ;
477+
478+ await app . workspaceState . update ( DbManager . DB_EXPANDED_STATE_KEY , [
479+ variantAnalysisList ,
480+ ] ) ;
481+ let expandedItems = await app . workspaceState . get < ExpandedDbItem [ ] > (
482+ DbManager . DB_EXPANDED_STATE_KEY ,
483+ ) ;
484+ expect ( expandedItems ?. length ) . toEqual ( 1 ) ;
485+ const expandedItem =
486+ expandedItems ! [ 0 ] as VariantAnalysisUserDefinedListExpandedDbItem ;
487+ expect ( expandedItem . listName ) . toEqual ( listName ) ;
488+
489+ // Trigger adding an item that is not in the config
490+ const dbItem = createVariantAnalysisUserDefinedListDbItem ( {
491+ listName : "new-item" ,
492+ } ) ;
493+
494+ await dbManager . addDbItemToExpandedState ( dbItem ) ;
495+ expandedItems = await app . workspaceState . get < ExpandedDbItem [ ] > (
496+ DbManager . DB_EXPANDED_STATE_KEY ,
497+ ) ;
498+
499+ expect ( expandedItems ?. length ) . toEqual ( 0 ) ;
500+ } ) ;
467501 } ) ;
468502
469503 async function saveDbConfig ( dbConfig : DbConfig ) : Promise < void > {
0 commit comments