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。

3.7 KB
Raw Blame
import assert from "node:assert/strict";
import { test } from "vitest";
import { createPinia, setActivePinia } from "pinia";
import { DEFAULT_UI_FONT_FAMILY } from "../../apps/desktop/src/lib/app/appFonts.ts";
import { editorSettingsDraftFromSettings, editorSettingsPatchFromDraft } from "../../apps/desktop/src/lib/settings/editorSettingsDraft.ts";
import { DEFAULT_EDITOR_SETTINGS, useSettingsStore } from "../../apps/desktop/src/stores/settingsStore.ts";

test("keeps a loaded editor font when an old appearance draft only changes the UI font", () => {
  setActivePinia(createPinia());
  const store = useSettingsStore();
  const savedEditorFont = "'Cascadia Code', 'Cascadia Mono', monospace";

  store.updateEditorSettings({ fontFamily: savedEditorFont });

  const staleDraftBase = editorSettingsDraftFromSettings(DEFAULT_EDITOR_SETTINGS);
  const staleDraft = {
    ...staleDraftBase,
    uiFontFamily: `"Aptos", ${DEFAULT_UI_FONT_FAMILY}`,
  };

  const patch = editorSettingsPatchFromDraft(staleDraft, staleDraftBase);
  store.updateEditorSettings(patch);

  assert.equal(patch.fontFamily, undefined);
  assert.equal(store.editorSettings.fontFamily, savedEditorFont);
  assert.equal(store.editorSettings.uiFontFamily, staleDraft.uiFontFamily);
});

test("applies a result grid font without overwriting editor or interface fonts", () => {
  setActivePinia(createPinia());
  const store = useSettingsStore();
  const draftBase = editorSettingsDraftFromSettings(store.editorSettings);
  const tableFontFamily = `"IBM Plex Mono", monospace`;
  const patch = editorSettingsPatchFromDraft({ ...draftBase, tableFontFamily }, draftBase);

  store.updateEditorSettings(patch);

  assert.equal(patch.fontFamily, undefined);
  assert.equal(patch.uiFontFamily, undefined);
  assert.equal(patch.tableFontFamily, tableFontFamily);
  assert.equal(store.editorSettings.tableFontFamily, tableFontFamily);
});

test("round-trips completion column ordering through the editor settings draft", () => {
  const base = editorSettingsDraftFromSettings(DEFAULT_EDITOR_SETTINGS);
  const patch = editorSettingsPatchFromDraft({ ...base, sortCompletionColumnsAlphabetically: false }, base);

  assert.deepEqual(patch, { sortCompletionColumnsAlphabetically: false });
  assert.equal(editorSettingsDraftFromSettings({ ...DEFAULT_EDITOR_SETTINGS, ...patch }).sortCompletionColumnsAlphabetically, false);
});

test("round-trips completion selection behavior through the editor settings draft", () => {
  const base = editorSettingsDraftFromSettings(DEFAULT_EDITOR_SETTINGS);
  const patch = editorSettingsPatchFromDraft({ ...base, selectFirstCompletionOnOpen: false }, base);

  assert.deepEqual(patch, { selectFirstCompletionOnOpen: false });
  assert.equal(editorSettingsDraftFromSettings({ ...DEFAULT_EDITOR_SETTINGS, ...patch }).selectFirstCompletionOnOpen, false);
});

test("round-trips the column header hover tooltip toggle through the editor settings draft", () => {
  const base = editorSettingsDraftFromSettings(DEFAULT_EDITOR_SETTINGS);
  assert.equal(base.showColumnHeaderTooltips, true);

  const patch = editorSettingsPatchFromDraft({ ...base, showColumnHeaderTooltips: false }, base);

  assert.deepEqual(patch, { showColumnHeaderTooltips: false });
  assert.equal(editorSettingsDraftFromSettings({ ...DEFAULT_EDITOR_SETTINGS, ...patch }).showColumnHeaderTooltips, false);
});

test("round-trips the persisted CSV quote mode through the editor settings draft", () => {
  const base = editorSettingsDraftFromSettings(DEFAULT_EDITOR_SETTINGS);
  const patch = editorSettingsPatchFromDraft({ ...base, csvQuoteMode: "necessary" }, base);

  assert.deepEqual(patch, { csvQuoteMode: "necessary" });
  assert.equal(editorSettingsDraftFromSettings({ ...DEFAULT_EDITOR_SETTINGS, ...patch }).csvQuoteMode, "necessary");
});