@rind-ui/testing 0.3.0 → 0.5.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 { r as EnvFactory } from "./adapter-B05M46SW.mjs";
1
+ import { r as EnvFactory } from "./adapter-BcAjuBjR.mjs";
2
2
  import { FrameLocator, Locator, Page } from "playwright";
3
3
  //#region src/adapters/playwright.d.ts
4
4
  type PlaywrightTarget = Page | Locator | FrameLocator;
@@ -1,4 +1,4 @@
1
- import { c as renamedSnapshot, r as describeBy, s as poll, t as composeInPage } from "./compose-BpR_PG11.mjs";
1
+ import { c as renamedSnapshot, r as describeBy, s as poll, t as composeInPage } from "./compose-m76ER6GL.mjs";
2
2
  //#region src/adapters/chromium-tree.ts
3
3
  const toNode = (n) => ({
4
4
  role: n.role?.value ?? "",
@@ -74,7 +74,10 @@ const PW_KEYS = {
74
74
  F6: "F6",
75
75
  F10: "F10",
76
76
  ContextMenu: "ContextMenu",
77
- A: "a"
77
+ A: "a",
78
+ "+": "NumpadAdd",
79
+ "-": "NumpadSubtract",
80
+ "0": "Digit0"
78
81
  };
79
82
  const keyName = (key, o = {}, apple) => [
80
83
  o.shift && "Shift",
@@ -208,10 +211,10 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform, partN
208
211
  timeout,
209
212
  wait
210
213
  });
211
- const byLocator = (root, by) => "role" in by ? root.getByRole(by.role, { ...by.name === void 0 ? {} : {
214
+ const byLocator = (root, by) => "role" in by ? [by.role].flat().map((role) => root.getByRole(role, { ...by.name === void 0 ? {} : {
212
215
  name: by.name,
213
216
  exact: true
214
- } }) : "label" in by ? root.getByLabel(by.label, { exact: true }) : "part" in by ? root.locator(`[data-scope="${scope}"][data-part="${partName?.(by.part) ?? by.part}"]`) : root.getByText(by.text, { exact: true });
217
+ } })).reduce((all, one) => all.or(one)) : "label" in by ? root.getByLabel(by.label, { exact: true }) : "part" in by ? root.locator(`[data-scope="${scope}"][data-part="${partName?.(by.part) ?? by.part}"]`) : root.getByText(by.text, { exact: true });
215
218
  const describeAll = (l) => l.evaluateAll((els) => els.map((el) => el.outerHTML.slice(0, 160)).join("\n"));
216
219
  /** What tells a navigation: the URL, the open pages, and the in-page log (fakeRouter). */
217
220
  const navigationState = async () => {
@@ -230,7 +233,10 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform, partN
230
233
  const n = await a.count();
231
234
  if (n === 0) throw new Error(`${scope}: no element matches the anchor (${describeBy(anchor)})`);
232
235
  if (n > 1) throw new Error(`${scope}: ${n} elements match the anchor (${describeBy(anchor)}):\n${await describeAll(a)}`);
233
- const id = await a.evaluate((el) => el.closest("[data-instance]")?.getAttribute("data-instance"));
236
+ const id = await a.evaluate((el) => el.closest("[data-instance]")?.getAttribute("data-instance"), void 0, { timeout: 1e3 }).catch((e) => {
237
+ if (e instanceof Error && e.name === "TimeoutError") throw new Error(`${scope}: no element matches the anchor (${describeBy(anchor)})`);
238
+ throw e;
239
+ });
234
240
  if (!id) throw new Error(`${scope}: the anchor has no data-instance`);
235
241
  return id;
236
242
  };
@@ -243,6 +249,16 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform, partN
243
249
  return l;
244
250
  };
245
251
  const now = async () => single(await locate());
252
+ const read = async (get) => {
253
+ const l = await now();
254
+ try {
255
+ return await get(l, { timeout: 1e3 });
256
+ } catch (e) {
257
+ if (e instanceof Error && e.name === "TimeoutError") throw new Error(`${label}: not found`);
258
+ throw e;
259
+ }
260
+ };
261
+ const readEval = (fn) => read((l, o) => l.evaluate(fn, void 0, o));
246
262
  const waitFor = async () => {
247
263
  const l = await locate();
248
264
  await until(() => l.count(), (n) => n > 0).catch(() => 0);
@@ -581,38 +597,99 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform, partN
581
597
  input.dispatchEvent(new InputEvent("input", init));
582
598
  }, text);
