|
1 | 1 | import { TreeItemCollapsibleState, ThemeIcon, ThemeColor } from "vscode"; |
2 | 2 | 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"; |
8 | 5 | import { DbManager } from "../../../../src/databases/db-manager"; |
9 | 6 | import { DbConfigStore } from "../../../../src/databases/config/db-config-store"; |
10 | 7 | 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"; |
12 | 9 | import { DbTreeViewItem } from "../../../../src/databases/ui/db-tree-view-item"; |
13 | 10 | import { ExtensionApp } from "../../../../src/common/vscode/vscode-app"; |
14 | 11 | import { createMockExtensionContext } from "../../../factories/extension-context"; |
@@ -48,182 +45,6 @@ describe("db panel", () => { |
48 | 45 | await remove(workspaceStoragePath); |
49 | 46 | }); |
50 | 47 |
|
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 | | - |
227 | 48 | describe("config errors", () => { |
228 | 49 | it("should show error for invalid config", async () => { |
229 | 50 | // We're intentionally bypassing the type check because we'd |
@@ -387,11 +208,4 @@ describe("db panel", () => { |
387 | 208 | expect(item.collapsibleState).toBe(TreeItemCollapsibleState.None); |
388 | 209 | expect(item.children.length).toBe(0); |
389 | 210 | } |
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 | | - } |
397 | 211 | }); |
0 commit comments