feat(editor): add sql editor split panes with shared results

This commit is contained in:
Lan-zk authored and GitHub committed 2026-09-04 14:44:03 +08:00
1 parent 24a274bd89
commit 5a3a6e2bb0
76 files changed
+7997 -3343

No files matched your search

@@ -0,0 +1,40 @@
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("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);
});
});
+23
View File
@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest";
import { parseTabDragPayload, serializeTabDragPayload, TAB_DRAG_MIME } from "@/lib/tabs/tabDrag";
describe("tab drag payload", () => {
it("serializes and parses a valid payload", () => {
const raw = serializeTabDragPayload({ tabId: "tab-1", sourceGroupId: "group-1" });
expect(raw).toContain(TAB_DRAG_MIME);
expect(parseTabDragPayload(raw)).toEqual({ mime: TAB_DRAG_MIME, tabId: "tab-1", sourceGroupId: "group-1" });
});
it("rejects malformed payloads", () => {
expect(parseTabDragPayload("not-json")).toBeNull();
expect(parseTabDragPayload(JSON.stringify({ tabId: "tab-1" }))).toBeNull();
});
it("rejects payloads carrying a foreign MIME discriminator", () => {
expect(parseTabDragPayload(JSON.stringify({ mime: "application/json", tabId: "tab-1", sourceGroupId: "group-1" }))).toBeNull();
});
it("exposes the custom MIME type", () => {
expect(TAB_DRAG_MIME).toBe("application/x-dbx-tab");
});
});
+135
View File
@@ -0,0 +1,135 @@
import { describe, expect, it } from "vitest";
import { createCloseAllTabMenuItem, createCloseLeftTabMenuItem, createCloseOtherTabMenuItem, createCloseRightTabMenuItem, createCloseTabMenuItem, createLocateTabMenuItem, createPinTabMenuItem, createRenameDuplicateTabItems } from "@/lib/tabs/tabMenu";
const t = (key: string) => key;
describe("shared tab menu helpers", () => {
it("builds rename and duplicate items only when renaming is allowed", () => {
const items = createRenameDuplicateTabItems({
tab: { id: "t1" } as never,
t,
canRename: true,
onRename: () => undefined,
onDuplicate: () => undefined,
});
expect(items).toHaveLength(2);
expect(items[0]?.label).toBe("contextMenu.renameTab");
expect(items[1]?.label).toBe("contextMenu.duplicateTab");
expect(items[1]?.visible).toBe(true);
const queryOnly = createRenameDuplicateTabItems({
tab: { id: "t2" } as never,
t,
canRename: false,
onRename: () => undefined,
onDuplicate: () => undefined,
});
expect(queryOnly).toHaveLength(1);
expect(queryOnly[0]?.visible).toBe(false);
});
it("builds locate and pin menu items with the expected actions", () => {
let located = false;
let toggled = false;
const locate = createLocateTabMenuItem({
t,
visible: true,
onLocate: () => {
located = true;
},
});
locate.action?.();
expect(located).toBe(true);
expect(locate.label).toBe("sidebar.locateActiveTab");
const hiddenLocate = createLocateTabMenuItem({
t,
visible: false,
onLocate: () => undefined,
});
expect(hiddenLocate.visible).toBe(false);
const pin = createPinTabMenuItem({
label: "Pin",
iconClass: "fill-current",
onToggle: () => {
toggled = true;
},
});
pin.action?.();
expect(toggled).toBe(true);
expect(pin.iconClass).toBe("fill-current");
const pinWithoutIconClass = createPinTabMenuItem({
label: "Pin",
onToggle: () => undefined,
});
expect(pinWithoutIconClass.iconClass).toBeUndefined();
});
it("builds close menu items with labels and actions", () => {
let closed = false;
const close = createCloseTabMenuItem({
label: "Close",
onClose: () => {
closed = true;
},
});
close.action?.();
expect(closed).toBe(true);
const closeOther = createCloseOtherTabMenuItem({
label: "Close Other",
disabled: true,
onClose: () => undefined,
});
expect(closeOther.disabled).toBe(true);
const closeOtherWithoutDisabled = createCloseOtherTabMenuItem({
label: "Close Other",
onClose: () => undefined,
});
expect("disabled" in closeOtherWithoutDisabled).toBe(false);
const closeRight = createCloseRightTabMenuItem({
label: "Close Right",
disabled: false,
onClose: () => undefined,
});
expect(closeRight.disabled).toBe(false);
const closeRightWithoutDisabled = createCloseRightTabMenuItem({
label: "Close Right",
onClose: () => undefined,
});
expect("disabled" in closeRightWithoutDisabled).toBe(false);
const closeLeft = createCloseLeftTabMenuItem({
label: "Close Left",
disabled: true,
onClose: () => undefined,
});
expect(closeLeft.disabled).toBe(true);
const closeLeftWithoutDisabled = createCloseLeftTabMenuItem({
label: "Close Left",
onClose: () => undefined,
});
expect("disabled" in closeLeftWithoutDisabled).toBe(false);
const closeAll = createCloseAllTabMenuItem({
label: "Close All",
variant: "destructive",
onClose: () => undefined,
});
expect(closeAll.variant).toBe("destructive");
const closeAllDefault = createCloseAllTabMenuItem({
label: "Close All",
onClose: () => undefined,
});
expect(closeAllDefault.variant).toBeUndefined();
});
});
@@ -12,9 +12,13 @@ import {
resultGridInstanceKey,
resultSourceRange,
statementExecutionMarkers,
tabColorStyle,
tabDatabaseIconType,
tabDisplayTitle,
tabIconClass,
tabTooltipLines,
tabularResultItems,
dirtyTabTitleStyle,
} from "@/lib/tabs/tabPresentation";
import { sqlTextFingerprint } from "@/lib/sql/sqlTextFingerprint";
import type { ConnectionConfig, QueryTab } from "@/types/database";
@@ -396,3 +400,38 @@ describe("statement execution markers", () => {
expect(statementExecutionMarkers(`-- edited\n${executedSql}`, [{ columns: ["value"], rows: [[1]], affected_rows: 0, execution_time_ms: 1, statement_index: 0, sourceStatement: "SELECT 1" }], "mysql", "stale-editor-fingerprint", executedSql)).toEqual([]);
});
});
describe("shared tab presentation helpers", () => {
it("classifies tab icon colors without MQ special-casing", () => {
expect(tabIconClass(queryTab({ mode: "data" }))).toContain("text-emerald-600");
expect(tabIconClass(queryTab({ mode: "mq" }))).toBe("");
expect(tabIconClass(queryTab({ externalSqlFileMissing: true }))).toContain("text-amber-600");
});
it("builds active/inactive color styles for classic and non-classic layouts", () => {
const activeClassic = tabColorStyle(queryTab({}), true, true);
expect(activeClassic?.boxShadow).toContain("var(--ring)");
const inactiveModern = tabColorStyle(queryTab({}), false, false);
expect(inactiveModern?.borderColor).toBeUndefined();
});
it("resolves MQ driver icons from the connection store", () => {
const connectionStore = useConnectionStore();
connectionStore.connections = [
{
id: "mq-1",
name: "MQ",
db_type: "mq",
driver_profile: "kafka",
color: "",
} as ConnectionConfig,
];
expect(tabDatabaseIconType(queryTab({ connectionId: "mq-1", mode: "mq" }))).toBe("kafka");
});
it("returns a dirty-title style only when the tab is dirty", () => {
expect(dirtyTabTitleStyle(false)).toBeUndefined();
expect(dirtyTabTitleStyle(true)?.fontStyle).toBe("italic");
expect(dirtyTabTitleStyle(true)?.fontWeight).toBe(700);
});
});