@rind-ui/testing 0.1.0 → 0.2.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.
@@ -1,4 +1,4 @@
1
- import { o as poll, r as describeBy, t as composeInPage } from "./compose-C7RIqRoi.mjs";
1
+ import { o as poll, r as describeBy, t as composeInPage } from "./compose-DPLnCCnJ.mjs";
2
2
  import { ANNOUNCEMENTS, KEY_DEBOUNCE_MS, PENDING_ANNOUNCEMENTS, isKeptVisible } from "@rind-ui/core";
3
3
  import { computeAccessibleDescription, computeAccessibleName } from "dom-accessibility-api";
4
4
  //#region src/announcements.ts
@@ -412,6 +412,21 @@ const nextCoords = (el) => {
412
412
  pageY: y + window.scrollY
413
413
  };
414
414
  };
415
+ /**
416
+ * Resolves once no finite transition or animation is running in the document (or after `max`
417
+ * ms). A sibling panel opening shifts the target's box for a while, and a press aimed at
418
+ * coordinates read before the shift releases outside it (the press is then not a press).
419
+ * Without running animations (every jsdom test, most browser ones) it returns at once; fake
420
+ * timers have no frames to wait on.
421
+ */
422
+ const settled = async (el, fake, max = 1e3) => {
423
+ const doc = el.ownerDocument;
424
+ const view = doc.defaultView;
425
+ if (fake || !view?.requestAnimationFrame || !doc.getAnimations) return;
426
+ const running = () => doc.getAnimations().some((a) => a.playState === "running" && a.effect?.getComputedTiming().iterations !== Number.POSITIVE_INFINITY);
427
+ const end = Date.now() + max;
428
+ while (running() && Date.now() < end) await new Promise((done) => view.requestAnimationFrame(() => done()));
429
+ };
415
430
  const KEY_NAMES = {
416
431
  Enter: "{Enter}",
417
432
  Escape: "{Escape}",
@@ -457,8 +472,10 @@ function installErrorLog(win = globalThis.window ?? null) {
457
472
  const entries = [];
458
473
  const { console } = win;
459
474
  const original = console.error.bind(console);
475
+ const realBrowser = !(win.navigator?.userAgent ?? "").includes("jsdom");
460
476
  console.error = (...args) => {
461
- entries.push(args.map(String).join(" "));
477
+ const message = args.map(String).join(" ");
478
+ if (!(realBrowser && message.includes("not wrapped in act("))) entries.push(message);
462
479
  original(...args);
463
480
  };
464
481
  win.addEventListener("error", (e) => entries.push(String(e.error ?? e.message)));
@@ -541,6 +558,7 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
541
558
  const name = by.name;
542
559
  return queryAllByRole(within, by.role, { ...name === void 0 ? {} : { name: typeof name === "string" ? (n) => normalize(n) === name : name } });
543
560
  }
561
+ if ("part" in by) return Array.from(within.querySelectorAll(`[data-scope="${CSS.escape(scope)}"][data-part="${CSS.escape(by.part)}"]`));
544
562
  const { text } = by;
545
563
  const matches = (el) => {
546
564
  const own = normalize(el.textContent);
@@ -632,6 +650,7 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
632
650
  const press = async (el, touch) => {
633
651
  const u = await getUser();
634
652
  if (!u.pointer) return act(() => u.click(el));
653
+ await settled(el, options.advanceTimers !== void 0);
635
654
  const coords = nextCoords(el);
636
655
  const steps = touch ? [{
637
656
  keys: "[TouchA]",
@@ -725,6 +744,7 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
725
744
  attr: async (name) => (await now()).getAttribute(name),
726
745
  tagName: async () => (await now()).tagName.toLowerCase(),
727
746
  scoped: (scope, partName) => handle(`${scope}.${partName} in ${label}`, async () => Array.from((await now()).querySelectorAll(`[data-scope="${scope}"][data-part="${partName}"]`))),
747
+ withAttr: (name, value) => handle(`[${name}] in ${label}`, async () => Array.from((await now()).querySelectorAll(value === void 0 ? `[${name}]` : `[${name}="${CSS.escape(value)}"]`))),
728
748
  text: async () => normalize((await now()).textContent),
729
749
  value: async () => (await now()).value ?? "",
730
750
  checked: async () => (await now()).checked === true,
package/dist/dom.mjs CHANGED
@@ -1 +1 @@
1
- export { t as domEnv } from "./dom-Ds2Cv9wy.mjs";
1
+ export { t as domEnv } from "./dom-DZtl6G1E.mjs";
package/dist/index.d.mts CHANGED
@@ -2218,6 +2218,36 @@ export declare function getSegmentedControl(target: Target, anchor: {
2218
2218
  };
2219
2219
  }>>;
2220
2220
  //#endregion
2221
+ //#region src/components/separator.d.ts
2222
+ /**
2223
+ * A driver for a Separator: the one named `name`, or the one separator part inside
2224
+ * `within` (a container element or a Playwright locator; default the target). `host`: the
2225
+ * scope of the component that draws it (`"toolbar"` for `Toolbar.Separator`).
2226
+ */
2227
+ export declare function getSeparator(target: Target, anchor?: {
2228
+ readonly name?: string | RegExp;
2229
+ readonly within?: Target;
2230
+ readonly host?: string;
2231
+ }, options?: DriverOptions): Driver<import("@rind-ui/core").Contract<import("@rind-ui/core").Machine<"static", {
2232
+ props: Record<never, never>;
2233
+ events: {
2234
+ type: "$none";
2235
+ };
2236
+ env: Record<never, never>;
2237
+ }, import("@rind-ui/core").Implementations<{
2238
+ props: Record<never, never>;
2239
+ events: {
2240
+ type: "$none";
2241
+ };
2242
+ env: Record<never, never>;
2243
+ }>, Record<never, never>>, "root" | "separator", readonly [anchor?: {
2244
+ readonly name?: string | RegExp;
2245
+ } | undefined], {
2246
+ readonly orientation: (env: import("@rind-ui/core").Env<"root" | "separator">) => Promise<string>;
2247
+ readonly isDecorative: (env: import("@rind-ui/core").Env<"root" | "separator">) => Promise<boolean>;
2248
+ readonly isExposed: (env: import("@rind-ui/core").Env<"root" | "separator">) => Promise<boolean>;
2249
+ }, {}>>;
2250
+ //#endregion
2221
2251
  //#region src/components/switch.d.ts
2222
2252
  /** A driver for the Switch named `name`. */
2223
2253
  export declare function getSwitch(target: Target, anchor: {
@@ -2786,6 +2816,101 @@ export declare function getToggleGroup(target: Target, anchor: {
2786
2816
  };
2787
2817
  }>>;
2788
2818
  //#endregion
2819
+ //#region src/components/toolbar.d.ts
2820
+ /** A driver for the Toolbar named `name`. */
2821
+ export declare function getToolbar(target: Target, anchor: {
2822
+ readonly name: string | RegExp;
2823
+ }, options?: DriverOptions): Driver<import("@rind-ui/core").Contract<import("@rind-ui/core").Machine<"focused" | "idle", {
2824
+ props: import("@rind-ui/core").ToolbarProps;
2825
+ events: import("@rind-ui/core").ToolbarEvent;
2826
+ env: import("@rind-ui/core").CollectionEnv;
2827
+ context: import("@rind-ui/core").CollectionContext;
2828
+ }, {
2829
+ readonly types: {
2830
+ props: import("@rind-ui/core").ToolbarProps;
2831
+ events: import("@rind-ui/core").ToolbarEvent;
2832
+ env: import("@rind-ui/core").CollectionEnv;
2833
+ context: import("@rind-ui/core").CollectionContext;
2834
+ };
2835
+ readonly actions: {
2836
+ readonly navigate: (a: import("@rind-ui/core").ActionArgs<{
2837
+ props: import("@rind-ui/core").ToolbarProps;
2838
+ events: import("@rind-ui/core").ToolbarEvent;
2839
+ env: import("@rind-ui/core").CollectionEnv;
2840
+ context: import("@rind-ui/core").CollectionContext;
2841
+ }>) => void;
2842
+ readonly focusHighlighted: (a: import("@rind-ui/core").ActionArgs<{
2843
+ props: import("@rind-ui/core").ToolbarProps;
2844
+ events: import("@rind-ui/core").ToolbarEvent;
2845
+ env: import("@rind-ui/core").CollectionEnv;
2846
+ context: import("@rind-ui/core").CollectionContext;
2847
+ }>) => void;
2848
+ readonly repairCollection: (a: import("@rind-ui/core").ActionArgs<{
2849
+ props: import("@rind-ui/core").ToolbarProps;
2850
+ events: import("@rind-ui/core").ToolbarEvent;
2851
+ env: import("@rind-ui/core").CollectionEnv;
2852
+ context: import("@rind-ui/core").CollectionContext;
2853
+ }>) => void;
2854
+ readonly keepFocusInside: (a: import("@rind-ui/core").ActionArgs<{
2855
+ props: import("@rind-ui/core").ToolbarProps;
2856
+ events: import("@rind-ui/core").ToolbarEvent;
2857
+ env: import("@rind-ui/core").CollectionEnv;
2858
+ context: import("@rind-ui/core").CollectionContext;
2859
+ }>) => void;
2860
+ readonly highlightFocused: ({ event, props, set }: import("@rind-ui/core").ActionArgs<{
2861
+ props: import("@rind-ui/core").ToolbarProps;
2862
+ events: import("@rind-ui/core").ToolbarEvent;
2863
+ env: import("@rind-ui/core").CollectionEnv;
2864
+ context: import("@rind-ui/core").CollectionContext;
2865
+ }>) => void;
2866
+ readonly focusStop: ({ props, context, env, set }: import("@rind-ui/core").ActionArgs<{
2867
+ props: import("@rind-ui/core").ToolbarProps;
2868
+ events: import("@rind-ui/core").ToolbarEvent;
2869
+ env: import("@rind-ui/core").CollectionEnv;
2870
+ context: import("@rind-ui/core").CollectionContext;
2871
+ }>) => void;
2872
+ };
2873
+ }, Record<never, never>>, "button" | "group" | "item" | "link" | "root" | "separator", readonly [{
2874
+ readonly name: string | RegExp;
2875
+ }], {
2876
+ readonly items: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">) => Promise<string[]>;
2877
+ readonly focusedItem: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">) => Promise<string | null>;
2878
+ readonly tabStop: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">) => Promise<string | null>;
2879
+ readonly isDisabled: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">, name: string | RegExp) => Promise<boolean>;
2880
+ readonly orientation: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">) => Promise<"horizontal" | "vertical">;
2881
+ }, {
2882
+ readonly tabIn: {
2883
+ readonly keyboard: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">) => Promise<void>;
2884
+ readonly done: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">) => Promise<boolean>;
2885
+ };
2886
+ readonly moveTo: {
2887
+ readonly keyboard: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">, name: string | RegExp) => Promise<void>;
2888
+ readonly done: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">, name: string | RegExp) => Promise<boolean>;
2889
+ };
2890
+ readonly press: {
2891
+ readonly pointer: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">, name: string | RegExp) => Promise<void>;
2892
+ readonly touch: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">, name: string | RegExp) => Promise<void>;
2893
+ readonly keyboard: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">, name: string | RegExp) => Promise<void>;
2894
+ readonly done: () => Promise<boolean>;
2895
+ };
2896
+ readonly tabOut: {
2897
+ readonly keyboard: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">) => Promise<void>;
2898
+ readonly done: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">) => Promise<boolean>;
2899
+ };
2900
+ readonly focusControl: {
2901
+ readonly keyboard: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">, name: string | RegExp) => Promise<void>;
2902
+ readonly done: () => Promise<boolean>;
2903
+ };
2904
+ readonly arrowNext: {
2905
+ readonly keyboard: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">) => Promise<void>;
2906
+ readonly done: () => Promise<boolean>;
2907
+ };
2908
+ readonly leave: {
2909
+ readonly keyboard: (env: import("@rind-ui/core").Env<"button" | "group" | "item" | "link" | "root" | "separator">) => Promise<void>;
2910
+ readonly done: () => Promise<boolean>;
2911
+ };
2912
+ }>>;
2913
+ //#endregion
2789
2914
  //#region src/form-invariants.d.ts
2790
2915
  type FormInvariant = ConsumerInvariant<typeof formContract>;
2791
2916
  interface FormStepInvariants {
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { a as mirror, i as isEnvFactory, n as UntilTimeout } from "./compose-C7RIqRoi.mjs";
2
- import { a as navigationLog, i as interceptNativeNavigation, n as installErrorLog, o as installAnnouncementLog, r as fakeRouter, s as recordingAnnouncer, t as domEnv } from "./dom-Ds2Cv9wy.mjs";
3
- import { n as playwrightEnv, r as watchPageErrors, t as isPage } from "./playwright-CNUCI2Xe.mjs";
4
- import { accordionContract, buttonContract, checkboxContract, checkboxGroupContract, collapsibleContract, createService, fieldContract, fieldsetContract, formContract, headingContract, labelContract, linkContract, platforms, platforms as platforms$1, quirkActive, radioGroupContract, segmentedControlContract, switchContract, tabsContract, textFieldContract, toggleContract, toggleGroupContract, withEngine, withEngine as withEngine$1 } from "@rind-ui/core";
1
+ import { a as mirror, i as isEnvFactory, n as UntilTimeout } from "./compose-DPLnCCnJ.mjs";
2
+ import { a as navigationLog, i as interceptNativeNavigation, n as installErrorLog, o as installAnnouncementLog, r as fakeRouter, s as recordingAnnouncer, t as domEnv } from "./dom-DZtl6G1E.mjs";
3
+ import { n as playwrightEnv, r as watchPageErrors, t as isPage } from "./playwright-C2LKzGS_.mjs";
4
+ import { accordionContract, buttonContract, checkboxContract, checkboxGroupContract, collapsibleContract, createService, fieldContract, fieldsetContract, formContract, headingContract, labelContract, linkContract, platforms, platforms as platforms$1, quirkActive, radioGroupContract, segmentedControlContract, separatorContract, separatorContractFor, switchContract, tabsContract, textFieldContract, toggleContract, toggleGroupContract, toolbarContract, withEngine, withEngine as withEngine$1 } from "@rind-ui/core";
5
5
  //#region src/accordion-invariants.ts
6
6
  const NAVIGATION_KEYS = /* @__PURE__ */ new Set([
7
7
  "ArrowUp",
@@ -146,6 +146,7 @@ function directed(env, direction) {
146
146
  nth: (i) => wrap(part.nth(i)),
147
147
  all: async () => (await part.all()).map(wrap),
148
148
  scoped: (scope, inner) => wrap(part.scoped(scope, inner)),
149
+ withAttr: (name, value) => wrap(part.withAttr(name, value)),
149
150
  labelled: () => wrap(part.labelled())
150
151
  });
151
152
  return {
@@ -326,6 +327,17 @@ function getSegmentedControl(target, anchor, options) {
326
327
  return createDriverWith(segmentedControlContract, target, [anchor], options);
327
328
  }
328
329
  //#endregion
330
+ //#region src/components/separator.ts
331
+ /**
332
+ * A driver for a Separator: the one named `name`, or the one separator part inside
333
+ * `within` (a container element or a Playwright locator; default the target). `host`: the
334
+ * scope of the component that draws it (`"toolbar"` for `Toolbar.Separator`).
335
+ */
336
+ function getSeparator(target, anchor = {}, options) {
337
+ const { within, name, host } = anchor;
338
+ return createDriverWith(host === void 0 ? separatorContract : separatorContractFor(host), within ?? target, [name === void 0 ? {} : { name }], options);
339
+ }
340
+ //#endregion
329
341
  //#region src/components/switch.ts
330
342
  /** A driver for the Switch named `name`. */
331
343
  function getSwitch(target, anchor, options) {
@@ -356,6 +368,12 @@ function getToggleGroup(target, anchor, options) {
356
368
  return createDriverWith(toggleGroupContract, target, [anchor], options);
357
369
  }
358
370
  //#endregion
371
+ //#region src/components/toolbar.ts
372
+ /** A driver for the Toolbar named `name`. */
373
+ function getToolbar(target, anchor, options) {
374
+ return createDriverWith(toolbarContract, target, [anchor], options);
375
+ }
376
+ //#endregion
359
377
  //#region src/form-invariants.ts
360
378
  /**
361
379
  * - `form-focus-only-on-attempt`: a step that is not a submit attempt (Validate, Reset)
@@ -619,7 +637,7 @@ const hiddenFocus = (f) => {
619
637
  if (focused?.inAriaHidden) out.push(`focus is on ${focused.describe}, inside aria-hidden`);
620
638
  if (focused?.inInert) out.push(`focus is on ${focused.describe}, inside inert`);
621
639
  for (const el of f.after.elements) {
622
- const formInput = f.traits.includes("form-associated") && el.attrs["data-part"] === "hidden-input" && el.attrs["tabindex"] === "-1";
640
+ const formInput = el.attrs["data-scope"] !== void 0 && el.attrs["data-part"] === "hidden-input" && el.attrs["tabindex"] === "-1";
623
641
  if (el.focusable && el.inAriaHidden && !el.hidden && !formInput) out.push(`${el.describe} is focusable inside aria-hidden`);
624
642
  }
625
643
  return out;
@@ -1466,7 +1484,8 @@ function replayEnv(base, snapshot, mode) {
1466
1484
  },
1467
1485
  nth: (i) => wrap(part.nth(i), name),
1468
1486
  all: async () => (await part.all()).map((p) => wrap(p, name)),
1469
- scoped: (scope, inner) => wrap(part.scoped(scope, inner), null)
1487
+ scoped: (scope, inner) => wrap(part.scoped(scope, inner), null),
1488
+ withAttr: (name, value) => wrap(part.withAttr(name, value), null)
1470
1489
  });
1471
1490
  return {
1472
1491
  env: {
@@ -1985,4 +2004,4 @@ function liveAnnouncements(log) {
1985
2004
  });
1986
2005
  }
1987
2006
  //#endregion
1988
- export { accordionStepInvariants, checkGeneric, checkboxStepInvariants, createDriver, createDriverWith, currentRun, domEnv, englishLeaks, fakePositioning, fakeRouter, formStepInvariants, genericInvariants, getAccordion, getButton, getCheckbox, getCheckboxGroup, getCollapsible, getField, getFieldset, getForm, getHeading, getLabel, getLink, getRadioGroup, getSegmentedControl, getSwitch, getTabs, getTextField, getToggle, getToggleGroup, installAnnouncementLog, interceptNativeNavigation, layoutInvariant, liveAnnouncements, machinePaths, missingAriaLines, missingStateStories, navigationLog, paths, platforms, playwrightEnv, pseudo, pseudoMessages, recordingAnnouncer, runAction, spokenLog, switchStepInvariants, testMachine, textFieldStepInvariants, toGraph, traitInvariants, uncovered, withEngine };
2007
+ export { accordionStepInvariants, checkGeneric, checkboxStepInvariants, createDriver, createDriverWith, currentRun, domEnv, englishLeaks, fakePositioning, fakeRouter, formStepInvariants, genericInvariants, getAccordion, getButton, getCheckbox, getCheckboxGroup, getCollapsible, getField, getFieldset, getForm, getHeading, getLabel, getLink, getRadioGroup, getSegmentedControl, getSeparator, getSwitch, getTabs, getTextField, getToggle, getToggleGroup, getToolbar, installAnnouncementLog, interceptNativeNavigation, layoutInvariant, liveAnnouncements, machinePaths, missingAriaLines, missingStateStories, navigationLog, paths, platforms, playwrightEnv, pseudo, pseudoMessages, recordingAnnouncer, runAction, spokenLog, switchStepInvariants, testMachine, textFieldStepInvariants, toGraph, traitInvariants, uncovered, withEngine };