@@ -478,10 +478,7 @@ describe("db panel", () => {
478478
479479 await dbManager . addNewRemoteRepo ( "owner2/repo2" ) ;
480480
481- // Read the workspace databases JSON file directly to check that the new repo has been added.
482- // We can't use the dbConfigStore's `read` function here because it depends on the file watcher
483- // picking up changes, and we don't control the timing of that.
484- const dbConfigFileContents = await readJSON ( dbConfigFilePath ) ;
481+ const dbConfigFileContents = await readDbConfigDirectly ( ) ;
485482 expect ( dbConfigFileContents . databases . remote . repositories . length ) . toBe ( 2 ) ;
486483 expect ( dbConfigFileContents . databases . remote . repositories [ 1 ] ) . toEqual (
487484 "owner2/repo2" ,
@@ -572,10 +569,7 @@ describe("db panel", () => {
572569
573570 await dbManager . addNewList ( DbListKind . Remote , "my-list-2" ) ;
574571
575- // Read the workspace databases JSON file directly to check that the new list has been added.
576- // We can't use the dbConfigStore's `read` function here because it depends on the file watcher
577- // picking up changes, and we don't control the timing of that.
578- const dbConfigFileContents = await readJSON ( dbConfigFilePath ) ;
572+ const dbConfigFileContents = await readDbConfigDirectly ( ) ;
579573 expect ( dbConfigFileContents . databases . remote . repositoryLists . length ) . toBe (
580574 2 ,
581575 ) ;
@@ -586,12 +580,42 @@ describe("db panel", () => {
586580 } ) ;
587581
588582 it ( "should throw error when adding a new list to a local node" , async ( ) => {
589- const dbConfig : DbConfig = createDbConfig ( ) ;
583+ const dbConfig : DbConfig = createDbConfig ( {
584+ localLists : [
585+ {
586+ name : "my-list-1" ,
587+ databases : [ ] ,
588+ } ,
589+ ] ,
590+ } ) ;
590591 await saveDbConfig ( dbConfig ) ;
591592
592- await expect ( dbManager . addNewList ( DbListKind . Local , "" ) ) . rejects . toThrow (
593- new Error ( "Cannot add a local list" ) ,
593+ const dbTreeItems = await dbTreeDataProvider . getChildren ( ) ;
594+
595+ expect ( dbTreeItems ) . toBeTruthy ( ) ;
596+ const items = dbTreeItems ! ;
597+
598+ const localRootNode = items [ 1 ] ;
599+ const localUserDefinedLists = localRootNode . children . filter (
600+ ( c ) => c . dbItem ?. kind === DbItemKind . LocalList ,
601+ ) ;
602+ const list1 = localRootNode . children . find (
603+ ( c ) =>
604+ c . dbItem ?. kind === DbItemKind . LocalList &&
605+ c . dbItem ?. listName === "my-list-1" ,
594606 ) ;
607+
608+ expect ( localUserDefinedLists . length ) . toBe ( 1 ) ;
609+ expect ( localUserDefinedLists [ 0 ] ) . toBe ( list1 ) ;
610+
611+ await dbManager . addNewList ( DbListKind . Local , "my-list-2" ) ;
612+
613+ const dbConfigFileContents = await readDbConfigDirectly ( ) ;
614+ expect ( dbConfigFileContents . databases . local . lists . length ) . toBe ( 2 ) ;
615+ expect ( dbConfigFileContents . databases . local . lists [ 1 ] ) . toEqual ( {
616+ name : "my-list-2" ,
617+ databases : [ ] ,
618+ } ) ;
595619 } ) ;
596620 } ) ;
597621
@@ -838,4 +862,11 @@ describe("db panel", () => {
838862 SELECTED_DB_ITEM_RESOURCE_URI && treeViewItem . contextValue === undefined
839863 ) ;
840864 }
865+
866+ async function readDbConfigDirectly ( ) : Promise < DbConfig > {
867+ // Read the workspace databases JSON file directly to check that the new list has been added.
868+ // We can't use the dbConfigStore's `read` function here because it depends on the file watcher
869+ // picking up changes, and we don't control the timing of that.
870+ return ( await readJSON ( dbConfigFilePath ) ) as DbConfig ;
871+ }
841872} ) ;
0 commit comments