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 { describe, expect, it } from "vitest";
import { EDITOR_TOOLBAR_MAX_TIER, EDITOR_TOOLBAR_STEP_DOWN_MIN_GROWTH_PX, EDITOR_TOOLBAR_STEP_DOWN_SLACK_PX, resolveNextEditorToolbarTier } from "@/lib/tabs/editorToolbarLayout";

describe("editor toolbar measured condensation", () => {
  it("steps up one tier while the content overflows", () => {
    expect(resolveNextEditorToolbarTier({ tier: 0, availableWidth: 400, contentWidth: 700 })).toBe(1);
    expect(resolveNextEditorToolbarTier({ tier: 1, availableWidth: 400, contentWidth: 450 })).toBe(2);
    expect(resolveNextEditorToolbarTier({ tier: 2, availableWidth: 400, contentWidth: 420 })).toBe(3);
  });

  it("holds at the maximum tier when even the condensed row overflows", () => {
    expect(resolveNextEditorToolbarTier({ tier: EDITOR_TOOLBAR_MAX_TIER, availableWidth: 200, contentWidth: 400 })).toBe(EDITOR_TOOLBAR_MAX_TIER);
  });

  it("holds the current tier while the row fits without real slack", () => {
    expect(resolveNextEditorToolbarTier({ tier: 1, availableWidth: 500, contentWidth: 480 })).toBe(1);
    expect(resolveNextEditorToolbarTier({ tier: 1, availableWidth: 500, contentWidth: 500 - EDITOR_TOOLBAR_STEP_DOWN_SLACK_PX + 1 })).toBe(1);
  });

  it("steps down only with slack and real pane growth since the last condensation", () => {
    const grown = 400 + EDITOR_TOOLBAR_STEP_DOWN_MIN_GROWTH_PX + 10;
    expect(resolveNextEditorToolbarTier({ tier: 2, availableWidth: grown, contentWidth: grown - EDITOR_TOOLBAR_STEP_DOWN_SLACK_PX - 10, condensedAtWidth: 400 })).toBe(1);
  });

  it("restores the fullest measured tier that fits after the pane expands", () => {
    expect(
      resolveNextEditorToolbarTier({
        tier: 3,
        availableWidth: 920,
        contentWidth: 920,
        condensedAtWidth: 420,
        expandedTierRequiredWidths: { 0: 840, 1: 700, 2: 560 },
      }),
    ).toBe(0);

    expect(
      resolveNextEditorToolbarTier({
        tier: 3,
        availableWidth: 760,
        contentWidth: 760,
        condensedAtWidth: 420,
        expandedTierRequiredWidths: { 0: 840, 1: 700, 2: 560 },
      }),
    ).toBe(1);
  });

  it("does not use the condensed flex row width to restore a tier that cannot fit", () => {
    expect(
      resolveNextEditorToolbarTier({
        tier: 2,
        availableWidth: 720,
        contentWidth: 720,
        condensedAtWidth: 420,
        expandedTierRequiredWidths: { 0: 840, 1: 700 },
      }),
    ).toBe(2);
  });

  it("does not restore a measured tier before the pane has grown past the hysteresis gap", () => {
    expect(
      resolveNextEditorToolbarTier({
        tier: 2,
        availableWidth: 460,
        contentWidth: 460,
        condensedAtWidth: 420,
        expandedTierRequiredWidths: { 1: 400 },
      }),
    ).toBe(2);
  });

  it("never oscillates: slack alone without pane growth keeps the condensed tier", () => {
    // The row fits with plenty of slack, but the pane barely grew since the
    // toolbar condensed at this width — stepping down would overflow again.
    expect(resolveNextEditorToolbarTier({ tier: 2, availableWidth: 410, contentWidth: 350, condensedAtWidth: 400 })).toBe(2);
    expect(resolveNextEditorToolbarTier({ tier: 2, availableWidth: 410, contentWidth: 410 - EDITOR_TOOLBAR_STEP_DOWN_SLACK_PX - 1, condensedAtWidth: 400 })).toBe(2);
  });

  it("allows stepping down immediately when the toolbar was never condensed", () => {
    expect(resolveNextEditorToolbarTier({ tier: 1, availableWidth: 900, contentWidth: 500 })).toBe(0);
  });

  it("keeps the current tier for unmeasured or invalid input", () => {
    expect(resolveNextEditorToolbarTier({ tier: 1, availableWidth: 0, contentWidth: 0 })).toBe(1);
    expect(resolveNextEditorToolbarTier({ tier: 2, availableWidth: Number.NaN, contentWidth: 100 })).toBe(2);
  });
});