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.2 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { createGlobalNavigationHistory, moveGlobalNavigation, recordGlobalNavigation } from "../globalNavigationHistory";
import type { GlobalNavigationEntry } from "../navigationEntry";

const entry = (id: string): GlobalNavigationEntry => ({ id, surface: "query", tabId: id });

describe("global navigation history", () => {
  it("records visits without duplicating the current entry", () => {
    let history = createGlobalNavigationHistory();
    history = recordGlobalNavigation(history, entry("a"));
    history = recordGlobalNavigation(history, entry("a"));
    expect(history.entries.map((item) => item.id)).toEqual(["a"]);
    expect(history.index).toBe(0);
  });

  it("clears the forward branch after a new visit", () => {
    let history = createGlobalNavigationHistory();
    for (const id of ["a", "b", "c"]) history = recordGlobalNavigation(history, entry(id));
    const back = moveGlobalNavigation(history, -1, () => true);
    expect(back?.entry.id).toBe("b");
    history = back!.history;
    history = recordGlobalNavigation(history, entry("d"));
    expect(history.entries.map((item) => item.id)).toEqual(["a", "b", "d"]);
    expect(moveGlobalNavigation(history, 1, () => true)).toBeNull();
  });

  it("skips invalid entries while moving", () => {
    let history = createGlobalNavigationHistory();
    for (const id of ["a", "closed", "c"]) history = recordGlobalNavigation(history, entry(id));
    const back = moveGlobalNavigation(history, -1, (item) => item.id !== "closed");
    expect(back?.entry.id).toBe("a");
  });
  it("coalesces an asynchronous source identity resolution into the same visit", () => {
    let history = recordGlobalNavigation(createGlobalNavigationHistory(), entry("previous"));
    history = recordGlobalNavigation(history, { id: "pending", surface: "query", kind: "objectSource", tabId: "source", objectType: "PROCEDURE" });
    history = recordGlobalNavigation(history, { id: "loaded", surface: "query", kind: "objectSource", tabId: "source", objectType: "FUNCTION" });
    expect(history.entries.map((item) => item.id)).toEqual(["previous", "loaded"]);
    expect(moveGlobalNavigation(history, -1, () => true)?.entry.id).toBe("previous");
  });
});