|
| 1 | +import { test, expect } from './fixtures/server' |
| 2 | + |
| 3 | +// docs/goals/0096-display-density.md: Comfortable/Compact, a |
| 4 | +// Settings-driven app root attribute (data-density) that tightens |
| 5 | +// row-based surfaces' vertical padding. Measures a real workflow row's |
| 6 | +// rendered height rather than any internal Primer class/DOM shape -- |
| 7 | +// robust to how ActionList happens to structure its own markup, and a |
| 8 | +// direct proxy for the CSS custom property chain this goal wires |
| 9 | +// (index.css's --mill-density-row-pad-y -> InventoryList.module.css's |
| 10 | +// --control-medium-paddingBlock override). |
| 11 | + |
| 12 | +async function firstWorkflowRow(page: import('@playwright/test').Page) { |
| 13 | + await page.getByRole('link', { name: 'Workflows' }).click() |
| 14 | + const row = page.locator('[data-testid="inventory-row"][data-entity="workflow"]').first() |
| 15 | + await expect(row).toBeVisible() |
| 16 | + return row |
| 17 | +} |
| 18 | + |
| 19 | +async function setDensity(page: import('@playwright/test').Page, label: 'Comfortable' | 'Compact') { |
| 20 | + await page.getByRole('link', { name: 'Settings' }).click() |
| 21 | + await expect(page.getByTestId('settings-view')).toBeVisible() |
| 22 | + await page.getByTestId('density-control').getByRole('button', { name: label }).click() |
| 23 | +} |
| 24 | + |
| 25 | +test('Compact visibly tightens a workflow row, persists across reload, and Comfortable restores the original height', async ({ page }) => { |
| 26 | + await page.goto('/') |
| 27 | + |
| 28 | + const comfortableRow = await firstWorkflowRow(page) |
| 29 | + const comfortableBox = await comfortableRow.boundingBox() |
| 30 | + const comfortableHeight = comfortableBox?.height ?? 0 |
| 31 | + expect(comfortableHeight).toBeGreaterThan(0) |
| 32 | + |
| 33 | + await setDensity(page, 'Compact') |
| 34 | + const compactRow = await firstWorkflowRow(page) |
| 35 | + await expect.poll(async () => (await compactRow.boundingBox())?.height ?? 0).toBeLessThan(comfortableHeight) |
| 36 | + |
| 37 | + await page.reload() |
| 38 | + const afterReloadRow = await firstWorkflowRow(page) |
| 39 | + await expect.poll(async () => (await afterReloadRow.boundingBox())?.height ?? 0).toBeLessThan(comfortableHeight) |
| 40 | + |
| 41 | + // Leaves the shared e2e settings file back at the default, matching |
| 42 | + // this repo's other settings specs' own cleanup discipline. |
| 43 | + await setDensity(page, 'Comfortable') |
| 44 | + const restoredRow = await firstWorkflowRow(page) |
| 45 | + await expect.poll(async () => (await restoredRow.boundingBox())?.height ?? 0).toBe(comfortableHeight) |
| 46 | +}) |
| 47 | + |
| 48 | +test('Density select reflects the persisted preference on a fresh Settings visit', async ({ page }) => { |
| 49 | + await page.goto('/') |
| 50 | + await setDensity(page, 'Compact') |
| 51 | + |
| 52 | + await page.reload() |
| 53 | + await page.getByRole('link', { name: 'Settings' }).click() |
| 54 | + await expect(page.getByTestId('density-control').getByRole('button', { name: 'Compact' })).toHaveAttribute('aria-pressed', 'true') |
| 55 | + |
| 56 | + // Cleanup, same reasoning as the test above. |
| 57 | + await setDensity(page, 'Comfortable') |
| 58 | +}) |
| 59 | + |
| 60 | +test.describe('mobile viewport', () => { |
| 61 | + test.use({ viewport: { width: 390, height: 844 } }) |
| 62 | + |
| 63 | + test('Compact keeps a 44px workflow row touch target at the companion breakpoint', async ({ page }) => { |
| 64 | + await page.goto('/') |
| 65 | + await page.getByTestId('mobile-nav-toggle').click() |
| 66 | + await page.getByRole('link', { name: 'Settings' }).click() |
| 67 | + await expect(page.getByTestId('settings-view')).toBeVisible() |
| 68 | + await page.getByTestId('density-control').getByRole('button', { name: 'Compact' }).click() |
| 69 | + |
| 70 | + await page.getByTestId('mobile-nav-toggle').click() |
| 71 | + const row = await firstWorkflowRow(page) |
| 72 | + const box = await row.boundingBox() |
| 73 | + expect(box?.height ?? 0).toBeGreaterThanOrEqual(44) |
| 74 | + |
| 75 | + // Cleanup, same reasoning as the tests above. |
| 76 | + await page.getByTestId('mobile-nav-toggle').click() |
| 77 | + await page.getByRole('link', { name: 'Settings' }).click() |
| 78 | + await page.getByTestId('density-control').getByRole('button', { name: 'Comfortable' }).click() |
| 79 | + }) |
| 80 | +}) |
0 commit comments