|
| 1 | +// Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | + |
| 3 | +/** |
| 4 | + * @file ListTouchRows.interaction.browser.spec.ts |
| 5 | + * @input The built List stories in the touch phone context (primary pointer |
| 6 | + * coarse) and the row heights from the UIKit constants table |
| 7 | + * (motion/uikit/list.ts) |
| 8 | + * @output Layout proofs for List rows on a touch screen: a one-line row is |
| 9 | + * UIKit's table row height, a row with a description its subtitle height, |
| 10 | + * a compact row the platform's control size, dividers included; a |
| 11 | + * storyboard of the three |
| 12 | + * @position Interaction evidence for ListItem's touch row heights |
| 13 | + * (listRow.stylex.ts) |
| 14 | + */ |
| 15 | + |
| 16 | +import {expect, test, type Page} from '@playwright/test'; |
| 17 | +import { |
| 18 | + openStory, |
| 19 | + Storyboard, |
| 20 | + withStorybook, |
| 21 | +} from '@astryxdesign/interaction-harness'; |
| 22 | +import {list} from '../../motion/uikit/list'; |
| 23 | + |
| 24 | +const storybook = withStorybook(test); |
| 25 | + |
| 26 | +async function rowHeights(page: Page): Promise<number[]> { |
| 27 | + // The story's rows (Storybook's own hidden error page has list items too). |
| 28 | + return page |
| 29 | + .locator('#storybook-root li') |
| 30 | + .evaluateAll(rows => |
| 31 | + rows.map(row => Math.round(row.getBoundingClientRect().height)), |
| 32 | + ); |
| 33 | +} |
| 34 | + |
| 35 | +const isTouch = async (page: Page) => |
| 36 | + page.evaluate(() => matchMedia('(pointer: coarse)').matches); |
| 37 | + |
| 38 | +const CASES = [ |
| 39 | + { |
| 40 | + story: 'core-list--interactive', |
| 41 | + what: 'a one-line row is UIKit’s table row height', |
| 42 | + height: list.metrics.rowHeight, |
| 43 | + }, |
| 44 | + { |
| 45 | + story: 'core-list--basic', |
| 46 | + what: 'a row with a description is UIKit’s subtitle row height', |
| 47 | + height: list.metrics.subtitleRowHeight, |
| 48 | + }, |
| 49 | + { |
| 50 | + story: 'core-list--compact', |
| 51 | + what: 'a compact row, divider included, is the platform’s control size', |
| 52 | + height: list.metrics.controlSize, |
| 53 | + }, |
| 54 | +] as const; |
| 55 | + |
| 56 | +test('on a touch screen, spacious density keeps its padding over the same minimum', async ({ |
| 57 | + page, |
| 58 | +}) => { |
| 59 | + await openStory(page, storybook(), 'core-list--spacious'); |
| 60 | + test.skip( |
| 61 | + !(await isTouch(page)), |
| 62 | + 'this engine reports a fine primary pointer; the touch heights apply under (pointer: coarse)', |
| 63 | + ); |
| 64 | + const rows = await page.locator('#storybook-root li').evaluateAll(elements => |
| 65 | + elements.map(el => { |
| 66 | + const style = getComputedStyle(el); |
| 67 | + return { |
| 68 | + height: el.getBoundingClientRect().height, |
| 69 | + paddingTop: style.paddingTop, |
| 70 | + minHeight: style.minHeight, |
| 71 | + }; |
| 72 | + }), |
| 73 | + ); |
| 74 | + expect(rows.length).toBeGreaterThan(0); |
| 75 | + for (const row of rows) { |
| 76 | + // Its rows have descriptions: the subtitle minimum, which spacious |
| 77 | + // padding already exceeds, so the row keeps its own taller height. |
| 78 | + expect(row.minHeight).toBe(`${list.metrics.subtitleRowHeight}px`); |
| 79 | + expect(row.paddingTop).toBe('12px'); |
| 80 | + expect(row.height).toBeGreaterThanOrEqual(list.metrics.subtitleRowHeight); |
| 81 | + } |
| 82 | +}); |
| 83 | + |
| 84 | +for (const {story, what, height} of CASES) { |
| 85 | + test(`on a touch screen, ${what}`, async ({page}) => { |
| 86 | + await openStory(page, storybook(), story); |
| 87 | + test.skip( |
| 88 | + !(await isTouch(page)), |
| 89 | + 'this engine reports a fine primary pointer; the touch heights apply under (pointer: coarse)', |
| 90 | + ); |
| 91 | + const heights = await rowHeights(page); |
| 92 | + expect(heights.length).toBeGreaterThan(0); |
| 93 | + for (const h of heights) { |
| 94 | + expect(h).toBe(height); |
| 95 | + } |
| 96 | + }); |
| 97 | +} |
| 98 | + |
| 99 | +test('storyboard: List rows on a touch screen @storyboard', async ({ |
| 100 | + page, |
| 101 | +}, testInfo) => { |
| 102 | + test.skip( |
| 103 | + testInfo.project.name !== 'chromium', |
| 104 | + 'One engine is enough for the record', |
| 105 | + ); |
| 106 | + const storyboard = new Storyboard(page, { |
| 107 | + name: 'list-touch-rows', |
| 108 | + columns: 3, |
| 109 | + cellScale: 0.6, |
| 110 | + }); |
| 111 | + for (const {story} of CASES) { |
| 112 | + await openStory(page, storybook(), story); |
| 113 | + // One clip size for every cell of the sheet. |
| 114 | + await page.setViewportSize({width: 402, height: 714}); |
| 115 | + await storyboard.capture(story, 0, {rows: await rowHeights(page)}); |
| 116 | + } |
| 117 | + await storyboard.write(testInfo); |
| 118 | +}); |
0 commit comments