|
1 | 1 | import { TreeItemCollapsibleState, ThemeIcon } from "vscode"; |
2 | 2 | import { join } from "path"; |
3 | | -import { ensureDir, remove, writeJson } from "fs-extra"; |
| 3 | +import { ensureDir, readJSON, remove, writeJson } from "fs-extra"; |
4 | 4 | import { |
5 | 5 | DbConfig, |
6 | 6 | SelectedDbItemKind, |
@@ -531,6 +531,66 @@ describe("db panel", () => { |
531 | 531 | } |
532 | 532 | }); |
533 | 533 |
|
| 534 | + it("should add a new list to the remote db list", async () => { |
| 535 | + const dbConfig: DbConfig = { |
| 536 | + databases: { |
| 537 | + remote: { |
| 538 | + repositoryLists: [ |
| 539 | + { |
| 540 | + name: "my-list-1", |
| 541 | + repositories: ["owner1/repo1", "owner1/repo2"], |
| 542 | + }, |
| 543 | + ], |
| 544 | + owners: [], |
| 545 | + repositories: [], |
| 546 | + }, |
| 547 | + local: { |
| 548 | + lists: [], |
| 549 | + databases: [], |
| 550 | + }, |
| 551 | + }, |
| 552 | + expanded: [], |
| 553 | + selected: { |
| 554 | + kind: SelectedDbItemKind.RemoteUserDefinedList, |
| 555 | + listName: "my-list-1", |
| 556 | + }, |
| 557 | + }; |
| 558 | + |
| 559 | + await saveDbConfig(dbConfig); |
| 560 | + |
| 561 | + const dbTreeItems = await dbTreeDataProvider.getChildren(); |
| 562 | + |
| 563 | + expect(dbTreeItems).toBeTruthy(); |
| 564 | + const items = dbTreeItems!; |
| 565 | + |
| 566 | + const remoteRootNode = items[0]; |
| 567 | + const remoteUserDefinedLists = remoteRootNode.children.filter( |
| 568 | + (c) => c.dbItem?.kind === DbItemKind.RemoteUserDefinedList, |
| 569 | + ); |
| 570 | + const list1 = remoteRootNode.children.find( |
| 571 | + (c) => |
| 572 | + c.dbItem?.kind === DbItemKind.RemoteUserDefinedList && |
| 573 | + c.dbItem?.listName === "my-list-1", |
| 574 | + ); |
| 575 | + |
| 576 | + expect(remoteUserDefinedLists.length).toBe(1); |
| 577 | + expect(remoteUserDefinedLists[0]).toBe(list1); |
| 578 | + |
| 579 | + await dbManager.addNewRemoteList("my-list-2"); |
| 580 | + |
| 581 | + // Read the workspace databases JSON file directly to check that the new list has been added. |
| 582 | + // We can't use the dbConfigStore's `read` function here because it depends on the file watcher |
| 583 | + // picking up changes, and we don't control the timing of that. |
| 584 | + const dbConfigFileContents = await readJSON(dbConfigFilePath); |
| 585 | + expect(dbConfigFileContents.databases.remote.repositoryLists.length).toBe( |
| 586 | + 2, |
| 587 | + ); |
| 588 | + expect(dbConfigFileContents.databases.remote.repositoryLists[1]).toEqual({ |
| 589 | + name: "my-list-2", |
| 590 | + repositories: [], |
| 591 | + }); |
| 592 | + }); |
| 593 | + |
534 | 594 | async function saveDbConfig(dbConfig: DbConfig): Promise<void> { |
535 | 595 | await writeJson(dbConfigFilePath, dbConfig); |
536 | 596 |
|
|
0 commit comments