fix(editor): final review round, prettier on shell chrome files
This commit is contained in:
1 parent
6bf9290da7
commit
d6e501ef04
2 files changed
+69
-19
No files matched your search
@@ -39,7 +39,9 @@ export const EDITOR_SHELL: ShellBreakpoint = {
|
|||||||
/** Title of the current /app page for the top bar, from the nav table. */
|
/** Title of the current /app page for the top bar, from the nav table. */
|
||||||
function pageTitleKey(pathname: string): string {
|
function pageTitleKey(pathname: string): string {
|
||||||
const match = NAV_ITEMS.find((item) =>
|
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'
|
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)]`}
|
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">
|
<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" />
|
<Brand size="md" />
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
@@ -90,10 +96,16 @@ export function TopBar({ shell, menuOpen, onOpenMenu }: TopBarProps) {
|
|||||||
>
|
>
|
||||||
<Icon name="menu" />
|
<Icon name="menu" />
|
||||||
</button>
|
</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" />
|
<Brand size="sm" />
|
||||||
</Link>
|
</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))}
|
{t(pageTitleKey(pathname))}
|
||||||
</h1>
|
</h1>
|
||||||
<div className="ml-auto flex items-center gap-2 sm:gap-3">
|
<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"
|
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" />
|
<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>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -78,7 +78,10 @@ function mount(path = '/app') {
|
|||||||
<Route path="/app" element={<AppLayout />}>
|
<Route path="/app" element={<AppLayout />}>
|
||||||
<Route index element={<p>dashboard page</p>} />
|
<Route index element={<p>dashboard page</p>} />
|
||||||
<Route path="account" element={<p>account 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 path="admin/sheets/:sheetId" element={<p>overview page</p>} />
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
@@ -122,7 +125,9 @@ describe('AppLayout', () => {
|
|||||||
|
|
||||||
it('shows the photo everywhere once the store holds a blob URL, the monogram otherwise', () => {
|
it('shows the photo everywhere once the store holds a blob URL, the monogram otherwise', () => {
|
||||||
mount()
|
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)
|
expect(screen.getAllByText('AL').length).toBeGreaterThan(0)
|
||||||
cleanup()
|
cleanup()
|
||||||
useAuthStore.setState({ avatarUrl: 'blob:photo' })
|
useAuthStore.setState({ avatarUrl: 'blob:photo' })
|
||||||
@@ -136,7 +141,9 @@ describe('AppLayout', () => {
|
|||||||
it('marks the active destination', () => {
|
it('marks the active destination', () => {
|
||||||
mount('/app/account')
|
mount('/app/account')
|
||||||
const nav = screen.getByRole('navigation', { name: fr['shell.nav_label'] })
|
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')
|
expect(link).toHaveAttribute('aria-current', 'page')
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -144,10 +151,16 @@ describe('AppLayout', () => {
|
|||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
stubScreen(40)
|
stubScreen(40)
|
||||||
mount()
|
mount()
|
||||||
await user.click(screen.getByRole('button', { name: fr['shell.open_menu'] }))
|
await user.click(
|
||||||
const drawer = await screen.findByRole('dialog', { name: fr['shell.nav_label'] })
|
screen.getByRole('button', { name: fr['shell.open_menu'] }),
|
||||||
|
)
|
||||||
|
const drawer = await screen.findByRole('dialog', {
|
||||||
|
name: fr['shell.nav_label'],
|
||||||
|
})
|
||||||
expect(drawer).toBeInTheDocument()
|
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])
|
await user.click(links[links.length - 1])
|
||||||
expect(await screen.findByText('account page')).toBeInTheDocument()
|
expect(await screen.findByText('account page')).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
@@ -155,7 +168,9 @@ describe('AppLayout', () => {
|
|||||||
it('signs out and returns to the local tool', async () => {
|
it('signs out and returns to the local tool', async () => {
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
mount()
|
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)
|
await user.click(button)
|
||||||
expect(fake.auth.signOut).toHaveBeenCalled()
|
expect(fake.auth.signOut).toHaveBeenCalled()
|
||||||
expect(await screen.findByText('local tool')).toBeInTheDocument()
|
expect(await screen.findByText('local tool')).toBeInTheDocument()
|
||||||
@@ -164,14 +179,17 @@ describe('AppLayout', () => {
|
|||||||
|
|
||||||
describe('AppLayout, editor sidebar from 1 280 px', () => {
|
describe('AppLayout, editor sidebar from 1 280 px', () => {
|
||||||
const sidebar = () => document.querySelector('aside') as HTMLElement
|
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', () => {
|
it('uses the xl class set on the editor path, the lg set elsewhere', () => {
|
||||||
mount('/app/admin/sheets/s-1/draft')
|
mount('/app/admin/sheets/s-1/draft')
|
||||||
expect(sidebar()).toHaveClass('xl:flex')
|
expect(sidebar()).toHaveClass('xl:flex')
|
||||||
expect(sidebar()).not.toHaveClass('lg:flex')
|
expect(sidebar()).not.toHaveClass('lg:flex')
|
||||||
expect(topBarMenu()).toHaveClass('xl:hidden')
|
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()
|
cleanup()
|
||||||
mount('/app/admin/sheets/s-1')
|
mount('/app/admin/sheets/s-1')
|
||||||
expect(sidebar()).toHaveClass('lg:flex')
|
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', () => {
|
it('keeps the sidebar fixed while the content scrolls, with its own scroll', () => {
|
||||||
mount('/app/admin/sheets/s-1/draft')
|
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()
|
cleanup()
|
||||||
mount('/app/admin/sheets/s-1')
|
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 () => {
|
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)
|
const fire = stubScreen(73.75)
|
||||||
mount('/app/admin/sheets/s-1/draft')
|
mount('/app/admin/sheets/s-1/draft')
|
||||||
await user.click(topBarMenu())
|
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: 64rem)')).toBe(false)
|
||||||
expect(fire.listening('(min-width: 80rem)')).toBe(true)
|
expect(fire.listening('(min-width: 80rem)')).toBe(true)
|
||||||
fire('(min-width: 80rem)')
|
fire('(min-width: 80rem)')
|
||||||
@@ -218,7 +250,9 @@ describe('AppLayout, editor sidebar from 1 280 px', () => {
|
|||||||
cleanup()
|
cleanup()
|
||||||
mount('/app/admin/sheets/s-1/draft')
|
mount('/app/admin/sheets/s-1/draft')
|
||||||
await user.click(topBarMenu())
|
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 () => {
|
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')
|
mount('/app/admin/sheets/s-1/draft')
|
||||||
useLeaveGuardStore.getState().arm(true)
|
useLeaveGuardStore.getState().arm(true)
|
||||||
await user.click(topBarMenu())
|
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'])
|
const account = new RegExp(fr['shell.nav.account'])
|
||||||
await user.click(within(drawer).getByRole('link', { name: account }))
|
await user.click(within(drawer).getByRole('link', { name: account }))
|
||||||
expect(screen.queryByText('account page')).toBeNull()
|
expect(screen.queryByText('account page')).toBeNull()
|
||||||
|
|||||||
Reference in new issue
Block a user