diff --git a/apps/app/e2e/shell/editor-shell.spec.ts b/apps/app/e2e/shell/editor-shell.spec.ts index e747bab9..3fd2084b 100644 --- a/apps/app/e2e/shell/editor-shell.spec.ts +++ b/apps/app/e2e/shell/editor-shell.spec.ts @@ -274,7 +274,10 @@ test.describe('editor shell, sidebar from 1 280 px (F)', () => { scrollWidth: document.documentElement.scrollWidth, clientWidth: document.documentElement.clientWidth, })) - console.log(`F-measure ${width}px canvas=${canvas?.width} ${JSON.stringify(scroll)}`) + test.info().annotations.push({ + type: 'canvas-width', + description: `${canvas?.width}px at ${width}px`, + }) return scroll } @@ -302,7 +305,9 @@ test.describe('editor shell, sidebar from 1 280 px (F)', () => { await menu(page).click() await expect(drawer(page)).toBeVisible() await page.setViewportSize({ width: 1279, height: 800 }) - await page.waitForTimeout(300) + await page.evaluate( + () => new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(done))), + ) await expect(drawer(page)).toBeVisible() await page.setViewportSize({ width: 1280, height: 800 }) await expect(drawer(page)).toBeHidden() diff --git a/apps/app/src/components/shell/MobileDrawer.tsx b/apps/app/src/components/shell/MobileDrawer.tsx index 38f8a18b..55e51744 100644 --- a/apps/app/src/components/shell/MobileDrawer.tsx +++ b/apps/app/src/components/shell/MobileDrawer.tsx @@ -4,6 +4,7 @@ import { AnimatePresence, motion, useReducedMotion } from 'motion/react' import Brand from '@/components/brand/Brand' import Icon from '@/components/ui/Icon' import ModalDialog from '@/components/ui/ModalDialog' +import { DEFAULT_SHELL } from './ShellChrome' import SidebarNav from './SidebarNav' import SignOutButton from './SignOutButton' import UserBadge from './UserBadge' @@ -17,7 +18,7 @@ export interface MobileDrawerProps { } /** Left-side navigation drawer for small screens (transform + opacity only). */ -export default function MobileDrawer({ open, onClose, closesFrom = '64rem' }: MobileDrawerProps) { +export default function MobileDrawer({ open, onClose, closesFrom = DEFAULT_SHELL.closesFrom }: MobileDrawerProps) { return ( {open && } diff --git a/apps/app/tests/unit/shell.AppLayout.test.tsx b/apps/app/tests/unit/shell.AppLayout.test.tsx index a421ac8f..6bc2b144 100644 --- a/apps/app/tests/unit/shell.AppLayout.test.tsx +++ b/apps/app/tests/unit/shell.AppLayout.test.tsx @@ -1,8 +1,20 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { act, cleanup, render, screen, waitFor, within } from '@testing-library/react' +import { + act, + cleanup, + render, + screen, + waitFor, + within, +} from '@testing-library/react' import userEvent from '@testing-library/user-event' import { MemoryRouter, Route, Routes } from 'react-router-dom' -import { createFakeSupabase, fakeProfile, fakeUser, type FakeSupabase } from '../helpers/fakeSupabase' +import { + createFakeSupabase, + fakeProfile, + fakeUser, + type FakeSupabase, +} from '../helpers/fakeSupabase' const mocks = vi.hoisted(() => ({ fake: null as unknown })) vi.mock('@/lib/supabase', () => ({ @@ -51,8 +63,11 @@ function stubScreen(widthRem: number) { listeners.get(query)?.delete(fn) }, })) - return (query: string) => + const fire = (query: string) => act(() => listeners.get(query)?.forEach((fn) => fn({ matches: true }))) + return Object.assign(fire, { + listening: (query: string) => (listeners.get(query)?.size ?? 0) > 0, + }) } function mount(path = '/app') { @@ -170,8 +185,8 @@ describe('AppLayout, editor sidebar from 1 280 px', () => { mount('/app/admin/sheets/s-1/draft') await user.click(topBarMenu()) expect(await screen.findByRole('dialog', { name: fr['shell.nav_label'] })).toBeInTheDocument() - fire('(min-width: 64rem)') - expect(screen.getByRole('dialog', { name: fr['shell.nav_label'] })).toBeInTheDocument() + expect(fire.listening('(min-width: 64rem)')).toBe(false) + expect(fire.listening('(min-width: 80rem)')).toBe(true) fire('(min-width: 80rem)') await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()) }) @@ -205,7 +220,8 @@ describe('AppLayout, editor sidebar from 1 280 px', () => { useLeaveGuardStore.getState().arm(true) await user.click(topBarMenu()) const drawer = await screen.findByRole('dialog', { name: fr['shell.nav_label'] }) - await user.click(within(drawer).getByRole('link', { name: new RegExp(fr['shell.nav.account']) })) + const account = new RegExp(fr['shell.nav.account']) + await user.click(within(drawer).getByRole('link', { name: account })) expect(screen.queryByText('account page')).toBeNull() expect(await screen.findByText(fr['leave.title'])).toBeInTheDocument() })