@@ -447,6 +447,91 @@ describe("db panel", () => {
447447 }
448448 } ) ;
449449
450+ describe ( "addNewRemoteRepo" , ( ) => {
451+ it ( "should add a new remote repo" , async ( ) => {
452+ const dbConfig : DbConfig = createDbConfig ( {
453+ remoteRepos : [ "owner1/repo1" ] ,
454+ } ) ;
455+
456+ await saveDbConfig ( dbConfig ) ;
457+
458+ const dbTreeItems = await dbTreeDataProvider . getChildren ( ) ;
459+
460+ expect ( dbTreeItems ) . toBeTruthy ( ) ;
461+ const items = dbTreeItems ! ;
462+
463+ const remoteRootNode = items [ 0 ] ;
464+ const remoteRepos = remoteRootNode . children . filter (
465+ ( c ) => c . dbItem ?. kind === DbItemKind . RemoteRepo ,
466+ ) ;
467+ const repo1 = remoteRootNode . children . find (
468+ ( c ) =>
469+ c . dbItem ?. kind === DbItemKind . RemoteRepo &&
470+ c . dbItem ?. repoFullName === "owner1/repo1" ,
471+ ) ;
472+
473+ expect ( remoteRepos . length ) . toBe ( 1 ) ;
474+ expect ( remoteRepos [ 0 ] ) . toBe ( repo1 ) ;
475+
476+ await dbManager . addNewRemoteRepo ( "owner2/repo2" ) ;
477+
478+ // Read the workspace databases JSON file directly to check that the new repo has been added.
479+ // We can't use the dbConfigStore's `read` function here because it depends on the file watcher
480+ // picking up changes, and we don't control the timing of that.
481+ const dbConfigFileContents = await readJSON ( dbConfigFilePath ) ;
482+ expect ( dbConfigFileContents . databases . remote . repositories . length ) . toBe ( 2 ) ;
483+ expect ( dbConfigFileContents . databases . remote . repositories [ 1 ] ) . toEqual (
484+ "owner2/repo2" ,
485+ ) ;
486+ } ) ;
487+
488+ it ( "should add a new remote repo to a user defined list" , async ( ) => {
489+ const dbConfig : DbConfig = createDbConfig ( {
490+ remoteLists : [
491+ {
492+ name : "my-list-1" ,
493+ repositories : [ "owner1/repo1" ] ,
494+ } ,
495+ ] ,
496+ } ) ;
497+
498+ await saveDbConfig ( dbConfig ) ;
499+
500+ const dbTreeItems = await dbTreeDataProvider . getChildren ( ) ;
501+
502+ expect ( dbTreeItems ) . toBeTruthy ( ) ;
503+ const items = dbTreeItems ! ;
504+
505+ const remoteRootNode = items [ 0 ] ;
506+ const remoteUserDefinedLists = remoteRootNode . children . filter (
507+ ( c ) => c . dbItem ?. kind === DbItemKind . RemoteUserDefinedList ,
508+ ) ;
509+ const list1 = remoteRootNode . children . find (
510+ ( c ) =>
511+ c . dbItem ?. kind === DbItemKind . RemoteUserDefinedList &&
512+ c . dbItem ?. listName === "my-list-1" ,
513+ ) ;
514+
515+ expect ( remoteUserDefinedLists . length ) . toBe ( 1 ) ;
516+ expect ( remoteUserDefinedLists [ 0 ] ) . toBe ( list1 ) ;
517+
518+ await dbManager . addNewRemoteRepo ( "owner2/repo2" , "my-list-1" ) ;
519+
520+ // Read the workspace databases JSON file directly to check that the new repo has been added.
521+ // We can't use the dbConfigStore's `read` function here because it depends on the file watcher
522+ // picking up changes, and we don't control the timing of that.
523+ const dbConfigFileContents = await readJSON ( dbConfigFilePath ) ;
524+ expect ( dbConfigFileContents . databases . remote . repositoryLists . length ) . toBe (
525+ 1 ,
526+ ) ;
527+
528+ expect ( dbConfigFileContents . databases . remote . repositoryLists [ 0 ] ) . toEqual ( {
529+ name : "my-list-1" ,
530+ repositories : [ "owner1/repo1" , "owner2/repo2" ] ,
531+ } ) ;
532+ } ) ;
533+ } ) ;
534+
450535 describe ( "addNewList" , ( ) => {
451536 it ( "should add a new remote list" , async ( ) => {
452537 const dbConfig : DbConfig = createDbConfig ( {
0 commit comments