feat(queryStore): 添加数据库打开状态跟踪功能 (#2251)
- 新增 isDatabaseOpen 方法,用于检查特定连接的数据库是否处于打开状态 - 在 TreeItem 组件中显示数据库打开指示器 - 添加 queryStore.database-open.spec.ts 测试文件,验证数据库打开状态的逻辑
This commit is contained in:
3 files changed
+47
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
function installLocalStorage() {
|
||||
const data = new Map<string, string>();
|
||||
vi.stubGlobal("localStorage", {
|
||||
getItem: vi.fn((key: string) => data.get(key) ?? null),
|
||||
setItem: vi.fn((key: string, value: string) => data.set(key, value)),
|
||||
removeItem: vi.fn((key: string) => data.delete(key)),
|
||||
});
|
||||
}
|
||||
|
||||
describe("queryStore database open state", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
vi.unstubAllGlobals();
|
||||
installLocalStorage();
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
it("tracks whether a connection database has open tabs", async () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
|
||||
const tabId = store.createTab("pg-1", "app", "query_1");
|
||||
|
||||
expect(store.isDatabaseOpen("pg-1", "app")).toBe(true);
|
||||
expect(store.isDatabaseOpen("pg-1", "analytics")).toBe(false);
|
||||
expect(store.isDatabaseOpen("pg-2", "app")).toBe(false);
|
||||
|
||||
store.updateDatabase(tabId, "analytics");
|
||||
|
||||
expect(store.isDatabaseOpen("pg-1", "app")).toBe(false);
|
||||
expect(store.isDatabaseOpen("pg-1", "analytics")).toBe(true);
|
||||
|
||||
store.closeTab(tabId);
|
||||
|
||||
expect(store.isDatabaseOpen("pg-1", "analytics")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -984,6 +984,10 @@ export const useQueryStore = defineStore("query", () => {
|
||||
releaseTabsWhere((tab) => tab.connectionId === connectionId && tab.database === database);
|
||||
}
|
||||
|
||||
function isDatabaseOpen(connectionId: string, database: string) {
|
||||
return tabs.value.some((tab) => tab.connectionId === connectionId && tab.database === database);
|
||||
}
|
||||
|
||||
function updateSql(id: string, sql: string) {
|
||||
const tab = tabs.value.find((t) => t.id === id);
|
||||
if (tab) {
|
||||
@@ -2484,6 +2488,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
closeDatabaseTabs,
|
||||
releaseConnectionTabs,
|
||||
releaseDatabaseTabs,
|
||||
isDatabaseOpen,
|
||||
updateSql,
|
||||
updateEditorViewport,
|
||||
updateEditorSelection,
|
||||
|
||||
Reference in new issue
Block a user