feat(app): editor sidebar hidden below 1 280 px, menu one tap away
AC9: on the draft editor path AppLayout uses the xl class set (sidebar
from 1 280 px, menu button and brand below); other pages keep lg.
AppLayout split: Sidebar and TopBar in ShellChrome.tsx. MobileDrawer
takes closesFrom ('64rem' | '80rem') and also closes at setup when
its query already matches.
Rewritten assertions (R-24):
- shell.AppLayout "opens the mobile drawer" and shell.navigation
"carries the same entries into the mobile drawer": stub a narrow
matchMedia, the drawer now closes at setup at the happy-dom width.
New: unit tests (class sets, 64rem/80rem close, setup close, leave
guard on a drawer link) and editor-shell.spec F journeys (sidebar at
1024/1180/1279/1280, one-tap menu, drawer open at 1180, guard).
This commit is contained in:
1 parent
89da8d3f55
commit
580ff28214
6 files changed
+317
-74
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
openEditor,
|
||||
openReferences,
|
||||
openSection,
|
||||
pickAnnotation,
|
||||
place,
|
||||
pointOf,
|
||||
seedDraft,
|
||||
@@ -244,3 +245,85 @@ test.describe('editor shell, width crossing (B2b)', () => {
|
||||
await expect(field).toHaveValue('Brouillon')
|
||||
})
|
||||
})
|
||||
|
||||
// V1-2.6 U1 F (AC9): in the editor the sidebar shows from 1 280 px only; below, the top
|
||||
// bar's menu button opens the drawer, which stays open while the sidebar stays hidden.
|
||||
test.describe('editor shell, sidebar from 1 280 px (F)', () => {
|
||||
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
|
||||
test.beforeEach(async ({ context }, info) => {
|
||||
test.skip(isPhone(info), 'the widths are set by the tests themselves') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access
|
||||
await routeToSandbox(context)
|
||||
})
|
||||
test.afterEach(async ({ context }) => {
|
||||
await dropLateReplays(context)
|
||||
})
|
||||
|
||||
const nav = (page: Page) =>
|
||||
page.getByRole('navigation', { name: dict['shell.nav_label'] })
|
||||
const menu = (page: Page) =>
|
||||
page.getByRole('button', { name: dict['shell.open_menu'] })
|
||||
const drawer = (page: Page) =>
|
||||
page.getByRole('dialog', { name: dict['shell.nav_label'] })
|
||||
|
||||
async function measure(page: Page, width: number) {
|
||||
await page.setViewportSize({ width, height: 800 })
|
||||
await selectTab(page, dict, 'annotations')
|
||||
await pickAnnotation(page, dict, 'Point libre')
|
||||
const canvas = await page.getByTestId('annotation-canvas').boundingBox()
|
||||
const scroll = await page.evaluate(() => ({
|
||||
scrollWidth: document.documentElement.scrollWidth,
|
||||
clientWidth: document.documentElement.clientWidth,
|
||||
}))
|
||||
console.log(`F-measure ${width}px canvas=${canvas?.width} ${JSON.stringify(scroll)}`)
|
||||
return scroll
|
||||
}
|
||||
|
||||
test('the sidebar is hidden below 1 280 px and shown from 1 280 px', async ({
|
||||
page,
|
||||
}) => {
|
||||
await open(page)
|
||||
for (const width of [1024, 1180, 1279]) {
|
||||
const scroll = await measure(page, width)
|
||||
expect(scroll.scrollWidth, `${width} px`).toBeLessThanOrEqual(scroll.clientWidth)
|
||||
await expect(nav(page), `${width} px`).toHaveCount(0)
|
||||
await expect(menu(page), `${width} px`).toBeVisible()
|
||||
}
|
||||
const scroll = await measure(page, 1280)
|
||||
expect(scroll.scrollWidth).toBeLessThanOrEqual(scroll.clientWidth)
|
||||
await expect(nav(page)).toBeVisible()
|
||||
await expect(menu(page)).toHaveCount(0)
|
||||
})
|
||||
|
||||
test('the menu is one tap away and the drawer stays open at 1 180 px', async ({
|
||||
page,
|
||||
}) => {
|
||||
await open(page)
|
||||
await page.setViewportSize({ width: 1180, height: 800 })
|
||||
await menu(page).click()
|
||||
await expect(drawer(page)).toBeVisible()
|
||||
await page.setViewportSize({ width: 1279, height: 800 })
|
||||
await page.waitForTimeout(300)
|
||||
await expect(drawer(page)).toBeVisible()
|
||||
await page.setViewportSize({ width: 1280, height: 800 })
|
||||
await expect(drawer(page)).toBeHidden()
|
||||
await expect(nav(page)).toBeVisible()
|
||||
})
|
||||
|
||||
test('a drawer link asks before leaving while the draft has unsaved changes', async ({
|
||||
page,
|
||||
}) => {
|
||||
await open(page)
|
||||
await page.setViewportSize({ width: 1180, height: 800 })
|
||||
await selectTab(page, dict, 'general')
|
||||
await page.locator('#general-name-fr').fill('Travail non enregistré')
|
||||
await menu(page).click()
|
||||
await drawer(page)
|
||||
.getByRole('link', { name: new RegExp(dict['shell.nav.account']) })
|
||||
.click()
|
||||
const leave = page.getByRole('dialog', { name: dict['leave.title'] })
|
||||
await expect(leave).toBeVisible()
|
||||
await leave.getByRole('button', { name: dict['leave.stay'] }).click()
|
||||
await expect(leave).toBeHidden()
|
||||
await expect(page).toHaveURL(/\/draft/)
|
||||
})
|
||||
})
|
||||
@@ -1,30 +1,16 @@
|
||||
import { useState, type MouseEvent } from 'react'
|
||||
import { Link, Outlet, matchPath, useLocation, useNavigate } from 'react-router-dom'
|
||||
import Brand from '@/components/brand/Brand'
|
||||
import LanguageSwitcher from '@/components/brand/LanguageSwitcher'
|
||||
import { Outlet, matchPath, useLocation, useNavigate } from 'react-router-dom'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import MobileDrawer from './MobileDrawer'
|
||||
import SidebarNav, { NAV_ITEMS } from './SidebarNav'
|
||||
import SignOutButton from './SignOutButton'
|
||||
import UserBadge, { AvatarCircle } from './UserBadge'
|
||||
import { DEFAULT_SHELL, EDITOR_SHELL, Sidebar, TopBar } from './ShellChrome'
|
||||
import { usePurgeForeignCopies } from '@/app/usePurgeForeignCopies'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useLeaveGuardStore } from '@/state/leaveGuardStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/** The draft editor takes the whole width (board 04's three columns). */
|
||||
const DRAFT_EDITOR_PATH = '/app/admin/sheets/:sheetId/draft'
|
||||
|
||||
/** Title of the current /app page for the top bar, from the nav table. */
|
||||
function pageTitleKey(pathname: string): string {
|
||||
const match = NAV_ITEMS.find((item) =>
|
||||
item.end ? item.to === pathname : pathname.startsWith(item.to) && item.to !== '/',
|
||||
)
|
||||
return match?.labelKey ?? 'shell.nav.dashboard'
|
||||
}
|
||||
|
||||
/** An in-app link a plain click would follow: same origin, same tab, no modifier key. */
|
||||
function followedLink(event: MouseEvent): HTMLAnchorElement | null {
|
||||
if (event.defaultPrevented || event.button !== 0) return null
|
||||
@@ -67,58 +53,15 @@ export default function AppLayout() {
|
||||
setDrawerOpen(false)
|
||||
navigate(to)
|
||||
}
|
||||
const profile = useAuthStore((s) => s.profile)
|
||||
const user = useAuthStore((s) => s.user)
|
||||
const fullWidth = matchPath(DRAFT_EDITOR_PATH, location.pathname) !== null
|
||||
const displayName = profile?.display_name ?? user?.email ?? ''
|
||||
const shell = fullWidth ? EDITOR_SHELL : DEFAULT_SHELL
|
||||
|
||||
return (
|
||||
<div className="flex min-h-dvh bg-[var(--color-bg)]" onClickCapture={askBeforeLeaving}>
|
||||
<aside className="hidden lg:flex lg:w-64 lg:shrink-0 lg:flex-col border-r border-[var(--color-border)] bg-[var(--color-surface)]">
|
||||
<div className="px-5 py-5">
|
||||
<Link to="/app" aria-label={t('shell.nav.dashboard')} className="inline-block">
|
||||
<Brand size="md" />
|
||||
</Link>
|
||||
</div>
|
||||
<div className="flex-1 px-3">
|
||||
<SidebarNav />
|
||||
</div>
|
||||
<div className="space-y-3 border-t border-[var(--color-border)] px-4 py-4">
|
||||
<UserBadge />
|
||||
<SignOutButton className="w-full" />
|
||||
</div>
|
||||
</aside>
|
||||
<Sidebar shell={shell} />
|
||||
|
||||
<div className="flex min-w-0 flex-1 flex-col">
|
||||
<header className="sticky top-0 z-30 flex h-14 items-center gap-3 border-b border-[var(--color-border)] bg-[var(--color-surface)]/95 px-3 backdrop-blur-sm sm:px-6 pt-[env(safe-area-inset-top)]">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setDrawerOpen(true)}
|
||||
aria-label={t('shell.open_menu')}
|
||||
aria-expanded={drawerOpen}
|
||||
className="grid h-11 w-11 place-items-center rounded-lg text-[var(--color-ink)] hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] lg:hidden"
|
||||
>
|
||||
<Icon name="menu" />
|
||||
</button>
|
||||
<Link to="/app" className="lg:hidden" aria-label={t('shell.nav.dashboard')}>
|
||||
<Brand size="sm" />
|
||||
</Link>
|
||||
<h1 className="hidden lg:block text-sm font-medium text-[var(--color-ink-muted)]">
|
||||
{t(pageTitleKey(location.pathname))}
|
||||
</h1>
|
||||
<div className="ml-auto flex items-center gap-2 sm:gap-3">
|
||||
<LanguageSwitcher />
|
||||
<Link
|
||||
to="/app/account"
|
||||
aria-label={t('shell.nav.account')}
|
||||
data-testid="topbar-account"
|
||||
className="flex min-h-11 items-center gap-2 rounded-full pr-1 pl-1 text-sm text-[var(--color-ink)] hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] sm:pr-3"
|
||||
>
|
||||
<AvatarCircle size="sm" />
|
||||
<span className="hidden max-w-[12rem] truncate sm:inline">{displayName}</span>
|
||||
</Link>
|
||||
</div>
|
||||
</header>
|
||||
<TopBar shell={shell} menuOpen={drawerOpen} onOpenMenu={() => setDrawerOpen(true)} />
|
||||
<main className="flex-1 px-4 py-6 sm:px-8 sm:py-8">
|
||||
<div className={`mx-auto w-full ${fullWidth ? '' : 'max-w-4xl'}`}>
|
||||
<Outlet />
|
||||
@@ -126,7 +69,11 @@ export default function AppLayout() {
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<MobileDrawer open={drawerOpen} onClose={() => setDrawerOpen(false)} />
|
||||
<MobileDrawer
|
||||
open={drawerOpen}
|
||||
onClose={() => setDrawerOpen(false)}
|
||||
closesFrom={shell.closesFrom}
|
||||
/>
|
||||
<Dialog
|
||||
open={leaveTo !== null}
|
||||
onClose={() => setLeaveTo(null)}
|
||||
|
||||
@@ -12,27 +12,31 @@ import { useT } from '@/i18n/useT'
|
||||
export interface MobileDrawerProps {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
/** The sidebar's breakpoint (Tailwind `lg` or `xl`): from there the drawer has no reason to stay open. */
|
||||
closesFrom?: '64rem' | '80rem'
|
||||
}
|
||||
|
||||
/** The sidebar's breakpoint (Tailwind `lg`): from there the drawer has no reason to stay open. */
|
||||
const LARGE_SCREEN = '(min-width: 64rem)'
|
||||
|
||||
/** Left-side navigation drawer for small screens (transform + opacity only). */
|
||||
export default function MobileDrawer({ open, onClose }: MobileDrawerProps) {
|
||||
return <AnimatePresence>{open && <DrawerSurface onClose={onClose} />}</AnimatePresence>
|
||||
export default function MobileDrawer({ open, onClose, closesFrom = '64rem' }: MobileDrawerProps) {
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{open && <DrawerSurface onClose={onClose} closesFrom={closesFrom} />}
|
||||
</AnimatePresence>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerSurface({ onClose }: Pick<MobileDrawerProps, 'onClose'>) {
|
||||
function DrawerSurface({ onClose, closesFrom }: Required<Omit<MobileDrawerProps, 'open'>>) {
|
||||
const t = useT()
|
||||
const reduced = useReducedMotion()
|
||||
const slide = reduced ? { x: 0 } : { x: '-100%' }
|
||||
// A modal drawer left open while the window widens would keep the page inert.
|
||||
useEffect(() => {
|
||||
const query = window.matchMedia(LARGE_SCREEN)
|
||||
const query = window.matchMedia(`(min-width: ${closesFrom})`)
|
||||
if (query.matches) onClose()
|
||||
const onChange = (event: MediaQueryListEvent) => event.matches && onClose()
|
||||
query.addEventListener('change', onChange)
|
||||
return () => query.removeEventListener('change', onChange)
|
||||
}, [onClose])
|
||||
}, [onClose, closesFrom])
|
||||
|
||||
return (
|
||||
<ModalDialog onClose={onClose} label={t('shell.nav_label')} className="open:block">
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
import { Link, useLocation } from 'react-router-dom'
|
||||
import Brand from '@/components/brand/Brand'
|
||||
import LanguageSwitcher from '@/components/brand/LanguageSwitcher'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import SidebarNav, { NAV_ITEMS } from './SidebarNav'
|
||||
import SignOutButton from './SignOutButton'
|
||||
import UserBadge, { AvatarCircle } from './UserBadge'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/**
|
||||
* Where the sidebar shows and the top bar swaps its menu button for the page title.
|
||||
* Tailwind needs literal class strings: two static sets, never a built string.
|
||||
*/
|
||||
export interface ShellBreakpoint {
|
||||
sidebar: string
|
||||
menuControl: string
|
||||
title: string
|
||||
/** The width from which the drawer has no reason to stay open. */
|
||||
closesFrom: '64rem' | '80rem'
|
||||
}
|
||||
|
||||
/** Every page but the editor: the sidebar from 1 024 px (Tailwind `lg`). */
|
||||
export const DEFAULT_SHELL: ShellBreakpoint = {
|
||||
sidebar: 'hidden lg:flex lg:w-64 lg:shrink-0 lg:flex-col',
|
||||
menuControl: 'lg:hidden',
|
||||
title: 'hidden lg:block',
|
||||
closesFrom: '64rem',
|
||||
}
|
||||
|
||||
/** The draft editor needs the width for its three columns: sidebar from 1 280 px (`xl`). */
|
||||
export const EDITOR_SHELL: ShellBreakpoint = {
|
||||
sidebar: 'hidden xl:flex xl:w-64 xl:shrink-0 xl:flex-col',
|
||||
menuControl: 'xl:hidden',
|
||||
title: 'hidden xl:block',
|
||||
closesFrom: '80rem',
|
||||
}
|
||||
|
||||
/** Title of the current /app page for the top bar, from the nav table. */
|
||||
function pageTitleKey(pathname: string): string {
|
||||
const match = NAV_ITEMS.find((item) =>
|
||||
item.end ? item.to === pathname : pathname.startsWith(item.to) && item.to !== '/',
|
||||
)
|
||||
return match?.labelKey ?? 'shell.nav.dashboard'
|
||||
}
|
||||
|
||||
export function Sidebar({ shell }: { shell: ShellBreakpoint }) {
|
||||
const t = useT()
|
||||
return (
|
||||
<aside
|
||||
className={`${shell.sidebar} border-r border-[var(--color-border)] bg-[var(--color-surface)]`}
|
||||
>
|
||||
<div className="px-5 py-5">
|
||||
<Link to="/app" aria-label={t('shell.nav.dashboard')} className="inline-block">
|
||||
<Brand size="md" />
|
||||
</Link>
|
||||
</div>
|
||||
<div className="flex-1 px-3">
|
||||
<SidebarNav />
|
||||
</div>
|
||||
<div className="space-y-3 border-t border-[var(--color-border)] px-4 py-4">
|
||||
<UserBadge />
|
||||
<SignOutButton className="w-full" />
|
||||
</div>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
|
||||
interface TopBarProps {
|
||||
shell: ShellBreakpoint
|
||||
menuOpen: boolean
|
||||
onOpenMenu: () => void
|
||||
}
|
||||
|
||||
export function TopBar({ shell, menuOpen, onOpenMenu }: TopBarProps) {
|
||||
const t = useT()
|
||||
const { pathname } = useLocation()
|
||||
const profile = useAuthStore((s) => s.profile)
|
||||
const user = useAuthStore((s) => s.user)
|
||||
const displayName = profile?.display_name ?? user?.email ?? ''
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-30 flex h-14 items-center gap-3 border-b border-[var(--color-border)] bg-[var(--color-surface)]/95 px-3 backdrop-blur-sm sm:px-6 pt-[env(safe-area-inset-top)]">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onOpenMenu}
|
||||
aria-label={t('shell.open_menu')}
|
||||
aria-expanded={menuOpen}
|
||||
className={`grid h-11 w-11 place-items-center rounded-lg text-[var(--color-ink)] hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] ${shell.menuControl}`}
|
||||
>
|
||||
<Icon name="menu" />
|
||||
</button>
|
||||
<Link to="/app" className={shell.menuControl} aria-label={t('shell.nav.dashboard')}>
|
||||
<Brand size="sm" />
|
||||
</Link>
|
||||
<h1 className={`${shell.title} text-sm font-medium text-[var(--color-ink-muted)]`}>
|
||||
{t(pageTitleKey(pathname))}
|
||||
</h1>
|
||||
<div className="ml-auto flex items-center gap-2 sm:gap-3">
|
||||
<LanguageSwitcher />
|
||||
<Link
|
||||
to="/app/account"
|
||||
aria-label={t('shell.nav.account')}
|
||||
data-testid="topbar-account"
|
||||
className="flex min-h-11 items-center gap-2 rounded-full pr-1 pl-1 text-sm text-[var(--color-ink)] hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] sm:pr-3"
|
||||
>
|
||||
<AvatarCircle size="sm" />
|
||||
<span className="hidden max-w-[12rem] truncate sm:inline">{displayName}</span>
|
||||
</Link>
|
||||
</div>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, render, screen, 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'
|
||||
@@ -13,6 +13,7 @@ vi.mock('@/lib/supabase', () => ({
|
||||
import AppLayout from '@/components/shell/AppLayout'
|
||||
import { monogram } from '@/components/shell/UserBadge'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useLeaveGuardStore } from '@/state/leaveGuardStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { fr } from '@/i18n/fr'
|
||||
|
||||
@@ -31,7 +32,28 @@ beforeEach(() => {
|
||||
avatarUrl: null,
|
||||
})
|
||||
})
|
||||
afterEach(cleanup)
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.unstubAllGlobals()
|
||||
useLeaveGuardStore.getState().arm(false)
|
||||
})
|
||||
|
||||
/** A matchMedia whose queries match from `widthRem`; `fire` flips it to a wider screen. */
|
||||
function stubScreen(widthRem: number) {
|
||||
const listeners = new Map<string, Set<(e: { matches: boolean }) => void>>()
|
||||
const min = (query: string) => Number(/min-width: (\d+)rem/.exec(query)![1])
|
||||
vi.stubGlobal('matchMedia', (query: string) => ({
|
||||
matches: widthRem >= min(query),
|
||||
addEventListener: (_: string, fn: (e: { matches: boolean }) => void) => {
|
||||
listeners.set(query, (listeners.get(query) ?? new Set()).add(fn))
|
||||
},
|
||||
removeEventListener: (_: string, fn: (e: { matches: boolean }) => void) => {
|
||||
listeners.get(query)?.delete(fn)
|
||||
},
|
||||
}))
|
||||
return (query: string) =>
|
||||
act(() => listeners.get(query)?.forEach((fn) => fn({ matches: true })))
|
||||
}
|
||||
|
||||
function mount(path = '/app') {
|
||||
return render(
|
||||
@@ -105,6 +127,7 @@ describe('AppLayout', () => {
|
||||
|
||||
it('opens the mobile drawer from the menu button and closes it on navigation', async () => {
|
||||
const user = userEvent.setup()
|
||||
stubScreen(40)
|
||||
mount()
|
||||
await user.click(screen.getByRole('button', { name: fr['shell.open_menu'] }))
|
||||
const drawer = await screen.findByRole('dialog', { name: fr['shell.nav_label'] })
|
||||
@@ -124,6 +147,70 @@ describe('AppLayout', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('AppLayout, editor sidebar from 1 280 px', () => {
|
||||
const sidebar = () => document.querySelector('aside') as HTMLElement
|
||||
const topBarMenu = () => screen.getByRole('button', { name: fr['shell.open_menu'], hidden: true })
|
||||
|
||||
it('uses the xl class set on the editor path, the lg set elsewhere', () => {
|
||||
mount('/app/admin/sheets/s-1/draft')
|
||||
expect(sidebar()).toHaveClass('xl:flex')
|
||||
expect(sidebar()).not.toHaveClass('lg:flex')
|
||||
expect(topBarMenu()).toHaveClass('xl:hidden')
|
||||
expect(screen.getByRole('heading', { level: 1, hidden: true })).toHaveClass('xl:block')
|
||||
cleanup()
|
||||
mount('/app/admin/sheets/s-1')
|
||||
expect(sidebar()).toHaveClass('lg:flex')
|
||||
expect(sidebar()).not.toHaveClass('xl:flex')
|
||||
expect(topBarMenu()).toHaveClass('lg:hidden')
|
||||
})
|
||||
|
||||
it('keeps the drawer open at 1 180 px in the editor, closes it from 1 280 px', async () => {
|
||||
const user = userEvent.setup()
|
||||
const fire = stubScreen(73.75)
|
||||
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()
|
||||
fire('(min-width: 80rem)')
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
})
|
||||
|
||||
it('closes the drawer on the 64rem query on other pages', async () => {
|
||||
const user = userEvent.setup()
|
||||
const fire = stubScreen(50)
|
||||
mount('/app')
|
||||
await user.click(topBarMenu())
|
||||
await screen.findByRole('dialog', { name: fr['shell.nav_label'] })
|
||||
fire('(min-width: 64rem)')
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
})
|
||||
|
||||
it('closes at setup when its query already matches', async () => {
|
||||
const user = userEvent.setup()
|
||||
stubScreen(73.75)
|
||||
mount('/app')
|
||||
await user.click(topBarMenu())
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
cleanup()
|
||||
mount('/app/admin/sheets/s-1/draft')
|
||||
await user.click(topBarMenu())
|
||||
expect(await screen.findByRole('dialog', { name: fr['shell.nav_label'] })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('asks before leaving from a drawer link while changes are unsaved', async () => {
|
||||
const user = userEvent.setup()
|
||||
stubScreen(73.75)
|
||||
mount('/app/admin/sheets/s-1/draft')
|
||||
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']) }))
|
||||
expect(screen.queryByText('account page')).toBeNull()
|
||||
expect(await screen.findByText(fr['leave.title'])).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('monogram', () => {
|
||||
it('takes initials, else two letters, else ?', () => {
|
||||
expect(monogram('Alice Local', undefined)).toBe('AL')
|
||||
|
||||
@@ -80,7 +80,10 @@ beforeEach(() => {
|
||||
avatarUrl: null,
|
||||
})
|
||||
})
|
||||
afterEach(cleanup)
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('SidebarNav entries', () => {
|
||||
it('hides both V1-2 entries from an account without a right', () => {
|
||||
@@ -126,6 +129,12 @@ describe('SidebarNav entries', () => {
|
||||
|
||||
it('carries the same entries into the mobile drawer', async () => {
|
||||
const user = userEvent.setup()
|
||||
// A narrow screen: the drawer closes by itself once the sidebar breakpoint matches.
|
||||
vi.stubGlobal('matchMedia', () => ({
|
||||
matches: false,
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
}))
|
||||
mount([grant('sheet_editor')])
|
||||
await user.click(screen.getByRole('button', { name: fr['shell.open_menu'] }))
|
||||
const drawer = await screen.findByRole('dialog', { name: fr['shell.nav_label'] })
|
||||
|
||||
Reference in new issue
Block a user