Skip to content

Commit 9f667ef

Browse files
committed
db-panel: remove tests and functionality
1 parent cce8585 commit 9f667ef

File tree

3 files changed

+6
-283
lines changed

3 files changed

+6
-283
lines changed

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

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import {
2121
DbItem,
2222
DbItemKind,
2323
DbListKind,
24-
LocalDatabaseDbItem,
25-
LocalListDbItem,
2624
RemoteUserDefinedListDbItem,
2725
} from "../db-item";
2826
import { getDbItemName } from "../db-item-naming";
@@ -42,10 +40,6 @@ export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
4240
remoteDatabaseKind: string;
4341
}
4442

45-
export interface AddListQuickPickItem extends QuickPickItem {
46-
databaseKind: DbListKind;
47-
}
48-
4943
interface CodeSearchQuickPickItem extends QuickPickItem {
5044
language: string;
5145
}
@@ -277,57 +271,11 @@ export class DbPanel extends DisposableObject {
277271
return;
278272
}
279273

280-
switch (dbItem.kind) {
281-
case DbItemKind.LocalList:
282-
await this.renameLocalListItem(dbItem, newName);
283-
break;
284-
case DbItemKind.LocalDatabase:
285-
await this.renameLocalDatabaseItem(dbItem, newName);
286-
break;
287-
case DbItemKind.RemoteUserDefinedList:
288-
await this.renameVariantAnalysisUserDefinedListItem(dbItem, newName);
289-
break;
290-
default:
291-
throw Error(`Action not allowed for the '${dbItem.kind}' db item kind`);
292-
}
293-
}
294-
295-
private async renameLocalListItem(
296-
dbItem: LocalListDbItem,
297-
newName: string,
298-
): Promise<void> {
299-
if (dbItem.listName === newName) {
300-
return;
301-
}
302-
303-
if (this.dbManager.doesListExist(DbListKind.Local, newName)) {
304-
void showAndLogErrorMessage(
305-
this.app.logger,
306-
`The list '${newName}' already exists`,
307-
);
308-
return;
309-
}
310-
311-
await this.dbManager.renameList(dbItem, newName);
312-
}
313-
314-
private async renameLocalDatabaseItem(
315-
dbItem: LocalDatabaseDbItem,
316-
newName: string,
317-
): Promise<void> {
318-
if (dbItem.databaseName === newName) {
319-
return;
320-
}
321-
322-
if (this.dbManager.doesLocalDbExist(newName, dbItem.parentListName)) {
323-
void showAndLogErrorMessage(
324-
this.app.logger,
325-
`The database '${newName}' already exists`,
326-
);
327-
return;
274+
if (dbItem.kind === DbItemKind.RemoteUserDefinedList) {
275+
await this.renameVariantAnalysisUserDefinedListItem(dbItem, newName);
276+
} else {
277+
throw Error(`Action not allowed for the '${dbItem.kind}' db item kind`);
328278
}
329-
330-
await this.dbManager.renameLocalDb(dbItem, newName);
331279
}
332280

333281
private async renameVariantAnalysisUserDefinedListItem(

extensions/ql-vscode/test/vscode-tests/activated-extension/databases/db-panel.test.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import {
66
DbConfig,
77
SelectedDbItemKind,
88
} from "../../../../src/databases/config/db-config";
9-
import {
10-
AddListQuickPickItem,
11-
RemoteDatabaseQuickPickItem,
12-
} from "../../../../src/databases/ui/db-panel";
13-
import { DbListKind } from "../../../../src/databases/db-item";
9+
import { RemoteDatabaseQuickPickItem } from "../../../../src/databases/ui/db-panel";
1410
import { createDbTreeViewItemSystemDefinedList } from "../../../../src/databases/ui/db-tree-view-item";
1511
import { createRemoteSystemDefinedListDbItem } from "../../../factories/db-item-factories";
1612
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
@@ -57,22 +53,6 @@ describe("Db panel UI commands", () => {
5753
);
5854
});
5955

60-
it.skip("should add new local db list", async () => {
61-
// Add db list
62-
jest.spyOn(window, "showQuickPick").mockResolvedValue({
63-
databaseKind: DbListKind.Local,
64-
} as AddListQuickPickItem);
65-
jest.spyOn(window, "showInputBox").mockResolvedValue("my-list-1");
66-
await commandManager.execute(
67-
"codeQLVariantAnalysisRepositories.addNewList",
68-
);
69-
70-
// Check db config
71-
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
72-
expect(dbConfig.databases.local.lists).toHaveLength(1);
73-
expect(dbConfig.databases.local.lists[0].name).toBe("my-list-1");
74-
});
75-
7656
it("should add new remote repository", async () => {
7757
// Add db
7858
jest.spyOn(window, "showQuickPick").mockResolvedValue({

extensions/ql-vscode/test/vscode-tests/minimal-workspace/databases/db-panel-rendering.test.ts

Lines changed: 1 addition & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import { DbConfig } from "../../../../src/databases/config/db-config";
55
import { DbManager } from "../../../../src/databases/db-manager";
66
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
77
import { DbTreeDataProvider } from "../../../../src/databases/ui/db-tree-data-provider";
8-
import {
9-
DbItemKind,
10-
LocalDatabaseDbItem,
11-
} from "../../../../src/databases/db-item";
8+
import { DbItemKind } from "../../../../src/databases/db-item";
129
import { DbTreeViewItem } from "../../../../src/databases/ui/db-tree-view-item";
1310
import { ExtensionApp } from "../../../../src/common/vscode/vscode-app";
1411
import { createMockExtensionContext } from "../../../factories/extension-context";
1512
import { createDbConfig } from "../../../factories/db-config-factories";
1613
import { setRemoteControllerRepo } from "../../../../src/config";
17-
import { QueryLanguage } from "../../../../src/common/query-language";
1814

1915
describe("db panel rendering nodes", () => {
2016
const workspaceStoragePath = join(__dirname, "test-workspace-storage");
@@ -174,178 +170,6 @@ describe("db panel rendering nodes", () => {
174170
checkRemoteRepoItem(repoItems[0], "owner1/repo1");
175171
checkRemoteRepoItem(repoItems[1], "owner1/repo2");
176172
});
177-
178-
it.skip("should render local list nodes", async () => {
179-
const dbConfig: DbConfig = createDbConfig({
180-
localLists: [
181-
{
182-
name: "my-list-1",
183-
databases: [
184-
{
185-
name: "db1",
186-
dateAdded: 1668428293677,
187-
language: QueryLanguage.Cpp,
188-
storagePath: "/path/to/db1/",
189-
origin: {
190-
type: "folder",
191-
},
192-
},
193-
{
194-
name: "db2",
195-
dateAdded: 1668428472731,
196-
language: QueryLanguage.Cpp,
197-
storagePath: "/path/to/db2/",
198-
origin: {
199-
type: "folder",
200-
},
201-
},
202-
],
203-
},
204-
{
205-
name: "my-list-2",
206-
databases: [
207-
{
208-
name: "db3",
209-
dateAdded: 1668428472731,
210-
language: "ruby",
211-
storagePath: "/path/to/db3/",
212-
origin: {
213-
type: "folder",
214-
},
215-
},
216-
],
217-
},
218-
],
219-
});
220-
221-
await saveDbConfig(dbConfig);
222-
223-
const dbTreeItems = await dbTreeDataProvider.getChildren();
224-
expect(dbTreeItems).toBeTruthy();
225-
226-
const localRootNode = dbTreeItems?.find(
227-
(i) => i.dbItem?.kind === DbItemKind.RootLocal,
228-
);
229-
expect(localRootNode).toBeTruthy();
230-
231-
expect(localRootNode!.dbItem).toBeTruthy();
232-
expect(localRootNode!.collapsibleState).toBe(
233-
TreeItemCollapsibleState.Collapsed,
234-
);
235-
expect(localRootNode!.children).toBeTruthy();
236-
expect(localRootNode!.children.length).toBe(2);
237-
238-
const localListItems = localRootNode!.children.filter(
239-
(item) => item.dbItem?.kind === DbItemKind.LocalList,
240-
);
241-
expect(localListItems.length).toBe(2);
242-
checkLocalListItem(localListItems[0], "my-list-1", [
243-
{
244-
kind: DbItemKind.LocalDatabase,
245-
databaseName: "db1",
246-
dateAdded: 1668428293677,
247-
language: QueryLanguage.Cpp,
248-
storagePath: "/path/to/db1/",
249-
selected: false,
250-
origin: {
251-
type: "folder",
252-
},
253-
},
254-
{
255-
kind: DbItemKind.LocalDatabase,
256-
databaseName: "db2",
257-
dateAdded: 1668428472731,
258-
language: QueryLanguage.Cpp,
259-
storagePath: "/path/to/db2/",
260-
selected: false,
261-
origin: {
262-
type: "folder",
263-
},
264-
},
265-
]);
266-
checkLocalListItem(localListItems[1], "my-list-2", [
267-
{
268-
kind: DbItemKind.LocalDatabase,
269-
databaseName: "db3",
270-
dateAdded: 1668428472731,
271-
language: "ruby",
272-
storagePath: "/path/to/db3/",
273-
selected: false,
274-
origin: {
275-
type: "folder",
276-
},
277-
},
278-
]);
279-
});
280-
281-
it.skip("should render local database nodes", async () => {
282-
const dbConfig: DbConfig = createDbConfig({
283-
localDbs: [
284-
{
285-
name: "db1",
286-
dateAdded: 1668428293677,
287-
language: "csharp",
288-
storagePath: "/path/to/db1/",
289-
origin: {
290-
type: "folder",
291-
},
292-
},
293-
{
294-
name: "db2",
295-
dateAdded: 1668428472731,
296-
language: "go",
297-
storagePath: "/path/to/db2/",
298-
origin: {
299-
type: "folder",
300-
},
301-
},
302-
],
303-
});
304-
305-
await saveDbConfig(dbConfig);
306-
307-
const dbTreeItems = await dbTreeDataProvider.getChildren();
308-
309-
expect(dbTreeItems).toBeTruthy();
310-
const localRootNode = dbTreeItems?.find(
311-
(i) => i.dbItem?.kind === DbItemKind.RootLocal,
312-
);
313-
expect(localRootNode).toBeTruthy();
314-
315-
expect(localRootNode!.dbItem).toBeTruthy();
316-
expect(localRootNode!.collapsibleState).toBe(
317-
TreeItemCollapsibleState.Collapsed,
318-
);
319-
expect(localRootNode!.children).toBeTruthy();
320-
expect(localRootNode!.children.length).toBe(2);
321-
322-
const localDatabaseItems = localRootNode!.children.filter(
323-
(item) => item.dbItem?.kind === DbItemKind.LocalDatabase,
324-
);
325-
expect(localDatabaseItems.length).toBe(2);
326-
checkLocalDatabaseItem(localDatabaseItems[0], {
327-
kind: DbItemKind.LocalDatabase,
328-
databaseName: "db1",
329-
dateAdded: 1668428293677,
330-
language: "csharp",
331-
storagePath: "/path/to/db1/",
332-
selected: false,
333-
origin: {
334-
type: "folder",
335-
},
336-
});
337-
checkLocalDatabaseItem(localDatabaseItems[1], {
338-
kind: DbItemKind.LocalDatabase,
339-
databaseName: "db2",
340-
dateAdded: 1668428472731,
341-
language: "go",
342-
storagePath: "/path/to/db2/",
343-
selected: false,
344-
origin: {
345-
type: "folder",
346-
},
347-
});
348-
});
349173
});
350174

351175
async function saveDbConfig(dbConfig: DbConfig): Promise<void> {
@@ -419,35 +243,6 @@ describe("db panel rendering nodes", () => {
419243
]);
420244
}
421245

422-
function checkLocalListItem(
423-
item: DbTreeViewItem,
424-
listName: string,
425-
databases: LocalDatabaseDbItem[],
426-
): void {
427-
expect(item.label).toBe(listName);
428-
expect(item.tooltip).toBeUndefined();
429-
expect(item.iconPath).toBeUndefined();
430-
expect(item.collapsibleState).toBe(TreeItemCollapsibleState.Collapsed);
431-
checkDbItemActions(item, ["canBeSelected", "canBeRemoved", "canBeRenamed"]);
432-
expect(item.children).toBeTruthy();
433-
expect(item.children.length).toBe(databases.length);
434-
435-
for (let i = 0; i < databases.length; i++) {
436-
checkLocalDatabaseItem(item.children[i], databases[i]);
437-
}
438-
}
439-
440-
function checkLocalDatabaseItem(
441-
item: DbTreeViewItem,
442-
database: LocalDatabaseDbItem,
443-
): void {
444-
expect(item.label).toBe(database.databaseName);
445-
expect(item.tooltip).toBe(`Language: ${database.language}`);
446-
expect(item.iconPath).toEqual(new ThemeIcon("database"));
447-
expect(item.collapsibleState).toBe(TreeItemCollapsibleState.None);
448-
checkDbItemActions(item, ["canBeSelected", "canBeRemoved", "canBeRenamed"]);
449-
}
450-
451246
function checkDbItemActions(item: DbTreeViewItem, actions: string[]): void {
452247
const itemActions = item.contextValue?.split(",");
453248
expect(itemActions).toBeDefined();

0 commit comments

Comments
 (0)