diff --git a/packages/frontend/editor-ui/src/features/ndv/panel/composables/useNdvLayout.test.ts b/packages/frontend/editor-ui/src/features/ndv/panel/composables/useNdvLayout.test.ts index 62db1d60a48..331e52e5fe1 100644 --- a/packages/frontend/editor-ui/src/features/ndv/panel/composables/useNdvLayout.test.ts +++ b/packages/frontend/editor-ui/src/features/ndv/panel/composables/useNdvLayout.test.ts @@ -1,16 +1,16 @@ -import { ref, type Ref } from 'vue'; +import { nextTick, ref, type Ref } from 'vue'; import { useNdvLayout } from './useNdvLayout'; import { LOCAL_STORAGE_NDV_PANEL_WIDTH } from '@/features/ndv/shared/ndv.constants'; import { mock } from 'vitest-mock-extended'; -vi.mock('@vueuse/core', () => { - return { - useElementSize: () => ({ - width: ref(1000), - height: ref(500), - }), - }; -}); +const containerWidth = ref(1000); + +vi.mock('@vueuse/core', () => ({ + useElementSize: vi.fn(() => ({ + width: containerWidth, + height: ref(500), + })), +})); describe('useNdvLayout', () => { let containerRef: HTMLDivElement; @@ -23,6 +23,7 @@ describe('useNdvLayout', () => { container = ref(containerRef); hasInputPanel = ref(true); paneType = ref('regular'); + containerWidth.value = 1000; localStorage.clear(); }); @@ -84,4 +85,28 @@ describe('useNdvLayout', () => { onResizeEnd(); expect(spy).toHaveBeenCalledWith(expect.stringContaining('_REGULAR'), expect.any(String)); }); + + it('restores correct proportions after container width changes (zoom simulation)', async () => { + const key = `${LOCAL_STORAGE_NDV_PANEL_WIDTH}_REGULAR`; + localStorage.setItem(key, JSON.stringify({ left: 29, main: 42, right: 29 })); + + const { panelWidthPercentage } = useNdvLayout({ container, hasInputPanel, paneType }); + + // Manually corrupt in-memory state to simulate what the old code did when + // zooming in inflated minMainPanelWidthPercentage and clamped main upward. + panelWidthPercentage.value = { left: 15, main: 70, right: 15 }; + + // Simulate zoom in — should reload from storage and restore correct proportions. + containerWidth.value = 600; + await nextTick(); + await nextTick(); + + containerWidth.value = 1000; + await nextTick(); + await nextTick(); + + expect(panelWidthPercentage.value.left).toBeCloseTo(29); + expect(panelWidthPercentage.value.main).toBeCloseTo(42); + expect(panelWidthPercentage.value.right).toBeCloseTo(29); + }); }); diff --git a/packages/frontend/editor-ui/src/features/ndv/panel/composables/useNdvLayout.ts b/packages/frontend/editor-ui/src/features/ndv/panel/composables/useNdvLayout.ts index 9bd2e56b7dc..a47fc0c6592 100644 --- a/packages/frontend/editor-ui/src/features/ndv/panel/composables/useNdvLayout.ts +++ b/packages/frontend/editor-ui/src/features/ndv/panel/composables/useNdvLayout.ts @@ -172,14 +172,10 @@ export function useNdvLayout(options: UseNdvLayoutOptions) { panelWidthPercentage.value.right = newRight; }; - watch(containerWidth, (newWidth, oldWidth) => { + watch(containerWidth, (newWidth) => { if (!newWidth) return; - if (!oldWidth) { - loadPanelSize(); - } else { - panelWidthPercentage.value = safePanelWidth(panelWidthPercentage.value); - } + loadPanelSize(); }); watch(