@rind-ui/testing 0.2.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.
@@ -1,14 +1,17 @@
1
- import { r as EnvFactory } from "./adapter-UPhu17S6.mjs";
1
+ import { r as EnvFactory } from "./adapter-B05M46SW.mjs";
2
2
  import { FrameLocator, Locator, Page } from "playwright";
3
3
  //#region src/adapters/playwright.d.ts
4
4
  type PlaywrightTarget = Page | Locator | FrameLocator;
5
5
  interface PlaywrightAdapterOptions {
6
6
  /** `until` timeout in ms (default 5000, Playwright's expect timeout). */
7
7
  readonly timeout?: number;
8
- /** Advances time when the page uses `page.clock`; defaults to waiting. */
8
+ /**
9
+ * Advances time when the page uses `page.clock`; defaults to waiting. Pause the clock
10
+ * (`page.clock.pauseAt`) after installing it: an installed clock also flows with real
11
+ * time, so polling and load would move the page's time too.
12
+ */
9
13
  readonly advanceTimers?: (ms: number) => Promise<unknown>;
10
14
  }
11
- /** The Playwright adapter. */
12
15
  declare function playwrightEnv(target: PlaywrightTarget, options?: PlaywrightAdapterOptions): EnvFactory;
13
16
  //#endregion
14
17
  export { PlaywrightTarget as n, playwrightEnv as r, PlaywrightAdapterOptions as t };
@@ -1,4 +1,4 @@
1
- import { o as poll, r as describeBy, t as composeInPage } from "./compose-DPLnCCnJ.mjs";
1
+ import { c as renamedSnapshot, r as describeBy, s as poll, t as composeInPage } from "./compose-BpR_PG11.mjs";
2
2
  //#region src/adapters/chromium-tree.ts
3
3
  const toNode = (n) => ({
4
4
  role: n.role?.value ?? "",
@@ -71,6 +71,7 @@ const PW_KEYS = {
71
71
  ArrowRight: "ArrowRight",
72
72
  Backspace: "Backspace",
73
73
  Delete: "Delete",
74
+ F6: "F6",
74
75
  F10: "F10",
75
76
  ContextMenu: "ContextMenu",
76
77
  A: "a"
@@ -162,6 +163,8 @@ function watchPageErrors(page) {
162
163
  return log;
163
164
  }
164
165
  /** The Playwright adapter. */
166
+ /** Per page: the CDP session holding its animation rate at 0 (an armed hold, Chromium). */
167
+ const armedHolds = /* @__PURE__ */ new WeakMap();
165
168
  function playwrightEnv(target, options = {}) {
166
169
  let base;
167
170
  const getBase = () => {
@@ -181,7 +184,7 @@ function playwrightEnv(target, options = {}) {
181
184
  create: (envOptions) => createPlaywrightEnv(getBase, envOptions, options)
182
185
  };
183
186
  }
184
- function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, options) {
187
+ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform, partName, anatomyName }, options) {
185
188
  const apple = platform?.apple;
186
189
  const composingInit = (key, o = {}) => ({
187
190
  key: key === "Space" ? " " : key,
@@ -192,6 +195,15 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, opt
192
195
  });
193
196
  const timeout = options.timeout ?? 5e3;
194
197
  const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
198
+ /**
199
+ * One frame after a key press: what the press changed is committed before the next read
200
+ * (a driver arrowing through options reads the selection after every key; under load the
201
+ * read could beat the commit and overshoot). No person types faster than a frame.
202
+ */
203
+ const settle = async () => {
204
+ if (options.advanceTimers) return options.advanceTimers(16);
205
+ await (await getBase()).root.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => resolve())));
206
+ };
195
207
  const until = (read, accept) => poll(read, accept, {
196
208
  timeout,
197
209
  wait
@@ -199,7 +211,7 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, opt
199
211
  const byLocator = (root, by) => "role" in by ? root.getByRole(by.role, { ...by.name === void 0 ? {} : {
200
212
  name: by.name,
201
213
  exact: true
202
- } }) : "part" in by ? root.locator(`[data-scope="${scope}"][data-part="${by.part}"]`) : root.getByText(by.text, { 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 });
203
215
  const describeAll = (l) => l.evaluateAll((els) => els.map((el) => el.outerHTML.slice(0, 160)).join("\n"));
204
216
  /** What tells a navigation: the URL, the open pages, and the in-page log (fakeRouter). */
205
217
  const navigationState = async () => {
@@ -272,6 +284,15 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, opt
272
284
  await l.dispatchEvent("pointerenter", { pointerType: "touch" });
273
285
  },
274
286
  focus: async () => (await waitFor()).focus(),
287
+ async focusWithTab() {
288
+ await (await waitFor()).evaluate((el) => {
289
+ const stops = Array.from(el.ownerDocument.querySelectorAll("a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]")).filter((s) => s.tabIndex >= 0 && !s.matches(":disabled") && !s.closest("[inert]") && s.getClientRects().length > 0);
290
+ const before = stops[stops.indexOf(el) - 1];
291
+ if (before) before.focus();
292
+ else el.ownerDocument.activeElement?.blur?.();
293
+ });
294
+ await (await getBase()).page.keyboard.press("Tab");
295
+ },
275
296
  async press(key, keyOptions) {
276
297
  const l = await waitFor();
277
298
  if (!await l.evaluate((el) => el === document.activeElement)) await l.focus();
@@ -280,6 +301,7 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, opt
280
301
  return;
281
302
  }
282
303
  await l.press(keyName(key, keyOptions, apple));
304
+ await settle();
283
305
  },
284
306
  async type(text) {
285
307
  const l = await waitFor();
@@ -332,11 +354,232 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, opt
332
354
  commit
333
355
  });
