@remit/ui 0.0.215 → 0.0.217

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/ui",
3
- "version": "0.0.215",
3
+ "version": "0.0.217",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -0,0 +1,98 @@
1
+ import "@remit/test-dom";
2
+ import assert from "node:assert/strict";
3
+ import { afterEach, beforeEach, describe, it } from "node:test";
4
+ import { act, createElement } from "react";
5
+ import { createRoot, type Root } from "react-dom/client";
6
+ import {
7
+ CalendarSuggestionDeck,
8
+ type CalendarSuggestionDeckProps,
9
+ } from "./calendar-suggestion-deck.js";
10
+
11
+ let container: HTMLElement;
12
+ let root: Root;
13
+ let captured: number[];
14
+ let confirmed: number;
15
+ let pressed: number;
16
+
17
+ const originalSet = HTMLElement.prototype.setPointerCapture;
18
+ const originalHas = HTMLElement.prototype.hasPointerCapture;
19
+
20
+ beforeEach(() => {
21
+ captured = [];
22
+ confirmed = 0;
23
+ pressed = 0;
24
+ HTMLElement.prototype.setPointerCapture = (pointerId: number) => {
25
+ captured.push(pointerId);
26
+ };
27
+ HTMLElement.prototype.hasPointerCapture = (pointerId: number) =>
28
+ captured.includes(pointerId);
29
+ const deckProps: CalendarSuggestionDeckProps = {
30
+ hasCard: true,
31
+ remaining: 1,
32
+ blocked: false,
33
+ blockedReason: "",
34
+ onConfirm: () => {
35
+ confirmed += 1;
36
+ },
37
+ onReject: () => undefined,
38
+ children: createElement(
39
+ "button",
40
+ {
41
+ type: "button",
42
+ onClick: () => {
43
+ pressed += 1;
44
+ },
45
+ },
46
+ "Change first",
47
+ ),
48
+ };
49
+ container = document.createElement("div");
50
+ document.body.append(container);
51
+ root = createRoot(container);
52
+ act(() => {
53
+ root.render(createElement(CalendarSuggestionDeck, deckProps));
54
+ });
55
+ });
56
+
57
+ afterEach(() => {
58
+ act(() => root.unmount());
59
+ container.remove();
60
+ HTMLElement.prototype.setPointerCapture = originalSet;
61
+ HTMLElement.prototype.hasPointerCapture = originalHas;
62
+ });
63
+
64
+ const pointer = (target: Element, type: string, clientX: number) => {
65
+ act(() => {
66
+ target.dispatchEvent(
67
+ new PointerEvent(type, { bubbles: true, clientX, pointerId: 1 }),
68
+ );
69
+ });
70
+ };
71
+
72
+ const button = (): HTMLButtonElement => {
73
+ const found = container.querySelector("button");
74
+ if (!found) throw new Error("the card's button is not drawn");
75
+ return found;
76
+ };
77
+
78
+ describe("pressing a button on the top card", () => {
79
+ it("leaves the pointer to the button, so the press reaches it", () => {
80
+ pointer(button(), "pointerdown", 100);
81
+ pointer(button(), "pointerup", 100);
82
+ act(() => button().click());
83
+
84
+ assert.deepEqual(captured, []);
85
+ assert.equal(pressed, 1);
86
+ assert.equal(confirmed, 0);
87
+ });
88
+
89
+ it("still takes the pointer once the card is dragged, and a long drag confirms", () => {
90
+ pointer(button(), "pointerdown", 100);
91
+ pointer(button(), "pointermove", 150);
92
+ pointer(button(), "pointermove", 220);
93
+ pointer(button(), "pointerup", 220);
94
+
95
+ assert.deepEqual(captured, [1]);
96
+ assert.equal(confirmed, 1);
97
+ });
98
+ });
@@ -9,6 +9,7 @@ import { cn } from "../lib/cn.js";
9
9
  */
10
10
 
11
11
  const COMMIT_DISTANCE = 96;
12
+ const DRAG_SLOP = 6;
12
13
 
13
14
  export interface CalendarSuggestionDeckProps {
14
15
  children: ReactNode;
@@ -68,12 +69,17 @@ export function CalendarSuggestionDeck({
68
69
  transition: from === null ? "transform 180ms ease-out" : "none",
69
70
  }}
70
71
  onPointerDown={(e) => {
71
- e.currentTarget.setPointerCapture(e.pointerId);
72
72
  setFrom(e.clientX);
73
73
  }}
74
74
  onPointerMove={(e) => {
75
75
  if (from === null) return;
76
- setDrag(e.clientX - from);
76
+ const moved = e.clientX - from;
77
+ if (
78
+ Math.abs(moved) > DRAG_SLOP &&
79
+ !e.currentTarget.hasPointerCapture(e.pointerId)
80
+ )
81
+ e.currentTarget.setPointerCapture(e.pointerId);
82
+ setDrag(moved);
77
83
  }}
78
84
  onPointerUp={() => {
79
85
  if (Math.abs(drag) > COMMIT_DISTANCE) {
@@ -1,5 +1,6 @@
1
1
  import type { Meta, StoryObj } from "@storybook/react";
2
2
  import { type ReactNode, useState } from "react";
3
+ import { expect, userEvent, within } from "storybook/test";
3
4
  import type { RsvpState } from "./calendar-types.js";
4
5
  import type { IntelligenceCalendarData } from "./intelligence-calendar.js";
5
6
  import {
@@ -114,6 +115,11 @@ function PanelDemo({
114
115
  onMuteInvite: () => setRemoved(true),
115
116
  onOfferOtherTimes: () => setOffering(true),
116
117
  onRemoveInvite: () => setRemoved(true),
118
+ onOpenNewerInvite:
119
+ calendar.invite?.invite.state === "superseded"
120
+ ? () =>
121
+ setLastAction("opened the newer revision's conversation")
122
+ : undefined,
117
123
  onToggleSlot: (slot) => {
118
124
  setPicked((prev) =>
119
125
  prev.includes(slot.startTime)
@@ -374,13 +380,20 @@ export const InviteWithNothingBooked = rail(
374
380
  * A later message carried a higher SEQUENCE for the same UID. The stale one is
375
381
  * dimmed and its buttons are gone: answering a revision that has been replaced
376
382
  * puts the wrong hour on the calendar, so the card offers the newer one instead
377
- * of an answer.
383
+ * of an answer, and pressing it opens the conversation that carries it.
378
384
  */
379
- export const SupersededInvitation = rail(
380
- KICKOFF,
381
- organiserSender,
382
- supersededInvite,
383
- );
385
+ export const SupersededInvitation: Story = {
386
+ ...rail(KICKOFF, organiserSender, supersededInvite),
387
+ play: async ({ canvasElement }) => {
388
+ const canvas = within(canvasElement);
389
+ await userEvent.click(
390
+ canvas.getByRole("button", { name: "Open the newer invitation" }),
391
+ );
392
+ await expect(
393
+ canvas.getByText("Prototype: opened the newer revision's conversation"),
394
+ ).toBeVisible();
395
+ },
396
+ };
384
397
 
385
398
  /**
386
399
  * METHOD:CANCEL on something already accepted. Reader does not take it off by