@bevelo/testing 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,311 @@
1
+ import { Description, accessibleName, accessibleRole } from "@bevelo/core";
2
+ interface MountOptions {
3
+ /** Where the component is appended. Defaults to a fresh div in document.body. */
4
+ readonly container?: HTMLElement;
5
+ }
6
+ /** The part of a component instance mount() relies on. */
7
+ interface MountableInstance<Props extends object, Api> {
8
+ readonly element: HTMLElement;
9
+ readonly api: Api;
10
+ update(next: Props): void;
11
+ dispose(): void;
12
+ }
13
+ /** A mounted component plus the queries a test needs. */
14
+ interface Mounted<Props extends object, Instance extends MountableInstance<Props, unknown>> {
15
+ /** The component's own root element. Queries and events are scoped to it. */
16
+ readonly root: HTMLElement;
17
+ /** The component instance, for tests that need more than the DOM. */
18
+ readonly instance: Instance;
19
+ /** The component's imperative surface. */
20
+ readonly api: Instance["api"];
21
+ /** Replaces props and settles the render before returning. */
22
+ update(props: Props): void;
23
+ /** Runs pending reactive effects. Call after an interaction. */
24
+ flush(): void;
25
+ /** Disposes the instance and removes the component (and the wrapper mount
26
+ * created, if any). Idempotent. */
27
+ dispose(): void;
28
+ /** The first descendant (or the root) matching a selector. */
29
+ query(selector: string): HTMLElement | null;
30
+ /** Every descendant (or the root) matching a selector. */
31
+ queryAll(selector: string): HTMLElement[];
32
+ /** The element with this accessible role, optionally with this accessible name. */
33
+ get(role: string, name?: string): HTMLElement;
34
+ /** Dispatches keydown to the focused element (or a named one) and returns it. */
35
+ press(key: string, target?: Element | string): KeyboardEvent;
36
+ /** Clicks the root, or a named element inside it. */
37
+ click(target?: Element | string): void;
38
+ /** The root's serialised markup, for snapshotting a whole component. */
39
+ html(): string;
40
+ }
41
+ /**
42
+ * Creates a component, appends it to a container, settles the first render and
43
+ * returns queries scoped to the component's root.
44
+ *
45
+ * The wrapper div is removed by dispose(); a caller-provided container is left
46
+ * in place, because the test owns it.
47
+ */
48
+ export declare function mount<Props extends object, Instance extends MountableInstance<Props, unknown>>(factory: (props?: Props) => Instance, props?: NoInfer<Props>, options?: MountOptions): Mounted<Props, Instance>;
49
+ /** An attribute value a test can assert: `null` and `false` mean "absent". */
50
+ type AriaAttributeValue = string | boolean | null;
51
+ type AriaProblemCode = "duplicate-id" | "dangling-reference" | "empty-reference" | "hidden-focusable" | "tab-stop-count" | "missing-element" | "count-mismatch" | "role-mismatch" | "name-mismatch" | "attribute-mismatch";
52
+ /** One defect, with the element that owns it when there is one. */
53
+ interface AriaProblem {
54
+ readonly code: AriaProblemCode;
55
+ readonly message: string;
56
+ readonly element?: Element;
57
+ }
58
+ /** What checkAria checked and what it found. */
59
+ interface AriaReport {
60
+ readonly ok: boolean;
61
+ readonly problems: readonly AriaProblem[];
62
+ }
63
+ /** One selector and the ARIA facts every match must satisfy. */
64
+ interface AriaExpectation {
65
+ /** Selector relative to the root passed to checkAria. */
66
+ readonly selector: string;
67
+ /** Accessible role every match must have (explicit or implicit). */
68
+ readonly role?: string;
69
+ /** Accessible name every match must have. */
70
+ readonly name?: string;
71
+ /** Attribute values every match must carry; `null` or `false` means absent. */
72
+ readonly attrs?: Readonly<Record<string, AriaAttributeValue>>;
73
+ /** Exact number of matches; omitted means "at least one". */
74
+ readonly count?: number;
75
+ }
76
+ interface AriaCheckOptions {
77
+ /**
78
+ * Selector for a group that uses a roving tabindex. Exactly one match must
79
+ * carry `tabindex="0"`; zero means the group cannot be entered from the
80
+ * keyboard, and more than one means the group adds extra tab stops.
81
+ */
82
+ readonly tabStop?: string;
83
+ }
84
+ /** Raised when checkAria finds any problem; carries the full report. */
85
+ export declare class AriaError extends Error {
86
+ readonly report: AriaReport;
87
+ constructor(report: AriaReport);
88
+ }
89
+ /**
90
+ * Checks a rendered subtree against the ARIA contract and the caller's
91
+ * expectations, and throws with every problem listed rather than the first.
92
+ *
93
+ * The invariants are always checked:
94
+ * - ids inside the root are unique;
95
+ * - every ID reference an ARIA attribute names resolves in the document;
96
+ * - no keyboard-focusable element sits inside an aria-hidden subtree;
97
+ * - when `options.tabStop` is given, exactly one of its matches is a tab stop.
98
+ */
99
+ export declare function checkAria(root: ParentNode, expectations?: readonly AriaExpectation[], options?: AriaCheckOptions): AriaReport;
100
+ /** Reads the identity of the item a component landed on. */
101
+ type DirectionReader<Props extends object, Instance extends MountableInstance<Props, unknown>> = (mounted: Mounted<Props, Instance>) => string;
102
+ interface DirectionOptions<Props extends object, Instance extends MountableInstance<Props, unknown>> {
103
+ /** The item to move between. Defaults to the roving items the kit renders. */
104
+ readonly selector?: string;
105
+ /** The key to press. Defaults to "ArrowRight", the forward key in LTR. */
106
+ readonly key?: string;
107
+ /** The key that should do the same thing in RTL. Defaults to "ArrowLeft". */
108
+ readonly mirrored?: string;
109
+ /** What "landed on" means. Defaults to the focused element's `data-value`, then
110
+ * its text; a slider passes one that reads `aria-valuenow`. */
111
+ readonly read?: DirectionReader<Props, Instance>;
112
+ }
113
+ interface DirectionReport {
114
+ readonly forward: {
115
+ readonly ltr: string;
116
+ readonly rtl: string;
117
+ };
118
+ readonly mirrored: {
119
+ readonly ltr: string;
120
+ readonly rtl: string;
121
+ };
122
+ }
123
+ /**
124
+ * Mounts a component left to right and right to left and presses the two
125
+ * horizontal arrows, checking the direction contract:
126
+ *
127
+ * - the mirrored key in RTL lands where the forward key lands in LTR, and
128
+ * - the forward key in RTL does **not** land there (it moves the other way, or
129
+ * stays put at the end of a clamped group).
130
+ *
131
+ * Throws one error with every problem when the component ignores `dir`, when the
132
+ * arrows do nothing at all (there is nothing to check), and when the two
133
+ * directions agree.
134
+ */
135
+ export declare function checkDirection<Props extends object, Instance extends MountableInstance<Props, unknown>>(factory: (props?: Props) => Instance, props?: NoInfer<Props>, options?: DirectionOptions<Props, Instance>): DirectionReport;
136
+ /** What should be true of the focused element after a key. */
137
+ interface PatternExpectation {
138
+ /** Accessible role of the element that should have focus. */
139
+ readonly role?: string;
140
+ /** Accessible name of that element. */
141
+ readonly name?: string;
142
+ /** Semantic aria-selected: `false` passes when the attribute is absent. */
143
+ readonly selected?: boolean;
144
+ /** Semantic aria-expanded: `false` passes when the attribute is absent. */
145
+ readonly expanded?: boolean;
146
+ /** Semantic aria-checked; `"mixed"` requires the literal mixed state. */
147
+ readonly checked?: boolean | "mixed";
148
+ /** Semantic aria-pressed: `false` passes when the attribute is absent. */
149
+ readonly pressed?: boolean | "mixed";
150
+ /** Native `disabled` or aria-disabled="true". */
151
+ readonly disabled?: boolean;
152
+ /** Exact attribute values; `null` or `false` means absent. */
153
+ readonly attrs?: Readonly<Record<string, AriaAttributeValue>>;
154
+ /** Normalised text content. */
155
+ readonly text?: string;
156
+ /**
157
+ * The row named by `aria-activedescendant` on the focused element.
158
+ *
159
+ * A listbox, combobox, menu or grid keeps DOM focus on one element and moves
160
+ * a virtual "active" row instead; every APG sequence for those patterns is
161
+ * about which row that is, so the runner has to be able to ask. The id must
162
+ * resolve: a dangling `aria-activedescendant` fails here rather than passing
163
+ * because nothing was checked.
164
+ */
165
+ readonly activeDescendant?: {
166
+ readonly role?: string;
167
+ readonly name?: string;
168
+ readonly text?: string;
169
+ };
170
+ }
171
+ /** One key press and the expectation that follows it. */
172
+ interface PatternStep {
173
+ /** KeyboardEvent.key, e.g. "ArrowDown", "Enter", " " (Space). */
174
+ readonly key: string;
175
+ /** Extra KeyboardEventInit fields (shiftKey, ctrlKey, metaKey, altKey, repeat). */
176
+ readonly init?: Omit<KeyboardEventInit, "key">;
177
+ /** Element to dispatch to. Defaults to the focused element. */
178
+ readonly target?: Element | string;
179
+ /** Assertions about the element focused after the key. */
180
+ readonly expect?: PatternExpectation;
181
+ }
182
+ /** What a successful sequence ran. */
183
+ interface PatternReport {
184
+ readonly steps: number;
185
+ readonly keys: readonly string[];
186
+ }
187
+ /** Raised at the first step whose expectation or focus precondition fails. */
188
+ export declare class PatternError extends Error {
189
+ /** 1-based number of the failing step. */
190
+ readonly step: number;
191
+ readonly key: string;
192
+ constructor(step: number, key: string, detail: string);
193
+ }
194
+ /**
195
+ * Runs an APG keyboard sequence against a rendered subtree.
196
+ *
197
+ * Each step dispatches keydown to the focused element (or `step.target`),
198
+ * settles the render, then checks `step.expect` against the element that ends
199
+ * up focused. A missing focus is a precondition failure, not a silent pass:
200
+ * dispatching a key to the body would test nothing.
201
+ */
202
+ export declare function checkPattern(root: ParentNode, steps: readonly PatternStep[]): PatternReport;
203
+ /** A parsed element. Structurally compatible with core's Description, so a
204
+ * parsed tree can be rendered again. */
205
+ interface MarkupNode {
206
+ readonly tag: string;
207
+ /** Attribute values; a boolean attribute is the empty string. */
208
+ readonly attrs?: Readonly<Record<string, string>>;
209
+ readonly children?: readonly (MarkupNode | string)[];
210
+ }
211
+ /** Raised by parseMarkup, with the offset where the markup stopped making sense. */
212
+ export declare class MarkupParseError extends Error {
213
+ /** Zero-based offset into the input. */
214
+ readonly index: number;
215
+ constructor(message: string, index: number);
216
+ }
217
+ /**
218
+ * Serialises a description tree (or a parsed tree) to HTML.
219
+ *
220
+ * Attributes are written in object order, booleans as `name=""`, and false,
221
+ * null and undefined are omitted — the same rules the renderer applies. Void
222
+ * elements get no closing tag and reject children, because a description that
223
+ * puts children inside <br> has no HTML representation.
224
+ */
225
+ export declare function renderMarkup(description: Description | MarkupNode): string;
226
+ /**
227
+ * Parses markup produced by renderMarkup (or a hand-written fixture in the same
228
+ * subset) into a tree that can be compared structurally and rendered again.
229
+ *
230
+ * Text outside the root element is ignored only while it is whitespace; a
231
+ * second root is an error, because that usually means a fixture was pasted
232
+ * wrong rather than that the test wanted a fragment.
233
+ */
234
+ export declare function parseMarkup(html: string): MarkupNode;
235
+ /** The contract a server-renderable component answers. Strict elements expose
236
+ * exactly this shape as a static `render`. */
237
+ interface ServerRenderable<Props extends object = Record<string, unknown>> {
238
+ render(props?: Props, options?: {
239
+ readonly hydrate?: boolean;
240
+ }): string;
241
+ }
242
+ interface ServerReport {
243
+ /** The serialized server markup, for snapshotting. */
244
+ readonly markup: string;
245
+ /** Part names (data-part values) found in the server markup. */
246
+ readonly parts: readonly string[];
247
+ /** True when hydration consumed the hydrate marker instead of doubling the tree. */
248
+ readonly adopted: boolean;
249
+ }
250
+ /** Raised at the first fact that does not hold, with the failing phase named. */
251
+ export declare class ServerError extends Error {
252
+ readonly phase: "render" | "parse" | "hydrate" | "empty";
253
+ constructor(phase: ServerError["phase"], detail: string);
254
+ }
255
+ /**
256
+ * Checks the server contract of one component.
257
+ *
258
+ * `connect` is the host's half of hydration: given the server markup inside a
259
+ * container element, do whatever the framework needs to upgrade it (for strict
260
+ * elements, nothing — insertion is enough) and return the live host. The check
261
+ * asserts the hydrate marker is gone afterwards and the host holds one tree,
262
+ * then runs `verify` against the adopted host if the caller passed one.
263
+ */
264
+ export declare function checkServer<Props extends object>(component: ServerRenderable<Props>, props?: Props, options?: {
265
+ readonly connect?: (container: HTMLElement) => HTMLElement | null;
266
+ readonly expectParts?: readonly string[];
267
+ readonly verify?: (host: HTMLElement) => void;
268
+ }): ServerReport;
269
+ /** Serializes a server render through the markup tree, normalizing attribute
270
+ * order for stable snapshots. */
271
+ export declare function serverMarkup<Props extends object>(component: ServerRenderable<Props>, props?: Props): string;
272
+ /** How a roving group names its items, for the sequences that assert identity. */
273
+ interface RovingSpec {
274
+ /** Accessible names of the items in DOM order. */
275
+ readonly items: readonly string[];
276
+ /** Role of one item, e.g. "option", "tab", "menuitem", "radio". */
277
+ readonly role: string;
278
+ /** Orientation: horizontal groups reverse the arrow keys' meaning. */
279
+ readonly orientation?: "horizontal" | "vertical";
280
+ }
281
+ /**
282
+ * The movement contract every APG listbox, menu, tablist, radio group and
283
+ * toolbar shares: the forward arrow moves one item, the backward arrow moves
284
+ * one back, and Home/End jump to the edges.
285
+ *
286
+ * Edge behavior has no default because the APG does not give it one: radio
287
+ * groups wrap, listboxes clamp, tablists may do either. The test has to state
288
+ * which contract the component claims — passing nothing would hide the
289
+ * decision the pattern leaves open.
290
+ */
291
+ export declare function rovingSteps(spec: RovingSpec, options: {
292
+ readonly wraps: boolean;
293
+ }): readonly PatternStep[];
294
+ /**
295
+ * The listbox pattern adds selection to movement: arrows move the active
296
+ * option, and the active option is the selected one in a single-select listbox
297
+ * that follows focus (the APG's recommended model).
298
+ */
299
+ export declare function listboxSteps(spec: Omit<RovingSpec, "role">, options: {
300
+ readonly wraps: boolean;
301
+ }): readonly PatternStep[];
302
+ /**
303
+ * The tablist pattern: arrows move across tabs, and a tab is selected when it
304
+ * is activated. Manual-activation lists assert only focus here; automatic ones
305
+ * pass `automatic: true` and get the selection assertion on movement.
306
+ */
307
+ export declare function tabsSteps(spec: Omit<RovingSpec, "role" | "orientation">, options: {
308
+ readonly automatic?: boolean;
309
+ readonly wraps: boolean;
310
+ }): readonly PatternStep[];
311
+ export { type AriaAttributeValue, type AriaCheckOptions, type AriaExpectation, type AriaProblem, type AriaProblemCode, type AriaReport, type DirectionOptions, type DirectionReader, type DirectionReport, type MarkupNode, type MountOptions, type MountableInstance, type Mounted, type PatternExpectation, type PatternReport, type PatternStep, type RovingSpec, type ServerRenderable, type ServerReport, accessibleName, accessibleRole };
@@ -0,0 +1,311 @@
1
+ import { Description, accessibleName, accessibleRole } from "@bevelo/core";
2
+ interface MountOptions {
3
+ /** Where the component is appended. Defaults to a fresh div in document.body. */
4
+ readonly container?: HTMLElement;
5
+ }
6
+ /** The part of a component instance mount() relies on. */
7
+ interface MountableInstance<Props extends object, Api> {
8
+ readonly element: HTMLElement;
9
+ readonly api: Api;
10
+ update(next: Props): void;
11
+ dispose(): void;
12
+ }
13
+ /** A mounted component plus the queries a test needs. */
14
+ interface Mounted<Props extends object, Instance extends MountableInstance<Props, unknown>> {
15
+ /** The component's own root element. Queries and events are scoped to it. */
16
+ readonly root: HTMLElement;
17
+ /** The component instance, for tests that need more than the DOM. */
18
+ readonly instance: Instance;
19
+ /** The component's imperative surface. */
20
+ readonly api: Instance["api"];
21
+ /** Replaces props and settles the render before returning. */
22
+ update(props: Props): void;
23
+ /** Runs pending reactive effects. Call after an interaction. */
24
+ flush(): void;
25
+ /** Disposes the instance and removes the component (and the wrapper mount
26
+ * created, if any). Idempotent. */
27
+ dispose(): void;
28
+ /** The first descendant (or the root) matching a selector. */
29
+ query(selector: string): HTMLElement | null;
30
+ /** Every descendant (or the root) matching a selector. */
31
+ queryAll(selector: string): HTMLElement[];
32
+ /** The element with this accessible role, optionally with this accessible name. */
33
+ get(role: string, name?: string): HTMLElement;
34
+ /** Dispatches keydown to the focused element (or a named one) and returns it. */
35
+ press(key: string, target?: Element | string): KeyboardEvent;
36
+ /** Clicks the root, or a named element inside it. */
37
+ click(target?: Element | string): void;
38
+ /** The root's serialised markup, for snapshotting a whole component. */
39
+ html(): string;
40
+ }
41
+ /**
42
+ * Creates a component, appends it to a container, settles the first render and
43
+ * returns queries scoped to the component's root.
44
+ *
45
+ * The wrapper div is removed by dispose(); a caller-provided container is left
46
+ * in place, because the test owns it.
47
+ */
48
+ export declare function mount<Props extends object, Instance extends MountableInstance<Props, unknown>>(factory: (props?: Props) => Instance, props?: NoInfer<Props>, options?: MountOptions): Mounted<Props, Instance>;
49
+ /** An attribute value a test can assert: `null` and `false` mean "absent". */
50
+ type AriaAttributeValue = string | boolean | null;
51
+ type AriaProblemCode = "duplicate-id" | "dangling-reference" | "empty-reference" | "hidden-focusable" | "tab-stop-count" | "missing-element" | "count-mismatch" | "role-mismatch" | "name-mismatch" | "attribute-mismatch";
52
+ /** One defect, with the element that owns it when there is one. */
53
+ interface AriaProblem {
54
+ readonly code: AriaProblemCode;
55
+ readonly message: string;
56
+ readonly element?: Element;
57
+ }
58
+ /** What checkAria checked and what it found. */
59
+ interface AriaReport {
60
+ readonly ok: boolean;
61
+ readonly problems: readonly AriaProblem[];
62
+ }
63
+ /** One selector and the ARIA facts every match must satisfy. */
64
+ interface AriaExpectation {
65
+ /** Selector relative to the root passed to checkAria. */
66
+ readonly selector: string;
67
+ /** Accessible role every match must have (explicit or implicit). */
68
+ readonly role?: string;
69
+ /** Accessible name every match must have. */
70
+ readonly name?: string;
71
+ /** Attribute values every match must carry; `null` or `false` means absent. */
72
+ readonly attrs?: Readonly<Record<string, AriaAttributeValue>>;
73
+ /** Exact number of matches; omitted means "at least one". */
74
+ readonly count?: number;
75
+ }
76
+ interface AriaCheckOptions {
77
+ /**
78
+ * Selector for a group that uses a roving tabindex. Exactly one match must
79
+ * carry `tabindex="0"`; zero means the group cannot be entered from the
80
+ * keyboard, and more than one means the group adds extra tab stops.
81
+ */
82
+ readonly tabStop?: string;
83
+ }
84
+ /** Raised when checkAria finds any problem; carries the full report. */
85
+ export declare class AriaError extends Error {
86
+ readonly report: AriaReport;
87
+ constructor(report: AriaReport);
88
+ }
89
+ /**
90
+ * Checks a rendered subtree against the ARIA contract and the caller's
91
+ * expectations, and throws with every problem listed rather than the first.
92
+ *
93
+ * The invariants are always checked:
94
+ * - ids inside the root are unique;
95
+ * - every ID reference an ARIA attribute names resolves in the document;
96
+ * - no keyboard-focusable element sits inside an aria-hidden subtree;
97
+ * - when `options.tabStop` is given, exactly one of its matches is a tab stop.
98
+ */
99
+ export declare function checkAria(root: ParentNode, expectations?: readonly AriaExpectation[], options?: AriaCheckOptions): AriaReport;
100
+ /** Reads the identity of the item a component landed on. */
101
+ type DirectionReader<Props extends object, Instance extends MountableInstance<Props, unknown>> = (mounted: Mounted<Props, Instance>) => string;
102
+ interface DirectionOptions<Props extends object, Instance extends MountableInstance<Props, unknown>> {
103
+ /** The item to move between. Defaults to the roving items the kit renders. */
104
+ readonly selector?: string;
105
+ /** The key to press. Defaults to "ArrowRight", the forward key in LTR. */
106
+ readonly key?: string;
107
+ /** The key that should do the same thing in RTL. Defaults to "ArrowLeft". */
108
+ readonly mirrored?: string;
109
+ /** What "landed on" means. Defaults to the focused element's `data-value`, then
110
+ * its text; a slider passes one that reads `aria-valuenow`. */
111
+ readonly read?: DirectionReader<Props, Instance>;
112
+ }
113
+ interface DirectionReport {
114
+ readonly forward: {
115
+ readonly ltr: string;
116
+ readonly rtl: string;
117
+ };
118
+ readonly mirrored: {
119
+ readonly ltr: string;
120
+ readonly rtl: string;
121
+ };
122
+ }
123
+ /**
124
+ * Mounts a component left to right and right to left and presses the two
125
+ * horizontal arrows, checking the direction contract:
126
+ *
127
+ * - the mirrored key in RTL lands where the forward key lands in LTR, and
128
+ * - the forward key in RTL does **not** land there (it moves the other way, or
129
+ * stays put at the end of a clamped group).
130
+ *
131
+ * Throws one error with every problem when the component ignores `dir`, when the
132
+ * arrows do nothing at all (there is nothing to check), and when the two
133
+ * directions agree.
134
+ */
135
+ export declare function checkDirection<Props extends object, Instance extends MountableInstance<Props, unknown>>(factory: (props?: Props) => Instance, props?: NoInfer<Props>, options?: DirectionOptions<Props, Instance>): DirectionReport;
136
+ /** What should be true of the focused element after a key. */
137
+ interface PatternExpectation {
138
+ /** Accessible role of the element that should have focus. */
139
+ readonly role?: string;
140
+ /** Accessible name of that element. */
141
+ readonly name?: string;
142
+ /** Semantic aria-selected: `false` passes when the attribute is absent. */
143
+ readonly selected?: boolean;
144
+ /** Semantic aria-expanded: `false` passes when the attribute is absent. */
145
+ readonly expanded?: boolean;
146
+ /** Semantic aria-checked; `"mixed"` requires the literal mixed state. */
147
+ readonly checked?: boolean | "mixed";
148
+ /** Semantic aria-pressed: `false` passes when the attribute is absent. */
149
+ readonly pressed?: boolean | "mixed";
150
+ /** Native `disabled` or aria-disabled="true". */
151
+ readonly disabled?: boolean;
152
+ /** Exact attribute values; `null` or `false` means absent. */
153
+ readonly attrs?: Readonly<Record<string, AriaAttributeValue>>;
154
+ /** Normalised text content. */
155
+ readonly text?: string;
156
+ /**
157
+ * The row named by `aria-activedescendant` on the focused element.
158
+ *
159
+ * A listbox, combobox, menu or grid keeps DOM focus on one element and moves
160
+ * a virtual "active" row instead; every APG sequence for those patterns is
161
+ * about which row that is, so the runner has to be able to ask. The id must
162
+ * resolve: a dangling `aria-activedescendant` fails here rather than passing
163
+ * because nothing was checked.
164
+ */
165
+ readonly activeDescendant?: {
166
+ readonly role?: string;
167
+ readonly name?: string;
168
+ readonly text?: string;
169
+ };
170
+ }
171
+ /** One key press and the expectation that follows it. */
172
+ interface PatternStep {
173
+ /** KeyboardEvent.key, e.g. "ArrowDown", "Enter", " " (Space). */
174
+ readonly key: string;
175
+ /** Extra KeyboardEventInit fields (shiftKey, ctrlKey, metaKey, altKey, repeat). */
176
+ readonly init?: Omit<KeyboardEventInit, "key">;
177
+ /** Element to dispatch to. Defaults to the focused element. */
178
+ readonly target?: Element | string;
179
+ /** Assertions about the element focused after the key. */
180
+ readonly expect?: PatternExpectation;
181
+ }
182
+ /** What a successful sequence ran. */
183
+ interface PatternReport {
184
+ readonly steps: number;
185
+ readonly keys: readonly string[];
186
+ }
187
+ /** Raised at the first step whose expectation or focus precondition fails. */
188
+ export declare class PatternError extends Error {
189
+ /** 1-based number of the failing step. */
190
+ readonly step: number;
191
+ readonly key: string;
192
+ constructor(step: number, key: string, detail: string);
193
+ }
194
+ /**
195
+ * Runs an APG keyboard sequence against a rendered subtree.
196
+ *
197
+ * Each step dispatches keydown to the focused element (or `step.target`),
198
+ * settles the render, then checks `step.expect` against the element that ends
199
+ * up focused. A missing focus is a precondition failure, not a silent pass:
200
+ * dispatching a key to the body would test nothing.
201
+ */
202
+ export declare function checkPattern(root: ParentNode, steps: readonly PatternStep[]): PatternReport;
203
+ /** A parsed element. Structurally compatible with core's Description, so a
204
+ * parsed tree can be rendered again. */
205
+ interface MarkupNode {
206
+ readonly tag: string;
207
+ /** Attribute values; a boolean attribute is the empty string. */
208
+ readonly attrs?: Readonly<Record<string, string>>;
209
+ readonly children?: readonly (MarkupNode | string)[];
210
+ }
211
+ /** Raised by parseMarkup, with the offset where the markup stopped making sense. */
212
+ export declare class MarkupParseError extends Error {
213
+ /** Zero-based offset into the input. */
214
+ readonly index: number;
215
+ constructor(message: string, index: number);
216
+ }
217
+ /**
218
+ * Serialises a description tree (or a parsed tree) to HTML.
219
+ *
220
+ * Attributes are written in object order, booleans as `name=""`, and false,
221
+ * null and undefined are omitted — the same rules the renderer applies. Void
222
+ * elements get no closing tag and reject children, because a description that
223
+ * puts children inside <br> has no HTML representation.
224
+ */
225
+ export declare function renderMarkup(description: Description | MarkupNode): string;
226
+ /**
227
+ * Parses markup produced by renderMarkup (or a hand-written fixture in the same
228
+ * subset) into a tree that can be compared structurally and rendered again.
229
+ *
230
+ * Text outside the root element is ignored only while it is whitespace; a
231
+ * second root is an error, because that usually means a fixture was pasted
232
+ * wrong rather than that the test wanted a fragment.
233
+ */
234
+ export declare function parseMarkup(html: string): MarkupNode;
235
+ /** The contract a server-renderable component answers. Strict elements expose
236
+ * exactly this shape as a static `render`. */
237
+ interface ServerRenderable<Props extends object = Record<string, unknown>> {
238
+ render(props?: Props, options?: {
239
+ readonly hydrate?: boolean;
240
+ }): string;
241
+ }
242
+ interface ServerReport {
243
+ /** The serialized server markup, for snapshotting. */
244
+ readonly markup: string;
245
+ /** Part names (data-part values) found in the server markup. */
246
+ readonly parts: readonly string[];
247
+ /** True when hydration consumed the hydrate marker instead of doubling the tree. */
248
+ readonly adopted: boolean;
249
+ }
250
+ /** Raised at the first fact that does not hold, with the failing phase named. */
251
+ export declare class ServerError extends Error {
252
+ readonly phase: "render" | "parse" | "hydrate" | "empty";
253
+ constructor(phase: ServerError["phase"], detail: string);
254
+ }
255
+ /**
256
+ * Checks the server contract of one component.
257
+ *
258
+ * `connect` is the host's half of hydration: given the server markup inside a
259
+ * container element, do whatever the framework needs to upgrade it (for strict
260
+ * elements, nothing — insertion is enough) and return the live host. The check
261
+ * asserts the hydrate marker is gone afterwards and the host holds one tree,
262
+ * then runs `verify` against the adopted host if the caller passed one.
263
+ */
264
+ export declare function checkServer<Props extends object>(component: ServerRenderable<Props>, props?: Props, options?: {
265
+ readonly connect?: (container: HTMLElement) => HTMLElement | null;
266
+ readonly expectParts?: readonly string[];
267
+ readonly verify?: (host: HTMLElement) => void;
268
+ }): ServerReport;
269
+ /** Serializes a server render through the markup tree, normalizing attribute
270
+ * order for stable snapshots. */
271
+ export declare function serverMarkup<Props extends object>(component: ServerRenderable<Props>, props?: Props): string;
272
+ /** How a roving group names its items, for the sequences that assert identity. */
273
+ interface RovingSpec {
274
+ /** Accessible names of the items in DOM order. */
275
+ readonly items: readonly string[];
276
+ /** Role of one item, e.g. "option", "tab", "menuitem", "radio". */
277
+ readonly role: string;
278
+ /** Orientation: horizontal groups reverse the arrow keys' meaning. */
279
+ readonly orientation?: "horizontal" | "vertical";
280
+ }
281
+ /**
282
+ * The movement contract every APG listbox, menu, tablist, radio group and
283
+ * toolbar shares: the forward arrow moves one item, the backward arrow moves
284
+ * one back, and Home/End jump to the edges.
285
+ *
286
+ * Edge behavior has no default because the APG does not give it one: radio
287
+ * groups wrap, listboxes clamp, tablists may do either. The test has to state
288
+ * which contract the component claims — passing nothing would hide the
289
+ * decision the pattern leaves open.
290
+ */
291
+ export declare function rovingSteps(spec: RovingSpec, options: {
292
+ readonly wraps: boolean;
293
+ }): readonly PatternStep[];
294
+ /**
295
+ * The listbox pattern adds selection to movement: arrows move the active
296
+ * option, and the active option is the selected one in a single-select listbox
297
+ * that follows focus (the APG's recommended model).
298
+ */
299
+ export declare function listboxSteps(spec: Omit<RovingSpec, "role">, options: {
300
+ readonly wraps: boolean;
301
+ }): readonly PatternStep[];
302
+ /**
303
+ * The tablist pattern: arrows move across tabs, and a tab is selected when it
304
+ * is activated. Manual-activation lists assert only focus here; automatic ones
305
+ * pass `automatic: true` and get the selection assertion on movement.
306
+ */
307
+ export declare function tabsSteps(spec: Omit<RovingSpec, "role" | "orientation">, options: {
308
+ readonly automatic?: boolean;
309
+ readonly wraps: boolean;
310
+ }): readonly PatternStep[];
311
+ export { type AriaAttributeValue, type AriaCheckOptions, type AriaExpectation, type AriaProblem, type AriaProblemCode, type AriaReport, type DirectionOptions, type DirectionReader, type DirectionReport, type MarkupNode, type MountOptions, type MountableInstance, type Mounted, type PatternExpectation, type PatternReport, type PatternStep, type RovingSpec, type ServerRenderable, type ServerReport, accessibleName, accessibleRole };