diff --git a/browser_tests/tests/agent/agentPanelLifecycle.spec.ts b/browser_tests/tests/agent/agentPanelLifecycle.spec.ts index 0c885d29ad5..46cf4f252ad 100644 --- a/browser_tests/tests/agent/agentPanelLifecycle.spec.ts +++ b/browser_tests/tests/agent/agentPanelLifecycle.spec.ts @@ -127,6 +127,97 @@ test.describe( await expect(page.getByTestId('integrated-tab-bar-actions')).toBeVisible() }) + test('shrinks a maximized panel to stay inside a narrowed window', async ({ + page + }) => { + await page.setViewportSize({ width: 1600, height: 900 }) + await bootAgentApp(page, true) + + await page + .getByRole('button', { name: OPEN_AGENT_LABEL, exact: true }) + .click() + const panel = page.getByTestId('docked-agent-panel') + await expect(panel).toBeVisible() + + await panel + .getByRole('button', { name: enMessages.agent.maximize }) + .click() + await expect + .poll(async () => (await panel.boundingBox())?.width ?? 0) + .toBe(960) + + await page.setViewportSize({ width: 900, height: 900 }) + + await expect + .poll(async () => (await panel.boundingBox())?.width ?? 0) + .toBeLessThan(960) + const box = await panel.boundingBox() + expect(box).not.toBeNull() + expect(box!.x).toBeGreaterThanOrEqual(-1) + expect(box!.x + box!.width).toBeLessThanOrEqual(901) + + // "Inside the window" is not enough on its own: a panel that ignored the + // sidebar and took all 900px would satisfy every bound above. Pin it + // against the workspace it is supposed to be reserving room for. + const sideToolbar = page.getByTestId('side-toolbar') + const railBox = await sideToolbar.boundingBox() + expect(railBox).not.toBeNull() + expect(box!.x).toBeGreaterThanOrEqual(railBox!.x + railBox!.width - 1) + + // Still maximized, so the header offers to minimize rather than maximize. + await expect( + panel.getByRole('button', { name: enMessages.agent.minimize }) + ).toBeVisible() + }) + + test('keeps the canvas toolbar clear of the sidebar as the panel squeezes it', async ({ + page + }) => { + // 1300 puts the canvas at roughly 284px: narrower than the toolbar, so + // the overhang this fix prevents is actually in play, but not the + // degenerate case. At 900 a maximized panel leaves the canvas at zero + // and the toolbar collapses to 8px, which tests the unreserved-canvas + // gap rather than this fix. `agentPanelViewportDrag.spec.ts` owns that. + await page.setViewportSize({ width: 1300, height: 900 }) + await bootAgentApp(page, true) + + await page + .getByRole('button', { name: OPEN_AGENT_LABEL, exact: true }) + .click() + const panel = page.getByTestId('docked-agent-panel') + await expect(panel).toBeVisible() + await panel + .getByRole('button', { name: enMessages.agent.maximize }) + .click() + + const toolbar = page.getByRole('toolbar', { + name: enMessages.graphCanvasMenu.canvasToolbar + }) + const sideToolbar = page.getByTestId('side-toolbar') + await expect(toolbar).toBeVisible() + + const toolbarBox = await toolbar.boundingBox() + const sideToolbarBox = await sideToolbar.boundingBox() + expect(toolbarBox).not.toBeNull() + expect(sideToolbarBox).not.toBeNull() + + // Both edges matter. Checking only the left edge passes a toolbar that + // overhangs the other way, out from under the canvas and beneath the + // expanded panel, which is the case this fix is actually about. + expect(toolbarBox!.x).toBeGreaterThanOrEqual( + sideToolbarBox!.x + sideToolbarBox!.width - 1 + ) + // Position alone is satisfied by a toolbar squeezed to nothing, so prove + // the controls at both ends survived and are still operable. + expect(toolbarBox!.width).toBeGreaterThan(64) + await expect( + toolbar.getByRole('button', { name: enMessages.zoomControls.label }) + ).toBeVisible() + await toolbar + .getByRole('button', { name: enMessages.graphCanvasMenu.fitView }) + .click() + }) + test('restores an open panel after a browser reload', async ({ page }) => { await bootAgentApp(page, true) diff --git a/src/components/LiteGraphCanvasSplitterOverlay.test.ts b/src/components/LiteGraphCanvasSplitterOverlay.test.ts index 05160888df4..866d031968b 100644 --- a/src/components/LiteGraphCanvasSplitterOverlay.test.ts +++ b/src/components/LiteGraphCanvasSplitterOverlay.test.ts @@ -1,7 +1,7 @@ import { createTestingPinia } from '@pinia/testing' import { render, screen } from '@testing-library/vue' import { readFileSync } from 'fs' -import { setActivePinia } from 'pinia' +import { getActivePinia, setActivePinia } from 'pinia' import { resolve } from 'path' import { describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' @@ -12,7 +12,12 @@ import { useSettingStore } from '@/platform/settings/settingStore' import { useAgentNodeSelectionStore } from '@/stores/agentNodeSelectionStore' import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/agentPanelStore' import { useBottomPanelStore } from '@/stores/workspace/bottomPanelStore' +import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore' +import type { SidebarTabExtension } from '@/types/extensionTypes' +// This branch stubs the auth store directly rather than mocking `firebase/auth` +// the way main does, so the incoming `vi.mock(import('firebase/auth'))` is +// dropped and the existing stub kept. vi.mock('@/stores/authStore', () => ({ useAuthStore: vi.fn(() => ({ currentUser: null, loading: false })) })) @@ -120,6 +125,42 @@ describe('LiteGraphCanvasSplitterOverlay', () => { expect(screen.getByTestId('topmenu')).toBeInTheDocument() }) + it('reserves room for the sidebar so the Agent panel stops before it', async () => { + const agentPanelStore = useAgentPanelStore() + const sidebarTabStore = useSidebarTabStore() + const i18n = createI18n({ + legacy: false, + locale: 'en', + messages: { en: { sideToolbar: { sidebar: 'Sidebar' } } } + }) + + render(LiteGraphCanvasSplitterOverlay, { + global: { + plugins: [getActivePinia()!, i18n], + stubs: { Splitter: true, SplitterPanel: true } + } + }) + + window.innerWidth = 1200 + window.dispatchEvent(new Event('resize')) + agentPanelStore.toggleMaximize() + await nextTick() + const widthWithoutSidebar = agentPanelStore.width + + sidebarTabStore.sidebarTabs = [ + { id: 'probe', title: 'Probe' } as SidebarTabExtension + ] + sidebarTabStore.activeSidebarTabId = 'probe' + await nextTick() + + expect(agentPanelStore.width).toBeLessThan(widthWithoutSidebar) + + sidebarTabStore.activeSidebarTabId = null + await nextTick() + + expect(agentPanelStore.width).toBe(widthWithoutSidebar) + }) + it('refreshes the splitter only when the Agent panel becomes visible', async () => { const agentPanelStore = useAgentPanelStore() agentPanelStore.enabled = true diff --git a/src/components/LiteGraphCanvasSplitterOverlay.vue b/src/components/LiteGraphCanvasSplitterOverlay.vue index cb7c834aa47..2f4a661e80d 100644 --- a/src/components/LiteGraphCanvasSplitterOverlay.vue +++ b/src/components/LiteGraphCanvasSplitterOverlay.vue @@ -150,7 +150,7 @@ import { storeToRefs } from 'pinia' import Splitter from 'primevue/splitter' import type { SplitterResizeStartEvent } from 'primevue/splitter' import SplitterPanel from 'primevue/splitterpanel' -import { computed } from 'vue' +import { computed, watchEffect } from 'vue' import { useI18n } from 'vue-i18n' import { useAppMode } from '@/composables/useAppMode' @@ -158,7 +158,9 @@ import { BUILDER_MIN_SIZE, CENTER_PANEL_SIZE, SIDEBAR_MIN_SIZE, - SIDE_PANEL_SIZE + SIDEBAR_MIN_WIDTH, + SIDE_PANEL_SIZE, + SIDE_TOOLBAR_WIDTH } from '@/constants/splitterConstants' import { useSettingStore } from '@/platform/settings/settingStore' import { useAgentNodeSelectionStore } from '@/stores/agentNodeSelectionStore' @@ -223,6 +225,23 @@ const sidebarPanelVisible = computed( () => activeSidebarTab.value !== null && !isBuilderMode.value ) +/** + * The sidebar can never be squeezed past `min-w-78`, so it and the toolbar + * rail are the floor the agent panel has to respect. Feeding the floor rather + * than the sidebar's live width keeps this one-way: a panel that shrank would + * otherwise widen the sidebar and shrink itself again. + */ +watchEffect(() => { + agentPanelStore.setReservedWorkspaceWidth( + SIDE_TOOLBAR_WIDTH + + (sidebarPanelVisible.value && + !focusMode.value && + !agentNodeSelectionActive.value + ? SIDEBAR_MIN_WIDTH + : 0) + ) +}) + const firstPanelVisible = computed( () => sidebarLocation.value === 'left' || showOffsideSplitter.value ) diff --git a/src/components/graph/GraphCanvasMenu.vue b/src/components/graph/GraphCanvasMenu.vue index 94bcb71e722..53e7acea596 100644 --- a/src/components/graph/GraphCanvasMenu.vue +++ b/src/components/graph/GraphCanvasMenu.vue @@ -9,80 +9,86 @@ @click="hideModal" > - - - -
- -