feat(editor): add sql editor split panes with shared results
This commit is contained in:
1 parent
24a274bd89
commit
5a3a6e2bb0
76 files changed
+7997
-3343
No files matched your search
@@ -5,6 +5,7 @@ import { createQueryEditorExecutionViewportOwnership, isQueryEditorPositionVisib
|
||||
const queryEditorSource = readFileSync(new URL("../../../components/editor/QueryEditor.vue", import.meta.url), "utf8");
|
||||
const contentAreaSource = readFileSync(new URL("../../../components/layout/ContentArea.vue", import.meta.url), "utf8");
|
||||
const editorToolbarSource = readFileSync(new URL("../../../components/layout/EditorToolbar.vue", import.meta.url), "utf8");
|
||||
const editorGroupSource = readFileSync(new URL("../../../components/layout/EditorGroup.vue", import.meta.url), "utf8");
|
||||
const appSource = readFileSync(new URL("../../../App.vue", import.meta.url), "utf8");
|
||||
const sqlExecutionSource = readFileSync(new URL("../../../composables/useSqlExecution.ts", import.meta.url), "utf8");
|
||||
const queryStoreSource = readFileSync(new URL("../../../stores/queryStore.ts", import.meta.url), "utf8");
|
||||
@@ -56,14 +57,21 @@ describe("QueryEditor execution routing", () => {
|
||||
expect(queryEditorSource).toContain("return sqlExecutionSnapshotFromView(currentView);");
|
||||
expect(contentAreaSource).toContain("function captureQueryEditorExecutionSnapshot()");
|
||||
expect(contentAreaSource).toContain("queryEditorRef.value?.captureExecutionSnapshot();");
|
||||
expect(appSource).toContain("const pendingToolbarExecutionSnapshot = ref<SqlExecutionSnapshot>();");
|
||||
expect(appSource).toContain("pendingToolbarExecutionSnapshot.value = contentAreaRef.value?.captureQueryEditorExecutionSnapshot?.();");
|
||||
expect(appSource).toContain("const pendingToolbarExecutionSnapshot = ref<SqlExecutionSnapshot & { tabId?: string }>();");
|
||||
expect(appSource).toContain("pendingToolbarExecutionSnapshot.value = snapshot ? { ...snapshot, tabId: activeTab.value?.id } : undefined;");
|
||||
expect(appSource).toContain('if (source === "pointer")');
|
||||
expect(appSource).toContain("pendingToolbarExecutionSnapshot.value = undefined;");
|
||||
expect(appSource).toContain("void tryExecute(snapshot);");
|
||||
expect(appSource).toContain('@execute-pointer-down="captureActiveEditorExecutionSnapshot()"');
|
||||
expect(appSource).toContain('@execute="requestActiveEditorExecute($event)"');
|
||||
expect(appSource).toContain("void tryExecute(snapshot, { tabId: snapshot.tabId ?? activeTab.value?.id });");
|
||||
expect(appSource).toContain('@execute="(tabId: string, override?: SqlExecutionOverride) => tryExecute(override, { tabId })"');
|
||||
// Per-group toolbars call back into App-owned orchestration via injection.
|
||||
expect(appSource).toContain("provide(EDITOR_TOOLBAR_ACTIONS, {");
|
||||
expect(appSource).toContain("captureExecutionSnapshot: captureActiveEditorExecutionSnapshot,");
|
||||
expect(appSource).toContain("toolbarExecute: requestActiveEditorExecute,");
|
||||
expect(editorGroupSource).toContain('@execute-pointer-down="toolbar.captureExecutionSnapshot()"');
|
||||
expect(editorGroupSource).toContain('@toolbar-execute="toolbar.toolbarExecute($event)"');
|
||||
expect(editorToolbarSource).toContain("function onExecutePointerDown(event: MouseEvent)");
|
||||
expect(editorToolbarSource).toContain('emit("toolbarExecute", event.detail > 0 ? "pointer" : "keyboard")');
|
||||
expect(editorToolbarSource).not.toContain('emit("execute", event.detail > 0 ? "pointer" : "keyboard")');
|
||||
});
|
||||
|
||||
it("uses the opt-in blank-line fallback and otherwise reports the missing cursor statement", () => {
|
||||
|
||||
@@ -45,7 +45,7 @@ describe("QueryEditor auto focus wiring", () => {
|
||||
});
|
||||
|
||||
it("enables auto focus for query tabs", () => {
|
||||
expect(contentAreaSource).toMatch(/<QueryEditor[\s\S]*?\sauto-focus\s[\s\S]*?:model-value="activeTab\.sql"/);
|
||||
expect(contentAreaSource).toMatch(/<QueryEditor[\s\S]*?:\s*auto-focus="autoFocus !== false"\s[\s\S]*?:model-value="activeTab\.sql"/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const appSource = readFileSync(new URL("../../../App.vue", import.meta.url), "utf8");
|
||||
const useSqlExecutionSource = readFileSync(new URL("../../../composables/useSqlExecution.ts", import.meta.url), "utf8");
|
||||
|
||||
describe("toolbar explain routing", () => {
|
||||
it("passes the tab id as the execution context, not as SQL", () => {
|
||||
// Regression: the injected action once called tryExplain(tabId), whose
|
||||
// first parameter is sqlOverride — the id silently typed as SQL and the
|
||||
// EXPLAIN button sent the tab UUID to the backend.
|
||||
expect(appSource).toContain("explain: (tabId: string) => tryExplain(undefined, { tabId }),");
|
||||
expect(appSource).not.toContain("explain: (tabId: string) => tryExplain(tabId),");
|
||||
});
|
||||
|
||||
it("keeps tryExplain's first parameter an SQL override", () => {
|
||||
expect(useSqlExecutionSource).toContain("async function tryExplain(sqlOverride?: SqlExecutionOverride, options: SqlExecutionOptions = {})");
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user