Skip to content

Commit 55869e8

Browse files
authored
Merge pull request #1894 from github/charisk/add-db-integration-test
Add basic integration test for 'add db' functionality
2 parents 952faf5 + 47ac9c6 commit 55869e8

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

extensions/ql-vscode/src/databases/ui/db-panel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { DbManager } from "../db-manager";
1818
import { DbTreeDataProvider } from "./db-tree-data-provider";
1919
import { DbTreeViewItem } from "./db-tree-view-item";
2020

21-
interface RemoteDatabaseQuickPickItem extends QuickPickItem {
21+
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
2222
kind: string;
2323
}
2424

@@ -63,7 +63,7 @@ export class DbPanel extends DisposableObject {
6363
);
6464
this.push(
6565
commandRunner("codeQLDatabasesExperimental.addNewList", () =>
66-
this.addNewRemoteList(),
66+
this.addNewList(),
6767
),
6868
);
6969
this.push(
@@ -151,7 +151,7 @@ export class DbPanel extends DisposableObject {
151151
await this.dbManager.addNewRemoteOwner(owner);
152152
}
153153

154-
private async addNewRemoteList(): Promise<void> {
154+
private async addNewList(): Promise<void> {
155155
const listName = await window.showInputBox({
156156
prompt: "Enter a name for the new list",
157157
placeHolder: "example-list",

extensions/ql-vscode/src/vscode-tests/cli-integration/databases/db-panel.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CodeQLExtensionInterface } from "../../../extension";
44
import { readJson } from "fs-extra";
55
import * as path from "path";
66
import { DbConfig } from "../../../databases/config/db-config";
7+
import { RemoteDatabaseQuickPickItem } from "../../../databases/ui/db-panel";
78

89
jest.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

Comments
 (0)