Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions e2e/admin-frame-screenshots.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test } from '@playwright/test'

/**
* Review screenshots of the new admin's frame for the owner: light and dark, desktop (1280) and
* phone (390), with the drawer open on the phone. Saved to SCREENSHOTS_DIR (default
* .screenshots/admin). `bun --bun playwright test e2e/admin-frame-screenshots.spec.ts`.
*/
const DIR = process.env.SCREENSHOTS_DIR ?? '.screenshots/admin'
const sizes = { desktop: { width: 1280, height: 800 }, phone: { width: 390, height: 844 } }

for (const scheme of ['light', 'dark'] as const)
for (const [label, viewport] of Object.entries(sizes))
test(`@screenshots admin frame ${label} ${scheme}`, async ({ browser }) => {
const context = await browser.newContext({ viewport, hasTouch: label === 'phone', isMobile: label === 'phone' })
const page = await context.newPage()
await page.goto(`/admin-next?scheme=${scheme}&path=/admin/users/roles`)
await page.evaluate(() => document.fonts.ready)
await page.screenshot({ path: `${DIR}/frame-${label}-${scheme}.png` })
if (label === 'phone') {
await page.getByRole('button', { name: 'Menu' }).click()
await page.getByRole('dialog').waitFor()
await page.waitForTimeout(400)
await page.screenshot({ path: `${DIR}/frame-${label}-${scheme}-drawer.png` })
}
await context.close()
})
109 changes: 109 additions & 0 deletions e2e/admin-frame.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { expect, test, type Page } from '@playwright/test'
import { expectAccessible, expectFitsScreen } from './helpers'

/** The new admin's frame (kit 0.9.0, playground /admin-next), on a plain page unless a path is given. */
async function openFrame(page: Page, query = '') {
await page.goto(`/admin-next?${query.includes('path=') ? query : `path=/admin/stats&${query}`}`)
await expect(page.getByRole('heading', { level: 1 })).toBeVisible()
}

for (const scheme of ['light', 'dark'] as const)
test(`the frame is accessible and fits the screen (${scheme})`, async ({ page }) => {
await openFrame(page, `scheme=${scheme}`)
await expectAccessible(page)
await expectFitsScreen(page)
})

test('long names wrap or cut, never widen the page', async ({ page }) => {
await openFrame(page, 'long=1')
await expectFitsScreen(page)
})

test('the skip link is first and moves focus to the page', async ({ page }) => {
await openFrame(page)
await page.keyboard.press('Tab')
const skip = page.getByRole('link', { name: 'Skip to content' })
await expect(skip).toBeFocused()
await expect(skip).toBeInViewport()
await page.keyboard.press('Enter')
await expect(page.locator('#admin-main')).toBeFocused()
})

test('⌘K, Ctrl+K and / open the search; / types normally inside a field', async ({ page }) => {
await openFrame(page)
await page.keyboard.press('Control+k')
await expect(page.getByText('Search opened 1 time.')).toBeVisible()
await page.keyboard.press('Meta+k')
await page.keyboard.press('/')
await expect(page.getByText('Search opened 3 times.')).toBeVisible()
})

test.describe('wide screens', () => {
test.skip(({ viewport }) => (viewport?.width ?? 0) < 1040, 'desktop only')

test('the nav is a column that stays put while the page scrolls', async ({ page }) => {
await openFrame(page)
await expect(page.getByRole('button', { name: 'Menu', exact: true })).toBeHidden()
const nav = page.getByRole('navigation', { name: 'Admin' })
await expect(nav).toBeVisible()
const before = await nav.boundingBox()
await page.evaluate(() => scrollTo(0, document.body.scrollHeight))
await expect.poll(() => page.evaluate(() => scrollY)).toBeGreaterThan(100)
expect((await nav.boundingBox())!.y).toBe(before!.y)
})

test('one current item; its section opens; choosing another moves the mark', async ({ page }) => {
await openFrame(page, 'path=/admin/users/roles')
const nav = page.getByRole('navigation', { name: 'Admin' })
await expect(nav.locator('[aria-current="page"]')).toHaveCount(1)
await expect(nav.getByRole('link', { name: 'Roles' })).toHaveAttribute('aria-current', 'page')
await nav.getByRole('link', { name: 'Analytics' }).click()
await expect(nav.getByRole('link', { name: 'Analytics' })).toHaveAttribute('aria-current', 'page')
await expect(nav.getByRole('link', { name: 'Roles' })).toHaveCount(0)
await expect(page.getByRole('heading', { level: 1 })).toHaveText('Analytics')
})

test('a number badge reads in full to screen readers', async ({ page }) => {
await openFrame(page)
await expect(page.getByRole('link', { name: 'Reports 12 pending' })).toBeVisible()
})
})

