fix(editor): final review round, prettier on shell chrome files

This commit is contained in:
bchanot committed 2026-11-13 23:42:32 +01:00
1 parent 6bf9290da7
commit d6e501ef04
2 files changed
+69 -19

No files matched your search

+19 -5
View File
@@ -39,7 +39,9 @@ export const EDITOR_SHELL: ShellBreakpoint = {
/** 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 !== '/',
item.end
? item.to === pathname
: pathname.startsWith(item.to) && item.to !== '/',
)
return match?.labelKey ?? 'shell.nav.dashboard'
}
@@ -51,7 +53,11 @@ export function Sidebar({ shell }: { shell: ShellBreakpoint }) {
className={`${shell.sidebar} sticky top-0 h-dvh self-start overflow-y-auto 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">
<Link
to="/app"
aria-label={t('shell.nav.dashboard')}
className="inline-block"
>
<Brand size="md" />
</Link>
</div>
@@ -90,10 +96,16 @@ export function TopBar({ shell, menuOpen, onOpenMenu }: TopBarProps) {
>
<Icon name="menu" />
</button>
<Link to="/app" className={shell.menuControl} aria-label={t('shell.nav.dashboard')}>
<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)]`}>
<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">
@@ -105,7 +117,9 @@ export function TopBar({ shell, menuOpen, onOpenMenu }: TopBarProps) {
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>
<span className="hidden max-w-[12rem] truncate sm:inline">
{displayName}
</span>
</Link>
</div>
</header>
+50 -14
View File
@@ -78,7 +78,10 @@ function mount(path = '/app') {
<Route path="/app" element={<AppLayout />}>
<Route index element={<p>dashboard page</p>} />
<Route path="account" element={<p>account page</p>} />
<Route path="admin/sheets/:sheetId/draft" element={<p>draft page</p>} />
<Route
path="admin/sheets/:sheetId/draft"
element={<p>draft page</p>}
/>
<Route path="admin/sheets/:sheetId" element={<p>overview page</p>} />
</Route>
</Routes>
@@ -122,7 +125,9 @@ describe('AppLayout', () => {
it('shows the photo everywhere once the store holds a blob URL, the monogram otherwise', () => {
mount()
expect(screen.queryAllByRole('img', { name: fr['account.avatar.alt'] })).toHaveLength(0)
expect(
screen.queryAllByRole('img', { name: fr['account.avatar.alt'] }),
).toHaveLength(0)
expect(screen.getAllByText('AL').length).toBeGreaterThan(0)
cleanup()
useAuthStore.setState({ avatarUrl: 'blob:photo' })
@@ -136,7 +141,9 @@ describe('AppLayout', () => {
it('marks the active destination', () => {
mount('/app/account')
const nav = screen.getByRole('navigation', { name: fr['shell.nav_label'] })
const link = within(nav).getByRole('link', { name: new RegExp(fr['shell.nav.account']) })
const link = within(nav).getByRole('link', {
name: new RegExp(fr['shell.nav.account']),
})
expect(link).toHaveAttribute('aria-current', 'page')
})
@@ -144,10 +151,16 @@ describe('AppLayout', () => {
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'] })
await user.click(
screen.getByRole('button', { name: fr['shell.open_menu'] }),
)
const drawer = await screen.findByRole('dialog', {
name: fr['shell.nav_label'],
})
expect(drawer).toBeInTheDocument()
const links = screen.getAllByRole('link', { name: new RegExp(fr['shell.nav.account']) })
const links = screen.getAllByRole('link', {
name: new RegExp(fr['shell.nav.account']),
})
await user.click(links[links.length - 1])
expect(await screen.findByText('account page')).toBeInTheDocument()
})
@@ -155,7 +168,9 @@ describe('AppLayout', () => {
it('signs out and returns to the local tool', async () => {
const user = userEvent.setup()
mount()
const [button] = screen.getAllByRole('button', { name: fr['shell.sign_out'] })
const [button] = screen.getAllByRole('button', {
name: fr['shell.sign_out'],
})
await user.click(button)
expect(fake.auth.signOut).toHaveBeenCalled()
expect(await screen.findByText('local tool')).toBeInTheDocument()
@@ -164,14 +179,17 @@ 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 })
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')
expect(screen.getByRole('heading', { level: 1, hidden: true })).toHaveClass(
'xl:block',
)
cleanup()
mount('/app/admin/sheets/s-1')
expect(sidebar()).toHaveClass('lg:flex')
@@ -181,10 +199,22 @@ describe('AppLayout, editor sidebar from 1 280 px', () => {
it('keeps the sidebar fixed while the content scrolls, with its own scroll', () => {
mount('/app/admin/sheets/s-1/draft')
expect(sidebar()).toHaveClass('sticky', 'top-0', 'h-dvh', 'self-start', 'overflow-y-auto')
expect(sidebar()).toHaveClass(
'sticky',
'top-0',
'h-dvh',
'self-start',
'overflow-y-auto',
)
cleanup()
mount('/app/admin/sheets/s-1')
expect(sidebar()).toHaveClass('sticky', 'top-0', 'h-dvh', 'self-start', 'overflow-y-auto')
expect(sidebar()).toHaveClass(
'sticky',
'top-0',
'h-dvh',
'self-start',
'overflow-y-auto',
)
})
it('keeps the drawer open at 1 180 px in the editor, closes it from 1 280 px', async () => {
@@ -192,7 +222,9 @@ describe('AppLayout, editor sidebar from 1 280 px', () => {
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()
expect(
await screen.findByRole('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)')
@@ -218,7 +250,9 @@ describe('AppLayout, editor sidebar from 1 280 px', () => {
cleanup()
mount('/app/admin/sheets/s-1/draft')
await user.click(topBarMenu())
expect(await screen.findByRole('dialog', { name: fr['shell.nav_label'] })).toBeInTheDocument()
expect(
await screen.findByRole('dialog', { name: fr['shell.nav_label'] }),
).toBeInTheDocument()
})
it('asks before leaving from a drawer link while changes are unsaved', async () => {
@@ -227,7 +261,9 @@ describe('AppLayout, editor sidebar from 1 280 px', () => {
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'] })
const drawer = await screen.findByRole('dialog', {
name: fr['shell.nav_label'],
})
const account = new RegExp(fr['shell.nav.account'])
await user.click(within(drawer).getByRole('link', { name: account }))
expect(screen.queryByText('account page')).toBeNull()