334
356
  },
335
- async pressAtPosition() {
357
+ async pressAtPosition(at) {
336
358
  const box = await (await waitFor()).boundingBox();
337
359
  if (!box) throw new Error("pressAtPosition: the part has no box");
338
360
  const { page } = await getBase();
339
- await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
361
+ const [x, y] = at?.corner ? [box.x + 2, box.y + 2] : [box.x + box.width / 2, box.y + box.height / 2];
362
+ await page.mouse.click(x, y);
363
+ },
364
+ async longPress(hold) {
365
+ const l = await waitFor();
366
+ const box = await l.boundingBox();
367
+ const init = {
368
+ bubbles: true,
369
+ cancelable: true,
370
+ clientX: (box?.x ?? 0) + (box?.width ?? 0) * (hold?.at?.x ?? .5),
371
+ clientY: (box?.y ?? 0) + (box?.height ?? 0) * (hold?.at?.y ?? .5),
372
+ pointerId: 7,
373
+ pointerType: hold?.pointerType ?? "touch",
374
+ isPrimary: true,
375
+ pressure: .5,
376
+ width: 20,
377
+ height: 20
378
+ };
379
+ await l.dispatchEvent("pointerdown", {
380
+ ...init,
381
+ buttons: 1
382
+ });
383
+ const ms = hold?.ms ?? 520;
384
+ if (options.advanceTimers) await options.advanceTimers(ms);
385
+ else await (await getBase()).page.waitForTimeout(ms);
386
+ await l.dispatchEvent("pointerup", {
387
+ ...init,
388
+ buttons: 0
389
+ });
390
+ },
391
+ async drag(vector, dragOptions) {
392
+ const l = await waitFor();
393
+ const box = await l.boundingBox();
394
+ if (!box) throw new Error(`${label}: drag needs layout`);
395
+ const { page } = await getBase();
396
+ const x0 = box.x + box.width / 2;
397
+ const y0 = box.y + box.height / 2;
398
+ const type = dragOptions?.pointerType ?? "mouse";
399
+ const steps = Math.max(1, dragOptions?.steps ?? 10);
400
+ const stepMs = (dragOptions?.durationMs ?? 300) / steps;
401
+ const wait = async () => {
402
+ if (options.advanceTimers) await options.advanceTimers(stepMs);
403
+ else await page.waitForTimeout(stepMs);
404
+ };
405
+ const at = (i) => ({
406
+ x: x0 + vector.x * i / steps,
407
+ y: y0 + vector.y * i / steps
408
+ });
409
+ if (type === "touch") {
410
+ const fire = (kind, p, touching) => l.evaluate((el, a) => {
411
+ const target = document.elementFromPoint(a.p.x, a.p.y) ?? el;
412
+ const e = new Event(a.kind, {
413
+ bubbles: true,
414
+ cancelable: true,
415
+ composed: true
416
+ });
417
+ const point = {
418
+ identifier: 1,
419
+ target,
420
+ clientX: a.p.x,
421
+ clientY: a.p.y
422
+ };
423
+ const touches = a.touching ? [point] : [];
424
+ Object.defineProperties(e, {
425
+ touches: { value: touches },
426
+ targetTouches: { value: touches },
427
+ changedTouches: { value: [point] }
428
+ });
429
+ target.dispatchEvent(e);
430
+ }, {
431
+ kind,
432
+ p,
433
+ touching
434
+ });
435
+ const start = at(0);
436
+ await l.evaluate((el, p) => {
437
+ (document.elementFromPoint(p.x, p.y) ?? el).dispatchEvent(new PointerEvent("pointerdown", {
438
+ bubbles: true,
439
+ cancelable: true,
440
+ composed: true,
441
+ clientX: p.x,
442
+ clientY: p.y,
443
+ pointerId: 10,
444
+ pointerType: "touch",
445
+ isPrimary: true,
446
+ pressure: .5,
447
+ width: 20,
448
+ height: 20,
449
+ buttons: 1
450
+ }));
451
+ }, start);
452
+ await fire("touchstart", start, true);
453
+ for (let i = 1; i <= steps; i++) {
454
+ await wait();
455
+ await fire("touchmove", at(i), true);
456
+ }
457
+ await fire("touchend", at(steps), false);
458
+ return;
459
+ }
460
+ const start = at(0);
461
+ await page.mouse.move(start.x, start.y);
462
+ await page.mouse.down();
463
+ for (let i = 1; i <= steps; i++) {
464
+ await wait();
465
+ const p = at(i);
466
+ await page.mouse.move(p.x, p.y);
467
+ }
468
+ await page.mouse.up();
469
+ },
470
+ async contextMenu(options) {
471
+ const l = await waitFor();
472
+ const box = await l.boundingBox();
473
+ if (!box) throw new Error("contextMenu: the part has no box");
474
+ const position = {
475
+ x: box.width * (options?.at?.x ?? .5),
476
+ y: box.height * (options?.at?.y ?? .5)
477
+ };
478
+ if (modality === "virtual") {
479
+ await l.dispatchEvent("contextmenu", {
480
+ bubbles: true,
481
+ cancelable: true,
482
+ clientX: box.x + position.x,
483
+ clientY: box.y + position.y
484
+ });
485
+ return;
486
+ }
487
+ await l.click({
488
+ button: "right",
489
+ position
490
+ });
491
+ },
492
+ box: async () => {
493
+ const box = await (await now()).boundingBox();
494
+ return box && (box.width > 0 || box.height > 0) ? box : null;
495
+ },
496
+ async pointer(phase, pointerOptions) {
497
+ const l = await waitFor();
498
+ const box = await l.boundingBox();
499
+ if (!box || box.width === 0 && box.height === 0) throw new Error(`${label}: pointer("${phase}") needs layout, which this environment does not have`);
500
+ const x = box.x + pointerOptions.at.x * box.width;
501
+ const y = box.y + pointerOptions.at.y * box.height;
502
+ const pointerType = pointerOptions.pointerType ?? "mouse";
503
+ const { page } = await getBase();
504
+ if (pointerType === "mouse" && phase !== "cancel") {
505
+ await page.mouse.move(x, y);
506
+ if (phase === "down") await page.mouse.down();
507
+ if (phase === "up") await page.mouse.up();
508
+ return;
509
+ }
510
+ await l.evaluate((el, o) => {
511
+ const target = (o.phase === "down" ? document.elementFromPoint(o.x, o.y) : null) ?? el;
512
+ const pressing = o.phase === "down" || o.phase === "move";
513
+ target.dispatchEvent(new PointerEvent(`pointer${o.phase}`, {
514
+ bubbles: true,
515
+ cancelable: o.phase !== "cancel",
516
+ composed: true,
517
+ pointerId: o.pointerType === "mouse" ? 1 : 2,
518
+ pointerType: o.pointerType,
519
+ isPrimary: true,
520
+ clientX: o.x,
521
+ clientY: o.y,
522
+ button: o.phase === "move" ? -1 : 0,
523
+ buttons: pressing ? 1 : 0,
524
+ pressure: pressing ? .5 : 0
525
+ }));
526
+ }, {
527
+ phase,
528
+ x,
529
+ y,
530
+ pointerType
531
+ });
532
+ },
533
+ async fill(value) {
534
+ await (await waitFor()).evaluate((el, v) => {
535
+ const input = el;
536
+ const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), "value")?.set;
537
+ if (setter) setter.call(input, v);
538
+ else input.value = v;
539
+ input.dispatchEvent(new Event("input", { bubbles: true }));
540
+ input.dispatchEvent(new Event("change", { bubbles: true }));
541
+ }, value);
542
+ },
543
+ async paste(text) {
544
+ await (await waitFor()).evaluate((el, text) => {
545
+ const input = el;
546
+ const start = input.selectionStart ?? input.value.length;
547
+ const end = input.selectionEnd ?? start;
548
+ let paste;
549
+ if (typeof DataTransfer === "function" && typeof ClipboardEvent === "function") {
550
+ const clipboardData = new DataTransfer();
551
+ clipboardData.setData("text/plain", text);
552
+ paste = new ClipboardEvent("paste", {
553
+ clipboardData,
554
+ bubbles: true,
555
+ cancelable: true
556
+ });
557
+ if (!paste.clipboardData?.getData("text/plain")) Object.defineProperty(paste, "clipboardData", { value: clipboardData });
558
+ } else {
559
+ paste = new Event("paste", {
560
+ bubbles: true,
561
+ cancelable: true
562
+ });
563
+ Object.defineProperty(paste, "clipboardData", { value: { getData: (type) => /^text(\/plain)?$/.test(type) ? text : "" } });
564
+ }
565
+ if (!input.dispatchEvent(paste)) return;
566
+ const init = {
567
+ inputType: "insertFromPaste",
568
+ data: text,
569
+ bubbles: true
570
+ };
571
+ const before = new InputEvent("beforeinput", {
572
+ ...init,
573
+ cancelable: true
574
+ });
575
+ if (!input.dispatchEvent(before)) return;
576
+ const next = input.value.slice(0, start) + text + input.value.slice(end);
577
+ const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), "value")?.set;
578
+ if (setter) setter.call(input, next);
579
+ else input.value = next;
580
+ input.setSelectionRange(start + text.length, start + text.length);
581
+ input.dispatchEvent(new InputEvent("input", init));
582
+ }, text);
340
583
  },
