feat(settings): 启动时标签页恢复策略三选项 (all/pinned/none) (#2395)
* feat(settings): 添加启动标签页恢复策略 * i18n: 补齐启动标签页恢复策略 5 个 locale 译文 --------- Co-authored-by: staff <staff@qimaos-MacBook-Pro.local> Co-authored-by: t8y2 <1156263951@qq.com>
This commit is contained in:
14 files changed
+193
-8
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { ACTIVE_TAB_STORAGE_KEY, OPEN_TABS_STORAGE_KEY } from "@/lib/openTabsPersistence";
|
||||
|
||||
function installLocalStorage() {
|
||||
const data = new Map<string, string>();
|
||||
@@ -8,6 +9,7 @@ function installLocalStorage() {
|
||||
setItem: vi.fn((key: string, value: string) => data.set(key, value)),
|
||||
removeItem: vi.fn((key: string) => data.delete(key)),
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
describe("queryStore database open state", () => {
|
||||
@@ -37,4 +39,66 @@ describe("queryStore database open state", () => {
|
||||
|
||||
expect(store.isDatabaseOpen("pg-1", "analytics")).toBe(false);
|
||||
});
|
||||
|
||||
it("does not restore open tabs when launch restore mode is none", async () => {
|
||||
const persistedTabs = JSON.stringify([
|
||||
{
|
||||
id: "tab-1",
|
||||
title: "Query 1",
|
||||
connectionId: "pg-1",
|
||||
database: "app",
|
||||
sql: "select 1",
|
||||
},
|
||||
]);
|
||||
|
||||
vi.resetModules();
|
||||
vi.unstubAllGlobals();
|
||||
const storage = installLocalStorage();
|
||||
storage.set("dbx-editor-settings", JSON.stringify({ openTabsRestoreMode: "none" }));
|
||||
storage.set(OPEN_TABS_STORAGE_KEY, persistedTabs);
|
||||
storage.set(ACTIVE_TAB_STORAGE_KEY, "tab-1");
|
||||
setActivePinia(createPinia());
|
||||
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
|
||||
expect(store.tabs).toEqual([]);
|
||||
expect(store.activeTabId).toBeNull();
|
||||
expect(storage.get(OPEN_TABS_STORAGE_KEY)).toBe(persistedTabs);
|
||||
expect(storage.get(ACTIVE_TAB_STORAGE_KEY)).toBe("tab-1");
|
||||
});
|
||||
|
||||
it("restores only pinned tabs when launch restore mode is pinned", async () => {
|
||||
const persistedTabs = JSON.stringify([
|
||||
{
|
||||
id: "tab-1",
|
||||
title: "Pinned",
|
||||
connectionId: "pg-1",
|
||||
database: "app",
|
||||
sql: "select 1",
|
||||
pinned: true,
|
||||
},
|
||||
{
|
||||
id: "tab-2",
|
||||
title: "Regular",
|
||||
connectionId: "pg-1",
|
||||
database: "app",
|
||||
sql: "select 2",
|
||||
},
|
||||
]);
|
||||
|
||||
vi.resetModules();
|
||||
vi.unstubAllGlobals();
|
||||
const storage = installLocalStorage();
|
||||
storage.set("dbx-editor-settings", JSON.stringify({ openTabsRestoreMode: "pinned" }));
|
||||
storage.set(OPEN_TABS_STORAGE_KEY, persistedTabs);
|
||||
storage.set(ACTIVE_TAB_STORAGE_KEY, "tab-2");
|
||||
setActivePinia(createPinia());
|
||||
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
|
||||
expect(store.tabs.map((tab) => tab.id)).toEqual(["tab-1"]);
|
||||
expect(store.activeTabId).toBe("tab-1");
|
||||
});
|
||||
});
|
||||
@@ -30,6 +30,21 @@ describe("normalizeEditorSettings", () => {
|
||||
expect(normalizeEditorSettings({}).updateDownloadSource).toBe("official");
|
||||
});
|
||||
|
||||
it("restores all open tabs on launch by default", () => {
|
||||
expect(normalizeEditorSettings({}).openTabsRestoreMode).toBe("all");
|
||||
});
|
||||
|
||||
it("preserves explicit open tab restore modes", () => {
|
||||
expect(normalizeEditorSettings({ openTabsRestoreMode: "pinned" }).openTabsRestoreMode).toBe("pinned");
|
||||
expect(normalizeEditorSettings({ openTabsRestoreMode: "none" }).openTabsRestoreMode).toBe("none");
|
||||
expect(normalizeEditorSettings({ openTabsRestoreMode: "invalid" as any }).openTabsRestoreMode).toBe("all");
|
||||
});
|
||||
|
||||
it("migrates legacy open tab restore booleans", () => {
|
||||
expect(normalizeEditorSettings({ restoreOpenTabsOnLaunch: false } as any).openTabsRestoreMode).toBe("none");
|
||||
expect(normalizeEditorSettings({ restoreOpenTabsOnLaunch: true } as any).openTabsRestoreMode).toBe("all");
|
||||
});
|
||||
|
||||
it("preserves CNB update download source and rejects invalid values", () => {
|
||||
expect(normalizeEditorSettings({ updateDownloadSource: "cnb" }).updateDownloadSource).toBe("cnb");
|
||||
expect(normalizeEditorSettings({ updateDownloadSource: "mirror" as any }).updateDownloadSource).toBe("official");
|
||||
|
||||
Reference in new issue
Block a user