Phone hit editor tests: pin estate Targets nesting and selector, ClientRoot inline absolute, sidebar gap
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 3m33s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Void 2026-11-13 07:21:57 +00:00
commit 761d13fac5

View file

@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import { MOBILE_BREAKPOINT } from './hooks/useScreenSize';
import {
classLists,
emitted,
expectPhoneHitClasses,
expectSizeTie,
@ -23,7 +24,8 @@ describe('icon buttons in the editor, emoji board, upload cards and client root'
'PhoneHit', // Exit chip: text label, wider than 44 px
'PhoneHit', // markdown toggle, alone at the end of the toolbar
],
// A column of 40 px buttons: there is no vertical variant, so only PhoneHit; neighbours overlap by their 2 px gap.
// A column of 40 px buttons 4 px apart (the stack's gap="100", pinned below): there is no vertical variant, so only
// PhoneHit; the 44 px areas then touch with no overlap.
'components/emoji-board/components/Sidebar.tsx': ['PhoneHit'],
// Both cards put a Retry chip beside the cancel button when the upload failed.
'components/upload-card/UploadCardRenderer.tsx': ['PhoneHitSpread28'],
@ -43,19 +45,63 @@ describe('icon buttons in the editor, emoji board, upload cards and client root'
);
});
/** The JSX element opened at `open` (index of its `<Box`), to its matching `</Box>`: nesting is counted, not guessed (no self-closing Box here). */
const boxSpan = (src: string, open: number) => {
const marks = [...src.slice(open).matchAll(/<Box(?=[\s>])|<\/Box>/g)];
const depths = marks.map((m, i) =>
marks.slice(0, i + 1).reduce((d, x) => d + (x[0] === '</Box>' ? -1 : 1), 0)
);
const end = depths.indexOf(0);
if (end === -1) throw new Error('unbalanced <Box>');
return [open, open + (marks[end].index ?? 0) + marks[end][0].length] as const;
};
describe('the estate navigator find button', () => {
// The only IconButton there needs no PhoneHit: every button in the navigator header is 44 px on a phone because
// the Targets class sets a min size, and the button sits under that class.
// the Targets class sets a min size, and the button sits inside the Box that carries that class.
it('is 44 px by the Targets class instead', async () => {
const src = readSource('features/estate/EstateNavigator.tsx');
const tags = iconButtonTags(src);
expect(tags).toHaveLength(1);
expect(tags[0]).not.toMatch(/PhoneHit/);
const header = src.slice(src.indexOf('<PageNavHeader>'));
expect(header.indexOf('className={css.Targets}')).toBeGreaterThan(-1);
expect(header.indexOf('className={css.Targets}')).toBeLessThan(header.indexOf('<IconButton'));
const header = src.indexOf('<PageNavHeader>');
const boxStart = src.indexOf('<Box', header);
const [from, to] = boxSpan(src, boxStart);
expect(src.slice(boxStart, src.indexOf('>', boxStart))).toMatch(/className=\{css\.Targets\}/);
const button = src.indexOf('<IconButton');
expect(button).toBeGreaterThan(from);
expect(button).toBeLessThan(to);
// The rule is on the Targets class's own ident, for buttons, at the phone breakpoint.
const ident = (await classLists('features/estate/EstateNavigator.css.ts')).Targets[0];
const css = await emitted('features/estate/EstateNavigator.css.ts');
const phone = rulesFor(css, /button/, `screen and (max-width: ${MOBILE_BREAKPOINT}px)`);
expect(phone).toContainEqual({ 'min-height': 44, 'min-width': 44 });
const phone = rulesFor(
css,
new RegExp(`^\\.${ident} button(,|$)`),
`screen and (max-width: ${MOBILE_BREAKPOINT}px)`
);
expect(phone).toEqual([{ 'min-height': 44, 'min-width': 44 }]);
});
});
describe('what the PhoneHit class relies on', () => {
// PhoneHit makes the button position: relative on a phone; the inline style wins over a class, so the corner
// button stays absolute and its ::after anchors to it.
it('ClientRoot keeps its corner button absolutely positioned inline', () => {
const [tag] = iconButtonTags(readSource('pages/client/ClientRoot.tsx'));
expect(tag).toMatch(/style=\{\{[^}]*position:\s*'absolute'/);
});
// A 40 px button with a 44 px area, in a column 4 px apart: the areas touch and do not overlap. A smaller gap
// overlaps them, a larger one leaves a dead strip.
it('the emoji sidebar stack keeps its 4 px gap', () => {
const src = readSource('components/emoji-board/components/Sidebar.tsx');
const stack = src.slice(
src.indexOf('export const SidebarStack'),
src.indexOf('export function SidebarDivider')
);
expect(stack).toMatch(/direction="Column"/);
expect(stack).toMatch(/gap="100"/);
});
});