@@ -443,52 +443,63 @@ describe("db panel", () => {
443443 }
444444 } ) ;
445445
446- it ( "should add a new list to the remote db list" , async ( ) => {
447- const dbConfig : DbConfig = createDbConfig ( {
448- remoteLists : [
449- {
450- name : "my-list-1" ,
451- repositories : [ "owner1/repo1" , "owner1/repo2" ] ,
446+ describe ( "addNewList" , ( ) => {
447+ it ( "should add a new remote list" , async ( ) => {
448+ const dbConfig : DbConfig = createDbConfig ( {
449+ remoteLists : [
450+ {
451+ name : "my-list-1" ,
452+ repositories : [ "owner1/repo1" , "owner1/repo2" ] ,
453+ } ,
454+ ] ,
455+ selected : {
456+ kind : SelectedDbItemKind . RemoteUserDefinedList ,
457+ listName : "my-list-1" ,
452458 } ,
453- ] ,
454- selected : {
455- kind : SelectedDbItemKind . RemoteUserDefinedList ,
456- listName : "my-list-1" ,
457- } ,
458- } ) ;
459+ } ) ;
459460
460- await saveDbConfig ( dbConfig ) ;
461+ await saveDbConfig ( dbConfig ) ;
461462
462- const dbTreeItems = await dbTreeDataProvider . getChildren ( ) ;
463+ const dbTreeItems = await dbTreeDataProvider . getChildren ( ) ;
463464
464- expect ( dbTreeItems ) . toBeTruthy ( ) ;
465- const items = dbTreeItems ! ;
465+ expect ( dbTreeItems ) . toBeTruthy ( ) ;
466+ const items = dbTreeItems ! ;
466467
467- const remoteRootNode = items [ 0 ] ;
468- const remoteUserDefinedLists = remoteRootNode . children . filter (
469- ( c ) => c . dbItem ?. kind === DbItemKind . RemoteUserDefinedList ,
470- ) ;
471- const list1 = remoteRootNode . children . find (
472- ( c ) =>
473- c . dbItem ?. kind === DbItemKind . RemoteUserDefinedList &&
474- c . dbItem ?. listName === "my-list-1" ,
475- ) ;
468+ const remoteRootNode = items [ 0 ] ;
469+ const remoteUserDefinedLists = remoteRootNode . children . filter (
470+ ( c ) => c . dbItem ?. kind === DbItemKind . RemoteUserDefinedList ,
471+ ) ;
472+ const list1 = remoteRootNode . children . find (
473+ ( c ) =>
474+ c . dbItem ?. kind === DbItemKind . RemoteUserDefinedList &&
475+ c . dbItem ?. listName === "my-list-1" ,
476+ ) ;
476477
477- expect ( remoteUserDefinedLists . length ) . toBe ( 1 ) ;
478- expect ( remoteUserDefinedLists [ 0 ] ) . toBe ( list1 ) ;
478+ expect ( remoteUserDefinedLists . length ) . toBe ( 1 ) ;
479+ expect ( remoteUserDefinedLists [ 0 ] ) . toBe ( list1 ) ;
479480
480- await dbManager . addNewRemoteList ( "my-list-2" ) ;
481+ await dbManager . addNewList ( DbItemKind . RootRemote , "my-list-2" ) ;
481482
482- // Read the workspace databases JSON file directly to check that the new list has been added.
483- // We can't use the dbConfigStore's `read` function here because it depends on the file watcher
484- // picking up changes, and we don't control the timing of that.
485- const dbConfigFileContents = await readJSON ( dbConfigFilePath ) ;
486- expect ( dbConfigFileContents . databases . remote . repositoryLists . length ) . toBe (
487- 2 ,
488- ) ;
489- expect ( dbConfigFileContents . databases . remote . repositoryLists [ 1 ] ) . toEqual ( {
490- name : "my-list-2" ,
491- repositories : [ ] ,
483+ // Read the workspace databases JSON file directly to check that the new list has been added.
484+ // We can't use the dbConfigStore's `read` function here because it depends on the file watcher
485+ // picking up changes, and we don't control the timing of that.
486+ const dbConfigFileContents = await readJSON ( dbConfigFilePath ) ;
487+ expect ( dbConfigFileContents . databases . remote . repositoryLists . length ) . toBe (
488+ 2 ,
489+ ) ;
490+ expect ( dbConfigFileContents . databases . remote . repositoryLists [ 1 ] ) . toEqual ( {
491+ name : "my-list-2" ,
492+ repositories : [ ] ,
493+ } ) ;
494+ } ) ;
495+
496+ it ( "should throw error when adding a new list to a local node" , async ( ) => {
497+ const dbConfig : DbConfig = createDbConfig ( ) ;
498+ await saveDbConfig ( dbConfig ) ;
499+
500+ await expect (
501+ dbManager . addNewList ( DbItemKind . RootLocal , "" ) ,
502+ ) . rejects . toThrow ( new Error ( "Cannot add a local list" ) ) ;
492503 } ) ;
493504 } ) ;
494505
@@ -555,9 +566,9 @@ describe("db panel", () => {
555566
556567 await saveDbConfig ( dbConfig ) ;
557568
558- await expect ( dbManager . addNewRemoteList ( "" ) ) . rejects . toThrow (
559- new Error ( "List name cannot be empty ") ,
560- ) ;
569+ await expect (
570+ dbManager . addNewList ( DbItemKind . RootRemote , " ") ,
571+ ) . rejects . toThrow ( new Error ( "List name cannot be empty" ) ) ;
561572 } ) ;
562573
563574 it ( "should not allow adding a list with duplicate name" , async ( ) => {
@@ -572,7 +583,9 @@ describe("db panel", () => {
572583
573584 await saveDbConfig ( dbConfig ) ;
574585
575- await expect ( dbManager . addNewRemoteList ( "my-list-1" ) ) . rejects . toThrow (
586+ await expect (
587+ dbManager . addNewList ( DbItemKind . RootRemote , "my-list-1" ) ,
588+ ) . rejects . toThrow (
576589 new Error ( "A list with the name 'my-list-1' already exists" ) ,
577590 ) ;
578591 } ) ;
0 commit comments