Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

2.0 KB
Raw Blame
import { reactive } from "vue";
import { describe, expect, it, vi } from "vitest";
import { usePluginShortcutPreferences } from "../usePluginShortcutPreferences";
import { normalizePluginShortcutSettings } from "@/lib/plugins/pluginShortcuts";

const mocks = vi.hoisted(() => ({ settings: null as any }));
vi.mock("@/stores/settingsStore", () => ({ useSettingsStore: () => mocks.settings }));

describe("shortcut preference writes", () => {
  it("merges queued writes from different controls without replacing unrelated preferences", async () => {
    const state = reactive({ pluginShortcuts: normalizePluginShortcutSettings({}) });
    mocks.settings = {
      editorSettings: state,
      updateEditorSettingsAndPersist: vi.fn(async (patch) => {
        state.pluginShortcuts = patch.pluginShortcuts;
      }),
    };
    const bar = usePluginShortcutPreferences();
    const page = usePluginShortcutPreferences();
    await Promise.all([bar.update({ order: ["a", "b"] }), page.update({ hiddenPluginIds: ["p"] }), bar.update({ sidebarHeight: 132 })]);
    expect(state.pluginShortcuts).toMatchObject({ order: ["a", "b"], hiddenPluginIds: ["p"], sidebarHeight: 132 });
  });
  it("continues after a failed write without carrying its unpersisted patch forward", async () => {
    const state = reactive({ pluginShortcuts: normalizePluginShortcutSettings({}) });
    mocks.settings = {
      editorSettings: state,
      updateEditorSettingsAndPersist: vi
        .fn()
        .mockRejectedValueOnce(new Error("disk full"))
        .mockImplementation(async (patch) => {
          state.pluginShortcuts = patch.pluginShortcuts;
        }),
    };
    const preferences = usePluginShortcutPreferences();
    const failed = preferences.update({ order: ["lost"] });
    const next = preferences.update({ hiddenPluginIds: ["p"] });
    await expect(failed).rejects.toThrow("disk full");
    await next;
    expect(state.pluginShortcuts).toMatchObject({ order: [], hiddenPluginIds: ["p"] });
  });
});