|
| 1 | +import { commands, extensions, window } from "vscode"; |
| 2 | + |
| 3 | +import { CodeQLExtensionInterface } from "../../../extension"; |
| 4 | +import { readJson } from "fs-extra"; |
| 5 | +import * as path from "path"; |
| 6 | +import { DbConfig } from "../../../databases/config/db-config"; |
| 7 | + |
| 8 | +jest.setTimeout(60_000); |
| 9 | + |
| 10 | +describe("Db panel UI commands", () => { |
| 11 | + let extension: CodeQLExtensionInterface | Record<string, never>; |
| 12 | + let storagePath: string; |
| 13 | + |
| 14 | + beforeEach(async () => { |
| 15 | + extension = await extensions |
| 16 | + .getExtension<CodeQLExtensionInterface | Record<string, never>>( |
| 17 | + "GitHub.vscode-codeql", |
| 18 | + )! |
| 19 | + .activate(); |
| 20 | + |
| 21 | + storagePath = |
| 22 | + extension.ctx.storageUri?.fsPath || extension.ctx.globalStorageUri.fsPath; |
| 23 | + }); |
| 24 | + |
| 25 | + it("should add new remote db list", async () => { |
| 26 | + // Add db list |
| 27 | + jest.spyOn(window, "showInputBox").mockResolvedValue("my-list-1"); |
| 28 | + await commands.executeCommand("codeQLDatabasesExperimental.addNewList"); |
| 29 | + |
| 30 | + // Check db config |
| 31 | + const dbConfigFilePath = path.join(storagePath, "workspace-databases.json"); |
| 32 | + const dbConfig: DbConfig = await readJson(dbConfigFilePath); |
| 33 | + expect(dbConfig.databases.remote.repositoryLists).toHaveLength(1); |
| 34 | + expect(dbConfig.databases.remote.repositoryLists[0].name).toBe("my-list-1"); |
| 35 | + }); |
| 36 | +}); |
0 commit comments