@@ -4,6 +4,7 @@ import { CodeQLExtensionInterface } from "../../../extension";
44import { readJson } from "fs-extra" ;
55import * as path from "path" ;
66import { DbConfig } from "../../../databases/config/db-config" ;
7+ import { RemoteDatabaseQuickPickItem } from "../../../databases/ui/db-panel" ;
78
89jest . setTimeout ( 60_000 ) ;
910
@@ -33,4 +34,36 @@ describe("Db panel UI commands", () => {
3334 expect ( dbConfig . databases . remote . repositoryLists ) . toHaveLength ( 1 ) ;
3435 expect ( dbConfig . databases . remote . repositoryLists [ 0 ] . name ) . toBe ( "my-list-1" ) ;
3536 } ) ;
37+
38+ it ( "should add new remote repository" , async ( ) => {
39+ // Add db
40+ jest . spyOn ( window , "showQuickPick" ) . mockResolvedValue ( {
41+ kind : "repo" ,
42+ } as RemoteDatabaseQuickPickItem ) ;
43+
44+ jest . spyOn ( window , "showInputBox" ) . mockResolvedValue ( "owner1/repo1" ) ;
45+ await commands . executeCommand ( "codeQLDatabasesExperimental.addNewDatabase" ) ;
46+
47+ // Check db config
48+ const dbConfigFilePath = path . join ( storagePath , "workspace-databases.json" ) ;
49+ const dbConfig : DbConfig = await readJson ( dbConfigFilePath ) ;
50+ expect ( dbConfig . databases . remote . repositories ) . toHaveLength ( 1 ) ;
51+ expect ( dbConfig . databases . remote . repositories [ 0 ] ) . toBe ( "owner1/repo1" ) ;
52+ } ) ;
53+
54+ it ( "should add new remote owner" , async ( ) => {
55+ // Add owner
56+ jest . spyOn ( window , "showQuickPick" ) . mockResolvedValue ( {
57+ kind : "owner" ,
58+ } as RemoteDatabaseQuickPickItem ) ;
59+
60+ jest . spyOn ( window , "showInputBox" ) . mockResolvedValue ( "owner1" ) ;
61+ await commands . executeCommand ( "codeQLDatabasesExperimental.addNewDatabase" ) ;
62+
63+ // Check db config
64+ const dbConfigFilePath = path . join ( storagePath , "workspace-databases.json" ) ;
65+ const dbConfig : DbConfig = await readJson ( dbConfigFilePath ) ;
66+ expect ( dbConfig . databases . remote . owners ) . toHaveLength ( 1 ) ;
67+ expect ( dbConfig . databases . remote . owners [ 0 ] ) . toBe ( "owner1" ) ;
68+ } ) ;
3669} ) ;
0 commit comments