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/alert-dialog|internal/a11y-spec/src/harness|packages/core/src/AlertDialog/|packages/core/src/Dialog/|apps/storybook/stories/AlertDialogA11y)
/**
* @file alert-dialog.chromium.spec.ts
* @input ALERT_DIALOG_PATTERN and its fixtures in real Chromium (an invoker opens the native dialog; the fixture script implements Escape and the click-beside rule)
* @output Proof that every expectation passes the conforming fixture 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 {ALERT_DIALOG_PATTERN} from './alert-dialog';
import {
ALERT_DIALOG_MUTATIONS,
CONFORMING_FIXTURES,
INVOKER_SELECTOR,
RELATION_SELECTORS,
SUBJECT_SELECTOR,
fixture,
type AlertDialogFixture,
} from './alert-dialog.fixtures';
function fixturePage(html: string): string {
return `<!doctype html><html lang="en"><body>${html}</body></html>`;
}
async function results(
page: Page,
cdp: CDPSession,
target: AlertDialogFixture,
only?: readonly string[],
): Promise<readonly ExpectationResult[]> {
const run = await checkAccessibilitySpec({
spec: ALERT_DIALOG_PATTERN,
binding: 'fixture',
state: target.id,
facts: target.facts,
only,
mount: async () => {
await page.setContent(fixturePage(target.html));
await holdMotionStill(page);
// The surface opens the way a person reaches it: through its invoker.
await page.locator(INVOKER_SELECTOR).click();
await page.locator(SUBJECT_SELECTOR).waitFor({state: 'visible'});
return createChromiumHarness({
page,
cdp,
subject: page.locator(SUBJECT_SELECTOR),
related: Object.fromEntries(
Object.entries(RELATION_SELECTORS).map(([name, selector]) => [
name,
page.locator(selector),
]),
),
});
},
});
return run.results;
}
test.describe('alert-dialog 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('alert-dialog contract — deliberately violating fixtures', () => {
for (const expectation of ALERT_DIALOG_PATTERN.expectations) {
if (
!requiredLayers(expectation).every(layer =>
CHROMIUM_OBSERVES.includes(layer),
)
) {
continue;
}
for (const fixtureId of ALERT_DIALOG_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('');
});
}
}
});