@rind-ui/testing 0.1.0 → 0.3.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.
@@ -17,8 +17,10 @@ interface ElementInfo {
17
17
  readonly inAriaHidden: boolean;
18
18
  readonly inInert: boolean;
19
19
  readonly focusable: boolean;
20
- /** Finite animations running on the element (exit animations a presence waits for). */
20
+ /** Finite animations running (or held) on the element: exit animations presence waits for. */
21
21
  readonly animations: number;
22
+ /** Its computed style animates (a transition or animation duration above zero). */
23
+ readonly motion: boolean;
22
24
  /** The element's identity across snapshots of one page (same node, same number). */
23
25
  readonly node: number;
24
26
  /** Its border box in viewport coordinates (all zero without layout). */
@@ -120,6 +122,17 @@ interface AdapterEnv extends Env {
120
122
  announcements(): Promise<readonly Announcement[]>;
121
123
  /** Uncaught errors and `console.error` calls since the last call. */
122
124
  takeErrors(): Promise<readonly string[]>;
125
+ /**
126
+ * Pauses every running animation in the document and returns their resume: holds an exit
127
+ * animation while the runner reopens during it, however slow the run (CI Linux).
128
+ */
129
+ holdAnimations?(): Promise<() => Promise<void>>;
130
+ /**
131
+ * Called before a step that closes a presence layer, so its exit cannot end before
132
+ * `holdAnimations` runs (a slow round trip outlasts a 150 ms exit): animations starting
133
+ * now stay at their start until the hold, which ends this.
134
+ */
135
+ armHold?(): Promise<void>;
123
136
  /**
124
137
  * Chromium accessibility-tree checks for the instance (Playwright in Chromium only):
125
138
  * problems found, or "unavailable" elsewhere.
@@ -138,6 +151,10 @@ interface AdapterEnv extends Env {
138
151
  }
139
152
  interface EnvOptions {
140
153
  readonly scope: string;
154
+ /** A hosted component's part names (the contract's `partName`): a part's `data-part`. */
155
+ readonly partName?: ((part: string) => string) | undefined;
156
+ /** The inverse: a hosted `data-part` read from the DOM, as the contract names the part. */
157
+ readonly anatomyName?: ((part: string) => string) | undefined;
141
158
  readonly anchor: By;
142
159
  readonly modality: Modality;
143
160
  /** The platform the test runs as: decides the `mod` key (Meta on Apple, Control elsewhere). */
@@ -1,4 +1,36 @@
1
1
  //#region src/adapter.ts
2
+ /**
3
+ * A contract's `partName` for the adapters: applied to its anatomy names only, so a name read
4
+ * back from the DOM (already the host's) is used as it is.
5
+ */
6
+ function hostedPartName(contract) {
7
+ const map = contract.partName;
8
+ if (!map) return {};
9
+ const anatomy = new Set(contract.anatomy);
10
+ const back = new Map(contract.anatomy.map((part) => [map(part), part]));
11
+ return {
12
+ partName: (part) => anatomy.has(part) ? map(part) : part,
13
+ anatomyName: (part) => back.get(part) ?? part
14
+ };
15
+ }
16
+ /** A snapshot with its parts named as the contract names them (a hosted component's parts). */
17
+ function renamedSnapshot(snapshot, anatomyName) {
18
+ if (!anatomyName) return snapshot;
19
+ const rename = (el) => el.part === null ? el : {
20
+ ...el,
21
+ part: anatomyName(el.part)
22
+ };
23
+ return {
24
+ ...snapshot,
25
+ parts: snapshot.parts.map(rename),
26
+ elements: snapshot.elements.map(rename),
27
+ focus: {
28
+ ...snapshot.focus,
29
+ part: snapshot.focus.part === null ? null : anatomyName(snapshot.focus.part),
30
+ element: snapshot.focus.element === null ? null : rename(snapshot.focus.element)
31
+ }
32
+ };
33
+ }
2
34
  const isEnvFactory = (value) => typeof value === "object" && value !== null && "~rindEnvFactory" in value;
3
35
  /**
4
36
  * Shared `until` loop with a deadline. Elapsed time is the larger of the wall clock and the
@@ -35,7 +67,7 @@ var UntilTimeout = class extends Error {
35
67
  };
36
68
  /** Mirrors horizontal arrows for right-to-left runs; everything else is unchanged. */
37
69
  const mirror = (key, direction) => direction === "ltr" ? key : key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
38
- const describeBy = (by) => "role" in by ? `role "${by.role}"${by.name === void 0 ? "" : ` named ${JSON.stringify(String(by.name))}`}` : `text ${JSON.stringify(String(by.text))}`;
70
+ const describeBy = (by) => "role" in by ? `role "${by.role}"${by.name === void 0 ? "" : ` named ${JSON.stringify(String(by.name))}`}` : "label" in by ? `control labelled ${JSON.stringify(String(by.label))}` : "part" in by ? `part "${by.part}"` : `text ${JSON.stringify(String(by.text))}`;
39
71
  //#endregion
40
72
  //#region src/adapters/compose.ts
41
73
  /**
@@ -108,4 +140,4 @@ function composeInPage(el, { updates, commit }) {
108
140
  }));
109
141
  }
110
142
  //#endregion
111
- export { mirror as a, isEnvFactory as i, UntilTimeout as n, poll as o, describeBy as r, composeInPage as t };
143
+ export { isEnvFactory as a, renamedSnapshot as c, hostedPartName as i, UntilTimeout as n, mirror as o, describeBy as r, poll as s, composeInPage as t };