Skip to content

Commit 8cb0cd2

Browse files
committed
Add test for set selected item
1 parent 9f5e965 commit 8cb0cd2

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

extensions/ql-vscode/test/unit-tests/databases/config/db-config-store.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { join } from "path";
33
import { App } from "../../../../src/common/app";
44
import {
55
DbConfig,
6+
SelectedDbItem,
67
SelectedDbItemKind,
78
} from "../../../../src/databases/config/db-config";
89
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
@@ -636,4 +637,40 @@ describe("db config store", () => {
636637
configStore.dispose();
637638
});
638639
});
640+
641+
describe("set selected item", () => {
642+
let app: App;
643+
let configPath: string;
644+
645+
beforeEach(async () => {
646+
app = createMockApp({
647+
extensionPath,
648+
workspaceStoragePath: tempWorkspaceStoragePath,
649+
});
650+
651+
configPath = join(tempWorkspaceStoragePath, "workspace-databases.json");
652+
});
653+
654+
it("should set the selected item", async () => {
655+
// Initial set up
656+
const configStore = new DbConfigStore(app);
657+
await configStore.initialize();
658+
659+
// Set selected
660+
const selectedItem: SelectedDbItem = {
661+
kind: SelectedDbItemKind.RemoteOwner,
662+
ownerName: "owner2",
663+
};
664+
665+
await configStore.setSelectedDbItem(selectedItem);
666+
667+
// Read the config file
668+
const updatedDbConfig = (await readJSON(configPath)) as DbConfig;
669+
670+
// Check that the config file has been updated
671+
expect(updatedDbConfig.selected).toEqual(selectedItem);
672+
673+
configStore.dispose();
674+
});
675+
});
639676
});

0 commit comments

Comments
 (0)