Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 129 additions & 78 deletions Conformance/src/runConformance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ const interactionMessages = {
dismissal: 'The slot dismisses on Escape.',
} as const;

const recordInteractions = (
checks: ConformanceCheck[],
profile: SlotProfile,
observed: Awaited<ReturnType<NonNullable<SlotProfile['interact']>>>,
) => {
for (const concern of ['keyboard', 'focus', 'dismissal'] as const) {
const passed = observed[concern];
if (passed === undefined) continue;
addCheck(
checks,
ConformanceFamily.Behavior,
`behavior.${profile.slotId}.${concern}`,
{
passed,
message: passed
? interactionMessages[concern]
: `${interactionMessages[concern]} It did not respond as required.`,
slotId: profile.slotId,
evidence: { concern, passed, ...observed.detail },
},
);
}
};

/**
* Drives a fresh fixture of a stable atomic slot with dispatched keyboard and focus events and adds
* one check per concern the slot reports: `behavior.<slot>.keyboard`, `.focus` and `.dismissal`.
Expand All @@ -154,23 +178,7 @@ const checkInteractions = async (
const interacted =
(await act(async () => profile.interact?.(document, mounted.container))) ?? {};
const observed = { ...interacted, ...(await interacted.settled?.()) };
for (const concern of ['keyboard', 'focus', 'dismissal'] as const) {
const passed = observed[concern];
if (passed === undefined) continue;
addCheck(
checks,
ConformanceFamily.Behavior,
`behavior.${profile.slotId}.${concern}`,
{
passed,
message: passed
? interactionMessages[concern]
: `${interactionMessages[concern]} It did not respond as required.`,
slotId: profile.slotId,
evidence: { concern, passed, ...observed.detail },
},
);
}
recordInteractions(checks, profile, observed);
} catch (error) {
addError(checks, ConformanceFamily.Behavior, `behavior.${profile.slotId}.interaction`, { error, slotId: profile.slotId });
} finally {
Expand Down Expand Up @@ -317,7 +325,7 @@ const isImmutableLibrary = (library: unstable_UiLibrary) =>
(declaration) => declaration === undefined || Object.isFrozen(declaration),
);

const checkManifest = (
const checkMetadata = (
checks: ConformanceCheck[],
library: unstable_UiLibrary,
options: ConformanceOptions,
Expand Down Expand Up @@ -364,6 +372,14 @@ const checkManifest = (
);
}

};

const checkManifest = (
checks: ConformanceCheck[],
library: unstable_UiLibrary,
options: ConformanceOptions,
) => {
checkMetadata(checks, library, options);
const overDeclarations = overDeclaredCapabilities(library);
addCheck(
checks,
Expand Down Expand Up @@ -858,49 +874,55 @@ const checkStateCoverage = (
);
};

const checkServerRendering = (
const checkSlotServerRendering = (
checks: ConformanceCheck[],
library: unstable_UiLibrary,
profiles: readonly SlotProfile[],
wrapper: ConformanceOptions['wrapper'],
{ library, profile, wrapper }: {
library: unstable_UiLibrary;
profile: SlotProfile;
wrapper: ConformanceOptions['wrapper'];
},
outputs: Map<unstable_SlotId, string>,
) => {
const outputs = new Map<unstable_SlotId, string>();
for (const profile of profiles) {
const declaration = library.slots[profile.slotId];
if (!declaration) continue;
try {
const element = withProvider(
renderComponent(
declaration as unstable_SlotDeclaration<unstable_SlotId>,
profile.createProps(),
),
wrapper,
);
const first = renderToString(element);
const second = renderToString(element);
outputs.set(profile.slotId, first);
addCheck(
checks,
ConformanceFamily.ServerRendering,
`ssr.${profile.slotId}`,
{
passed: first === second,
message: first === second
? 'Server render is DOM-free and deterministic.'
: 'Repeated server renders differ.',
slotId: profile.slotId,
evidence: { bytes: first.length },
},
);
} catch (error) {
addError(
checks,
ConformanceFamily.ServerRendering,
`ssr.${profile.slotId}`,
{ error, slotId: profile.slotId },
);
}
const declaration = library.slots[profile.slotId];
if (!declaration) return;
try {
const element = withProvider(
renderComponent(
declaration as unstable_SlotDeclaration<unstable_SlotId>,
profile.createProps(),
),
wrapper,
);
const first = renderToString(element);
const second = renderToString(element);
outputs.set(profile.slotId, first);
addCheck(
checks,
ConformanceFamily.ServerRendering,
`ssr.${profile.slotId}`,
{
passed: first === second,
message: first === second
? 'Server render is DOM-free and deterministic.'
: 'Repeated server renders differ.',
slotId: profile.slotId,
evidence: { bytes: first.length },
},
);
} catch (error) {
addError(
checks,
ConformanceFamily.ServerRendering,
`ssr.${profile.slotId}`,
{ error, slotId: profile.slotId },
);
}
};

const checkServerOverlays = (
checks: ConformanceCheck[],
outputs: ReadonlyMap<unstable_SlotId, string>,
) => {
const tooltipOutput = outputs.get('common.tooltip');
const dialogOutput = outputs.get('dialogs.dialog');
const overlayPassed =
Expand All @@ -922,6 +944,12 @@ const checkServerRendering = (
},
},
);
};

const checkServerOutputIsolation = (
checks: ConformanceCheck[],
outputs: ReadonlyMap<unstable_SlotId, string>,
) => {
const distinctOutputs = new Set(outputs.values()).size === outputs.size;
addCheck(
checks,
Expand All @@ -937,6 +965,20 @@ const checkServerRendering = (
);
};

const checkServerRendering = (
checks: ConformanceCheck[],
library: unstable_UiLibrary,
profiles: readonly SlotProfile[],
wrapper: ConformanceOptions['wrapper'],
) => {
const outputs = new Map<unstable_SlotId, string>();
for (const profile of profiles) {
checkSlotServerRendering(checks, { library, profile, wrapper }, outputs);
}
checkServerOverlays(checks, outputs);
checkServerOutputIsolation(checks, outputs);
};

const checkHydration = async (
checks: ConformanceCheck[],
library: unstable_UiLibrary,
Expand Down Expand Up @@ -995,6 +1037,34 @@ const checkHydration = async (
);
};

const recordEnvironmentalEvidence = (
checks: ConformanceCheck[],
profile: SlotProfile,
native: Element | null,
host: HTMLElement,
) => {
const inputs = {
rtl: Boolean(native) && native?.closest('[dir="rtl"]') === host,
forcedColors: Boolean(native) && host.style.forcedColorAdjust === 'auto',
'motion.reduced': Boolean(native) && host.style.transitionDuration === '0s',
} as const;
for (const mode of ['rtl', 'forcedColors', 'motion.reduced'] as const) {
addCheck(
checks,
ConformanceFamily.Accessibility,
`a11y.environment.${mode}`,
{
passed: inputs[mode],
message: inputs[mode]
? `The ${profile.slotId} fixture rendered inside the bounded ${mode} DOM host input.`
: `The ${profile.slotId} fixture did not preserve the bounded ${mode} DOM host input.`,
slotId: profile.slotId,
evidence: { selector: profile.nativeSelector },
},
);
}
};

const checkEnvironmentalEvidence = async (
checks: ConformanceCheck[],
document: Document,
Expand Down Expand Up @@ -1036,26 +1106,7 @@ const checkEnvironmentalEvidence = async (
host,
);
const native = fixture.container.querySelector(profile.nativeSelector);
const inputs = {
rtl: Boolean(native) && native?.closest('[dir="rtl"]') === host,
forcedColors: Boolean(native) && host.style.forcedColorAdjust === 'auto',
'motion.reduced': Boolean(native) && host.style.transitionDuration === '0s',
} as const;
for (const mode of ['rtl', 'forcedColors', 'motion.reduced'] as const) {
addCheck(
checks,
ConformanceFamily.Accessibility,
`a11y.environment.${mode}`,
{
passed: inputs[mode],
message: inputs[mode]
? `The ${profile.slotId} fixture rendered inside the bounded ${mode} DOM host input.`
: `The ${profile.slotId} fixture did not preserve the bounded ${mode} DOM host input.`,
slotId: profile.slotId,
evidence: { selector: profile.nativeSelector },
},
);
}
recordEnvironmentalEvidence(checks, profile, native, host);
} catch (error) {
for (const mode of ['rtl', 'forcedColors', 'motion.reduced'] as const) {
addError(
Expand Down
33 changes: 13 additions & 20 deletions Source/DataTables/DataTableForObservableQuery.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,20 @@ class LiveTasksQuery extends TasksQuery {

// Status/priority render as theme-aware Tags with a severity, which stay
// WCAG-legible on both light and dark surfaces (unlike fixed text colors).
const getStatusSeverity = (status: string): TagSeverity => {
switch (status) {
case 'done':
return 'success';
case 'in-progress':
return 'info';
default:
return 'secondary';
}
};
const statusSeverities = new Map<string, TagSeverity>([
['done', 'success'],
['in-progress', 'info'],
]);
const prioritySeverities = new Map<string, TagSeverity>([
['high', 'danger'],
['medium', 'warn'],
]);

const getPrioritySeverity = (priority: string): TagSeverity => {
switch (priority) {
case 'high':
return 'danger';
case 'medium':
return 'warn';
default:
return 'secondary';
}
};
const getStatusSeverity = (status: string): TagSeverity =>
statusSeverities.get(status) ?? 'secondary';

const getPrioritySeverity = (priority: string): TagSeverity =>
prioritySeverities.get(priority) ?? 'secondary';

export const Default: Story = {
render: () => (
Expand Down
Loading
Loading