583
599
  },
600
+ async copySelection() {
601
+ await (await waitFor()).press("ControlOrMeta+C");
602
+ },
603
+ async selectRange(start, end) {
604
+ await (await waitFor()).evaluate((el, [a, b]) => {
605
+ el.setSelectionRange(a ?? 0, b ?? 0);
606
+ el.dispatchEvent(new Event("select", { bubbles: true }));
607
+ }, [start, end]);
608
+ },
609
+ async dropFiles(specs) {
610
+ await (await waitFor()).evaluate((el, specs) => {
611
+ const dt = new DataTransfer();
612
+ for (const f of specs) dt.items.add(new File([f.content], f.name, { type: f.type }));
613
+ for (const type of [
614
+ "dragenter",
615
+ "dragover",
616
+ "drop"
617
+ ]) el.dispatchEvent(new DragEvent(type, {
618
+ bubbles: true,
619
+ cancelable: true,
620
+ dataTransfer: dt
621
+ }));
622
+ }, specs);
623
+ },
624
+ async pasteFiles(specs) {
625
+ await (await waitFor()).evaluate((el, specs) => {
626
+ const dt = new DataTransfer();
627
+ for (const f of specs) dt.items.add(new File([f.content], f.name, { type: f.type }));
628
+ const e = new ClipboardEvent("paste", {
629
+ bubbles: true,
630
+ cancelable: true,
631
+ clipboardData: dt
632
+ });
633
+ if (!e.clipboardData?.files.length) Object.defineProperty(e, "clipboardData", { value: dt });
634
+ el.dispatchEvent(e);
635
+ }, specs);
636
+ },
637
+ async wheel(deltaY) {
638
+ await (await waitFor()).hover();
639
+ const { page } = await getBase();
640
+ await page.mouse.wheel(0, deltaY);
641
+ },
642
+ async dragFiles(phase) {
643
+ await (await waitFor()).evaluate((el, phase) => {
644
+ const dt = new DataTransfer();
645
+ dt.items.add(new File(["x"], "drag.txt", { type: "text/plain" }));
646
+ const types = phase === "enter" ? ["dragenter", "dragover"] : ["dragleave"];
647
+ for (const type of types) el.dispatchEvent(new DragEvent(type, {
648
+ bubbles: true,
649
+ cancelable: true,
650
+ dataTransfer: dt
651
+ }));
652
+ }, phase);
653
+ },
654
+ async setFiles(specs) {
655
+ await (await waitFor()).setInputFiles(specs.map((f) => ({
656
+ name: f.name,
657
+ mimeType: f.type,
658
+ buffer: Buffer.from(f.content)
659
+ })));
660
+ },
584
661
  waitForDetach: async () => {
585
662
  await until(async () => (await locate()).count(), (n) => n === 0);
586
663
  },
587
- isInert: async () => (await now()).evaluate((el) => el.closest("[inert]") !== null),
588
- attr: async (name) => (await now()).getAttribute(name),
589
- tagName: async () => (await now()).evaluate((el) => el.tagName.toLowerCase()),
664
+ isInert: async () => readEval((el) => el.closest("[inert]") !== null),
665
+ attr: async (name) => read((l, o) => l.getAttribute(name, o)),
666
+ tagName: async () => readEval((el) => el.tagName.toLowerCase()),
590
667
  scoped: (scope, partName) => handle(`${scope}.${partName} in ${label}`, async () => (await now()).locator(`[data-scope="${scope}"][data-part="${partName}"]`)),
591
668
  withAttr: (name, value) => handle(`[${name}] in ${label}`, async () => (await now()).locator(value === void 0 ? `[${name}]` : `[${name}="${value.replace(/["\\]/g, "\\$&")}"]`)),
