db-panel: remove tests and functionality

This commit is contained in:
Nora
2023-12-06 09:46:08 +00:00
parent cce858561f
commit 9f667ef2d2
3 changed files with 6 additions and 283 deletions

View File

@@ -21,8 +21,6 @@ import {
DbItem,
DbItemKind,
DbListKind,
LocalDatabaseDbItem,
LocalListDbItem,
RemoteUserDefinedListDbItem,
} from "../db-item";
import { getDbItemName } from "../db-item-naming";
@@ -42,10 +40,6 @@ export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
remoteDatabaseKind: string;
}
export interface AddListQuickPickItem extends QuickPickItem {
databaseKind: DbListKind;
}
interface CodeSearchQuickPickItem extends QuickPickItem {
language: string;
}
@@ -277,59 +271,13 @@ export class DbPanel extends DisposableObject {
return;
}
switch (dbItem.kind) {
case DbItemKind.LocalList:
await this.renameLocalListItem(dbItem, newName);
break;
case DbItemKind.LocalDatabase:
await this.renameLocalDatabaseItem(dbItem, newName);
break;
case DbItemKind.RemoteUserDefinedList:
await this.renameVariantAnalysisUserDefinedListItem(dbItem, newName);
break;
default:
throw Error(`Action not allowed for the '${dbItem.kind}' db item kind`);
if (dbItem.kind === DbItemKind.RemoteUserDefinedList) {
await this.renameVariantAnalysisUserDefinedListItem(dbItem, newName);
} else {
throw Error(`Action not allowed for the '${dbItem.kind}' db item kind`);
}
}
private async renameLocalListItem(
dbItem: LocalListDbItem,
newName: string,
): Promise<void> {
if (dbItem.listName === newName) {
return;
}
if (this.dbManager.doesListExist(DbListKind.Local, newName)) {
void showAndLogErrorMessage(
this.app.logger,
`The list '${newName}' already exists`,
);
return;
}
await this.dbManager.renameList(dbItem, newName);
}
private async renameLocalDatabaseItem(
dbItem: LocalDatabaseDbItem,
newName: string,
): Promise<void> {
if (dbItem.databaseName === newName) {
return;
}
if (this.dbManager.doesLocalDbExist(newName, dbItem.parentListName)) {
void showAndLogErrorMessage(
this.app.logger,
`The database '${newName}' already exists`,
);
return;
}
await this.dbManager.renameLocalDb(dbItem, newName);
}
private async renameVariantAnalysisUserDefinedListItem(
dbItem: RemoteUserDefinedListDbItem,
newName: string,

View File

@@ -6,11 +6,7 @@ import {
DbConfig,
SelectedDbItemKind,
} from "../../../../src/databases/config/db-config";
import {
AddListQuickPickItem,
RemoteDatabaseQuickPickItem,
} from "../../../../src/databases/ui/db-panel";
import { DbListKind } from "../../../../src/databases/db-item";
import { RemoteDatabaseQuickPickItem } from "../../../../src/databases/ui/db-panel";
import { createDbTreeViewItemSystemDefinedList } from "../../../../src/databases/ui/db-tree-view-item";
import { createRemoteSystemDefinedListDbItem } from "../../../factories/db-item-factories";
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
@@ -57,22 +53,6 @@ describe("Db panel UI commands", () => {
);
});
it.skip("should add new local db list", async () => {
// Add db list
jest.spyOn(window, "showQuickPick").mockResolvedValue({
databaseKind: DbListKind.Local,
} as AddListQuickPickItem);
jest.spyOn(window, "showInputBox").mockResolvedValue("my-list-1");
await commandManager.execute(
"codeQLVariantAnalysisRepositories.addNewList",
);
// Check db config
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
expect(dbConfig.databases.local.lists).toHaveLength(1);
expect(dbConfig.databases.local.lists[0].name).toBe("my-list-1");
});
it("should add new remote repository", async () => {
// Add db
jest.spyOn(window, "showQuickPick").mockResolvedValue({

View File

@@ -5,16 +5,12 @@ import { DbConfig } from "../../../../src/databases/config/db-config";
import { DbManager } from "../../../../src/databases/db-manager";
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
import { DbTreeDataProvider } from "../../../../src/databases/ui/db-tree-data-provider";
import {
DbItemKind,
LocalDatabaseDbItem,
} from "../../../../src/databases/db-item";
import { DbItemKind } from "../../../../src/databases/db-item";
import { DbTreeViewItem } from "../../../../src/databases/ui/db-tree-view-item";
import { ExtensionApp } from "../../../../src/common/vscode/vscode-app";
import { createMockExtensionContext } from "../../../factories/extension-context";
import { createDbConfig } from "../../../factories/db-config-factories";
import { setRemoteControllerRepo } from "../../../../src/config";
import { QueryLanguage } from "../../../../src/common/query-language";
describe("db panel rendering nodes", () => {
const workspaceStoragePath = join(__dirname, "test-workspace-storage");
@@ -174,178 +170,6 @@ describe("db panel rendering nodes", () => {
checkRemoteRepoItem(repoItems[0], "owner1/repo1");
checkRemoteRepoItem(repoItems[1], "owner1/repo2");
});
it.skip("should render local list nodes", async () => {
const dbConfig: DbConfig = createDbConfig({
localLists: [
{
name: "my-list-1",
databases: [
{
name: "db1",
dateAdded: 1668428293677,
language: QueryLanguage.Cpp,
storagePath: "/path/to/db1/",
origin: {
type: "folder",
},
},
{
name: "db2",
dateAdded: 1668428472731,
language: QueryLanguage.Cpp,
storagePath: "/path/to/db2/",
origin: {
type: "folder",
},
},
],
},
{
name: "my-list-2",
databases: [
{
name: "db3",
dateAdded: 1668428472731,
language: "ruby",
storagePath: "/path/to/db3/",
origin: {
type: "folder",
},
},
],
},
],
});
await saveDbConfig(dbConfig);
const dbTreeItems = await dbTreeDataProvider.getChildren();
expect(dbTreeItems).toBeTruthy();
const localRootNode = dbTreeItems?.find(
(i) => i.dbItem?.kind === DbItemKind.RootLocal,
);
expect(localRootNode).toBeTruthy();
expect(localRootNode!.dbItem).toBeTruthy();
expect(localRootNode!.collapsibleState).toBe(
TreeItemCollapsibleState.Collapsed,
);
expect(localRootNode!.children).toBeTruthy();
expect(localRootNode!.children.length).toBe(2);
const localListItems = localRootNode!.children.filter(
(item) => item.dbItem?.kind === DbItemKind.LocalList,
);
expect(localListItems.length).toBe(2);
checkLocalListItem(localListItems[0], "my-list-1", [
{
kind: DbItemKind.LocalDatabase,
databaseName: "db1",
dateAdded: 1668428293677,
language: QueryLanguage.Cpp,
storagePath: "/path/to/db1/",
selected: false,
origin: {
type: "folder",
},
},
{
kind: DbItemKind.LocalDatabase,
databaseName: "db2",
dateAdded: 1668428472731,
language: QueryLanguage.Cpp,
storagePath: "/path/to/db2/",
selected: false,
origin: {
type: "folder",
},
},
]);
checkLocalListItem(localListItems[1], "my-list-2", [
{
kind: DbItemKind.LocalDatabase,
databaseName: "db3",
dateAdded: 1668428472731,
language: "ruby",
storagePath: "/path/to/db3/",
selected: false,
origin: {
type: "folder",
},
},
]);
});
it.skip("should render local database nodes", async () => {
const dbConfig: DbConfig = createDbConfig({
localDbs: [
{
name: "db1",
dateAdded: 1668428293677,
language: "csharp",
storagePath: "/path/to/db1/",
origin: {
type: "folder",
},
},
{
name: "db2",
dateAdded: 1668428472731,
language: "go",
storagePath: "/path/to/db2/",
origin: {
type: "folder",
},
},
],
});
await saveDbConfig(dbConfig);
const dbTreeItems = await dbTreeDataProvider.getChildren();
expect(dbTreeItems).toBeTruthy();
const localRootNode = dbTreeItems?.find(
(i) => i.dbItem?.kind === DbItemKind.RootLocal,
);
expect(localRootNode).toBeTruthy();
expect(localRootNode!.dbItem).toBeTruthy();
expect(localRootNode!.collapsibleState).toBe(
TreeItemCollapsibleState.Collapsed,
);
expect(localRootNode!.children).toBeTruthy();
expect(localRootNode!.children.length).toBe(2);
const localDatabaseItems = localRootNode!.children.filter(
(item) => item.dbItem?.kind === DbItemKind.LocalDatabase,
);
expect(localDatabaseItems.length).toBe(2);
checkLocalDatabaseItem(localDatabaseItems[0], {
kind: DbItemKind.LocalDatabase,
databaseName: "db1",
dateAdded: 1668428293677,
language: "csharp",
storagePath: "/path/to/db1/",
selected: false,
origin: {
type: "folder",
},
});
checkLocalDatabaseItem(localDatabaseItems[1], {
kind: DbItemKind.LocalDatabase,
databaseName: "db2",
dateAdded: 1668428472731,
language: "go",
storagePath: "/path/to/db2/",
selected: false,
origin: {
type: "folder",
},
});
});
});
async function saveDbConfig(dbConfig: DbConfig): Promise<void> {
@@ -419,35 +243,6 @@ describe("db panel rendering nodes", () => {
]);
}
function checkLocalListItem(
item: DbTreeViewItem,
listName: string,
databases: LocalDatabaseDbItem[],
): void {
expect(item.label).toBe(listName);
expect(item.tooltip).toBeUndefined();
expect(item.iconPath).toBeUndefined();
expect(item.collapsibleState).toBe(TreeItemCollapsibleState.Collapsed);
checkDbItemActions(item, ["canBeSelected", "canBeRemoved", "canBeRenamed"]);
expect(item.children).toBeTruthy();
expect(item.children.length).toBe(databases.length);
for (let i = 0; i < databases.length; i++) {
checkLocalDatabaseItem(item.children[i], databases[i]);
}
}
function checkLocalDatabaseItem(
item: DbTreeViewItem,
database: LocalDatabaseDbItem,
): void {
expect(item.label).toBe(database.databaseName);
expect(item.tooltip).toBe(`Language: ${database.language}`);
expect(item.iconPath).toEqual(new ThemeIcon("database"));
expect(item.collapsibleState).toBe(TreeItemCollapsibleState.None);
checkDbItemActions(item, ["canBeSelected", "canBeRemoved", "canBeRenamed"]);
}
function checkDbItemActions(item: DbTreeViewItem, actions: string[]): void {
const itemActions = item.contextValue?.split(",");
expect(itemActions).toBeDefined();