@rind-ui/testing 0.4.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-C3LQTPFi.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;
@@ -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",
@@ -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,6 +597,60 @@ 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
+ },
584
654
  async setFiles(specs) {
585
655
  await (await waitFor()).setInputFiles(specs.map((f) => ({
586
656
  name: f.name,
@@ -591,35 +661,35 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform, partN
591
661
  waitForDetach: async () => {
592
662
  await until(async () => (await locate()).count(), (n) => n === 0);
593
663
  },
594
- isInert: async () => (await now()).evaluate((el) => el.closest("[inert]") !== null),
595
- attr: async (name) => (await now()).getAttribute(name),
596
- 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()),
597
667
  scoped: (scope, partName) => handle(`${scope}.${partName} in ${label}`, async () => (await now()).locator(`[data-scope="${scope}"][data-part="${partName}"]`)),
598
668
  withAttr: (name, value) => handle(`[${name}] in ${label}`, async () => (await now()).locator(value === void 0 ? `[${name}]` : `[${name}="${value.replace(/["\\]/g, "\\$&")}"]`)),
599
669
  accessibleName: async () => {
600
670
  const { root } = await getBase();
601
671
  await ensureInPage(root);
602
- return (await now()).evaluate((el) => globalThis.__rindTesting?.accessibleName(el) ?? "");
672
+ return readEval((el) => globalThis.__rindTesting?.accessibleName(el) ?? "");
603
673
  },
604
674
  accessibleDescription: async () => {
605
675
  const { root } = await getBase();
606
676
  await ensureInPage(root);
607
- return (await now()).evaluate((el) => globalThis.__rindTesting?.accessibleDescription(el) ?? "");
677
+ return readEval((el) => globalThis.__rindTesting?.accessibleDescription(el) ?? "");
608
678
  },
609
679
  labelled: () => handle(`the control of ${label}`, async () => {
610
- const text = (await (await now()).textContent() ?? "").replace(/\s+/g, " ").trim();
680
+ const text = (await read((l, o) => l.textContent(o)) ?? "").replace(/\s+/g, " ").trim();
611
681
  return (await getBase()).root.getByLabel(text, { exact: true });
612
682
  }),
613
683
  doubleClick: async () => (await waitFor()).dblclick(),
614
- text: async () => (await (await now()).textContent() ?? "").replace(/\s+/g, " ").trim(),
615
- value: async () => (await now()).inputValue(),
616
- checked: async () => (await now()).evaluate((el) => el.checked === true),
617
- 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),
618
688
  exists: async () => {
619
689
  await ensureInPage((await getBase()).root);
620
690
  return (await locate()).evaluateAll((els) => els.some((el) => globalThis.__rindTesting?.isVisible(el) === true));
621
691
  },
622
- isFocused: async () => (await now()).evaluate((el) => {
692
+ isFocused: async () => readEval((el) => {
623
693
  const active = document.activeElement;
624
694
  return active === el || el.id !== "" && active?.getAttribute("aria-activedescendant") === el.id;
625
695
  }),
@@ -1,4 +1,4 @@
1
- import { n as PlaywrightTarget, r as playwrightEnv, t as PlaywrightAdapterOptions } from "./playwright-D2coDhsT.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-BbVj53fU.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-DjurZVd0.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.4.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.4.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.4.0"
65
+ "@rind-ui/react": "0.5.0"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "@testing-library/dom": ">=10",