@baseline-ui/test-utils 0.61.0 → 0.63.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.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as _playwright_test from '@playwright/test';
1
+ import * as playwright_test from 'playwright/test';
2
2
  import { Page, Locator, FrameLocator } from '@playwright/test';
3
3
  import { SinonSpy } from 'sinon';
4
4
 
@@ -29,57 +29,57 @@ interface ToBeAccessibleOptions {
29
29
  attachmentName?: string;
30
30
  }
31
31
 
32
- declare const expect: _playwright_test.Expect<{
33
- toBeWithinDelta(this: _playwright_test.ExpectMatcherState, received: number, expected: number, delta: number): {
32
+ declare const expect: playwright_test.Expect<{
33
+ toBeWithinDelta(this: playwright_test.ExpectMatcherState, received: number, expected: number, delta: number): {
34
34
  message: () => string;
35
35
  pass: true;
36
36
  } | {
37
37
  message: () => string;
38
38
  pass: false;
39
39
  };
40
- toBeCalledOnce(this: _playwright_test.ExpectMatcherState, fn: SinonSpy): Promise<{
40
+ toBeCalledOnce(this: playwright_test.ExpectMatcherState, fn: SinonSpy): Promise<{
41
41
  message: () => string;
42
42
  pass: true;
43
43
  } | {
44
44
  message: () => string;
45
45
  pass: false;
46
46
  }>;
47
- toBeCalledTwice(this: _playwright_test.ExpectMatcherState, fn: SinonSpy): Promise<{
47
+ toBeCalledTwice(this: playwright_test.ExpectMatcherState, fn: SinonSpy): Promise<{
48
48
  message: () => string;
49
49
  pass: true;
50
50
  } | {
51
51
  message: () => string;
52
52
  pass: false;
53
53
  }>;
54
- toBeCalledThrice(this: _playwright_test.ExpectMatcherState, fn: SinonSpy): Promise<{
54
+ toBeCalledThrice(this: playwright_test.ExpectMatcherState, fn: SinonSpy): Promise<{
55
55
  message: () => string;
56
56
  pass: true;
57
57
  } | {
58
58
  message: () => string;
59
59
  pass: false;
60
60
  }>;
61
- toBeCalledWith(this: _playwright_test.ExpectMatcherState, fn: SinonSpy, ...args: unknown[]): Promise<{
61
+ toBeCalledWith(this: playwright_test.ExpectMatcherState, fn: SinonSpy, ...args: unknown[]): Promise<{
62
62
  message: () => string;
63
63
  pass: true;
64
64
  } | {
65
65
  message: () => string;
66
66
  pass: false;
67
67
  }>;
68
- toBeCalledWithExactly(this: _playwright_test.ExpectMatcherState, fn: SinonSpy, ...args: unknown[]): Promise<{
68
+ toBeCalledWithExactly(this: playwright_test.ExpectMatcherState, fn: SinonSpy, ...args: unknown[]): Promise<{
69
69
  message: () => string;
70
70
  pass: true;
71
71
  } | {
72
72
  message: () => string;
73
73
  pass: false;
74
74
  }>;
75
- toBeCalled(this: _playwright_test.ExpectMatcherState, fn: SinonSpy): {
75
+ toBeCalled(this: playwright_test.ExpectMatcherState, fn: SinonSpy): {
76
76
  message: () => string;
77
77
  pass: true;
78
78
  } | {
79
79
  message: () => string;
80
80
  pass: false;
81
81
  };
82
- toBeCalledTimes(this: _playwright_test.ExpectMatcherState, fn: SinonSpy, times: number): Promise<{
82
+ toBeCalledTimes(this: playwright_test.ExpectMatcherState, fn: SinonSpy, times: number): Promise<{
83
83
  message: () => string;
84
84
  pass: true;
85
85
  } | {
@@ -95,7 +95,7 @@ declare const expect: _playwright_test.Expect<{
95
95
  message: () => string;
96
96
  pass: false;
97
97
  }>;
98
- toMatchClassTree(this: _playwright_test.ExpectMatcherState, locator: Locator, snapshotName?: string, options?: {
98
+ toMatchClassTree(this: playwright_test.ExpectMatcherState, locator: Locator, snapshotName?: string, options?: {
99
99
  prefix?: string | string[];
100
100
  ignoreHashed?: boolean;
101
101
  }): Promise<{
@@ -107,4 +107,285 @@ declare const expect: _playwright_test.Expect<{
107
107
  }>;
108
108
  }>;
109
109
 
110
- export { DEFAULT_CRITICAL_INCOMPLETE_RULES, DEFAULT_DISABLED_RULES, DEFAULT_WCAG_TAGS, type ToBeAccessibleOptions, expect };
110
+ /**
111
+ * Either a Playwright `Page` or a `FrameLocator` — both expose the same
112
+ * locator-building API used by the testers. Component-test fixtures typically
113
+ * provide a `FrameLocator`; full E2E tests provide a `Page`.
114
+ */
115
+ type Frame = Page | FrameLocator;
116
+
117
+ /**
118
+ * Common options accepted by every component tester. Component testers extend
119
+ * this with their own optional fields (e.g. a custom listbox locator), but
120
+ * `frame` and `trigger` always behave the same way:
121
+ *
122
+ * - `frame` is the {@link Frame} the tester searches inside — typically the
123
+ * component-test mount frame, but may be a `Page` for full E2E tests.
124
+ * - `trigger` is the focusable element that opens/closes the component. Every
125
+ * tester provides a sensible default keyed off the component's stable
126
+ * `data-testid` (see CONVENTIONS.md). Override it when the consumer renders
127
+ * a custom trigger that doesn't carry that test id.
128
+ */
129
+ interface BaseTesterOptions {
130
+ frame: Frame;
131
+ trigger?: Locator;
132
+ }
133
+ /**
134
+ * Keys recognised by {@link disclosure}'s `open(how)`. The same set covers
135
+ * Select, Menu, Combobox and DatePicker — disclosure-style components whose
136
+ * trigger expands a popover. Components that only open via click (e.g. a
137
+ * Dialog with no keyboard activation other than Enter) can ignore the keyboard
138
+ * paths and simply call `open("click")`.
139
+ */
140
+ type DisclosureOpenWith = "click" | "Space" | "Enter" | "ArrowDown" | "ArrowUp";
141
+
142
+ /**
143
+ * Options for {@link editorTester}. The Editor has no single disclosure
144
+ * trigger, so instead of `trigger` it accepts `root` — the `.BaselineUI-Editor`
145
+ * container every other locator is scoped to. Pass it when more than one
146
+ * Editor is mounted in the same frame.
147
+ */
148
+ interface EditorTesterOptions {
149
+ frame: Frame;
150
+ /**
151
+ * The Editor root element. Defaults to `frame.locator(".BaselineUI-Editor")`.
152
+ */
153
+ root?: Locator;
154
+ }
155
+ /**
156
+ * Driver for an `<Editor>` in Playwright component tests. Construct with
157
+ * {@link editorTester} (or `testers(frame).editor()`).
158
+ *
159
+ * Works for both modes of the component: in rich text mode `textbox` resolves
160
+ * to the contenteditable area, in plain/minimal mode to the `<textarea>` —
161
+ * both expose `role="textbox"`, so no mode flag is needed. Rich-text-only
162
+ * surface (toolbar buttons, link popover, mention dropdown, help dialog)
163
+ * simply won't match when `enableRichText` is off.
164
+ */
165
+ interface EditorTester {
166
+ readonly root: Locator;
167
+ /**
168
+ * The editing area: the rich text contenteditable or the plain-mode
169
+ * textarea (both have `role="textbox"`).
170
+ */
171
+ readonly textbox: Locator;
172
+ /**
173
+ * The rich text placeholder overlay, attached only while the document is
174
+ * empty. (In plain mode the placeholder is a `<textarea>` attribute —
175
+ * assert on `textbox` instead.)
176
+ */
177
+ readonly placeholder: Locator;
178
+ readonly toolbar: Locator;
179
+ readonly boldButton: Locator;
180
+ readonly italicButton: Locator;
181
+ readonly underlineButton: Locator;
182
+ readonly fontColorButton: Locator;
183
+ readonly backgroundColorButton: Locator;
184
+ /**
185
+ * Opens the font color picker popover if it isn't already open.
186
+ * Idempotent — keys off `aria-expanded` on the trigger.
187
+ */
188
+ openFontColorPicker: (how?: DisclosureOpenWith) => Promise<void>;
189
+ openBackgroundColorPicker: (how?: DisclosureOpenWith) => Promise<void>;
190
+ readonly addLinkButton: Locator;
191
+ readonly linkDialog: Locator;
192
+ readonly linkInput: Locator;
193
+ readonly linkAddButton: Locator;
194
+ /** The "Edit Link" button in show mode (caret inside an existing link). */
195
+ readonly linkEditButton: Locator;
196
+ readonly linkRemoveButton: Locator;
197
+ readonly linkCancelButton: Locator;
198
+ readonly linkSaveButton: Locator;
199
+ openLinkDialog: (how?: DisclosureOpenWith) => Promise<void>;
200
+ readonly saveButton: Locator;
201
+ /** The cancel button (rendered only when `onCancel` is provided). */
202
+ readonly cancelButton: Locator;
203
+ /**
204
+ * The footer mention button (rendered only with rich text +
205
+ * `mentionableUsers`).
206
+ */
207
+ readonly mentionButton: Locator;
208
+ readonly helpButton: Locator;
209
+ /** The keyboard shortcuts help dialog (a modal, portalled to the body). */
210
+ readonly helpDialog: Locator;
211
+ readonly helpDialogCloseButton: Locator;
212
+ openHelpDialog: () => Promise<void>;
213
+ /**
214
+ * The inline mention combobox input, attached only while a mention flow is
215
+ * active (after "@" or {@link startMention}).
216
+ */
217
+ readonly mentionInput: Locator;
218
+ /** The mention suggestion listbox (portalled outside the editor root). */
219
+ readonly mentionListbox: Locator;
220
+ mentionOption: (name: string | RegExp) => Locator;
221
+ /**
222
+ * Starts a mention flow via the footer mention button if one isn't already
223
+ * active. Idempotent — bails when the mention input is visible.
224
+ */
225
+ startMention: () => Promise<void>;
226
+ }
227
+
228
+ /**
229
+ * Options for {@link selectTester}. Defaults the trigger to
230
+ * `frame.getByTestId("select-button")` (the convention for both single- and
231
+ * multi-select). Pass `trigger` when the Select renders a custom trigger that
232
+ * doesn't carry that test id.
233
+ *
234
+ * `multiple` and `autocomplete` are **orthogonal** flags that mirror the
235
+ * component shape:
236
+ *
237
+ * - `multiple: true` matches `<Select selectionMode="multiple">` and adds the
238
+ * `tag`, `removeTagButton`, `selectAllButton`, `clearButton` surface.
239
+ * - `autocomplete: true` matches `<Select>` wrapped in `<Autocomplete>` and
240
+ * adds `searchbox` + `filter()`.
241
+ *
242
+ * They can be combined.
243
+ */
244
+ interface SelectTesterOptions extends BaseTesterOptions {
245
+ multiple?: boolean;
246
+ autocomplete?: boolean;
247
+ }
248
+ /**
249
+ * Driver for a single-select `<Select>` in Playwright component tests.
250
+ * Construct with {@link selectTester}.
251
+ */
252
+ interface SelectTester {
253
+ /** The trigger button. */
254
+ readonly trigger: Locator;
255
+ /** The popover listbox. Only attached while the Select is open. */
256
+ readonly listbox: Locator;
257
+ /** Locator for a single option by accessible name. */
258
+ option: (name: string | RegExp) => Locator;
259
+ /**
260
+ * Opens the Select if it isn't already open. Idempotent — checks
261
+ * `aria-expanded` on the trigger and bails if the popover is already shown.
262
+ *
263
+ * @param how How to open. Defaults to `"click"`. Key names focus the
264
+ * trigger and press the key.
265
+ */
266
+ open: (how?: DisclosureOpenWith) => Promise<void>;
267
+ /** Opens the Select (if needed) and clicks the option matching `name`. */
268
+ selectOption: (name: string | RegExp) => Promise<void>;
269
+ }
270
+ /**
271
+ * Multi-select capability mixed in when {@link SelectTesterOptions.multiple}
272
+ * is `true`. Adds tag chips on the trigger plus the Select All / Clear
273
+ * buttons inside the popover.
274
+ */
275
+ interface MultiSelectTester extends SelectTester {
276
+ /**
277
+ * The "Select All" action button inside the popover. Located by stable
278
+ * `data-testid` rather than the translated label. Only present while open.
279
+ */
280
+ readonly selectAllButton: Locator;
281
+ /**
282
+ * The "Clear" action button inside the popover. Located by stable
283
+ * `data-testid` rather than the translated label. Only present while open.
284
+ */
285
+ readonly clearButton: Locator;
286
+ /**
287
+ * Locator for a selected-value tag chip rendered inside the trigger. Tags
288
+ * are rendered by `TagGroup` as `role="row"`; `name` is matched against
289
+ * the row's accessible name (string substring or RegExp — useful for the
290
+ * `+N more` overflow tag).
291
+ */
292
+ tag: (name: string | RegExp) => Locator;
293
+ /**
294
+ * The remove button on a tag chip identified by `tagName`. Resolved as the
295
+ * button *inside* the matching row, so the helper does not depend on the
296
+ * translated "Remove X" label format.
297
+ */
298
+ removeTagButton: (tagName: string | RegExp) => Locator;
299
+ }
300
+ /**
301
+ * Autocomplete capability mixed in when {@link SelectTesterOptions.autocomplete}
302
+ * is `true`. Adds the popover searchbox.
303
+ */
304
+ interface AutocompleteTester extends SelectTester {
305
+ /**
306
+ * The search input inside the popover. Only attached while the popover is
307
+ * open.
308
+ */
309
+ readonly searchbox: Locator;
310
+ /**
311
+ * Types into the searchbox to filter options. Does **not** open the
312
+ * Select — call `open()` first. Uses `fill` (replaces existing value); to
313
+ * clear, use `searchbox.clear()`.
314
+ */
315
+ filter: (text: string) => Promise<void>;
316
+ }
317
+ /**
318
+ * Overloaded call signature for {@link selectTester}. The return type narrows
319
+ * based on the `multiple` and `autocomplete` flags:
320
+ *
321
+ * - `select({})` → {@link SelectTester}
322
+ * - `select({ multiple: true })` → {@link MultiSelectTester}
323
+ * - `select({ autocomplete: true })` → {@link AutocompleteTester}
324
+ * - `select({ multiple: true, autocomplete: true })` →
325
+ * {@link MultiSelectTester} & {@link AutocompleteTester}
326
+ *
327
+ * @example
328
+ * ```ts
329
+ * const select = testers(frame).select();
330
+ * await select.open("Space");
331
+ * await select.selectOption("Square");
332
+ *
333
+ * const multi = testers(frame).select({ multiple: true });
334
+ * await multi.selectAllButton.click();
335
+ *
336
+ * const auto = testers(frame).select({ autocomplete: true });
337
+ * await auto.open();
338
+ * await auto.filter("first");
339
+ * ```
340
+ */
341
+ interface SelectTesterFactoryFor<O extends {
342
+ multiple?: boolean;
343
+ autocomplete?: boolean;
344
+ }> {
345
+ (options: O & {
346
+ multiple: true;
347
+ autocomplete: true;
348
+ }): MultiSelectTester & AutocompleteTester;
349
+ (options: O & {
350
+ multiple: true;
351
+ autocomplete?: false;
352
+ }): MultiSelectTester;
353
+ (options: O & {
354
+ multiple?: false;
355
+ autocomplete: true;
356
+ }): AutocompleteTester;
357
+ (options?: O): SelectTester;
358
+ }
359
+
360
+ type BoundSelectOptions = Omit<SelectTesterOptions, "frame">;
361
+ type BoundEditorOptions = Omit<EditorTesterOptions, "frame">;
362
+ /**
363
+ * The frame-bound tester factory. Methods are flat — one per component — so
364
+ * IDE autocomplete on `t.` lists the full surface in one place. Variants of a
365
+ * single component are options on its method (e.g. `t.select({ multiple: true })`),
366
+ * not separate top-level methods, so the namespace stays component-shaped.
367
+ *
368
+ * Each method's overloads mirror its underlying factory with `frame` stripped
369
+ * (the factory binds it), so the narrowing rules live in exactly one place.
370
+ */
371
+ interface Testers {
372
+ select: SelectTesterFactoryFor<BoundSelectOptions>;
373
+ editor: (options?: BoundEditorOptions) => EditorTester;
374
+ }
375
+ /**
376
+ * Build a frame-bound tester factory. Construct once per test and pick the
377
+ * component you need:
378
+ *
379
+ * ```ts
380
+ * const t = testers(frame);
381
+ * const select = t.select();
382
+ * const multi = t.select({ multiple: true, trigger: customTrigger });
383
+ * const auto = t.select({ autocomplete: true });
384
+ * ```
385
+ *
386
+ * Each method forwards per-call options to the underlying factory; `frame` is
387
+ * supplied automatically.
388
+ */
389
+ declare function testers(frame: Frame): Testers;
390
+
391
+ export { type AutocompleteTester, DEFAULT_CRITICAL_INCOMPLETE_RULES, DEFAULT_DISABLED_RULES, DEFAULT_WCAG_TAGS, type EditorTester, type Frame, type MultiSelectTester, type SelectTester, type Testers, type ToBeAccessibleOptions, expect, testers };