341
584
  waitForDetach: async () => {
342
585
  await until(async () => (await locate()).count(), (n) => n === 0);
@@ -385,7 +628,7 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, opt
385
628
  const partLocator = async (name, by) => {
386
629
  const { root } = await getBase();
387
630
  const id = await instance();
388
- const parts = root.locator(`[data-scope="${scope}"][data-part="${name}"][data-instance="${id}"]`);
631
+ const parts = root.locator(`[data-scope="${scope}"][data-part="${partName?.(name) ?? name}"][data-instance="${id}"]`);
389
632
  return by ? parts.and(byLocator(root, by)) : parts;
390
633
  };
391
634
  return {
@@ -399,6 +642,7 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, opt
399
642
  return;
400
643
  }
401
644
  await (await getBase()).page.keyboard.press(keyName(key, keyOptions, apple));
645
+ await settle();
402
646
  },
403
647
  async pointerOutside() {
404
648
  await (await getBase()).root.locator("body").click({
@@ -409,6 +653,15 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, opt
409
653
  force: true
410
654
  });
411
655
  },
656
+ async pointerAway() {
657
+ await (await getBase()).root.locator("body").hover({
658
+ position: {
659
+ x: 1,
660
+ y: 1
661
+ },
662
+ force: true
663
+ });
664
+ },
412
665
  until,
