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。

1.2 KB
Raw Blame
// @vitest-environment happy-dom

import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";

const indexSource = readFileSync(resolve(process.cwd(), "apps/desktop/index.html"), "utf8");

function installStartupInputGuard() {
  const script = indexSource.match(/<script data-dbx-startup-input-guard>([\s\S]*?)<\/script>/)?.[1];
  if (!script) throw new Error("Startup input guard script not found");
  new Function(script)();
}

describe("startup input guard", () => {
  it("prevents Escape until the app is mounted", () => {
    installStartupInputGuard();

    const startupEscape = new KeyboardEvent("keydown", { key: "Escape", cancelable: true });
    const regularKey = new KeyboardEvent("keydown", { key: "a", cancelable: true });
    window.dispatchEvent(startupEscape);
    window.dispatchEvent(regularKey);

    expect(startupEscape.defaultPrevented).toBe(true);
    expect(regularKey.defaultPrevented).toBe(false);

    window.dispatchEvent(new Event("dbx:startup-ready"));
    const readyEscape = new KeyboardEvent("keydown", { key: "Escape", cancelable: true });
    window.dispatchEvent(readyEscape);
    expect(readyEscape.defaultPrevented).toBe(false);
  });
});