test.describe('phones and tablets', () => {
test.skip(({ viewport }) => (viewport?.width ?? 0) >= 1040, 'narrow screens only')

test('the nav is a drawer: focus goes in, Esc closes it, focus comes back', async ({ page }) => {
await openFrame(page)
await expect(page.getByRole('navigation', { name: 'Admin' })).toHaveCount(0)
const menu = page.getByRole('button', { name: 'Menu', exact: true })
await expect(menu).toHaveAttribute('aria-expanded', 'false')
await menu.click()
const drawer = page.getByRole('dialog', { name: 'Admin' })
await expect(drawer).toBeVisible()
await expect(menu).toHaveAttribute('aria-expanded', 'true')
await expect(drawer.getByRole('button', { name: 'Close menu' })).toBeFocused()
await expectAccessible(page)
await page.keyboard.press('Escape')
await expect(drawer).toBeHidden()
await expect(menu).toBeFocused()
await expect(menu).toHaveAttribute('aria-expanded', 'false')
})

test('choosing a page closes the drawer; so does the scrim', async ({ page }) => {
await openFrame(page)
await page.getByRole('button', { name: 'Menu', exact: true }).click()
await page.getByRole('dialog', { name: 'Admin' }).getByRole('link', { name: 'Reports 12 pending' }).click()
await expect(page.getByRole('dialog', { name: 'Admin' })).toBeHidden()
await expect(page.getByRole('heading', { level: 1 })).toHaveText('Reports')
await page.getByRole('button', { name: 'Menu', exact: true }).click()
await expect(page.getByRole('dialog', { name: 'Admin' })).toBeVisible()
await page.mouse.click(380, 400) // right of the panel: the scrim
await expect(page.getByRole('dialog', { name: 'Admin' })).toBeHidden()
})

test('touch targets are at least 44 px', async ({ page }) => {
await openFrame(page)
for (const name of ['Menu', 'Search'])
expect((await page.getByRole('button', { name, exact: true }).boundingBox())!.height).toBeGreaterThanOrEqual(44)
})
})
102 changes: 102 additions & 0 deletions e2e/admin-list-screenshots.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { test, type Page } from '@playwright/test'

/**
* Review screenshots of the new admin's list page for the owner, light and dark, desktop (1280) and
* phone (390), plus a short recording of the list in use (desktop). Saved to SCREENSHOTS_DIR
* (default .screenshots/admin). `bun --bun playwright test e2e/admin-list-screenshots.spec.ts`.
*/
const DIR = process.env.SCREENSHOTS_DIR ?? '.screenshots/admin'
const sizes = { desktop: { width: 1280, height: 800 }, phone: { width: 390, height: 844 } }
const ready = async (page: Page) => {
await page.locator('[data-slot="admin-index"] [data-row-id]').filter({ visible: true }).first().waitFor()
await page.evaluate(() => document.fonts.ready)
await page.waitForTimeout(300)
}

for (const scheme of ['light', 'dark'] as const)
for (const [label, viewport] of Object.entries(sizes))
test(`@screenshots admin list ${label} ${scheme}`, async ({ browser }) => {
const phone = label === 'phone'
const context = await browser.newContext({ viewport, hasTouch: phone, isMobile: phone })
const page = await context.newPage()
const shot = (name: string) => page.screenshot({ path: `${DIR}/list-${label}-${scheme}-${name}.png` })
const base = `/admin-next?scheme=${scheme}&path=/admin/users`

await page.goto(base)
await page.waitForTimeout(150)
await shot('1-first-load')
await ready(page)
await shot('2-list')

await page.goto(`${base}&status=suspended,banned&sort=name`)
await ready(page)
await shot('3-filtered')

// The previous rows stay, faded, with the loading bar, while the next ones load.
await page.getByRole('combobox', { name: 'Role' }).selectOption('user')
await page.waitForTimeout(240)
await shot('4-refreshing')
await ready(page)

await page.goto(base)
await ready(page)
if (phone) await page.getByRole('button', { name: 'Select', exact: true }).click()
for (const index of [0, 1, 2])
await page.locator('[data-row-id]').filter({ visible: true }).nth(index).locator('[type="checkbox"]').click()
await page.waitForTimeout(200)
await shot('5-selected')
if (!phone) {
await page.getByRole('checkbox', { name: 'Select all on this page' }).check()
await page.waitForTimeout(200)
await shot('6-page-selected')
}
await page.locator('[data-slot="admin-bulk-bar"]').getByRole('button', { name: 'Suspend' }).click()
await page.waitForTimeout(350)
await shot('7-undo-toast')

await page.goto(`${base}&q=zzz`)
await page.getByText('No users found').filter({ visible: true }).waitFor()
await shot('8-no-results')
await context.close()
})

test('@screenshots admin list recording', async ({ browser }) => {
const context = await browser.newContext({
viewport: sizes.desktop,
recordVideo: { dir: `${DIR}/video`, size: sizes.desktop },
})
const page = await context.newPage()
const pause = (ms = 700) => page.waitForTimeout(ms)
await page.goto('/admin-next?path=/admin/users&scheme=light')
await ready(page)
await pause()
await page.getByRole('searchbox', { name: 'Search users' }).pressSequentially('ada', { delay: 140 })
await pause(1200)
await page.getByRole('combobox', { name: 'Status' }).selectOption('active')
await pause(1200)
await page.getByRole('button', { name: 'Remove filter Status: Active' }).click()
await page.getByRole('button', { name: 'Clear all' }).click()
await pause(1200)
await page.keyboard.press('j')
await pause(300)
await page.keyboard.press('x')
await pause(300)
await page.keyboard.press('j')
await page.keyboard.press('j')
await pause(300)
await page.keyboard.press('Shift+X')
await pause(1000)
await page.locator('[data-slot="admin-bulk-bar"]').getByRole('button', { name: 'Suspend' }).click()
await pause(1500)
await page.getByRole('button', { name: 'Undo' }).click()
await pause(1200)
await page.getByRole('link', { name: 'Next page' }).click()
await pause(1200)
await page.getByRole('button', { name: 'Posts' }).click()
await pause(1200)
await page.locator('[data-slot="admin-table"] tbody tr').nth(3).locator('td').last().click()
await pause(900)
await page.goBack()
await pause(1200)
await context.close()
})
Loading
Loading