592
669
  accessibleName: async () => {
593
670
  const { root } = await getBase();
594
671
  await ensureInPage(root);
595
- return (await now()).evaluate((el) => globalThis.__rindTesting?.accessibleName(el) ?? "");
672
+ return readEval((el) => globalThis.__rindTesting?.accessibleName(el) ?? "");
596
673
  },
597
674
  accessibleDescription: async () => {
598
675
  const { root } = await getBase();
599
676
  await ensureInPage(root);
600
- return (await now()).evaluate((el) => globalThis.__rindTesting?.accessibleDescription(el) ?? "");
677
+ return readEval((el) => globalThis.__rindTesting?.accessibleDescription(el) ?? "");
601
678
  },
602
679
  labelled: () => handle(`the control of ${label}`, async () => {
603
- const text = (await (await now()).textContent() ?? "").replace(/\s+/g, " ").trim();
680
+ const text = (await read((l, o) => l.textContent(o)) ?? "").replace(/\s+/g, " ").trim();
604
681
  return (await getBase()).root.getByLabel(text, { exact: true });
605
682
  }),
606
683
  doubleClick: async () => (await waitFor()).dblclick(),
607
- text: async () => (await (await now()).textContent() ?? "").replace(/\s+/g, " ").trim(),
608
- value: async () => (await now()).inputValue(),
609
- checked: async () => (await now()).evaluate((el) => el.checked === true),
610
- indeterminate: async () => (await now()).evaluate((el) => el.indeterminate === true),
684
+ text: async () => (await read((l, o) => l.textContent(o)) ?? "").replace(/\s+/g, " ").trim(),
685
+ value: async () => read((l, o) => l.inputValue(o)),
686
+ checked: async () => readEval((el) => el.checked === true),
687
+ indeterminate: async () => readEval((el) => el.indeterminate === true),
611
688
  exists: async () => {
612
689
  await ensureInPage((await getBase()).root);
613
690
  return (await locate()).evaluateAll((els) => els.some((el) => globalThis.__rindTesting?.isVisible(el) === true));
614
691
  },
615
- isFocused: async () => (await now()).evaluate((el) => {
692
+ isFocused: async () => readEval((el) => {
616
693
  const active = document.activeElement;
617
694
  return active === el || el.id !== "" && active?.getAttribute("aria-activedescendant") === el.id;
618
695
  }),
@@ -1,4 +1,4 @@
1
- import { n as PlaywrightTarget, r as playwrightEnv, t as PlaywrightAdapterOptions } from "./playwright-By15MZsN.mjs";
1
+ import { n as PlaywrightTarget, r as playwrightEnv, t as PlaywrightAdapterOptions } from "./playwright-CnXZVExy.mjs";
2
2
  import { Page } from "playwright";
3
3
  //#region src/adapters/chromium-tree.d.ts
4
4
  interface AxNode {
@@ -1 +1 @@
1
- export { i as axNodeOf, a as chromiumTree, n as playwrightEnv } from "./playwright-C3Ue38p3.mjs";
1
+ export { i as axNodeOf, a as chromiumTree, n as playwrightEnv } from "./playwright-D79Husn_.mjs";
package/dist/setup.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as navigationLog, n as installErrorLog, o as installAnnouncementLog } from "./dom-Bnnr_fg-.mjs";
1
+ import { a as navigationLog, n as installErrorLog, o as installAnnouncementLog } from "./dom-D9Da5Fku.mjs";
2
2
  //#region src/setup.ts
3
3
  function define(target, name, value) {
4
4
  if (!target || Reflect.get(target, name) != null) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rind-ui/testing",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Test drivers and environment setup for rind-ui components (Testing Library and Playwright).",
5
5
  "license": "MIT",
6
6
  "author": "Watermelon Bros",
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "dom-accessibility-api": "^0.7.1",
55
- "@rind-ui/core": "0.3.0"
55
+ "@rind-ui/core": "0.5.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@internationalized/date": "^3.12.4",
@@ -62,7 +62,7 @@
62
62
  "react": "^19.3.0",
63
63
  "react-dom": "^19.3.0",
64
64
  "rolldown": "1.2.13",
65
- "@rind-ui/react": "0.3.0"
65
+ "@rind-ui/react": "0.5.0"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "@testing-library/dom": ">=10",