An open source design system that's fully customizable and agent ready
TypeScript
// Copyright (c) Meta Platforms, Inc. and affiliates.
// @pr-a11y scope ^(internal/a11y-spec/src/patterns/menu-button|packages/core/src/DropdownMenu/|packages/core/src/MoreMenu/|apps/storybook/stories/MenuButtonA11y)
/**
* @file menu-button.chromium.spec.ts
* @input MENU_BUTTON_PATTERN and its fixtures in real Chromium
* @output Proof that every expectation passes conforming fixtures and fails its mutation at the layers only a browser observes
* @position Contract self-test, Chromium lane
*/
import {expect, test, type CDPSession, type Page} from '../playwright';
import {describeExpectation, requiredLayers} from '../contract';
import {checkAccessibilitySpec, type ExpectationResult} from '../check';
import {
CHROMIUM_OBSERVES,
createChromiumHarness,
holdMotionStill,
} from '../harness/chromium';
import {MENU_BUTTON_PATTERN} from './menu-button';
import {
MENU_BUTTON_MUTATIONS,
CONFORMING_FIXTURES,
FIRST_ITEM_SELECTOR,
LAST_ITEM_SELECTOR,
MENU_SELECTOR,
SUBJECT_SELECTOR,
fixture,
type MenuButtonFixture,
} from './menu-button.fixtures';
function fixturePage(html: string): string {
return `<!doctype html><html lang="en"><body>${html}<button type="button" id="after">After menu</button></body></html>`;
}
async function results(
page: Page,
cdp: CDPSession,
target: MenuButtonFixture,
only?: readonly string[],
): Promise<readonly ExpectationResult[]> {
const run = await checkAccessibilitySpec({
spec: MENU_BUTTON_PATTERN,
binding: 'fixture',
state: target.id,
facts: target.facts,
only,
mount: async () => {
await page.setContent(fixturePage(target.html));
await holdMotionStill(page);
return createChromiumHarness({
page,
cdp,
subject: page.locator(SUBJECT_SELECTOR),
related: {
menu: page.locator(MENU_SELECTOR),
'first-item': page.locator(FIRST_ITEM_SELECTOR),
'last-item': page.locator(LAST_ITEM_SELECTOR),
},
});
},
});
return run.results;
}
test.describe('menu-button contract — conforming fixtures', () => {
for (const id of CONFORMING_FIXTURES) {
test(`${id}: every applicable expectation passes`, async ({page}) => {
const cdp = await page.context().newCDPSession(page);
const observed = await results(page, cdp, fixture(id));
expect(
observed
.filter(
result =>
result.status !== 'pass' && result.status !== 'not-applicable',
)
.map(result => `${result.expectation}: ${result.detail ?? ''}`),
).toEqual([]);
});
}
});
test.describe('menu-button contract — deliberately violating fixtures', () => {
for (const expectation of MENU_BUTTON_PATTERN.expectations) {
if (
!requiredLayers(expectation).every(layer =>
CHROMIUM_OBSERVES.includes(layer),
)
) {
continue;
}
for (const fixtureId of MENU_BUTTON_MUTATIONS[expectation.id] ?? []) {
test(`${describeExpectation(expectation)} — fails against ${fixtureId}`, async ({
page,
}) => {
const cdp = await page.context().newCDPSession(page);
const [result] = await results(page, cdp, fixture(fixtureId), [
expectation.id,
]);
expect(result?.status, result?.detail ?? 'no result').toBe('fail');
expect(result?.detail ?? '').not.toBe('');
});
}
}
});