Skip to content

Commit 13389fd

Browse files
authored
Merge pull request #1983 from github/nora/db-panel-add-item
Extract db panel add items tests to new file
2 parents f97dbb1 + 9c011c5 commit 13389fd

File tree

2 files changed

+244
-189
lines changed

2 files changed

+244
-189
lines changed
Lines changed: 3 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { TreeItemCollapsibleState, ThemeIcon, ThemeColor } from "vscode";
22
import { join } from "path";
3-
import { ensureDir, readJSON, remove, writeJson } from "fs-extra";
4-
import {
5-
DbConfig,
6-
SelectedDbItemKind,
7-
} from "../../../../src/databases/config/db-config";
3+
import { ensureDir, remove, writeJson } from "fs-extra";
4+
import { DbConfig } from "../../../../src/databases/config/db-config";
85
import { DbManager } from "../../../../src/databases/db-manager";
96
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
107
import { DbTreeDataProvider } from "../../../../src/databases/ui/db-tree-data-provider";
11-
import { DbItemKind, DbListKind } from "../../../../src/databases/db-item";
8+
import { DbListKind } 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";
@@ -48,182 +45,6 @@ describe("db panel", () => {
4845
await remove(workspaceStoragePath);
4946
});
5047

51-
describe("addNewRemoteRepo", () => {
52-
it("should add a new remote repo", async () => {
53-
const dbConfig: DbConfig = createDbConfig({
54-
remoteRepos: ["owner1/repo1"],
55-
});
56-
57-
await saveDbConfig(dbConfig);
58-
59-
const dbTreeItems = await dbTreeDataProvider.getChildren();
60-
61-
expect(dbTreeItems).toBeTruthy();
62-
const items = dbTreeItems!;
63-
64-
const remoteRootNode = items[0];
65-
const remoteRepos = remoteRootNode.children.filter(
66-
(c) => c.dbItem?.kind === DbItemKind.RemoteRepo,
67-
);
68-
const repo1 = remoteRootNode.children.find(
69-
(c) =>
70-
c.dbItem?.kind === DbItemKind.RemoteRepo &&
71-
c.dbItem?.repoFullName === "owner1/repo1",
72-
);
73-
74-
expect(remoteRepos.length).toBe(1);
75-
expect(remoteRepos[0]).toBe(repo1);
76-
77-
await dbManager.addNewRemoteRepo("owner2/repo2");
78-
79-
const dbConfigFileContents = await readDbConfigDirectly();
80-
expect(
81-
dbConfigFileContents.databases.variantAnalysis.repositories.length,
82-
).toBe(2);
83-
expect(
84-
dbConfigFileContents.databases.variantAnalysis.repositories[1],
85-
).toEqual("owner2/repo2");
86-
});
87-
88-
it("should add a new remote repo to a user defined list", async () => {
89-
const dbConfig: DbConfig = createDbConfig({
90-
remoteLists: [
91-
{
92-
name: "my-list-1",
93-
repositories: ["owner1/repo1"],
94-
},
95-
],
96-
remoteRepos: ["owner2/repo2"],
97-
});
98-
99-
await saveDbConfig(dbConfig);
100-
101-
const dbTreeItems = await dbTreeDataProvider.getChildren();
102-
103-
expect(dbTreeItems).toBeTruthy();
104-
const items = dbTreeItems!;
105-
106-
const remoteRootNode = items[0];
107-
const remoteUserDefinedLists = remoteRootNode.children.filter(
108-
(c) => c.dbItem?.kind === DbItemKind.VariantAnalysisUserDefinedList,
109-
);
110-
const list1 = remoteRootNode.children.find(
111-
(c) =>
112-
c.dbItem?.kind === DbItemKind.VariantAnalysisUserDefinedList &&
113-
c.dbItem?.listName === "my-list-1",
114-
);
115-
116-
expect(remoteUserDefinedLists.length).toBe(1);
117-
expect(remoteUserDefinedLists[0]).toBe(list1);
118-
119-
await dbManager.addNewRemoteRepo("owner2/repo2", "my-list-1");
120-
121-
// Read the workspace databases JSON file directly to check that the new repo has been added.
122-
// We can't use the dbConfigStore's `read` function here because it depends on the file watcher
123-
// picking up changes, and we don't control the timing of that.
124-
const dbConfigFileContents = await readJSON(dbConfigFilePath);
125-
expect(
126-
dbConfigFileContents.databases.variantAnalysis.repositoryLists.length,
127-
).toBe(1);
128-
129-
expect(
130-
dbConfigFileContents.databases.variantAnalysis.repositoryLists[0],
131-
).toEqual({
132-
name: "my-list-1",
133-
repositories: ["owner1/repo1", "owner2/repo2"],
134-
});
135-
});
136-
});
137-
138-
describe("addNewList", () => {
139-
it("should add a new remote list", async () => {
140-
const dbConfig: DbConfig = createDbConfig({
141-
remoteLists: [
142-
{
143-
name: "my-list-1",
144-
repositories: ["owner1/repo1", "owner1/repo2"],
145-
},
146-
],
147-
selected: {
148-
kind: SelectedDbItemKind.VariantAnalysisUserDefinedList,
149-
listName: "my-list-1",
150-
},
151-
});
152-
153-
await saveDbConfig(dbConfig);
154-
155-
const dbTreeItems = await dbTreeDataProvider.getChildren();
156-
157-
expect(dbTreeItems).toBeTruthy();
158-
const items = dbTreeItems!;
159-
160-
const remoteRootNode = items[0];
161-
const remoteUserDefinedLists = remoteRootNode.children.filter(
162-
(c) => c.dbItem?.kind === DbItemKind.VariantAnalysisUserDefinedList,
163-
);
164-
const list1 = remoteRootNode.children.find(
165-
(c) =>
166-
c.dbItem?.kind === DbItemKind.VariantAnalysisUserDefinedList &&
167-
c.dbItem?.listName === "my-list-1",
168-
);
169-
170-
expect(remoteUserDefinedLists.length).toBe(1);
171-
expect(remoteUserDefinedLists[0]).toBe(list1);
172-
173-
await dbManager.addNewList(DbListKind.Remote, "my-list-2");
174-
175-
const dbConfigFileContents = await readDbConfigDirectly();
176-
expect(
177-
dbConfigFileContents.databases.variantAnalysis.repositoryLists.length,
178-
).toBe(2);
179-
expect(
180-
dbConfigFileContents.databases.variantAnalysis.repositoryLists[1],
181-
).toEqual({
182-
name: "my-list-2",
183-
repositories: [],
184-
});
185-
});
186-
187-
it("should throw error when adding a new list to a local node", async () => {
188-
const dbConfig: DbConfig = createDbConfig({
189-
localLists: [
190-
{
191-
name: "my-list-1",
192-
databases: [],
193-
},
194-
],
195-
});
196-
await saveDbConfig(dbConfig);
197-
198-
const dbTreeItems = await dbTreeDataProvider.getChildren();
199-
200-
expect(dbTreeItems).toBeTruthy();
201-
const items = dbTreeItems!;
202-
203-
const localRootNode = items[1];
204-
const localUserDefinedLists = localRootNode.children.filter(
205-
(c) => c.dbItem?.kind === DbItemKind.LocalList,
206-
);
207-
const list1 = localRootNode.children.find(
208-
(c) =>
209-
c.dbItem?.kind === DbItemKind.LocalList &&
210-
c.dbItem?.listName === "my-list-1",
211-
);
212-
213-
expect(localUserDefinedLists.length).toBe(1);
214-
expect(localUserDefinedLists[0]).toBe(list1);
215-
216-
await dbManager.addNewList(DbListKind.Local, "my-list-2");
217-
218-
const dbConfigFileContents = await readDbConfigDirectly();
219-
expect(dbConfigFileContents.databases.local.lists.length).toBe(2);
220-
expect(dbConfigFileContents.databases.local.lists[1]).toEqual({
221-
name: "my-list-2",
222-
databases: [],
223-
});
224-
});
225-
});
226-
22748
describe("config errors", () => {
22849
it("should show error for invalid config", async () => {
22950
// We're intentionally bypassing the type check because we'd
@@ -387,11 +208,4 @@ describe("db panel", () => {
387208
expect(item.collapsibleState).toBe(TreeItemCollapsibleState.None);
388209
expect(item.children.length).toBe(0);
389210
}
390-
391-
async function readDbConfigDirectly(): Promise<DbConfig> {
392-
// Read the workspace databases JSON file directly to check that the new list has been added.
393-
// We can't use the dbConfigStore's `read` function here because it depends on the file watcher
394-
// picking up changes, and we don't control the timing of that.
395-
return (await readJSON(dbConfigFilePath)) as DbConfig;
396-
}
397211
});

0 commit comments

Comments
 (0)