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
+43
-267
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const tabBarSource = readFileSync(new URL("../AppTabBar.vue", import.meta.url), "utf8");
|
||||
const groupTabBarSource = readFileSync(new URL("../EditorGroupTabBar.vue", import.meta.url), "utf8");
|
||||
|
||||
function sourceBetween(start: string, end: string): string {
|
||||
const startIndex = tabBarSource.indexOf(start);
|
||||
@@ -11,6 +12,27 @@ function sourceBetween(start: string, end: string): string {
|
||||
return tabBarSource.slice(startIndex, endIndex);
|
||||
}
|
||||
|
||||
describe("AppTabBar single production path", () => {
|
||||
it("no longer renders the regular or pinned tab strip", () => {
|
||||
expect(tabBarSource).not.toContain("hideRegularTabs");
|
||||
expect(tabBarSource).not.toContain("regularTabs");
|
||||
expect(tabBarSource).not.toContain("fixedTabsContainerRef");
|
||||
expect(tabBarSource).not.toContain("useTabDrag");
|
||||
expect(tabBarSource).not.toContain("createRenameDuplicateTabItems");
|
||||
expect(groupTabBarSource).toContain("createRenameDuplicateTabItems");
|
||||
});
|
||||
|
||||
it("keeps special pages and the close-confirm dialog as its only surfaces", () => {
|
||||
expect(tabBarSource).toContain("getSpecialRegularTabMenuItems('settings')");
|
||||
expect(tabBarSource).toContain("getSpecialRegularTabMenuItems('driverStore')");
|
||||
expect(tabBarSource).toContain(':open="queryStore.showCloseConfirm"');
|
||||
});
|
||||
|
||||
it("scopes the close-other shortcut to the active tab's owner group", () => {
|
||||
expect(tabBarSource).toContain("closeOtherTabsInGroup(ownerGroup.id, activeTabId)");
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar close confirmation layout", () => {
|
||||
it("allows long unbroken tab titles to shrink and wrap inside the dialog", () => {
|
||||
expect(tabBarSource).toMatch(/<DialogContent class="[^"]*\bmin-w-0\b[^"]*\bsm:max-w-md\b/);
|
||||
@@ -25,284 +47,38 @@ describe("AppTabBar close confirmation layout", () => {
|
||||
expect(tabBarSource).toContain('@click="handleSaveAndClose"');
|
||||
expect(tabBarSource).toContain('@click="handleCancelClose"');
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar HBase presentation", () => {
|
||||
it("uses the table icon in regular, pinned, and overflow tab surfaces", () => {
|
||||
expect(tabBarSource).toContain('if (tab.mode === "data" || tab.mode === "mongo" || tab.mode === "redis" || tab.mode === "hbase") return Table2;');
|
||||
expect(tabBarSource.match(/tab\.mode === 'hbase'/g)).toHaveLength(2);
|
||||
expect(tabBarSource).toContain('tab.mode === "hbase" || tab.mode === "structure"');
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar object browser presentation", () => {
|
||||
it("uses matching icons and colors for object and database browser tabs", () => {
|
||||
expect(tabBarSource).toContain('if (tab.mode === "databases" || tab.mode === "objects") return "text-amber-500 dark:text-amber-400";');
|
||||
expect(tabBarSource).toContain('if (tab.mode === "databases") return Database;');
|
||||
expect(tabBarSource).toContain('if (tab.mode === "objects") return TableProperties;');
|
||||
expect(tabBarSource.match(/tab\.mode === 'databases'/g)).toHaveLength(2);
|
||||
expect(tabBarSource.match(/:class="tabIconClass\(tab\)"/g)).toHaveLength(2);
|
||||
expect(tabBarSource.match(/tabMenuIcon\(tab\).*tabIconClass\(tab\)/g)).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar locate-in-sidebar action", () => {
|
||||
it("emits the exact right-clicked tab only when it has a sidebar target", () => {
|
||||
const menu = sourceBetween("function getTabMenuItems", "function handleSaveAndClose");
|
||||
|
||||
expect(tabBarSource).toContain('"locate-tab": [tab: QueryTab];');
|
||||
expect(menu).toMatch(/label: t\("sidebar\.locateActiveTab"\),\s*action: \(\) => emit\("locate-tab", tab\),\s*icon: Crosshair,\s*visible: !!activeTabSidebarTarget\(tab\)/);
|
||||
expect(menu).not.toContain("activateTab(tab.id)");
|
||||
});
|
||||
|
||||
it("leaves settings, driver, and existing regular-tab menu actions unchanged", () => {
|
||||
const specialMenu = sourceBetween("function getSpecialRegularTabMenuItems", "function getTabMenuItems");
|
||||
const regularMenu = sourceBetween("function getTabMenuItems", "function handleSaveAndClose");
|
||||
|
||||
expect(specialMenu).not.toContain('t("sidebar.locateActiveTab")');
|
||||
expect(regularMenu).toContain('label: t("contextMenu.copyName")');
|
||||
expect(regularMenu).toContain("action: () => queryStore.togglePinnedTab(tab.id)");
|
||||
expect(regularMenu).toContain("action: () => queryStore.closeTab(tab.id)");
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar Zen mode interaction", () => {
|
||||
it("switches Zen mode for data tabs while preserving query-tab renaming", () => {
|
||||
const handler = sourceBetween("function handleTabDoubleClick", "function handleTabMouseDown");
|
||||
|
||||
expect(tabBarSource).toContain('"toggle-zen-mode": [];');
|
||||
expect(handler).toContain('if (tab.mode === "data") {');
|
||||
expect(handler).toContain('emit("toggle-zen-mode");');
|
||||
expect(handler).toContain("startRenameTab(tab);");
|
||||
expect(handler).toContain("event.target instanceof Element && event.target.closest(\"button, input, [role='button']\")");
|
||||
expect(tabBarSource.match(/@dblclick="handleTabDoubleClick\(tab, \$event\)"/g)).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar right-side close action", () => {
|
||||
it("places the action after close-other and disables it when the target has no tabs to its right", () => {
|
||||
expect(tabBarSource).toContain('label: t("contextMenu.closeRightTabs")');
|
||||
expect(tabBarSource).toContain("action: () => closeTabsToRightFromTab(tab)");
|
||||
expect(tabBarSource).toContain("disabled: !hasTabsToRight(tab)");
|
||||
|
||||
const closeOtherPositions = [...tabBarSource.matchAll(/label: closeOtherLabel,/g)].map((match) => match.index);
|
||||
const closeRightPositions = [...tabBarSource.matchAll(/label: t\("contextMenu\.closeRightTabs"\),/g)].map((match) => match.index);
|
||||
const closeAllPositions = [...tabBarSource.matchAll(/label: closeAllLabel,/g)].map((match) => match.index);
|
||||
expect(closeOtherPositions).toHaveLength(2);
|
||||
expect(closeRightPositions).toHaveLength(2);
|
||||
expect(closeAllPositions).toHaveLength(2);
|
||||
closeRightPositions.forEach((position, index) => {
|
||||
expect(position).toBeGreaterThan(closeOtherPositions[index]);
|
||||
expect(position).toBeLessThan(closeAllPositions[index]);
|
||||
});
|
||||
});
|
||||
|
||||
it("waits for query tab confirmation before closing special surfaces", () => {
|
||||
expect(tabBarSource).toMatch(/queryStore\.closeTabsByIds\(tabsToClose, finalActiveTabId, \(\) => \{[\s\S]*closeSpecialRegularSurfaces\(\);/);
|
||||
expect(tabBarSource).toContain("if (shouldActivateTarget) activateTab(tab.id)");
|
||||
});
|
||||
|
||||
it("reactivates settings after closing an active driver store to its right", () => {
|
||||
expect(tabBarSource).toContain("const shouldActivateSettings = !!props.driverStoreActive");
|
||||
expect(tabBarSource).toMatch(/emit\("close-driver-store"\);\s*if \(shouldActivateSettings\) emit\("activate-settings-page"\);/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar left-side close action", () => {
|
||||
it("places the action after close-other, before close-right, and disables it when the target has no tabs to its left", () => {
|
||||
expect(tabBarSource).toContain('label: t("contextMenu.closeLeftTabs")');
|
||||
expect(tabBarSource).toContain("action: () => closeTabsToLeftFromTab(tab)");
|
||||
expect(tabBarSource).toContain("disabled: !hasTabsToLeft(tab)");
|
||||
|
||||
const closeOtherPositions = [...tabBarSource.matchAll(/label: closeOtherLabel,/g)].map((match) => match.index);
|
||||
const closeLeftPositions = [...tabBarSource.matchAll(/label: t\("contextMenu\.closeLeftTabs"\),/g)].map((match) => match.index);
|
||||
const closeRightPositions = [...tabBarSource.matchAll(/label: t\("contextMenu\.closeRightTabs"\),/g)].map((match) => match.index);
|
||||
expect(closeOtherPositions).toHaveLength(2);
|
||||
// The special-surface menu has no left-side action: settings and the
|
||||
// driver store sit at the rightmost end of the tab bar, so nothing can be
|
||||
// to the left of them. Only the regular/pinned tab menu gets the item.
|
||||
expect(closeLeftPositions).toHaveLength(1);
|
||||
expect(closeRightPositions).toHaveLength(2);
|
||||
const closeLeftPosition = closeLeftPositions[0];
|
||||
expect(closeLeftPosition).toBeGreaterThan(closeOtherPositions[1]);
|
||||
expect(closeLeftPosition).toBeLessThan(closeRightPositions[1]);
|
||||
it("shows the dirty tab list using the shared tab title presentation", () => {
|
||||
const listBlock = sourceBetween('v-for="tab in closeConfirmDirtyTabs"', "</PopoverContent>");
|
||||
expect(listBlock).toContain("tabDisplayTitle(tab, t)");
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar special page selection", () => {
|
||||
it("shows the active settings or driver-manager tab with the same ring used by regular tabs", () => {
|
||||
expect(tabBarSource).toContain("function specialTabActiveStyle(active: boolean | undefined)");
|
||||
expect(tabBarSource).toContain('return isClassicLayout.value ? { boxShadow: "inset 0 -2px 0 var(--ring)" } : { borderColor: "var(--ring)" };');
|
||||
expect(tabBarSource).toContain(':style="specialTabActiveStyle(settingsPageActive)"');
|
||||
expect(tabBarSource).toContain(':style="specialTabActiveStyle(driverStoreActive)"');
|
||||
it("renders settings and driver store as app-level pills outside the editor groups", () => {
|
||||
expect(tabBarSource).toContain("data-settings-page-tab");
|
||||
expect(tabBarSource).toContain("data-driver-store-tab");
|
||||
expect(tabBarSource).toContain("@click=\"emit('activate-settings-page')\"");
|
||||
expect(tabBarSource).toContain("@click=\"emit('activate-driver-store')\"");
|
||||
expect(tabBarSource).toContain('t("toolbar.driverManager")');
|
||||
});
|
||||
|
||||
it("does not leave a query group highlighted behind an active special page", () => {
|
||||
const groupActive = sourceBetween("function isTabGroupActive", "function toggleTabGroup");
|
||||
|
||||
expect(groupActive).toContain("if (props.driverStoreActive || props.settingsPageActive) return false;");
|
||||
});
|
||||
|
||||
it("restores the active special page after closing the group containing the retained query tab", () => {
|
||||
const restoreSurface = sourceBetween("function restoreSpecialRegularSurface", "function closeSpecialRegularSurfaces");
|
||||
const closeGroup = sourceBetween("function closeTabGroup", "function tabsToRightInGroup");
|
||||
|
||||
expect(restoreSurface).toContain('if (surface === "settings" && props.settingsPageOpen) emit("activate-settings-page")');
|
||||
expect(restoreSurface).toContain('if (surface === "driverStore" && props.driverStoreOpen) emit("activate-driver-store")');
|
||||
expect(restoreSurface).toContain("const surface = pendingGroupCloseSpecialSurface.value;");
|
||||
expect(restoreSurface).toContain("pendingGroupCloseSpecialSurface.value = null;");
|
||||
expect(closeGroup).toContain('props.settingsPageActive ? "settings" : props.driverStoreActive ? "driverStore" : null');
|
||||
expect(closeGroup).toContain("pendingGroupCloseSpecialSurface.value = activeSpecialSurface;");
|
||||
expect(closeGroup).toContain("queryStore.closeTabsByIds(tabsToClose, finalActiveTabId, finishSpecialSurfacePreservingGroupClose)");
|
||||
expect(closeGroup).toContain("restoreSpecialRegularSurface(activeSpecialSurface);");
|
||||
});
|
||||
|
||||
it("keeps and restores the special page while dirty grouped tabs are confirmed or cancelled", () => {
|
||||
const activeTabWatch = sourceBetween("watch(\n () => queryStore.activeTabId", "watch(\n () => props.driverStoreActive");
|
||||
const dismissClose = sourceBetween("function dismissCloseConfirm", "function handleCancelClose");
|
||||
const cancelClose = sourceBetween("function handleCancelClose", "const tabsContainerRef");
|
||||
|
||||
expect(activeTabWatch).toContain("restoreSpecialRegularSurface(pendingGroupCloseSpecialSurface.value);");
|
||||
expect(dismissClose).toContain("pendingGroupCloseSpecialSurface.value = null;");
|
||||
expect(dismissClose).toContain("restoreSpecialRegularSurface(specialSurface);");
|
||||
expect(cancelClose).toContain("dismissCloseConfirm();");
|
||||
expect(tabBarSource).toContain("if (!open) dismissCloseConfirm();");
|
||||
it("keeps the driver update badge on the driver store pill", () => {
|
||||
expect(tabBarSource).toContain("agentDriverUpdateCount");
|
||||
expect(tabBarSource).toContain("aria-label=\"t('toolbar.updatableDriverCount')\"");
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar overflow search", () => {
|
||||
it("filters every open tab by its display and source titles", () => {
|
||||
expect(tabBarSource).toContain('const tabSearchQuery = ref("");');
|
||||
expect(tabBarSource).toContain("const filteredOpenTabs = computed(() => {");
|
||||
expect(tabBarSource).toContain("return displayedTabs.value.filter((tab) => tabMatchesSearch(tab, query));");
|
||||
expect(tabBarSource).toContain("return tabTitleText(tab).toLocaleLowerCase().includes(query) || tab.title.toLocaleLowerCase().includes(query) || connectionName.toLocaleLowerCase().includes(query);");
|
||||
describe("Group tabbar inherited presentation", () => {
|
||||
it("imports the shared tab bar stylesheet so pills, scrollbar, and wrap styles apply", () => {
|
||||
expect(groupTabBarSource).toContain('import "./appTabBar.css"');
|
||||
expect(groupTabBarSource).toContain("app-tab-pill");
|
||||
expect(groupTabBarSource).toContain("app-tab-scrollbar");
|
||||
expect(groupTabBarSource).toContain("app-tab-bar");
|
||||
});
|
||||
|
||||
it("provides the same focused search control and empty state in both overflow menus", () => {
|
||||
expect(tabBarSource.match(/<Input data-tab-search-input=/g)).toHaveLength(2);
|
||||
expect(tabBarSource.match(/v-for="tab in filteredOpenTabs"/g)).toHaveLength(2);
|
||||
expect(tabBarSource.match(/tabs\.noMatchingTabs/g)).toHaveLength(2);
|
||||
expect(tabBarSource).toContain('[data-tab-search-input="regular"]');
|
||||
expect(tabBarSource).toContain('[data-tab-search-input="fixed"]');
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar query execution status", () => {
|
||||
it("replaces the icon through one shared status component in every tab surface", () => {
|
||||
expect(tabBarSource).toContain('import TabExecutionStatus from "@/components/layout/TabExecutionStatus.vue";');
|
||||
expect(tabBarSource.match(/<TabExecutionStatus :tab="tab">/g)).toHaveLength(4);
|
||||
expect(tabBarSource.match(/<\/TabExecutionStatus>/g)).toHaveLength(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe("AppTabBar collapsible groups", () => {
|
||||
it("supports a persistent icon-only vertical tab bar without losing tab actions", () => {
|
||||
expect(tabBarSource).toContain("tabBarCollapsed?: boolean;");
|
||||
expect(tabBarSource).toContain('"toggle-collapse": [];');
|
||||
expect(tabBarSource).toContain('return { width: "3.5rem", flex: "0 0 3.5rem" };');
|
||||
expect(tabBarSource).toContain('<component :is="tabBarCollapseIcon"');
|
||||
expect(tabBarSource).toContain("@click=\"emit('toggle-collapse')\"");
|
||||
expect(tabBarSource).toContain('v-if="!isTabBarCollapsed" class="panel-resize-handle"');
|
||||
expect(tabBarSource).toContain(".vertical-tab-layout--collapsed .app-tab-pill");
|
||||
expect(tabBarSource).toContain(".vertical-tab-layout.vertical-tab-layout--collapsed .tab-group-tab::before");
|
||||
expect(tabBarSource.match(/v-if="isTabBarCollapsed && isDirtyTab\(tab\)"/g)).toHaveLength(2);
|
||||
expect(tabBarSource).toMatch(/\(collapsed\) => \{\s*if \(collapsed\) tabSearchQuery\.value = "";/);
|
||||
});
|
||||
|
||||
it("keeps horizontal placements immune to the persisted vertical collapse state", () => {
|
||||
expect(tabBarSource).toContain("const isTabBarCollapsed = computed(() => isVerticalLayout.value && !!props.tabBarCollapsed);");
|
||||
expect(tabBarSource).not.toContain('v-else-if="!tabBarCollapsed"');
|
||||
expect(tabBarSource).not.toContain('v-if="!tabBarCollapsed" class="min-w-0 truncate');
|
||||
expect(tabBarSource).not.toContain('v-if="tabBarCollapsed && isDirtyTab');
|
||||
// The only raw-prop guards left render inside the vertical-only toolbar.
|
||||
expect(tabBarSource.match(/!tabBarCollapsed/g)).toHaveLength(3);
|
||||
});
|
||||
|
||||
it("keeps only grouping and collapse in the compact vertical toolbar", () => {
|
||||
expect(tabBarSource).toContain('const verticalTabToolbarButtonClass = "inline-flex h-7 w-7');
|
||||
expect(tabBarSource.match(/:trigger-class="verticalTabToolbarButtonClass"/g)).toHaveLength(1);
|
||||
const toolbar = sourceBetween('<div v-if="!tabBarCollapsed" class="flex shrink-0 items-center gap-0">', "</div>\n <button");
|
||||
expect(toolbar).toContain(':trigger-icon="ListFilter"');
|
||||
expect(toolbar).not.toContain(':trigger-icon="ArrowDownUp"');
|
||||
expect(toolbar).not.toContain(':trigger-icon="PanelTop"');
|
||||
expect(tabBarSource).toContain('class="flex shrink-0 items-center gap-0.5 border-b p-1.5"');
|
||||
expect(tabBarSource).toContain('class="flex shrink-0 items-center gap-0"');
|
||||
});
|
||||
|
||||
it("keeps separate collapsed state for regular and fixed groups", () => {
|
||||
expect(tabBarSource).toContain("const collapsedTabGroups = ref<Set<string>>(new Set());");
|
||||
expect(tabBarSource).toContain('return `${tab.pinned ? "fixed" : "regular"}:${tabGroupKey(tab)}`;');
|
||||
expect(tabBarSource).toContain("function toggleTabGroup(tab: QueryTab)");
|
||||
expect(tabBarSource.match(/:aria-expanded="!isTabGroupCollapsed\(tab\)"/g)).toHaveLength(2);
|
||||
expect(tabBarSource.match(/<CustomContextMenu v-if="!isTabGroupCollapsed\(tab\)"/g)).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("temporarily reveals matches and expands a collapsed group when one of its tabs becomes active", () => {
|
||||
expect(tabBarSource).toContain('if (settingsStore.editorSettings.tabGroupMode === "none" || tabSearchQuery.value.trim()) return false;');
|
||||
expect(tabBarSource).toContain("expandTabGroupForTab(tabId);");
|
||||
});
|
||||
|
||||
it("uses compact group pills and places the accent next to content for top and bottom bars", () => {
|
||||
expect(tabBarSource).toContain(':data-placement="settingsStore.editorSettings.tabPlacement"');
|
||||
expect(tabBarSource).toContain(".app-tab-bar:not(.vertical-tab-layout) .tab-group-header");
|
||||
expect(tabBarSource).toContain(".app-tab-bar:not(.vertical-tab-layout) .tab-group-header::after");
|
||||
expect(tabBarSource).toContain(".app-tab-bar:not(.vertical-tab-layout) .tab-group-header--collapsed::after");
|
||||
expect(tabBarSource).toContain('.app-tab-bar:not(.vertical-tab-layout)[data-placement="bottom"] .tab-group-tab::after');
|
||||
expect(tabBarSource).toContain(".app-tab-bar:not(.vertical-tab-layout) .tab-group-tab--last::after");
|
||||
expect(tabBarSource).toContain(".vertical-tab-layout .tab-group-tab::before");
|
||||
});
|
||||
|
||||
it("supports persistent names and colors from the group header context menu", () => {
|
||||
expect(tabBarSource.match(/:items="\(\) => getTabGroupMenuItems\(tab\)"/g)).toHaveLength(2);
|
||||
expect(tabBarSource).toContain('["#2563eb", "#d97706", "#7c3aed", "#059669", "#dc2626", "#0891b2", "#db2777", "#475569"]');
|
||||
expect(tabBarSource).toContain("tabGroupCustomizations: customizations");
|
||||
expect(tabBarSource).toContain("data-tab-group-name-input");
|
||||
expect(tabBarSource).toContain('type="color"');
|
||||
});
|
||||
|
||||
it("exposes placement, grouping, and sorting preferences from the group context menu", () => {
|
||||
const preferences = sourceBetween("function getTabPreferenceMenuItems", "function getTabGroupMenuItems");
|
||||
const groupMenu = sourceBetween("function getTabGroupMenuItems", "function openTabGroupContextMenu");
|
||||
expect(preferences).toContain('label: t("settings.tabPlacement")');
|
||||
expect(preferences).toContain("action: () => updateTabPlacement(item.value)");
|
||||
expect(preferences).toContain('label: t("settings.tabGroup")');
|
||||
expect(preferences).toContain("action: () => updateTabGroupMode(item.value)");
|
||||
expect(preferences).toContain('label: t("settings.tabSort")');
|
||||
expect(preferences).toContain("action: () => updateTabSortMode(item.value)");
|
||||
expect(preferences.match(/checked: item\.value === settingsStore\.editorSettings\./g)).toHaveLength(3);
|
||||
expect(groupMenu).toContain("...getTabPreferenceMenuItems()");
|
||||
});
|
||||
|
||||
it("exposes placement, grouping, and sorting preferences from each tab context menu", () => {
|
||||
const menu = sourceBetween("function getTabMenuItems", "function handleSaveAndClose");
|
||||
expect(menu).toContain("...getTabPreferenceMenuItems()");
|
||||
});
|
||||
|
||||
it("waits for tab preference persistence and treats the whole group title as the context target", () => {
|
||||
expect(tabBarSource).toContain("await settingsStore.updateEditorSettingsAndPersist(partial)");
|
||||
expect(tabBarSource.match(/openTabGroupContextMenu\(\$event, onContextMenu\)/g)).toHaveLength(2);
|
||||
expect(tabBarSource).toContain("document.getSelection()?.removeAllRanges()");
|
||||
expect(tabBarSource).toContain("user-select: none;");
|
||||
});
|
||||
|
||||
it("removes the unexplained fixed-tab divider from vertical placement", () => {
|
||||
expect(tabBarSource).toContain("isVerticalLayout ? 'max-h-[40%] flex-col bg-background pt-1'");
|
||||
expect(tabBarSource).toContain('<Pin v-if="!isTabBarCollapsed" class="tab-group-pin" aria-hidden="true" />');
|
||||
});
|
||||
|
||||
it("uses a soft active shadow and a single indented rail for sidebar groups", () => {
|
||||
expect(tabBarSource).toContain("if (isVerticalLayout.value) {");
|
||||
expect(tabBarSource).toContain('"--app-tab-background": "var(--accent)"');
|
||||
expect(tabBarSource).toContain('.vertical-tab-layout .app-tab-pill[data-active-tab="true"]');
|
||||
expect(tabBarSource).toContain("inset 0 0 0 1px color-mix");
|
||||
expect(tabBarSource).toContain(".vertical-tab-layout .tab-group-header:not(.tab-group-header--collapsed)::after");
|
||||
expect(tabBarSource).toContain(".vertical-tab-layout .tab-group-tab::after");
|
||||
expect(tabBarSource).toContain("margin-inline: 2.5rem 0.5rem;");
|
||||
expect(tabBarSource).toContain("padding-inline-start: 0.65rem !important;");
|
||||
expect(tabBarSource).toContain("left: -0.65rem;");
|
||||
expect(tabBarSource).toContain(".vertical-tab-layout .tab-group-tab--first::before");
|
||||
expect(tabBarSource).toContain("bottom: -1.08rem;");
|
||||
expect(tabBarSource).toContain("top: 50%;");
|
||||
expect(tabBarSource).toContain("border-bottom-left-radius: 0.1875rem;");
|
||||
it("keeps the dirty marker and dirty title styling", () => {
|
||||
expect(groupTabBarSource).toContain("dirty-tab-marker");
|
||||
expect(groupTabBarSource).toContain("dirtyTabTitleStyle");
|
||||
});
|
||||
});
|
||||
+5
-3
@@ -11,11 +11,13 @@ describe("ContentArea data-mode header", () => {
|
||||
expect(chipsBlock.length).toBeGreaterThan(0);
|
||||
|
||||
// Fixed max-w-48/max-w-56 caps clipped table names even with plenty of free
|
||||
// space in the header row (#7880); chips must rely on min-w-0 + truncate so
|
||||
// they only clip when the row itself runs out of space.
|
||||
// space in the header row (#7880); chips must rely on truncate so they only
|
||||
// clip when the row itself runs out of space. The min-w-12 floor keeps
|
||||
// scrollWidth reporting real overflow for the measured condensation tiers —
|
||||
// below the floor the tiers condense the row instead of crushing chips.
|
||||
expect(chipsBlock).not.toContain("max-w-48");
|
||||
expect(chipsBlock).not.toContain("max-w-56");
|
||||
expect(chipsBlock).toContain("inline-flex min-w-0 items-center truncate");
|
||||
expect(chipsBlock).toContain("inline-flex min-w-12 items-center truncate");
|
||||
});
|
||||
|
||||
it("keeps the full table and schema names reachable via title tooltips", () => {
|
||||
|
||||
+5
-1
@@ -6,7 +6,11 @@ const contentAreaSource = readFileSync(new URL("../ContentArea.vue", import.meta
|
||||
describe("ContentArea completed query output", () => {
|
||||
it("re-evaluates the no-table fallback when tab activation resets the shared view", () => {
|
||||
expect(contentAreaSource).toContain("props.activeTab.isExecuting, props.activeOutputView] as const");
|
||||
expect(contentAreaSource).toContain('emit("update:activeOutputView", result ? defaultViewForResult(result) : "summary")');
|
||||
expect(contentAreaSource).toContain('emit("update:activeOutputView", props.activeTab.id, result ? defaultViewForResult(result) : "summary")');
|
||||
});
|
||||
|
||||
it("scopes the output-view watcher to the shared result surface", () => {
|
||||
expect(contentAreaSource).toContain("if (props.editorOnly) return;");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@ describe("ContentArea restored data-tab refresh", () => {
|
||||
|
||||
it("passes the restored tab's own WHERE/ORDER BY into the reload event", () => {
|
||||
expect(contentAreaSource).toContain("const { whereInput, orderBy } = restoredDataTabReloadFilters(props.activeTab);");
|
||||
expect(contentAreaSource).toContain(`emit("reload", undefined, undefined, whereInput, orderBy);`);
|
||||
// tabId-first contract: the reload event carries the owning tab's id.
|
||||
expect(contentAreaSource).toContain(`emit("reload", props.activeTab.id, undefined, whereInput, orderBy);`);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,185 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { createApp, nextTick } from "vue";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { createI18n } from "vue-i18n";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@/components/layout/EditorGroupTabBar.vue", () => ({
|
||||
default: {
|
||||
name: "EditorGroupTabBarStub",
|
||||
template: `<div data-test="group-tabbar" />`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/layout/EditorToolbar.vue", () => ({
|
||||
default: {
|
||||
name: "EditorToolbarStub",
|
||||
props: ["activeTab"],
|
||||
template: `<div data-test="group-toolbar">{{ activeTab.id }}</div>`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/layout/QueryEditorSurface.vue", () => ({
|
||||
default: {
|
||||
name: "QueryEditorSurfaceStub",
|
||||
props: ["activeTab", "autoFocus"],
|
||||
template: `<div data-test="query-editor">{{ activeTab.id }}</div>`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/layout/ContentArea.vue", () => ({
|
||||
default: {
|
||||
name: "ContentAreaStub",
|
||||
template: `<div data-test="content-area" />`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/backend/safeStorage", () => ({
|
||||
safeLocalStorageGet: () => null,
|
||||
safeLocalStorageSet: () => undefined,
|
||||
}));
|
||||
|
||||
import EditorGroup from "../EditorGroup.vue";
|
||||
import { createNoopEditorToolbarActions, EDITOR_TOOLBAR_ACTIONS, type EditorToolbarActions } from "../editorToolbarActions";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
|
||||
function tab(id: string) {
|
||||
return {
|
||||
id,
|
||||
title: id,
|
||||
connectionId: "conn-1",
|
||||
database: "db",
|
||||
sql: "SELECT 1",
|
||||
mode: "query",
|
||||
} as const;
|
||||
}
|
||||
|
||||
function createHost(): HTMLDivElement {
|
||||
const host = document.createElement("div");
|
||||
document.body.appendChild(host);
|
||||
return host;
|
||||
}
|
||||
|
||||
describe("EditorGroup mount contract", () => {
|
||||
let pinia: ReturnType<typeof createPinia>;
|
||||
let i18n: ReturnType<typeof createI18n>;
|
||||
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: "en",
|
||||
messages: { en: {} },
|
||||
});
|
||||
});
|
||||
|
||||
it("passes the group active tab to the query editor surface instead of the global active tab", async () => {
|
||||
const store = useQueryStore();
|
||||
store.tabs = [tab("tab-a"), tab("tab-b")];
|
||||
|
||||
const host = createHost();
|
||||
const app = createApp(EditorGroup, {
|
||||
groupId: "group-1",
|
||||
tabIds: ["tab-a", "tab-b"],
|
||||
activeTabId: "tab-b",
|
||||
// Global active tab is intentionally different from the group active tab.
|
||||
activeTab: tab("tab-a"),
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
const editor = host.querySelector<HTMLElement>('[data-test="query-editor"]');
|
||||
expect(editor).not.toBeNull();
|
||||
expect(editor?.textContent).toBe("tab-b");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("renders its own toolbar for query tabs and routes events to the injected actions", async () => {
|
||||
const store = useQueryStore();
|
||||
const queryId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const dataId = store.createTab("pg-1", "app", "rows", "data", "public");
|
||||
|
||||
const actions: EditorToolbarActions = {
|
||||
...createNoopEditorToolbarActions(),
|
||||
cancelExecution: vi.fn(),
|
||||
explain: vi.fn(),
|
||||
saveSql: vi.fn(),
|
||||
};
|
||||
|
||||
const host = createHost();
|
||||
const app = createApp(EditorGroup, {
|
||||
groupId: "group-1",
|
||||
tabIds: [queryId, dataId],
|
||||
activeTabId: queryId,
|
||||
activeTab: tab(queryId),
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
});
|
||||
app.provide(EDITOR_TOOLBAR_ACTIONS, actions);
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
// Query tab: the group carries its own toolbar bound to the group tab.
|
||||
const toolbar = host.querySelector<HTMLElement>('[data-test="group-toolbar"]');
|
||||
expect(toolbar?.textContent).toBe(queryId);
|
||||
|
||||
// Toolbar events flow to the injected actions with the group's tab id.
|
||||
(toolbar as any).__vueParentComponent.emit("cancel");
|
||||
(toolbar as any).__vueParentComponent.emit("explain");
|
||||
(toolbar as any).__vueParentComponent.emit("saveSql", queryId);
|
||||
await nextTick();
|
||||
expect(actions.cancelExecution).toHaveBeenCalledWith(queryId);
|
||||
expect(actions.explain).toHaveBeenCalledWith(queryId);
|
||||
expect(actions.saveSql).toHaveBeenCalledWith(queryId);
|
||||
|
||||
// Data tab: no SQL toolbar — the data grid carries its own built-in bar.
|
||||
app.unmount();
|
||||
const app2 = createApp(EditorGroup, {
|
||||
groupId: "group-1",
|
||||
tabIds: [queryId, dataId],
|
||||
activeTabId: dataId,
|
||||
activeTab: tab(queryId),
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
});
|
||||
app2.provide(EDITOR_TOOLBAR_ACTIONS, actions);
|
||||
app2.use(pinia);
|
||||
app2.use(i18n);
|
||||
app2.mount(host);
|
||||
await nextTick();
|
||||
|
||||
expect(host.querySelector('[data-test="group-toolbar"]')).toBeNull();
|
||||
expect(host.querySelector('[data-test="content-area"]')).not.toBeNull();
|
||||
|
||||
app2.unmount();
|
||||
host.remove();
|
||||
});
|
||||
});
|
||||
+562
@@ -0,0 +1,562 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { createApp, nextTick } from "vue";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { createI18n } from "vue-i18n";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@/components/ui/CustomContextMenu.vue", () => ({
|
||||
default: {
|
||||
name: "CustomContextMenuStub",
|
||||
props: ["items"],
|
||||
template: `<div class="ctx-menu-stub" :data-menu-items="JSON.stringify(items.map((item) => ({ label: item.label, disabled: item.disabled === true, visible: item.visible })))"><slot /></div>`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/ui/tooltip", () => ({
|
||||
Tooltip: { name: "TooltipStub", template: `<div><slot /></div>` },
|
||||
TooltipTrigger: { name: "TooltipTriggerStub", template: `<div><slot /></div>` },
|
||||
TooltipContent: { name: "TooltipContentStub", template: `<div><slot /></div>` },
|
||||
}));
|
||||
|
||||
vi.mock("@/components/ui/popover", () => ({
|
||||
Popover: { name: "PopoverStub", props: ["open"], template: `<div v-if="open"><slot /></div>` },
|
||||
PopoverContent: { name: "PopoverContentStub", template: `<div><slot /></div>` },
|
||||
PopoverTrigger: { name: "PopoverTriggerStub", template: `<div><slot /></div>` },
|
||||
}));
|
||||
|
||||
vi.mock("@/components/connection/ReadOnlySessionControl.vue", () => ({
|
||||
default: { name: "ReadOnlySessionControlStub", template: `<span />` },
|
||||
}));
|
||||
|
||||
vi.mock("@/components/layout/TabExecutionStatus.vue", () => ({
|
||||
default: { name: "TabExecutionStatusStub", template: `<span><slot /></span>` },
|
||||
}));
|
||||
|
||||
vi.mock("@/components/icons/DatabaseIcon.vue", () => ({
|
||||
default: { name: "DatabaseIconStub", template: `<span />` },
|
||||
}));
|
||||
|
||||
import EditorGroupTabBar from "../EditorGroupTabBar.vue";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
|
||||
function createHost(): HTMLDivElement {
|
||||
const host = document.createElement("div");
|
||||
document.body.appendChild(host);
|
||||
return host;
|
||||
}
|
||||
|
||||
interface Mounted {
|
||||
app: ReturnType<typeof createApp>;
|
||||
host: HTMLDivElement;
|
||||
}
|
||||
|
||||
function mountBar(groupId: string, tabs: string[], activeTabId: string | null, activePinia: ReturnType<typeof createPinia>, onActivateTab?: (tabId: string) => void): Mounted {
|
||||
const store = useQueryStore();
|
||||
const host = createHost();
|
||||
const app = createApp(EditorGroupTabBar, {
|
||||
groupId,
|
||||
tabs: tabs.map((id) => store.tabs.find((candidate) => candidate.id === id)!),
|
||||
activeTabId,
|
||||
"onActivate-tab": onActivateTab,
|
||||
});
|
||||
// Reuse the active pinia so the component's internal store is the same
|
||||
// instance the test drives — otherwise drag validation runs against an
|
||||
// empty store and silently early-returns.
|
||||
app.use(activePinia);
|
||||
app.use(
|
||||
createI18n({
|
||||
legacy: false,
|
||||
locale: "en",
|
||||
messages: {
|
||||
en: {
|
||||
contextMenu: {
|
||||
splitRight: "Split right",
|
||||
splitDown: "Split down",
|
||||
changeOrientation: "Change orientation",
|
||||
unsplit: "Unsplit",
|
||||
renameTab: "Rename",
|
||||
duplicateTab: "Duplicate",
|
||||
copyName: "Copy name",
|
||||
closeTab: "Close",
|
||||
closeOtherTabs: "Close other tabs",
|
||||
closeLeftTabs: "Close left tabs",
|
||||
closeRightTabs: "Close right tabs",
|
||||
closeAllTabs: "Close all tabs",
|
||||
pinTab: "Pin",
|
||||
unpinTab: "Unpin",
|
||||
fullTabTitle: "Full title",
|
||||
compactTabTitle: "Compact title",
|
||||
},
|
||||
sidebar: { locateActiveTab: "Locate" },
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
app.mount(host);
|
||||
return { app, host };
|
||||
}
|
||||
|
||||
async function settle() {
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
}
|
||||
|
||||
function tabPill(host: HTMLElement, tabId: string): HTMLElement {
|
||||
return host.querySelector<HTMLElement>(`[data-tab-id="${tabId}"]`)!;
|
||||
}
|
||||
|
||||
function pointerDownOn(element: HTMLElement) {
|
||||
element.dispatchEvent(
|
||||
new PointerEvent("pointerdown", {
|
||||
bubbles: true,
|
||||
button: 0,
|
||||
buttons: 1,
|
||||
clientX: 10,
|
||||
clientY: 10,
|
||||
pointerId: 1,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function pointerMoveTo(x: number, y: number) {
|
||||
window.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, buttons: 1, clientX: x, clientY: y, pointerId: 1 }));
|
||||
}
|
||||
|
||||
function pointerUpAt(x: number, y: number) {
|
||||
window.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, buttons: 1, clientX: x, clientY: y, pointerId: 1 }));
|
||||
}
|
||||
|
||||
function fakeDropTarget(tabId: string, groupId: string): HTMLElement {
|
||||
const element = document.createElement("div");
|
||||
element.dataset.tabId = tabId;
|
||||
element.dataset.groupId = groupId;
|
||||
vi.spyOn(element, "getBoundingClientRect").mockReturnValue({ left: 0, right: 100, width: 100, top: 0, height: 30 } as DOMRect);
|
||||
return element;
|
||||
}
|
||||
|
||||
describe("EditorGroupTabBar behavior", () => {
|
||||
let pinia: ReturnType<typeof createPinia>;
|
||||
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
vi.restoreAllMocks();
|
||||
pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
});
|
||||
|
||||
it("activates a tab on plain click", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const activated: string[] = [];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia, (tabId) => activated.push(tabId));
|
||||
await settle();
|
||||
|
||||
tabPill(host, secondId).click();
|
||||
await settle();
|
||||
|
||||
expect(activated).toEqual([secondId]);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("suppresses the click that follows a drag, and only that click", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const activated: string[] = [];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia, (tabId) => activated.push(tabId));
|
||||
await settle();
|
||||
|
||||
vi.spyOn(document, "elementFromPoint").mockReturnValue(null);
|
||||
const pill = tabPill(host, secondId);
|
||||
pointerDownOn(pill);
|
||||
pointerMoveTo(80, 60);
|
||||
pointerUpAt(80, 60);
|
||||
pill.click();
|
||||
await settle();
|
||||
|
||||
// The drag consumed its own click; the tab must not be activated…
|
||||
expect(activated).toEqual([]);
|
||||
|
||||
// …but a fresh, ordinary click still activates.
|
||||
pill.click();
|
||||
await settle();
|
||||
expect(activated).toEqual([secondId]);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("does not arm a drag when the primary button is not held", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
vi.spyOn(document, "elementFromPoint").mockReturnValue(null);
|
||||
// macOS reports a trackpad tap as a mouse pointer with button=0 but buttons=0.
|
||||
tabPill(host, secondId).dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, button: 0, buttons: 0, clientX: 10, clientY: 10, pointerId: 1 }));
|
||||
window.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, buttons: 0, clientX: 80, clientY: 60, pointerId: 1 }));
|
||||
window.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, clientX: 80, clientY: 60, pointerId: 1 }));
|
||||
await settle();
|
||||
|
||||
expect(store.groups.find((group) => group.id === mainGroup.id)?.tabIds).toContain(secondId);
|
||||
expect(document.body.style.cursor).toBe("");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("cancels a pending drag when the primary button is released before movement", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
vi.spyOn(document, "elementFromPoint").mockReturnValue(null);
|
||||
const pill = tabPill(host, secondId);
|
||||
pointerDownOn(pill);
|
||||
window.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, buttons: 0, clientX: 80, clientY: 10, pointerId: 1 }));
|
||||
window.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, buttons: 1, clientX: 90, clientY: 10, pointerId: 1 }));
|
||||
window.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, clientX: 90, clientY: 10, pointerId: 1 }));
|
||||
await settle();
|
||||
|
||||
expect(store.groups.find((group) => group.id === mainGroup.id)?.tabIds).toContain(secondId);
|
||||
expect(document.body.style.cursor).toBe("");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("cancels an active drag when the primary button is no longer held", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
vi.spyOn(document, "elementFromPoint").mockReturnValue(null);
|
||||
const pill = tabPill(host, secondId);
|
||||
pointerDownOn(pill);
|
||||
pointerMoveTo(80, 60);
|
||||
expect(document.body.style.cursor).toBe("grabbing");
|
||||
window.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, buttons: 0, clientX: 90, clientY: 60, pointerId: 1 }));
|
||||
await settle();
|
||||
|
||||
expect(document.body.style.cursor).toBe("");
|
||||
expect(document.body.style.userSelect).toBe("");
|
||||
expect(store.groups.find((group) => group.id === mainGroup.id)?.tabIds).toContain(secondId);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("ignores movement from a different pointer", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
vi.spyOn(document, "elementFromPoint").mockReturnValue(null);
|
||||
const pill = tabPill(host, secondId);
|
||||
pill.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, button: 0, buttons: 1, clientX: 10, clientY: 10, pointerId: 7 }));
|
||||
window.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, buttons: 1, clientX: 90, clientY: 10, pointerId: 8 }));
|
||||
await settle();
|
||||
|
||||
expect(document.body.style.cursor).toBe("");
|
||||
expect(store.groups.find((group) => group.id === mainGroup.id)?.tabIds).toContain(secondId);
|
||||
window.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, clientX: 90, clientY: 10, pointerId: 7 }));
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("clears completed-drag click suppression on a later trackpad tap", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const activated: string[] = [];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia, (tabId) => activated.push(tabId));
|
||||
await settle();
|
||||
|
||||
vi.spyOn(document, "elementFromPoint").mockReturnValue(null);
|
||||
const pill = tabPill(host, secondId);
|
||||
pointerDownOn(pill);
|
||||
pointerMoveTo(80, 60);
|
||||
pointerUpAt(80, 60);
|
||||
|
||||
// The completed drag left click suppression armed; a trackpad tap
|
||||
// (pointerdown with buttons=0) must consume it without arming a drag.
|
||||
pill.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, button: 0, buttons: 0, clientX: 10, clientY: 10, pointerId: 1 }));
|
||||
window.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, buttons: 0, clientX: 10, clientY: 12, pointerId: 1 }));
|
||||
pill.click();
|
||||
await settle();
|
||||
|
||||
expect(activated).toEqual([secondId]);
|
||||
expect(document.body.style.cursor).toBe("");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("moves a dragged tab to the target group under the payload's source group", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
// Drag the second tab over the (virtual) right group's strip.
|
||||
vi.spyOn(document, "elementFromPoint").mockReturnValue(fakeDropTarget(firstId, "target-group"));
|
||||
|
||||
// Seed a second group to receive the drop.
|
||||
store.groups = [mainGroup, { id: "target-group", tabIds: [], activeTabId: null }];
|
||||
const pill = tabPill(host, secondId);
|
||||
pointerDownOn(pill);
|
||||
pointerMoveTo(300, 10);
|
||||
pointerUpAt(300, 10);
|
||||
await settle();
|
||||
|
||||
expect(store.groups.find((group) => group.id === "target-group")?.tabIds).toContain(secondId);
|
||||
expect(store.groups.find((group) => group.id === mainGroup.id)?.tabIds).not.toContain(secondId);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("ignores a drop when the tab's current owner no longer matches the payload", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
vi.spyOn(document, "elementFromPoint").mockReturnValue(fakeDropTarget(firstId, "target-group"));
|
||||
store.groups = [mainGroup, { id: "target-group", tabIds: [], activeTabId: null }];
|
||||
|
||||
const pill = tabPill(host, secondId);
|
||||
pointerDownOn(pill);
|
||||
// While the button is held, the tab is relocated behind the drag's back —
|
||||
// the stale payload no longer matches the current owner.
|
||||
store.moveTabToGroup(secondId, "target-group");
|
||||
pointerMoveTo(300, 10);
|
||||
pointerUpAt(300, 10);
|
||||
await settle();
|
||||
|
||||
// Only the intervening store move happened; the drop itself was rejected.
|
||||
expect(store.groups.find((group) => group.id === "target-group")?.tabIds).toEqual([secondId]);
|
||||
expect(store.groups.find((group) => group.id === mainGroup.id)?.tabIds).toEqual([firstId]);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("disables the split actions while only one tab exists, enabling them once a second tab joins", async () => {
|
||||
const store = useQueryStore();
|
||||
const onlyId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [onlyId], onlyId, pinia);
|
||||
await settle();
|
||||
|
||||
// Splitting the only tab would return to the same single-group layout, so
|
||||
// the actions render disabled instead of doing nothing.
|
||||
const splitItems = (host: HTMLElement) => JSON.parse(host.querySelector<HTMLElement>(".ctx-menu-stub")!.dataset.menuItems ?? "[]").filter((item: { label: string }) => item.label === "Split right" || item.label === "Split down");
|
||||
expect(splitItems(host)).toHaveLength(2);
|
||||
for (const item of splitItems(host)) {
|
||||
expect(item).toMatchObject({ disabled: true });
|
||||
}
|
||||
|
||||
store.createTab("pg-1", "app", "Query 2", "query");
|
||||
await settle();
|
||||
|
||||
for (const item of splitItems(host)) {
|
||||
expect(item).toMatchObject({ disabled: false });
|
||||
}
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("offers the split actions for non-query tabs, enabled like query tabs", async () => {
|
||||
const store = useQueryStore();
|
||||
const queryId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const dataId = store.createTab("pg-1", "app", "users", "data", "public");
|
||||
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [queryId, dataId], dataId, pinia);
|
||||
await settle();
|
||||
|
||||
const pill = tabPill(host, dataId);
|
||||
const stub = pill.closest<HTMLElement>(".ctx-menu-stub")!;
|
||||
const items = JSON.parse(stub.dataset.menuItems ?? "[]");
|
||||
const splitItems = items.filter((item: { label: string }) => item.label === "Split right" || item.label === "Split down");
|
||||
expect(splitItems).toHaveLength(2);
|
||||
for (const item of splitItems) {
|
||||
expect(item).toMatchObject({ disabled: false });
|
||||
}
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("keeps split actions visible but disabled once four groups exist", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const thirdId = store.createTab("pg-1", "app", "Query 3", "query");
|
||||
const fourthId = store.createTab("pg-1", "app", "Query 4", "query");
|
||||
const fifthId = store.createTab("pg-1", "app", "Query 5", "query");
|
||||
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId, thirdId, fourthId, fifthId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
// Two tabs, two groups.
|
||||
store.splitTabRight(secondId);
|
||||
await settle();
|
||||
|
||||
const menus = host.querySelectorAll<HTMLElement>(".ctx-menu-stub");
|
||||
const splitItem = (menu: HTMLElement) => JSON.parse(menu.dataset.menuItems ?? "[]").find((item: { label: string }) => item.label === "Split right");
|
||||
expect(splitItem(menus[0]!)).toMatchObject({ disabled: false });
|
||||
|
||||
store.splitTabDown(thirdId);
|
||||
store.splitTabDown(fourthId);
|
||||
await settle();
|
||||
expect(store.groups.length).toBe(4);
|
||||
|
||||
const disabledSplit = splitItem(menus[0]!);
|
||||
expect(disabledSplit).toMatchObject({ disabled: true });
|
||||
// The store rejects a fifth split with the same capacity rule.
|
||||
expect(store.splitTabRight(fifthId)).toBe(false);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("offers close-left between close-other and close-right, disabled when nothing is to the left", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
// One stub per tab; the stub wraps the tab pill, so scope by ancestor.
|
||||
// The stub only serializes label/disabled/visible — the closing behavior
|
||||
// itself is covered by queryStore.groups.spec.
|
||||
const menuFor = (tabId: string) => {
|
||||
const pill = tabPill(host, tabId);
|
||||
const stub = pill.closest<HTMLElement>(".ctx-menu-stub");
|
||||
return JSON.parse(stub!.dataset.menuItems ?? "[]");
|
||||
};
|
||||
const labels = (tabId: string) => menuFor(tabId).map((item: { label: string }) => item.label);
|
||||
|
||||
// First tab: nothing to its left — the action exists but is disabled.
|
||||
expect(menuFor(firstId).find((item: { label: string }) => item.label === "Close left tabs")).toMatchObject({ disabled: true });
|
||||
const order = labels(firstId);
|
||||
expect(order.indexOf("Close left tabs")).toBeGreaterThan(order.indexOf("Close other tabs"));
|
||||
expect(order.indexOf("Close left tabs")).toBeLessThan(order.indexOf("Close right tabs"));
|
||||
|
||||
// Second tab: a tab exists to its left — the action becomes enabled.
|
||||
expect(menuFor(secondId).find((item: { label: string }) => item.label === "Close left tabs")).toMatchObject({ disabled: false });
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("flushes pending grid edits via before-tab-switch before activating another tab", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
const events: Array<CustomEvent | Event> = [];
|
||||
const listener = (event: Event) => events.push(event as CustomEvent);
|
||||
window.addEventListener("dbx:before-tab-switch", listener);
|
||||
// The legacy bar flushed pending edits on pointerdown, before activation.
|
||||
pointerDownOn(tabPill(host, secondId));
|
||||
tabPill(host, secondId).click();
|
||||
await settle();
|
||||
window.removeEventListener("dbx:before-tab-switch", listener);
|
||||
|
||||
expect(events).toHaveLength(1);
|
||||
expect((events[0] as CustomEvent).detail).toEqual({ tabId: secondId, fromTabId: firstId });
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("dims the dragged pill and shows the insertion indicator on the hovered pill", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
const fake = fakeDropTarget(secondId, mainGroup.id);
|
||||
vi.spyOn(document, "elementFromPoint").mockReturnValue(fake);
|
||||
|
||||
const sourcePill = tabPill(host, firstId);
|
||||
const targetPill = tabPill(host, secondId);
|
||||
pointerDownOn(sourcePill);
|
||||
pointerMoveTo(300, 10);
|
||||
await settle();
|
||||
|
||||
// Dragged pill dims; hovered pill shows the after-insertion ring line.
|
||||
expect(sourcePill.style.opacity).toBe("0.4");
|
||||
expect(targetPill.style.boxShadow).toBe("inset -3px 0 0 0 var(--ring)");
|
||||
|
||||
// Crossing the pill's midpoint flips the indicator to "before".
|
||||
vi.spyOn(fake, "getBoundingClientRect").mockReturnValue({ left: 0, right: 600, width: 600, top: 0, height: 30 } as DOMRect);
|
||||
pointerMoveTo(20, 10);
|
||||
await settle();
|
||||
expect(targetPill.style.boxShadow).toBe("inset 3px 0 0 0 var(--ring)");
|
||||
|
||||
// Dropping clears every drag visual.
|
||||
pointerUpAt(20, 10);
|
||||
await settle();
|
||||
expect(sourcePill.style.opacity).toBe("");
|
||||
expect(targetPill.style.boxShadow).toBe("");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("does not arm the drag for touch input", async () => {
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId, secondId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
const sourcePill = tabPill(host, firstId);
|
||||
sourcePill.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, button: 0, clientX: 10, clientY: 10, pointerType: "touch" }));
|
||||
pointerMoveTo(300, 10);
|
||||
await settle();
|
||||
|
||||
expect(sourcePill.style.opacity).toBe("");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
});
|
||||
+421
@@ -0,0 +1,421 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { readFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { createI18n } from "vue-i18n";
|
||||
import { createApp, nextTick } from "vue";
|
||||
import EditorGroupTabBar from "../EditorGroupTabBar.vue";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
|
||||
vi.mock("@/components/ui/tooltip", () => ({
|
||||
Tooltip: { name: "TooltipStub", template: `<div><slot /></div>` },
|
||||
TooltipTrigger: { name: "TooltipTriggerStub", template: `<div><slot /></div>` },
|
||||
TooltipContent: { name: "TooltipContentStub", template: `<div><slot /></div>` },
|
||||
}));
|
||||
|
||||
vi.mock("@/components/ui/popover", () => ({
|
||||
Popover: { name: "PopoverStub", props: ["open"], template: `<div v-if="open"><slot /></div>` },
|
||||
PopoverContent: { name: "PopoverContentStub", template: `<div><slot /></div>` },
|
||||
PopoverTrigger: { name: "PopoverTriggerStub", template: `<div><slot /></div>` },
|
||||
}));
|
||||
|
||||
const specDir = dirname(fileURLToPath(import.meta.url));
|
||||
const source = readFileSync(resolve(specDir, "../EditorGroupTabBar.vue"), "utf8");
|
||||
const sharedStyles = readFileSync(resolve(specDir, "../appTabBar.css"), "utf8");
|
||||
|
||||
describe("EditorGroupTabBar semantic tab groups", () => {
|
||||
it("keeps separate collapsed state for pinned and regular clusters under the same key", () => {
|
||||
expect(source).toContain("const collapsedTabGroups = ref<Set<string>>(new Set());");
|
||||
expect(source).toContain('return `${tab.pinned ? "fixed" : "regular"}:${tabGroupKey(tab)}`;');
|
||||
expect(source).toContain("function toggleTabGroup(tab: QueryTab)");
|
||||
expect(source).toContain(':aria-expanded="!isTabGroupCollapsed(entry.tab)"');
|
||||
});
|
||||
|
||||
it("expands a collapsed group when one of its tabs becomes active", () => {
|
||||
expect(source).toContain("expandTabGroupForTab(tabId);");
|
||||
});
|
||||
|
||||
it("supports persistent names and colors from the group header context menu", () => {
|
||||
expect(source).toContain('["#2563eb", "#d97706", "#7c3aed", "#059669", "#dc2626", "#0891b2", "#db2777", "#475569"]');
|
||||
expect(source).toContain("tabGroupCustomizations: customizations");
|
||||
expect(source).toContain("data-tab-group-name-input");
|
||||
expect(source).toContain('type="color"');
|
||||
});
|
||||
|
||||
it("exposes placement, grouping, and sorting preferences from the group context menu", () => {
|
||||
const preferences = sourceBetween("function getTabPreferenceMenuItems", "function getTabGroupMenuItems");
|
||||
const groupMenu = sourceBetween("function getTabGroupMenuItems", "function openTabGroupContextMenu");
|
||||
expect(preferences).toContain('label: t("settings.tabPlacement")');
|
||||
expect(preferences).toContain("action: () => updateTabPlacement(item.value)");
|
||||
expect(preferences).toContain('label: t("settings.tabGroup")');
|
||||
expect(preferences).toContain("action: () => updateTabGroupMode(item.value)");
|
||||
expect(preferences).toContain('label: t("settings.tabSort")');
|
||||
expect(preferences).toContain("action: () => updateTabSortMode(item.value)");
|
||||
expect(preferences.match(/checked: item\.value === settingsStore\.editorSettings\./g)).toHaveLength(3);
|
||||
expect(groupMenu).toContain("...getTabPreferenceMenuItems()");
|
||||
});
|
||||
|
||||
it("exposes preferences and the group close from each tab context menu", () => {
|
||||
const menuStart = source.indexOf("function getTabMenuItems");
|
||||
const menuEnd = source.indexOf("function handleTabDoubleClick");
|
||||
expect(menuStart).toBeGreaterThanOrEqual(0);
|
||||
expect(menuEnd).toBeGreaterThan(menuStart);
|
||||
const menu = source.slice(menuStart, menuEnd);
|
||||
expect(menu).toContain("...getTabPreferenceMenuItems()");
|
||||
expect(menu).toContain("action: () => closeTabGroup(tab)");
|
||||
expect(menu).toContain('visible: settingsStore.editorSettings.tabGroupMode !== "none"');
|
||||
});
|
||||
|
||||
it("closes the global semantic group by key, not just this pane's cluster", () => {
|
||||
// D1 (amended): closing a cluster is destructive and stays bar-local —
|
||||
// scoped to this pane's tabs (props.tabs), still within the trigger's
|
||||
// pinned section. Profile edits (rename/color/reset) keep global reach.
|
||||
const closeGroup = sourceBetween("function tabsInSemanticGroup", "function getTabPreferenceMenuItems");
|
||||
expect(closeGroup).toContain("props.tabs.filter((item) => item.pinned === tab.pinned && tabGroupKey(item) === groupKey)");
|
||||
expect(closeGroup).toContain("queryStore.closeTabsByIds(tabsToClose, finalActiveTabId)");
|
||||
});
|
||||
|
||||
it("waits for tab preference persistence and treats the whole group title as the context target", () => {
|
||||
expect(source).toContain("await settingsStore.updateEditorSettingsAndPersist(partial)");
|
||||
expect(source).toContain("openTabGroupContextMenu($event, onContextMenu)");
|
||||
expect(source).toContain("document.getSelection()?.removeAllRanges()");
|
||||
});
|
||||
|
||||
it("applies the group rail classes to clustered pills", () => {
|
||||
// The horizontal underline and vertical indent rails only render when the
|
||||
// pill carries tab-group-tab with its --first/--last markers.
|
||||
expect(source).toContain("'tab-group-tab': entry.grouping,");
|
||||
expect(source).toContain("'tab-group-tab--first': entry.grouping && entry.groupFirst,");
|
||||
expect(source).toContain("'tab-group-tab--last': entry.grouping && entry.groupLast,");
|
||||
expect(sharedStyles).toContain(".app-tab-bar:not(.vertical-tab-layout) .tab-group-tab::after");
|
||||
});
|
||||
|
||||
it("hides collapsed cluster pills but reveals them while searching", () => {
|
||||
expect(source).toContain("grouping && !tabSearchQuery.value.trim() && isTabGroupCollapsed(tab)");
|
||||
});
|
||||
|
||||
it("keeps wrap layout out of the vertical placement", () => {
|
||||
expect(source).toContain('const isWrapLayout = computed(() => !isVerticalLayout.value && settingsStore.editorSettings.tabLayout === "wrap");');
|
||||
});
|
||||
|
||||
it("uses compact group pills and places the accent next to content for horizontal bars", () => {
|
||||
expect(source).toContain(':data-placement="settingsStore.editorSettings.tabPlacement"');
|
||||
expect(sharedStyles).toContain(".app-tab-bar:not(.vertical-tab-layout) .tab-group-header");
|
||||
expect(sharedStyles).toContain(".app-tab-bar:not(.vertical-tab-layout) .tab-group-header::after");
|
||||
expect(sharedStyles).toContain(".app-tab-bar:not(.vertical-tab-layout) .tab-group-header--collapsed::after");
|
||||
expect(sharedStyles).toContain('.app-tab-bar:not(.vertical-tab-layout)[data-placement="bottom"] .tab-group-tab::after');
|
||||
expect(sharedStyles).toContain(".app-tab-bar:not(.vertical-tab-layout) .tab-group-tab--last::after");
|
||||
});
|
||||
|
||||
function sourceBetween(start: string, end: string): string {
|
||||
const startIndex = source.indexOf(start);
|
||||
const endIndex = source.indexOf(end, startIndex + start.length);
|
||||
expect(startIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(endIndex).toBeGreaterThan(startIndex);
|
||||
return source.slice(startIndex, endIndex);
|
||||
}
|
||||
});
|
||||
|
||||
describe("EditorGroupTabBar vertical placement", () => {
|
||||
const groupSource = readFileSync(resolve(specDir, "../EditorGroup.vue"), "utf8");
|
||||
const workspaceSource = readFileSync(resolve(specDir, "../SqlEditorWorkspace.vue"), "utf8");
|
||||
const appSource = readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../../../App.vue"), "utf8");
|
||||
|
||||
it("renders each pane's own bar as a vertical strip when placement is left/right", () => {
|
||||
expect(source).toContain('const isVerticalLayout = computed(() => settingsStore.editorSettings.tabPlacement === "left" || settingsStore.editorSettings.tabPlacement === "right");');
|
||||
expect(source).toContain('isVerticalLayout.value && props.tabBarCollapsed ? "vertical-tab-layout--collapsed" : ""');
|
||||
// The strip flips to a column with vertical scrolling; no horizontal strip remains.
|
||||
expect(source).toContain("isVerticalLayout ? 'flex-col items-stretch overflow-y-auto overflow-x-hidden py-1'");
|
||||
});
|
||||
|
||||
it("positions each pane's bar by the global placement without mixing directions", () => {
|
||||
expect(groupSource).toContain('case "bottom":');
|
||||
expect(groupSource).toContain('return "flex-col-reverse";');
|
||||
expect(groupSource).toContain('case "left":');
|
||||
expect(groupSource).toContain('return "flex-row";');
|
||||
expect(groupSource).toContain('case "right":');
|
||||
expect(groupSource).toContain('return "flex-row-reverse";');
|
||||
// The editor toolbar stays atop the pane's content column in every placement.
|
||||
expect(groupSource).toContain('class="flex min-h-0 min-w-0 flex-1 flex-col"');
|
||||
});
|
||||
|
||||
it("shares the vertical width/collapse state from App through the pane chain", () => {
|
||||
expect(appSource).toContain(':tab-bar-width="tabBarWidth"');
|
||||
expect(appSource).toContain(':tab-bar-collapsed="tabBarCollapsed"');
|
||||
expect(appSource).toContain('@start-resize="startTabBarResize"');
|
||||
expect(appSource).toContain('@toggle-collapse="toggleTabBarCollapsed"');
|
||||
expect(workspaceSource).toContain(':tab-bar-width="tabBarWidth"');
|
||||
expect(workspaceSource).toContain("@start-resize=\"emit('start-resize', $event)\"");
|
||||
expect(groupSource).toContain(':tab-bar-width="tabBarWidth"');
|
||||
// Dragging any pane's handle drives the shared resize handler.
|
||||
expect(source).toContain("@mousedown=\"emit('start-resize', $event)\"");
|
||||
expect(source).toContain("@click=\"emit('toggle-collapse')\"");
|
||||
});
|
||||
|
||||
it("keeps horizontal placements immune to the persisted collapse state", () => {
|
||||
expect(source).toContain("const isTabBarCollapsed = computed(() => isVerticalLayout.value && !!props.tabBarCollapsed);");
|
||||
expect(source).toContain("if (!isVerticalLayout.value) return undefined;");
|
||||
});
|
||||
|
||||
it("uses the sidebar rail and soft active shadow for vertical pills", () => {
|
||||
expect(sharedStyles).toContain(".vertical-tab-layout .tab-group-tab::before");
|
||||
expect(sharedStyles).toContain('.vertical-tab-layout .app-tab-pill[data-active-tab="true"]');
|
||||
expect(sharedStyles).toContain("inset 0 0 0 1px color-mix");
|
||||
expect(sharedStyles).toContain(".vertical-tab-layout .tab-group-header:not(.tab-group-header--collapsed)::after");
|
||||
expect(sharedStyles).toContain("margin-inline: 2.5rem 0.5rem;");
|
||||
});
|
||||
});
|
||||
|
||||
function createHost(): HTMLDivElement {
|
||||
const host = document.createElement("div");
|
||||
document.body.appendChild(host);
|
||||
return host;
|
||||
}
|
||||
|
||||
async function settle() {
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
}
|
||||
|
||||
function mountBar(groupId: string, tabs: ReturnType<ReturnType<typeof useQueryStore>["tabs"]>[number][], activeTabId: string | null, activePinia: ReturnType<typeof createPinia>, extraProps: Record<string, unknown> = {}) {
|
||||
const host = createHost();
|
||||
const app = createApp(EditorGroupTabBar, {
|
||||
groupId,
|
||||
tabs,
|
||||
activeTabId,
|
||||
...extraProps,
|
||||
});
|
||||
app.use(activePinia);
|
||||
app.use(
|
||||
createI18n({
|
||||
legacy: false,
|
||||
locale: "en",
|
||||
messages: {
|
||||
en: {
|
||||
contextMenu: {
|
||||
renameTab: "Rename",
|
||||
duplicateTab: "Duplicate",
|
||||
copyName: "Copy name",
|
||||
closeTab: "Close",
|
||||
closeOtherTabs: "Close other tabs",
|
||||
closeLeftTabs: "Close left tabs",
|
||||
closeRightTabs: "Close right tabs",
|
||||
closeAllTabs: "Close all tabs",
|
||||
closeTabGroup: "Close group",
|
||||
editTabGroup: "Edit group",
|
||||
resetTabGroup: "Reset group",
|
||||
pinTab: "Pin",
|
||||
unpinTab: "Unpin",
|
||||
fullTabTitle: "Full title",
|
||||
compactTabTitle: "Compact title",
|
||||
splitRight: "Split right",
|
||||
splitDown: "Split down",
|
||||
changeOrientation: "Change orientation",
|
||||
unsplit: "Unsplit",
|
||||
},
|
||||
sidebar: { locateActiveTab: "Locate" },
|
||||
settings: {
|
||||
tabPlacement: "Tab placement",
|
||||
tabPlacementTop: "Top",
|
||||
tabPlacementBottom: "Bottom",
|
||||
tabPlacementLeft: "Left",
|
||||
tabPlacementRight: "Right",
|
||||
tabGroup: "Group tabs by",
|
||||
tabGroupNone: "None",
|
||||
tabGroupDatabaseType: "Database type",
|
||||
tabGroupConnection: "Connection",
|
||||
tabSort: "Sort tabs",
|
||||
tabSortManual: "Manual",
|
||||
tabSortCreated: "Created",
|
||||
tabSortTitle: "Title",
|
||||
},
|
||||
tabs: {
|
||||
openInNewWindow: "Open in new window",
|
||||
settingsSaveFailed: "Save failed: {message}",
|
||||
editGroupTitle: "Edit group {name}",
|
||||
groupName: "Name",
|
||||
groupColor: "Color",
|
||||
groupColorAuto: "Auto",
|
||||
groupColorCustom: "Custom",
|
||||
resetGroup: "Reset",
|
||||
openTabs: "Open tabs",
|
||||
searchOpenTabs: "Search",
|
||||
noMatchingTabs: "No matching tabs",
|
||||
},
|
||||
common: { cancel: "Cancel", save: "Save" },
|
||||
toolbar: { formatSqlFailed: "Format failed" },
|
||||
grid: { copyFailed: "Copy failed: {message}" },
|
||||
connection: { copied: "Copied" },
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
app.mount(host);
|
||||
return { app, host };
|
||||
}
|
||||
|
||||
describe("EditorGroupTabBar group behavior", () => {
|
||||
let pinia: ReturnType<typeof createPinia>;
|
||||
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
vi.restoreAllMocks();
|
||||
pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
});
|
||||
|
||||
it("renders one header per connection cluster and collapses it to a count badge", async () => {
|
||||
const store = useQueryStore();
|
||||
const settings = useSettingsStore();
|
||||
settings.editorSettings.tabGroupMode = "connection";
|
||||
const pgA = store.createTab("pg-1", "app", "PG 1", "query");
|
||||
store.createTab("pg-1", "app", "PG 2", "query");
|
||||
const my = store.createTab("mysql-1", "app", "MY 1", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, store.tabs.slice(), pgA, pinia);
|
||||
await settle();
|
||||
|
||||
const headers = Array.from(host.querySelectorAll<HTMLButtonElement>(".tab-group-header"));
|
||||
// Sorted by group key: mysql-1 clusters before pg-1.
|
||||
expect(headers.map((header) => header.title)).toEqual(["mysql-1", "pg-1"]);
|
||||
expect(host.querySelectorAll("[data-tab-id]").length).toBe(3);
|
||||
|
||||
// Collapse the pg cluster: its pills hide, the count badge appears.
|
||||
headers[1]!.click();
|
||||
await settle();
|
||||
expect(Array.from(host.querySelectorAll("[data-tab-id]")).map((pill) => pill.getAttribute("data-tab-id"))).toEqual([my]);
|
||||
const pgHeader = host.querySelectorAll<HTMLButtonElement>(".tab-group-header")[1]!;
|
||||
expect(pgHeader.querySelector(".tab-group-count")?.textContent).toBe("2");
|
||||
expect(pgHeader.getAttribute("aria-expanded")).toBe("false");
|
||||
|
||||
// Expand again.
|
||||
pgHeader.click();
|
||||
await settle();
|
||||
expect(host.querySelectorAll("[data-tab-id]").length).toBe(3);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("exposes the drag-back hit-test anchor and highlights itself as the detached drop target", async () => {
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("pg-1", "app", "PG 1", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, store.tabs.slice(), tabId, pinia, { detachedDropTarget: true });
|
||||
await settle();
|
||||
|
||||
const bar = host.querySelector<HTMLElement>(".app-tab-bar");
|
||||
// Dropping a detached window over any pane's strip returns the tab, so
|
||||
// every strip must carry the hit-test anchor App unions rects over.
|
||||
expect(bar?.hasAttribute("data-main-tab-bar")).toBe(true);
|
||||
expect(bar?.classList.contains("ring-2")).toBe(true);
|
||||
expect(bar?.classList.contains("ring-inset")).toBe(true);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("closing a group stays within the invoking pane, sparing the same-key cluster elsewhere", async () => {
|
||||
const store = useQueryStore();
|
||||
const settings = useSettingsStore();
|
||||
settings.editorSettings.tabGroupMode = "connection";
|
||||
const pgA = store.createTab("pg-1", "app", "PG 1", "query");
|
||||
const pgB = store.createTab("pg-1", "app", "PG 2", "query");
|
||||
const my = store.createTab("mysql-1", "app", "MY 1", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
store.groups = [mainGroup, { id: "second-group", tabIds: [], activeTabId: null }];
|
||||
store.moveTabToGroup(pgB, "second-group");
|
||||
const mountedTabs = store.tabs.filter((tab) => tab.id === pgA || tab.id === my);
|
||||
const { app, host } = mountBar(mainGroup.id, mountedTabs, pgA, pinia);
|
||||
await settle();
|
||||
|
||||
// The pg cluster spans main (pgA) and second-group (pgB). Closing the
|
||||
// group from THIS pane's menu is bar-local: main loses its pg cluster,
|
||||
// while the same-key cluster in second-group survives untouched.
|
||||
const pgPill = host.querySelector<HTMLElement>(`[data-tab-id="${pgA}"]`)!;
|
||||
expect(pgPill).not.toBeNull();
|
||||
pgPill.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: 10, clientY: 10 }));
|
||||
await settle();
|
||||
|
||||
const menu = document.body.querySelector<HTMLElement>("[data-dbx-context-menu]")!;
|
||||
expect(menu).not.toBeNull();
|
||||
const closeGroupItem = Array.from(menu.querySelectorAll<HTMLButtonElement>("button")).find((button) => button.textContent?.includes("Close group"));
|
||||
expect(closeGroupItem).toBeDefined();
|
||||
closeGroupItem!.click();
|
||||
await settle();
|
||||
|
||||
const remainingIds = store.tabs.map((tab) => tab.id);
|
||||
expect(remainingIds).not.toContain(pgA);
|
||||
expect(remainingIds).toEqual(expect.arrayContaining([pgB, my]));
|
||||
// second-group keeps its tab, so it is not pruned either.
|
||||
expect(store.groups.map((group) => group.id)).toEqual(expect.arrayContaining(["second-group"]));
|
||||
expect(store.groups.find((group) => group.id === "second-group")?.tabIds).toEqual([pgB]);
|
||||
expect(store.groups.find((group) => group.id === mainGroup.id)?.tabIds).toEqual([my]);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("closing a group spares the pinned cluster that shares its key", async () => {
|
||||
const store = useQueryStore();
|
||||
const settings = useSettingsStore();
|
||||
settings.editorSettings.tabGroupMode = "connection";
|
||||
const pgA = store.createTab("pg-1", "app", "PG 1", "query");
|
||||
const pgB = store.createTab("pg-1", "app", "PG 2", "query");
|
||||
store.togglePinnedTab(pgB);
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, store.tabs.slice(), pgA, pinia);
|
||||
await settle();
|
||||
|
||||
const pgPill = host.querySelector<HTMLElement>(`[data-tab-id="${pgA}"]`)!;
|
||||
pgPill.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: 10, clientY: 10 }));
|
||||
await settle();
|
||||
const menu = document.body.querySelector<HTMLElement>("[data-dbx-context-menu]")!;
|
||||
const closeGroupItem = Array.from(menu.querySelectorAll<HTMLButtonElement>("button")).find((button) => button.textContent?.includes("Close group"));
|
||||
expect(closeGroupItem).toBeDefined();
|
||||
closeGroupItem!.click();
|
||||
await settle();
|
||||
|
||||
// The regular cluster is gone; the pinned tab with the same key survives.
|
||||
const remainingIds = store.tabs.map((tab) => tab.id);
|
||||
expect(remainingIds).toEqual([pgB]);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("offers the detach entry only for query and data tabs and emits the tab upward", async () => {
|
||||
const store = useQueryStore();
|
||||
const queryId = store.createTab("pg-1", "app", "PG 1", "query");
|
||||
const mongoId = store.createTab("mongo-1", "app", "MG 1", "mongo");
|
||||
const mainGroup = store.groups[0];
|
||||
const detached: string[] = [];
|
||||
const { app, host } = mountBar(mainGroup.id, store.tabs.slice(), queryId, pinia, { canDetachTabs: true, "onDetach-tab": (tab: { id: string }) => detached.push(tab.id) });
|
||||
await settle();
|
||||
|
||||
const openMenu = async (tabId: string) => {
|
||||
host.querySelector<HTMLElement>(`[data-tab-id="${tabId}"]`)!.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: 10, clientY: 10 }));
|
||||
await settle();
|
||||
const menu = document.body.querySelector<HTMLElement>("[data-dbx-context-menu]")!;
|
||||
return Array.from(menu.querySelectorAll<HTMLButtonElement>("button"));
|
||||
};
|
||||
|
||||
// Query tab: the entry exists and routes the whole tab object upward.
|
||||
const queryItems = await openMenu(queryId);
|
||||
const detachItem = queryItems.find((button) => button.textContent?.includes("Open in new window"));
|
||||
expect(detachItem).toBeDefined();
|
||||
detachItem!.click();
|
||||
await settle();
|
||||
expect(detached).toEqual([queryId]);
|
||||
|
||||
// Non-query/data tab: the entry is not rendered at all.
|
||||
const mongoItems = await openMenu(mongoId);
|
||||
expect(mongoItems.find((button) => button.textContent?.includes("Open in new window"))).toBeUndefined();
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const source = readFileSync(new URL("../EditorGroupTabBar.vue", import.meta.url), "utf8");
|
||||
const tabMenuSource = readFileSync(new URL("../../../lib/tabs/tabMenu.ts", import.meta.url), "utf8");
|
||||
|
||||
describe("EditorGroupTabBar compatibility with AppTabBar", () => {
|
||||
it("keeps data-tab double-click Zen mode behavior", () => {
|
||||
expect(source).toContain('"toggle-zen-mode": []');
|
||||
expect(source).toContain('tab.mode === "data"');
|
||||
expect(source).toContain('emit("toggle-zen-mode")');
|
||||
expect(source).toContain("if (tab.id !== props.activeTabId) {");
|
||||
expect(source).toContain("startRenameTab(tab);");
|
||||
});
|
||||
|
||||
it("only offers Duplicate for query tabs", () => {
|
||||
expect(tabMenuSource).toContain("visible: options.canRename");
|
||||
expect(source).toContain("createRenameDuplicateTabItems");
|
||||
});
|
||||
|
||||
it("does not double-activate from the tab item click", () => {
|
||||
expect(source).toContain("function activateTab(tabId: string) {");
|
||||
expect(source).toContain('emit("activate-tab", tabId);');
|
||||
expect(source).not.toContain("queryStore.activateTabInGroup(props.groupId, tabId);");
|
||||
});
|
||||
|
||||
it("cleans up drag listeners on cancel, blur, and unmount", () => {
|
||||
expect(source).toContain("function cleanupTabDrag(event?: Event)");
|
||||
expect(source).toContain('window.addEventListener("pointercancel", cleanupTabDrag)');
|
||||
expect(source).toContain('window.addEventListener("blur", cleanupTabDrag)');
|
||||
expect(source).toContain("onUnmounted(cleanupTabDrag)");
|
||||
});
|
||||
|
||||
it("validates drag source and target groups before moving", () => {
|
||||
expect(source).toContain("serializeTabDragPayload");
|
||||
expect(source).toContain("parseTabDragPayload");
|
||||
expect(source).toContain("const sourceGroupExists = queryStore.groups.some((group) => group.id === payload.sourceGroupId)");
|
||||
expect(source).toContain("const targetGroupExists = queryStore.groups.some((group) => group.id === targetGroupId)");
|
||||
expect(source).toContain("if (!sourceGroupExists || !targetGroupExists) {");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,203 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { createApp, nextTick } from "vue";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { createI18n } from "vue-i18n";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@/components/ui/button", () => ({
|
||||
Button: {
|
||||
name: "ButtonStub",
|
||||
template: `<button><slot /></button>`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/ui/searchable-select", () => ({
|
||||
SearchableSelect: {
|
||||
name: "SearchableSelectStub",
|
||||
template: `<div />`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/ui/tooltip", () => ({
|
||||
Tooltip: {
|
||||
name: "TooltipStub",
|
||||
template: `<span><slot /></span>`,
|
||||
},
|
||||
TooltipTrigger: {
|
||||
name: "TooltipTriggerStub",
|
||||
template: `<span><slot /></span>`,
|
||||
},
|
||||
TooltipContent: {
|
||||
name: "TooltipContentStub",
|
||||
template: `<span><slot /></span>`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/ui/TruncatedTextTooltip.vue", () => ({
|
||||
default: {
|
||||
name: "TruncatedTextTooltipStub",
|
||||
template: `<span />`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/icons/DatabaseIcon.vue", () => ({
|
||||
default: {
|
||||
name: "DatabaseIconStub",
|
||||
template: `<span />`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/connection/ConnectionTreeSelect.vue", () => ({
|
||||
default: {
|
||||
name: "ConnectionTreeSelectStub",
|
||||
template: `<div />`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/common/ProductionContextBadge.vue", () => ({
|
||||
default: {
|
||||
name: "ProductionContextBadgeStub",
|
||||
template: `<span />`,
|
||||
},
|
||||
}));
|
||||
|
||||
import EditorToolbar from "../EditorToolbar.vue";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
|
||||
function createHost(): HTMLDivElement {
|
||||
const host = document.createElement("div");
|
||||
document.body.appendChild(host);
|
||||
return host;
|
||||
}
|
||||
|
||||
describe("EditorToolbar mount contract", () => {
|
||||
let pinia: ReturnType<typeof createPinia>;
|
||||
let i18n: ReturnType<typeof createI18n>;
|
||||
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: "en",
|
||||
messages: { en: {} },
|
||||
});
|
||||
});
|
||||
|
||||
it("emits toolbarExecute instead of execute when the run button is clicked", async () => {
|
||||
const connectionStore = useConnectionStore();
|
||||
connectionStore.connections = [
|
||||
{
|
||||
id: "conn-1",
|
||||
name: "conn",
|
||||
db_type: "mysql",
|
||||
color: "",
|
||||
} as never,
|
||||
];
|
||||
|
||||
const host = createHost();
|
||||
const onToolbarExecute = vi.fn();
|
||||
const app = createApp(EditorToolbar, {
|
||||
activeTab: {
|
||||
id: "tab-1",
|
||||
title: "SQL",
|
||||
connectionId: "conn-1",
|
||||
database: "db",
|
||||
sql: "SELECT 1",
|
||||
mode: "query",
|
||||
isExecuting: false,
|
||||
isCancelling: false,
|
||||
isExplaining: false,
|
||||
},
|
||||
activeConnection: connectionStore.getConfig("conn-1"),
|
||||
executableSql: "SELECT 1",
|
||||
explainMode: "explain",
|
||||
blockDangerousRedisCommands: false,
|
||||
sqlKeywordCase: "preserve",
|
||||
databaseRequiredSignal: 0,
|
||||
autoCommit: true,
|
||||
txnSessionId: undefined,
|
||||
txnAutoRolledBack: false,
|
||||
oracleTxnPossiblyDirty: false,
|
||||
isOracleManualTransaction: false,
|
||||
onToolbarExecute,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
const buttons = host.querySelectorAll("button");
|
||||
expect(buttons.length).toBeGreaterThan(0);
|
||||
const runButton = buttons[0];
|
||||
runButton.dispatchEvent(new MouseEvent("click", { detail: 1, bubbles: true }));
|
||||
await nextTick();
|
||||
|
||||
expect(onToolbarExecute).toHaveBeenCalledTimes(1);
|
||||
expect(onToolbarExecute.mock.calls[0]?.[0]).toBe("pointer");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("mounts for a schema-aware connection whose watchEffect reads tier-gated selectors", async () => {
|
||||
// Regression: the tier-gated showSchemaSelector is read eagerly by the
|
||||
// schema-loading watchEffect, so the tier refs must be declared before any
|
||||
// computed that references them (a Postgres connection takes this branch;
|
||||
// MySQL never did, which is why the TDZ crash only reproduced live).
|
||||
const connectionStore = useConnectionStore();
|
||||
connectionStore.connections = [
|
||||
{
|
||||
id: "conn-pg",
|
||||
name: "pg",
|
||||
db_type: "postgres",
|
||||
host: "localhost",
|
||||
port: 5432,
|
||||
username: "root",
|
||||
password: "",
|
||||
} as never,
|
||||
];
|
||||
|
||||
const host = createHost();
|
||||
const errors: unknown[] = [];
|
||||
const app = createApp(EditorToolbar, {
|
||||
activeTab: {
|
||||
id: "tab-pg",
|
||||
title: "SQL",
|
||||
connectionId: "conn-pg",
|
||||
database: "app",
|
||||
sql: "SELECT 1",
|
||||
mode: "query",
|
||||
isExecuting: false,
|
||||
isCancelling: false,
|
||||
isExplaining: false,
|
||||
},
|
||||
activeConnection: connectionStore.getConfig("conn-pg"),
|
||||
executableSql: "SELECT 1",
|
||||
explainMode: "explain",
|
||||
blockDangerousRedisCommands: false,
|
||||
sqlKeywordCase: "preserve",
|
||||
databaseRequiredSignal: 0,
|
||||
autoCommit: true,
|
||||
txnSessionId: undefined,
|
||||
txnAutoRolledBack: false,
|
||||
oracleTxnPossiblyDirty: false,
|
||||
isOracleManualTransaction: false,
|
||||
});
|
||||
app.config.errorHandler = (err) => {
|
||||
errors.push(err);
|
||||
};
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
|
||||
expect(errors).toEqual([]);
|
||||
expect(host.querySelector(".app-editor-toolbar")).not.toBeNull();
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
});
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { createApp, nextTick } from "vue";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("../ContentArea.vue", () => ({
|
||||
default: {
|
||||
name: "ContentAreaStub",
|
||||
props: ["activeTab", "activeConnection", "executableSql", "activeOutputView", "formatSqlRequest", "compressSqlRequest", "selectedSql", "cursorPos", "blockDangerousRedisCommands"],
|
||||
emits: ["execute", "saveSql"],
|
||||
template: `<button data-test="emit-execute" @click="$emit('execute', { fullSql: 'SELECT 1', selectedSql: 'SELECT 1', cursorPos: 0, selectionFrom: 0, selectionTo: 8 })">emit</button><button data-test="emit-save" @click="$emit('saveSql', 'tab-1')">save</button>`,
|
||||
},
|
||||
}));
|
||||
|
||||
import QueryEditorSurface from "../QueryEditorSurface.vue";
|
||||
|
||||
function createHost(): HTMLDivElement {
|
||||
const host = document.createElement("div");
|
||||
document.body.appendChild(host);
|
||||
return host;
|
||||
}
|
||||
|
||||
describe("QueryEditorSurface mount contract", () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
it("forwards child ContentArea execute events to the parent", async () => {
|
||||
const host = createHost();
|
||||
const onExecute = vi.fn();
|
||||
|
||||
const app = createApp(QueryEditorSurface, {
|
||||
activeTab: {
|
||||
id: "tab-1",
|
||||
title: "SQL",
|
||||
connectionId: "conn-1",
|
||||
database: "db",
|
||||
sql: "SELECT 1",
|
||||
mode: "query",
|
||||
},
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
autoFocus: false,
|
||||
onExecute,
|
||||
});
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
const button = host.querySelector<HTMLButtonElement>('[data-test="emit-execute"]');
|
||||
expect(button).not.toBeNull();
|
||||
button?.click();
|
||||
await nextTick();
|
||||
|
||||
expect(onExecute).toHaveBeenCalledTimes(1);
|
||||
expect(onExecute.mock.calls[0]?.[0]).toMatchObject({ fullSql: "SELECT 1" });
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("forwards child ContentArea saveSql events with the tab id", async () => {
|
||||
const host = createHost();
|
||||
const onSaveSql = vi.fn();
|
||||
|
||||
const app = createApp(QueryEditorSurface, {
|
||||
activeTab: {
|
||||
id: "tab-1",
|
||||
title: "SQL",
|
||||
connectionId: "conn-1",
|
||||
database: "db",
|
||||
sql: "SELECT 1",
|
||||
mode: "query",
|
||||
},
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
autoFocus: false,
|
||||
onSaveSql,
|
||||
});
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
host.querySelector<HTMLButtonElement>('[data-test="emit-save"]')?.click();
|
||||
await nextTick();
|
||||
|
||||
expect(onSaveSql).toHaveBeenCalledWith("tab-1");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
});
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { createApp, nextTick } from "vue";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("../ContentArea.vue", () => ({
|
||||
default: {
|
||||
name: "ContentAreaStub",
|
||||
props: ["activeTab", "activeConnection", "executableSql", "activeOutputView", "formatSqlRequest", "compressSqlRequest", "selectedSql", "cursorPos", "blockDangerousRedisCommands"],
|
||||
emits: ["previewStatement", "focusStatement", "reload"],
|
||||
template: `<div><button data-test="emit-preview" @click="$emit('previewStatement', 'tab-1', { from: 0, to: 8 })">preview</button><button data-test="emit-focus" @click="$emit('focusStatement', 'tab-1', { from: 0, to: 8 })">focus</button><button data-test="emit-reload" @click="$emit('reload', 'SELECT 1')">reload</button></div>`,
|
||||
},
|
||||
}));
|
||||
|
||||
import QueryResultSurface from "../QueryResultSurface.vue";
|
||||
|
||||
function createHost(): HTMLDivElement {
|
||||
const host = document.createElement("div");
|
||||
document.body.appendChild(host);
|
||||
return host;
|
||||
}
|
||||
|
||||
describe("QueryResultSurface mount contract", () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
it("forwards preview and focus statement events to the parent", async () => {
|
||||
const host = createHost();
|
||||
const onPreviewStatement = vi.fn();
|
||||
const onFocusStatement = vi.fn();
|
||||
|
||||
const app = createApp(QueryResultSurface, {
|
||||
activeTab: {
|
||||
id: "tab-1",
|
||||
title: "SQL",
|
||||
connectionId: "conn-1",
|
||||
database: "db",
|
||||
sql: "SELECT 1",
|
||||
mode: "query",
|
||||
},
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
onPreviewStatement,
|
||||
onFocusStatement,
|
||||
});
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
host.querySelector<HTMLButtonElement>('[data-test="emit-preview"]')?.click();
|
||||
host.querySelector<HTMLButtonElement>('[data-test="emit-focus"]')?.click();
|
||||
await nextTick();
|
||||
|
||||
expect(onPreviewStatement).toHaveBeenCalledWith("tab-1", { from: 0, to: 8 });
|
||||
expect(onFocusStatement).toHaveBeenCalledWith("tab-1", { from: 0, to: 8 });
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("forwards generic reload events to the parent", async () => {
|
||||
const host = createHost();
|
||||
const onReload = vi.fn();
|
||||
|
||||
const app = createApp(QueryResultSurface, {
|
||||
activeTab: {
|
||||
id: "tab-1",
|
||||
title: "SQL",
|
||||
connectionId: "conn-1",
|
||||
database: "db",
|
||||
sql: "SELECT 1",
|
||||
mode: "query",
|
||||
},
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
onReload,
|
||||
});
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
host.querySelector<HTMLButtonElement>('[data-test="emit-reload"]')?.click();
|
||||
await nextTick();
|
||||
|
||||
expect(onReload).toHaveBeenCalledWith("SELECT 1");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
});
|
||||
+461
@@ -0,0 +1,461 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { createApp, nextTick } from "vue";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { createI18n } from "vue-i18n";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("splitpanes", () => ({
|
||||
Splitpanes: {
|
||||
name: "SplitpanesStub",
|
||||
template: `<div class="splitpanes-stub"><slot /></div>`,
|
||||
},
|
||||
Pane: {
|
||||
name: "PaneStub",
|
||||
template: `<div class="pane-stub"><slot /></div>`,
|
||||
},
|
||||
}));
|
||||
|
||||
const editorPreviewCalls = vi.hoisted(() => [] as Array<{ tabId: string; range: unknown }>);
|
||||
const editorFocusCalls = vi.hoisted(() => [] as Array<{ tabId: string; range: unknown }>);
|
||||
const groupHandleModRCalls = vi.hoisted(() => [] as Element[]);
|
||||
const groupFocusSearchCalls = vi.hoisted(() => [] as Array<Element | null>);
|
||||
const resultHandleModRCalls = vi.hoisted(() => [] as Element[]);
|
||||
const resultFocusSearchCalls = vi.hoisted(() => [] as boolean[]);
|
||||
|
||||
vi.mock("@/components/layout/EditorGroup.vue", () => ({
|
||||
default: {
|
||||
name: "EditorGroupStub",
|
||||
props: ["groupId", "tabIds", "activeTabId"],
|
||||
emits: ["execute"],
|
||||
methods: {
|
||||
previewStatementRange(tabId: string, range: unknown) {
|
||||
editorPreviewCalls.push({ tabId, range });
|
||||
return true;
|
||||
},
|
||||
focusStatementRange(tabId: string, range: unknown) {
|
||||
editorFocusCalls.push({ tabId, range });
|
||||
return true;
|
||||
},
|
||||
handleModRTarget(target: Element) {
|
||||
groupHandleModRCalls.push(target);
|
||||
return true;
|
||||
},
|
||||
focusSearch(target?: Element | null) {
|
||||
groupFocusSearchCalls.push(target ?? null);
|
||||
return true;
|
||||
},
|
||||
},
|
||||
template: `<div data-test="editor-group" :data-group-id="groupId" :data-tab-ids="tabIds.join(',')" :data-active-tab-id="activeTabId"><button data-test="emit-execute" @click="$emit('execute', { fullSql: 'SELECT 1', selectedSql: 'SELECT 1', cursorPos: 0, selectionFrom: 0, selectionTo: 8 })">execute</button></div>`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/layout/EditorToolbar.vue", () => ({
|
||||
default: {
|
||||
name: "EditorToolbarStub",
|
||||
props: ["activeTab"],
|
||||
template: `<div data-test="group-toolbar" />`,
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/layout/QueryResultSurface.vue", () => ({
|
||||
default: {
|
||||
name: "QueryResultSurfaceStub",
|
||||
props: ["activeTab"],
|
||||
emits: ["previewStatement", "focusStatement"],
|
||||
methods: {
|
||||
handleModRTarget(target: Element) {
|
||||
resultHandleModRCalls.push(target);
|
||||
return true;
|
||||
},
|
||||
focusSearch() {
|
||||
resultFocusSearchCalls.push(true);
|
||||
return true;
|
||||
},
|
||||
},
|
||||
template: `<div data-test="result-surface">{{ activeTab?.id }}<button data-test="emit-preview" @click="$emit('previewStatement', 'tab-a', { from: 0, to: 8 })">preview</button><button data-test="emit-focus" @click="$emit('focusStatement', 'tab-a', { from: 0, to: 8 })">focus</button></div>`,
|
||||
},
|
||||
}));
|
||||
|
||||
import SqlEditorWorkspace from "../SqlEditorWorkspace.vue";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
|
||||
function tab(id: string) {
|
||||
return {
|
||||
id,
|
||||
title: id,
|
||||
connectionId: "conn-1",
|
||||
database: "db",
|
||||
sql: "SELECT 1",
|
||||
mode: "query",
|
||||
} as const;
|
||||
}
|
||||
|
||||
function dataTab(id: string) {
|
||||
return { ...tab(id), mode: "data" };
|
||||
}
|
||||
|
||||
function createHost(): HTMLDivElement {
|
||||
const host = document.createElement("div");
|
||||
document.body.appendChild(host);
|
||||
return host;
|
||||
}
|
||||
|
||||
describe("SqlEditorWorkspace mount contract", () => {
|
||||
let pinia: ReturnType<typeof createPinia>;
|
||||
let i18n: ReturnType<typeof createI18n>;
|
||||
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
editorPreviewCalls.length = 0;
|
||||
editorFocusCalls.length = 0;
|
||||
groupHandleModRCalls.length = 0;
|
||||
groupFocusSearchCalls.length = 0;
|
||||
resultHandleModRCalls.length = 0;
|
||||
resultFocusSearchCalls.length = 0;
|
||||
pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: "en",
|
||||
messages: { en: {} },
|
||||
});
|
||||
});
|
||||
|
||||
it("renders one editor group per store group and binds the shared result to the global active tab", async () => {
|
||||
const store = useQueryStore();
|
||||
store.tabs = [tab("tab-a"), tab("tab-b")];
|
||||
store.activeTabId = "tab-a";
|
||||
store.groups = [
|
||||
{ id: "g1", tabIds: ["tab-a"], activeTabId: "tab-a" },
|
||||
{ id: "g2", tabIds: ["tab-b"], activeTabId: "tab-b" },
|
||||
];
|
||||
store.focusedGroupId = "g1";
|
||||
store.orientation = "vertical";
|
||||
store.sizes = [50, 50];
|
||||
|
||||
const host = createHost();
|
||||
const app = createApp(SqlEditorWorkspace, {
|
||||
activeTab: tab("tab-a"),
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
const groups = host.querySelectorAll('[data-test="editor-group"]');
|
||||
expect(groups).toHaveLength(2);
|
||||
expect(groups[0]?.getAttribute("data-group-id")).toBe("g1");
|
||||
expect(groups[0]?.getAttribute("data-tab-ids")).toBe("tab-a");
|
||||
expect(groups[1]?.getAttribute("data-group-id")).toBe("g2");
|
||||
expect(groups[1]?.getAttribute("data-tab-ids")).toBe("tab-b");
|
||||
|
||||
const result = host.querySelector<HTMLElement>('[data-test="result-surface"]');
|
||||
expect(result?.textContent).toContain("tab-a");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("forwards editor execute events from EditorGroup to the App listener", async () => {
|
||||
const store = useQueryStore();
|
||||
store.tabs = [tab("tab-a")];
|
||||
store.activeTabId = "tab-a";
|
||||
store.groups = [{ id: "g1", tabIds: ["tab-a"], activeTabId: "tab-a" }];
|
||||
store.focusedGroupId = "g1";
|
||||
store.orientation = "vertical";
|
||||
store.sizes = [100];
|
||||
|
||||
const host = createHost();
|
||||
const onExecute = vi.fn();
|
||||
const app = createApp(SqlEditorWorkspace, {
|
||||
activeTab: tab("tab-a"),
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
onExecute,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
host.querySelector<HTMLButtonElement>('[data-test="emit-execute"]')?.click();
|
||||
await nextTick();
|
||||
|
||||
expect(onExecute).toHaveBeenCalledTimes(1);
|
||||
expect(onExecute.mock.calls[0]?.[0]).toMatchObject({ fullSql: "SELECT 1" });
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("toggles the shared result pane through the exposed workspace method", async () => {
|
||||
const store = useQueryStore();
|
||||
store.tabs = [tab("tab-a")];
|
||||
store.activeTabId = "tab-a";
|
||||
store.groups = [{ id: "g1", tabIds: ["tab-a"], activeTabId: "tab-a" }];
|
||||
store.focusedGroupId = "g1";
|
||||
store.orientation = "vertical";
|
||||
store.sizes = [100];
|
||||
|
||||
const host = createHost();
|
||||
const app = createApp(SqlEditorWorkspace, {
|
||||
activeTab: tab("tab-a"),
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
const vm = app.mount(host) as any;
|
||||
await nextTick();
|
||||
|
||||
expect(host.querySelector('[data-test="result-surface"]')).not.toBeNull();
|
||||
|
||||
vm.toggleResultsPane();
|
||||
await nextTick();
|
||||
// Wait out the leave transition frame before asserting the unmount.
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
|
||||
expect(host.querySelector('[data-test="result-surface"]')).toBeNull();
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("routes result previewStatement events to the owning editor group", async () => {
|
||||
const store = useQueryStore();
|
||||
store.tabs = [tab("tab-a")];
|
||||
store.activeTabId = "tab-a";
|
||||
store.groups = [{ id: "g1", tabIds: ["tab-a"], activeTabId: "tab-a" }];
|
||||
store.focusedGroupId = "g1";
|
||||
store.orientation = "vertical";
|
||||
store.sizes = [100];
|
||||
|
||||
const host = createHost();
|
||||
const app = createApp(SqlEditorWorkspace, {
|
||||
activeTab: tab("tab-a"),
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
host.querySelector<HTMLButtonElement>('[data-test="emit-preview"]')?.click();
|
||||
await nextTick();
|
||||
|
||||
expect(editorPreviewCalls).toEqual([{ tabId: "tab-a", range: { from: 0, to: 8 } }]);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("routes result focusStatement events to the owning editor group", async () => {
|
||||
const store = useQueryStore();
|
||||
store.tabs = [tab("tab-a")];
|
||||
store.activeTabId = "tab-a";
|
||||
store.groups = [{ id: "g1", tabIds: ["tab-a"], activeTabId: "tab-a" }];
|
||||
store.focusedGroupId = "g1";
|
||||
store.orientation = "vertical";
|
||||
store.sizes = [100];
|
||||
|
||||
const host = createHost();
|
||||
const app = createApp(SqlEditorWorkspace, {
|
||||
activeTab: tab("tab-a"),
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
host.querySelector<HTMLButtonElement>('[data-test="emit-focus"]')?.click();
|
||||
await nextTick();
|
||||
|
||||
expect(editorFocusCalls).toEqual([{ tabId: "tab-a", range: { from: 0, to: 8 } }]);
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("hides the shared result pane while a non-query tab is active and restores it for query tabs", async () => {
|
||||
const store = useQueryStore();
|
||||
store.tabs = [tab("tab-a"), dataTab("tab-data")];
|
||||
store.activeTabId = "tab-a";
|
||||
store.groups = [{ id: "g1", tabIds: ["tab-a", "tab-data"], activeTabId: "tab-a" }];
|
||||
store.focusedGroupId = "g1";
|
||||
store.orientation = "vertical";
|
||||
store.sizes = [100];
|
||||
|
||||
const host = createHost();
|
||||
const app = createApp(SqlEditorWorkspace, {
|
||||
activeTab: tab("tab-a"),
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
|
||||
expect(host.querySelector('[data-test="result-surface"]')).not.toBeNull();
|
||||
|
||||
store.activeTabId = "tab-data";
|
||||
await nextTick();
|
||||
// The leave transition keeps the surface in the DOM for one more frame
|
||||
// before unmounting it (CSS durations collapse to zero in the test env).
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
|
||||
expect(host.querySelector("[data-shared-result-surface]")).toBeNull();
|
||||
// Outer editor pane + always-mounted result pane (collapsed to size 0)
|
||||
// + one pane per group.
|
||||
expect(host.querySelectorAll(".pane-stub")).toHaveLength(3);
|
||||
|
||||
store.activeTabId = "tab-a";
|
||||
await nextTick();
|
||||
|
||||
expect(host.querySelector('[data-test="result-surface"]')).not.toBeNull();
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("routes Mod+R grid targets to the shared result surface only while a query tab is active", async () => {
|
||||
const store = useQueryStore();
|
||||
store.tabs = [tab("tab-a"), dataTab("tab-data")];
|
||||
store.activeTabId = "tab-a";
|
||||
store.groups = [{ id: "g1", tabIds: ["tab-a", "tab-data"], activeTabId: "tab-a" }];
|
||||
store.focusedGroupId = "g1";
|
||||
store.orientation = "vertical";
|
||||
store.sizes = [100];
|
||||
|
||||
const host = createHost();
|
||||
const app = createApp(SqlEditorWorkspace, {
|
||||
activeTab: tab("tab-a"),
|
||||
activeConnection: undefined,
|
||||
executableSql: "SELECT 1",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
const vm = app.mount(host) as any;
|
||||
await nextTick();
|
||||
|
||||
// Query tab: grid targets inside the shared result surface route to it.
|
||||
const resultGridEl = document.createElement("div");
|
||||
resultGridEl.setAttribute("data-grid-root", "");
|
||||
host.querySelector('[data-test="result-surface"]')?.appendChild(resultGridEl);
|
||||
expect(vm.handleModRTarget(resultGridEl)).toBe(true);
|
||||
expect(resultHandleModRCalls).toEqual([resultGridEl]);
|
||||
expect(groupHandleModRCalls).toEqual([]);
|
||||
|
||||
// Query tab: the cell-detail editor is portaled to body, so it cannot be
|
||||
// resolved through the DOM — it still routes to the shared result surface.
|
||||
const portalEl = document.createElement("div");
|
||||
portalEl.setAttribute("data-cell-detail-editor-root", "");
|
||||
document.body.appendChild(portalEl);
|
||||
expect(vm.handleModRTarget(portalEl)).toBe(true);
|
||||
expect(resultHandleModRCalls).toEqual([resultGridEl, portalEl]);
|
||||
|
||||
// Data tab: the grid and its cell-detail dialog belong to the group.
|
||||
groupHandleModRCalls.length = 0;
|
||||
resultHandleModRCalls.length = 0;
|
||||
store.activeTabId = "tab-data";
|
||||
await nextTick();
|
||||
|
||||
const dataGridEl = document.createElement("div");
|
||||
dataGridEl.setAttribute("data-grid-root", "");
|
||||
host.querySelector('[data-test="editor-group"]')?.appendChild(dataGridEl);
|
||||
expect(vm.handleModRTarget(dataGridEl)).toBe(true);
|
||||
expect(groupHandleModRCalls).toEqual([dataGridEl]);
|
||||
expect(vm.handleModRTarget(portalEl)).toBe(true);
|
||||
expect(groupHandleModRCalls).toEqual([dataGridEl, portalEl]);
|
||||
expect(resultHandleModRCalls).toEqual([]);
|
||||
|
||||
portalEl.remove();
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("routes cell-detail search to the group's grid while a data tab is active", async () => {
|
||||
const store = useQueryStore();
|
||||
store.tabs = [dataTab("tab-data")];
|
||||
store.activeTabId = "tab-data";
|
||||
store.groups = [{ id: "g1", tabIds: ["tab-data"], activeTabId: "tab-data" }];
|
||||
store.focusedGroupId = "g1";
|
||||
store.orientation = "vertical";
|
||||
store.sizes = [100];
|
||||
|
||||
const host = createHost();
|
||||
const app = createApp(SqlEditorWorkspace, {
|
||||
activeTab: dataTab("tab-data"),
|
||||
activeConnection: undefined,
|
||||
executableSql: "",
|
||||
activeOutputView: "result",
|
||||
formatSqlRequest: null,
|
||||
compressSqlRequest: null,
|
||||
selectedSql: "",
|
||||
cursorPos: 0,
|
||||
blockDangerousRedisCommands: false,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
const vm = app.mount(host) as any;
|
||||
await nextTick();
|
||||
|
||||
const portalEl = document.createElement("div");
|
||||
portalEl.setAttribute("data-cell-detail-editor-root", "");
|
||||
document.body.appendChild(portalEl);
|
||||
expect(vm.focusSearch(portalEl)).toBe(true);
|
||||
expect(groupFocusSearchCalls.length).toBe(1);
|
||||
expect(resultFocusSearchCalls).toEqual([]);
|
||||
|
||||
portalEl.remove();
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,102 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const workspaceSource = readFileSync(new URL("../SqlEditorWorkspace.vue", import.meta.url), "utf8");
|
||||
const groupSource = readFileSync(new URL("../EditorGroup.vue", import.meta.url), "utf8");
|
||||
const groupTabBarSource = readFileSync(new URL("../EditorGroupTabBar.vue", import.meta.url), "utf8");
|
||||
const tabMenuSource = readFileSync(new URL("../../../lib/tabs/tabMenu.ts", import.meta.url), "utf8");
|
||||
const editorSurfaceSource = readFileSync(new URL("../QueryEditorSurface.vue", import.meta.url), "utf8");
|
||||
const resultSurfaceSource = readFileSync(new URL("../QueryResultSurface.vue", import.meta.url), "utf8");
|
||||
const contentAreaSource = readFileSync(new URL("../ContentArea.vue", import.meta.url), "utf8");
|
||||
const surfaceContractSource = readFileSync(new URL("../querySurfaces.ts", import.meta.url), "utf8");
|
||||
|
||||
describe("SQL editor workspace single-group tracer bullet", () => {
|
||||
it("composes splitpanes editor groups and one shared result surface", () => {
|
||||
expect(workspaceSource).toContain("Splitpanes");
|
||||
expect(workspaceSource).toContain("EditorGroup");
|
||||
expect(workspaceSource).toContain("QueryResultSurface");
|
||||
expect(groupSource).toContain("EditorGroupTabBar");
|
||||
expect(groupSource).toContain("QueryEditorSurface");
|
||||
expect(groupSource).toContain("ContentArea");
|
||||
expect(groupSource).toContain("tabIds");
|
||||
expect(groupSource).toContain("activeTabId");
|
||||
});
|
||||
|
||||
it("routes query editor and shared result through dedicated surface components", () => {
|
||||
expect(editorSurfaceSource).toContain("editor-only");
|
||||
expect(resultSurfaceSource).toContain("result-only");
|
||||
expect(contentAreaSource).toContain("editorOnly?: boolean");
|
||||
expect(contentAreaSource).toContain("resultOnly?: boolean");
|
||||
});
|
||||
|
||||
it("keeps AppTabBar as the global special-page bar while regular tabs move to groups", () => {
|
||||
const tabBarSource = readFileSync(new URL("../AppTabBar.vue", import.meta.url), "utf8");
|
||||
expect(tabBarSource).not.toContain("hideRegularTabs");
|
||||
expect(groupTabBarSource).toContain("app-tab-bar");
|
||||
});
|
||||
|
||||
it("makes the shared result area vertically resizable through the workspace splitter", () => {
|
||||
expect(workspaceSource).toContain("sql-editor-workspace-split");
|
||||
expect(workspaceSource).toContain("onSharedResultResized");
|
||||
expect(workspaceSource).toContain("dbx-shared-results-pane-size");
|
||||
expect(workspaceSource).not.toContain("h-1/3");
|
||||
});
|
||||
|
||||
it("routes shared-result statement navigation to the owning editor surface", () => {
|
||||
expect(workspaceSource).toContain("@preview-statement");
|
||||
expect(workspaceSource).toContain("@focus-statement");
|
||||
expect(workspaceSource).toContain("handlePreviewStatement");
|
||||
expect(workspaceSource).toContain("handleFocusStatement");
|
||||
expect(resultSurfaceSource).toContain("previewStatement");
|
||||
expect(resultSurfaceSource).toContain("focusStatement");
|
||||
expect(resultSurfaceSource).toContain("previewStatementRange");
|
||||
expect(resultSurfaceSource).toContain("focusStatementRange");
|
||||
expect(editorSurfaceSource).toContain("previewStatementRange");
|
||||
expect(editorSurfaceSource).toContain("focusStatementRange");
|
||||
expect(groupSource).toContain("previewStatementRange");
|
||||
expect(groupSource).toContain("focusStatementRange");
|
||||
expect(surfaceContractSource).toContain("previewStatement: [tabId: string, range: StatementRange | null]");
|
||||
expect(surfaceContractSource).toContain("focusStatement: [tabId: string, range: StatementRange | null]");
|
||||
});
|
||||
|
||||
it("keeps group tabbar behavior compatible with the legacy tab bar", () => {
|
||||
expect(workspaceSource).toContain("@toggle-zen-mode");
|
||||
expect(groupSource).toContain("@toggle-zen-mode");
|
||||
expect(groupTabBarSource).toContain('"toggle-zen-mode": []');
|
||||
expect(groupTabBarSource).toContain('tab.mode === "data"');
|
||||
expect(groupTabBarSource).toContain('emit("toggle-zen-mode")');
|
||||
expect(tabMenuSource).toContain("visible: options.canRename");
|
||||
expect(groupTabBarSource).toContain("createRenameDuplicateTabItems");
|
||||
expect(groupTabBarSource).toContain("cleanupTabDrag");
|
||||
expect(groupTabBarSource).toContain("onUnmounted(cleanupTabDrag)");
|
||||
expect(groupTabBarSource).toContain("pointercancel");
|
||||
});
|
||||
|
||||
it("keeps event forwarding and per-group active tab wiring intact", () => {
|
||||
expect(workspaceSource).toContain('v-bind="editorGroupBindings"');
|
||||
expect(workspaceSource).toContain('v-bind="resultSurfaceBindings"');
|
||||
expect(groupSource).toContain('v-bind="surfaceBindings"');
|
||||
expect(groupSource).toContain("activeTab: activeTab.value!");
|
||||
expect(editorSurfaceSource).toContain('v-bind="bindings"');
|
||||
expect(resultSurfaceSource).toContain('v-bind="bindings"');
|
||||
});
|
||||
|
||||
it("animates layout transitions for split groups and the shared result surface", () => {
|
||||
const workspaceCssSource = readFileSync(new URL("../sqlEditorWorkspace.css", import.meta.url), "utf8");
|
||||
expect(workspaceSource).toContain('import "./sqlEditorWorkspace.css"');
|
||||
// Split-created group panes emerge from the divider side; hydration-gated
|
||||
// so the restored layout never plays load choreography.
|
||||
expect(workspaceSource).toContain("paneEnterClass");
|
||||
expect(workspaceSource).toContain("workspace-pane-enter");
|
||||
expect(workspaceCssSource).toContain("@keyframes dbx-workspace-pane-in");
|
||||
// The result pane stays mounted and collapses via its size; the surface
|
||||
// fades through a Vue transition while the splitter hides.
|
||||
expect(workspaceSource).toContain("resultPaneTargetSize");
|
||||
expect(workspaceSource).toContain('name="result-surface"');
|
||||
expect(workspaceSource).toContain("result-pane-collapsed");
|
||||
expect(workspaceCssSource).toContain(".result-surface-enter-active");
|
||||
expect(workspaceCssSource).toContain(".result-surface-leave-active");
|
||||
// Motion degrades to instant under prefers-reduced-motion.
|
||||
expect(workspaceCssSource).toContain("@media (prefers-reduced-motion: reduce)");
|
||||
});
|
||||
});
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const appSource = readFileSync(new URL("../../../App.vue", import.meta.url), "utf8");
|
||||
|
||||
// The editor-content wrapper carries a v-show guard that hides it while the
|
||||
// settings page or driver store is the active surface. A past merge resolved
|
||||
// this region by nesting the special surfaces INSIDE that guarded wrapper,
|
||||
// which display:none-d the settings page exactly when it was active. These
|
||||
// assertions pin the sibling order so a future merge cannot re-introduce it.
|
||||
describe("App main content surface structure", () => {
|
||||
it("hides only the editor workspace via the surface guard, never the special pages", () => {
|
||||
const guard = 'v-show="!driverStoreActive && !settingsStore.settingsPageActive"';
|
||||
// One guarded wrapper; the welcome screen's v-else-if reuses the flags in
|
||||
// its own condition and must not be mistaken for a second guard.
|
||||
expect(appSource.split(guard).length - 1).toBe(1);
|
||||
|
||||
// Source order: special surfaces first, then the guarded editor wrapper.
|
||||
const markers = ["<DriverStorePage", "<EditorSettingsPage", guard, "<SqlEditorWorkspace", "<WelcomeScreen"];
|
||||
const indices = markers.map((marker) => appSource.indexOf(marker));
|
||||
expect(indices.every((index) => index >= 0)).toBe(true);
|
||||
expect([...indices].sort((a, b) => a - b)).toEqual(indices);
|
||||
});
|
||||
|
||||
it("guards the editor wrapper with the open-tab count and chains the welcome screen to it", () => {
|
||||
expect(appSource).toContain('<div v-if="queryStore.tabs.length > 0" v-show="!driverStoreActive && !settingsStore.settingsPageActive"');
|
||||
expect(appSource).toContain('v-else-if="queryStore.tabs.length === 0 && !driverStoreActive && !settingsStore.settingsPageActive"');
|
||||
});
|
||||
|
||||
it("anchors the drag-back hit test on every pane strip and the special-surfaces bar", () => {
|
||||
const groupBarSource = readFileSync(new URL("../EditorGroupTabBar.vue", import.meta.url), "utf8");
|
||||
const slimBarSource = readFileSync(new URL("../AppTabBar.vue", import.meta.url), "utf8");
|
||||
expect(groupBarSource).toContain("data-main-tab-bar");
|
||||
expect(groupBarSource).toContain("'ring-2 ring-primary ring-inset': detachedDropTarget");
|
||||
expect(slimBarSource).toContain("data-main-tab-bar");
|
||||
expect(slimBarSource).toContain("'ring-2 ring-primary ring-inset': detachedDropTarget");
|
||||
// The split workspace renders several bars; the hit test must union their rects.
|
||||
expect(appSource).toContain('querySelectorAll<HTMLElement>("[data-main-tab-bar]")');
|
||||
});
|
||||
});
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const contentAreaSource = readFileSync(new URL("../ContentArea.vue", import.meta.url), "utf8");
|
||||
const databaseBrowserSource = readFileSync(new URL("../../objects/DatabaseBrowser.vue", import.meta.url), "utf8");
|
||||
const objectBrowserSource = readFileSync(new URL("../../objects/ObjectBrowser.vue", import.meta.url), "utf8");
|
||||
const overflowMenuSource = readFileSync(new URL("../../../components/ui/ToolbarOverflowMenu.vue", import.meta.url), "utf8");
|
||||
|
||||
describe("measured toolbar condensation wiring (non-SQL toolbars)", () => {
|
||||
it("keeps the overflow trigger a single-layer dropdown (no Tooltip nesting)", () => {
|
||||
expect(overflowMenuSource).toContain("DropdownMenuTrigger as-child");
|
||||
expect(overflowMenuSource).not.toContain("TooltipTrigger");
|
||||
expect(overflowMenuSource).not.toContain("LightTooltip");
|
||||
});
|
||||
|
||||
it("condenses the data-mode header row through measured tiers", () => {
|
||||
expect(contentAreaSource).toContain("useToolbarOverflow(dataToolbarRef");
|
||||
// Chips keep a min-width floor so scrollWidth reports real overflow.
|
||||
expect(contentAreaSource).toContain("inline-flex min-w-12 items-center truncate");
|
||||
expect(contentAreaSource).toContain('ref="dataToolbarRef"');
|
||||
expect(contentAreaSource).toContain("showDataColumnsChip");
|
||||
expect(contentAreaSource).toContain("showDataTableInfoButton");
|
||||
expect(contentAreaSource).toContain("dataToolbarCompact");
|
||||
expect(contentAreaSource).toContain('v-if="showDataToolbarOverflow"');
|
||||
});
|
||||
|
||||
it("condenses the database browser header row through measured tiers", () => {
|
||||
expect(databaseBrowserSource).toContain("useToolbarOverflow(toolbarRef");
|
||||
expect(databaseBrowserSource).toContain('ref="toolbarRef"');
|
||||
expect(databaseBrowserSource).toContain("showInlineSortAndView");
|
||||
expect(databaseBrowserSource).toContain("showConnectionChip");
|
||||
expect(databaseBrowserSource).toContain('v-if="showToolbarOverflow"');
|
||||
});
|
||||
|
||||
it("condenses the object browser header row through measured tiers", () => {
|
||||
expect(objectBrowserSource).toContain("useToolbarOverflow(toolbarRef");
|
||||
expect(objectBrowserSource).toContain('ref="toolbarRef"');
|
||||
expect(objectBrowserSource).toContain("showInlineSortAndView");
|
||||
expect(objectBrowserSource).toContain("showInlineCheckboxToggle");
|
||||
expect(objectBrowserSource).toContain("showInlineObjectFilter");
|
||||
expect(objectBrowserSource).toContain("showDatabaseChip");
|
||||
expect(objectBrowserSource).toContain('v-if="showToolbarOverflow"');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user