413
666
  advance: async (ms) => {
414
667
  if (options.advanceTimers) await options.advanceTimers(ms);
@@ -445,7 +698,7 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, opt
445
698
  scope,
446
699
  instance: await instance()
447
700
  };
448
- return root.evaluate((a) => globalThis.__rindTesting?.collectDom(a), arg);
701
+ return renamedSnapshot(await root.evaluate((a) => globalThis.__rindTesting?.collectDom(a), arg), anatomyName);
449
702
  },
450
703
  announcements: async () => {
451
704
  const { root } = await getBase();
@@ -456,6 +709,46 @@ function createPlaywrightEnv(getBase, { scope, anchor, modality, platform }, opt
456
709
  return root.evaluate(() => [...Reflect.get(globalThis, Symbol.for("rind-ui.announcements")) ?? []]);
457
710
  },
458
711
  takeErrors: async () => watchPageErrors((await getBase()).page).splice(0),
712
+ armHold: async () => {
713
+ const { page } = await getBase();
714
+ if (page.context().browser()?.browserType().name() === "chromium") {
715
+ const cdp = await page.context().newCDPSession(page);
716
+ armedHolds.set(page, cdp);
717
+ await cdp.send("Animation.enable");
718
+ await cdp.send("Animation.setPlaybackRate", { playbackRate: 0 });
719
+ return;
720
+ }
721
+ await page.evaluate(() => {
722
+ const style = document.createElement("style");
723
+ style.setAttribute("data-rind-hold", "");
724
+ style.textContent = "*,*::before,*::after{animation-play-state:paused!important}";
725
+ document.head.append(style);
726
+ });
727
+ },
728
+ holdAnimations: async () => {
729
+ const { page } = await getBase();
730
+ await page.evaluate(() => {
731
+ const style = document.querySelector("style[data-rind-hold]");
732
+ const held = document.getAnimations().filter((a) => a.playState === "running" || style !== null && a.playState === "paused");
733
+ for (const a of held) a.pause();
734
+ Reflect.set(globalThis, Symbol.for("rind-ui.held-animations"), held);
735
+ style?.remove();
736
+ });
737
+ const cdp = armedHolds.get(page);
738
+ if (cdp) {
739
+ armedHolds.delete(page);
740
+ await cdp.send("Animation.setPlaybackRate", { playbackRate: 1 });
741
+ await cdp.detach();
742
+ }
743
+ return async () => {
744
+ await page.evaluate(() => {
745
+ const key = Symbol.for("rind-ui.held-animations");
746
+ const held = Reflect.get(globalThis, key) ?? [];
747
+ for (const a of held) if (a.playState === "paused") a.play();
748
+ Reflect.deleteProperty(globalThis, key);
749
+ });
750
+ };
751
+ },
459
752
  chromiumChecks: async () => {
460
753
  const { page, root } = await getBase();
461
754
  /**
@@ -1,4 +1,4 @@
1
- import { n as PlaywrightTarget, r as playwrightEnv, t as PlaywrightAdapterOptions } from "./playwright-CtIxjMKr.mjs";
1
+ import { n as PlaywrightTarget, r as playwrightEnv, t as PlaywrightAdapterOptions } from "./playwright-By15MZsN.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-C2LKzGS_.mjs";
1
+ export { i as axNodeOf, a as chromiumTree, n as playwrightEnv } from "./playwright-C3Ue38p3.mjs";
package/dist/setup.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as navigationLog, n as installErrorLog, o as installAnnouncementLog } from "./dom-DZtl6G1E.mjs";
1
+ import { a as navigationLog, n as installErrorLog, o as installAnnouncementLog } from "./dom-Bnnr_fg-.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.2.0",
3
+ "version": "0.3.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,16 +52,17 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "dom-accessibility-api": "^0.7.1",
55
- "@rind-ui/core": "0.2.0"
55
+ "@rind-ui/core": "0.3.0"
56
56
  },
57
57
  "devDependencies": {
58
+ "@internationalized/date": "^3.12.4",
58
59
  "@types/node": "^24.19.2",
59
60
  "@types/react": "^19.3.0",
60
61
  "@types/react-dom": "^19.3.0",
61
62
  "react": "^19.3.0",
62
63
  "react-dom": "^19.3.0",
63
64
  "rolldown": "1.2.13",
64
- "@rind-ui/react": "0.2.0"
65
+ "@rind-ui/react": "0.3.0"
65
66
  },
66
67
  "peerDependencies": {
67
68
  "@testing-library/dom": ">=10",