@remit/ui 0.0.164 → 0.0.165
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 +1 -1
- package/src/components/calendar-clash-strip.render.test.ts +51 -0
- package/src/components/calendar-clash-strip.stories.tsx +56 -0
- package/src/components/calendar-clash-strip.tsx +64 -0
- package/src/components/calendar-invite-card.render.test.ts +110 -0
- package/src/components/calendar-invite-card.stories.tsx +132 -0
- package/src/components/calendar-invite-card.tsx +288 -0
- package/src/components/calendar-parse-badge.render.test.ts +40 -0
- package/src/components/calendar-parse-badge.stories.tsx +46 -0
- package/src/components/calendar-parse-badge.tsx +59 -0
- package/src/components/calendar-slot-offers.render.test.ts +67 -0
- package/src/components/calendar-slot-offers.stories.tsx +79 -0
- package/src/components/calendar-slot-offers.tsx +67 -0
- package/src/components/calendar-suggestion-deck.render.test.ts +69 -0
- package/src/components/calendar-suggestion-deck.stories.tsx +165 -0
- package/src/components/calendar-suggestion-deck.tsx +116 -0
- package/src/components/calendar-types.ts +57 -0
- package/src/components/event-suggestion-card.tsx +8 -1
- package/src/components/intelligence-calendar-fixtures.ts +384 -0
- package/src/components/intelligence-calendar.deck-zone-gate.test.ts +142 -0
- package/src/components/intelligence-calendar.render.test.ts +122 -0
- package/src/components/intelligence-calendar.tsx +288 -0
- package/src/components/intelligence-panel-calendar.stories.tsx +401 -0
- package/src/components/intelligence-panel.render.test.ts +64 -1
- package/src/components/intelligence-panel.tab-strip.test.ts +163 -0
- package/src/components/intelligence-panel.tsx +239 -174
- package/src/components/intelligence-section.tsx +24 -0
- package/src/index.ts +40 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CalendarAttendee,
|
|
3
|
+
CalendarClash,
|
|
4
|
+
CalendarEventData,
|
|
5
|
+
CalendarInvite,
|
|
6
|
+
CalendarProposal,
|
|
7
|
+
CalendarSlotPick,
|
|
8
|
+
EventSuggestion,
|
|
9
|
+
} from "./calendar-types.js";
|
|
10
|
+
import type {
|
|
11
|
+
CalendarDayEntry,
|
|
12
|
+
CalendarInviteIntel,
|
|
13
|
+
CalendarProseIntel,
|
|
14
|
+
CalendarSuggestionIntel,
|
|
15
|
+
IntelligenceCalendarData,
|
|
16
|
+
} from "./intelligence-calendar.js";
|
|
17
|
+
import type { IntelligenceData } from "./intelligence-panel.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The Thursday everything in this file argues about, and the mail that argues
|
|
21
|
+
* about it. Entirely synthetic: invented people at `.example` domains, no
|
|
22
|
+
* address that resolves and no booking that exists. The shapes match the
|
|
23
|
+
* workbench's calendar-mail fixtures so the two prototypes describe one
|
|
24
|
+
* product rather than two.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const OFFSET = "+02:00";
|
|
28
|
+
const HOME_ZONE = "Europe/Amsterdam";
|
|
29
|
+
|
|
30
|
+
const workCalendarId = "cal_work";
|
|
31
|
+
const personalCalendarId = "cal_personal";
|
|
32
|
+
const travelCalendarId = "cal_travel";
|
|
33
|
+
|
|
34
|
+
function pad(value: number): string {
|
|
35
|
+
return String(value).padStart(2, "0");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function at(dayOfMonth: number, hour: number, minute = 0): string {
|
|
39
|
+
return `2026-06-${pad(dayOfMonth)}T${pad(hour)}:${pad(minute)}:00${OFFSET}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type EventSeed = Partial<CalendarEventData> &
|
|
43
|
+
Pick<CalendarEventData, "id" | "calendarId" | "title" | "start" | "end">;
|
|
44
|
+
|
|
45
|
+
function event(seed: EventSeed): CalendarEventData {
|
|
46
|
+
return {
|
|
47
|
+
allDay: false,
|
|
48
|
+
location: "",
|
|
49
|
+
notes: "",
|
|
50
|
+
attendees: [],
|
|
51
|
+
myRsvp: "accepted",
|
|
52
|
+
threadId: "",
|
|
53
|
+
threadSubject: "",
|
|
54
|
+
timeZone: HOME_ZONE,
|
|
55
|
+
zoneCertainty: "local",
|
|
56
|
+
recurrenceRule: "",
|
|
57
|
+
seriesId: "",
|
|
58
|
+
seriesException: false,
|
|
59
|
+
status: "confirmed",
|
|
60
|
+
...seed,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function guest(
|
|
65
|
+
name: string,
|
|
66
|
+
email: string,
|
|
67
|
+
rsvp: CalendarAttendee["rsvp"],
|
|
68
|
+
role: CalendarAttendee["role"] = "attendee",
|
|
69
|
+
): CalendarAttendee {
|
|
70
|
+
return { name, email, rsvp, role };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const THURSDAY_LABEL = "Thursday 11 June";
|
|
74
|
+
|
|
75
|
+
const inviteThreadId = "thr_invite";
|
|
76
|
+
const flightThreadId = "thr_klm";
|
|
77
|
+
|
|
78
|
+
/* ------------------------------------------------------------------ */
|
|
79
|
+
/* What is already true about the day */
|
|
80
|
+
/* ------------------------------------------------------------------ */
|
|
81
|
+
|
|
82
|
+
const sprintPlanning = event({
|
|
83
|
+
id: "evt_planning",
|
|
84
|
+
calendarId: workCalendarId,
|
|
85
|
+
title: "Sprint planning",
|
|
86
|
+
start: at(11, 9, 45),
|
|
87
|
+
end: at(11, 10, 45),
|
|
88
|
+
location: "Room Noord",
|
|
89
|
+
recurrenceRule: "Every Thursday, 09:45",
|
|
90
|
+
seriesId: "ser_planning",
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const supportRotation = event({
|
|
94
|
+
id: "evt_support",
|
|
95
|
+
calendarId: workCalendarId,
|
|
96
|
+
title: "Support rotation review",
|
|
97
|
+
start: at(11, 11),
|
|
98
|
+
end: at(11, 11, 30),
|
|
99
|
+
location: "Meet",
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const designReview = event({
|
|
103
|
+
id: "evt_design_review",
|
|
104
|
+
calendarId: workCalendarId,
|
|
105
|
+
title: "Design review: outbox retries",
|
|
106
|
+
start: at(11, 13),
|
|
107
|
+
end: at(11, 14),
|
|
108
|
+
location: "Studio",
|
|
109
|
+
threadId: "thr_outbox",
|
|
110
|
+
threadSubject: "Outbox retries — the shape of the backoff",
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const dentist = event({
|
|
114
|
+
id: "evt_dentist",
|
|
115
|
+
calendarId: personalCalendarId,
|
|
116
|
+
title: "Dentist",
|
|
117
|
+
start: at(11, 14, 30),
|
|
118
|
+
end: at(11, 15, 15),
|
|
119
|
+
location: "Overtoom 210",
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export const thursdayEntries: CalendarDayEntry[] = [
|
|
123
|
+
{ event: sprintPlanning, timeText: "09:45", color: "cal-2" },
|
|
124
|
+
{ event: supportRotation, timeText: "11:00", color: "cal-2" },
|
|
125
|
+
{ event: designReview, timeText: "13:00", color: "cal-2" },
|
|
126
|
+
{ event: dentist, timeText: "14:30", color: "cal-4" },
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
/* ------------------------------------------------------------------ */
|
|
130
|
+
/* The invitation */
|
|
131
|
+
/* ------------------------------------------------------------------ */
|
|
132
|
+
|
|
133
|
+
const proposedAttendees: CalendarAttendee[] = [
|
|
134
|
+
guest("Priya Natarajan", "priya@northwind.example", "accepted", "organizer"),
|
|
135
|
+
guest("Marcus Webb", "marcus@northwind.example", "accepted"),
|
|
136
|
+
guest("Dana Okafor", "dana@northwind.example", "noReply"),
|
|
137
|
+
guest("Ravi Mehta", "ravi@northwind.example", "tentative"),
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
const proposedKickoff = event({
|
|
141
|
+
id: "evt_invite_billing",
|
|
142
|
+
calendarId: workCalendarId,
|
|
143
|
+
title: "Billing migration kickoff",
|
|
144
|
+
start: at(11, 14),
|
|
145
|
+
end: at(11, 15),
|
|
146
|
+
location: "Room Zuid / Meet",
|
|
147
|
+
threadId: inviteThreadId,
|
|
148
|
+
threadSubject: "Invitation: Billing migration kickoff — Thu 11 Jun, 14:00",
|
|
149
|
+
myRsvp: "noReply",
|
|
150
|
+
status: "tentative",
|
|
151
|
+
attendees: proposedAttendees,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export const kickoffInvite: CalendarInvite = {
|
|
155
|
+
id: "inv_billing",
|
|
156
|
+
threadId: inviteThreadId,
|
|
157
|
+
proposed: proposedKickoff,
|
|
158
|
+
organizerName: "Priya Natarajan",
|
|
159
|
+
organizerEmail: "priya@northwind.example",
|
|
160
|
+
method: "ics",
|
|
161
|
+
evidence: "invite.ics · METHOD:REQUEST · DTSTART;TZID=Europe/Amsterdam",
|
|
162
|
+
state: "pending",
|
|
163
|
+
sequence: 0,
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/** The clash the reader would otherwise find out about after saying yes. */
|
|
167
|
+
export const dentistClash: CalendarClash[] = [
|
|
168
|
+
{ id: dentist.id, label: "Dentist · 14:30 – 15:15 · Personal (matthijs@)" },
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
const kickoffIntel: CalendarInviteIntel = {
|
|
172
|
+
invite: kickoffInvite,
|
|
173
|
+
whenText: "Thursday 11 June, 14:00 – 15:00",
|
|
174
|
+
calendarName: "Work",
|
|
175
|
+
color: "cal-2",
|
|
176
|
+
clashes: dentistClash,
|
|
177
|
+
rsvp: "noReply",
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** The same invitation an hour later, where the afternoon is still empty. */
|
|
181
|
+
const clearIntel: CalendarInviteIntel = {
|
|
182
|
+
...kickoffIntel,
|
|
183
|
+
invite: {
|
|
184
|
+
...kickoffInvite,
|
|
185
|
+
proposed: {
|
|
186
|
+
...proposedKickoff,
|
|
187
|
+
start: at(11, 16),
|
|
188
|
+
end: at(11, 17),
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
whenText: "Thursday 11 June, 16:00 – 17:00",
|
|
192
|
+
clashes: [],
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/** A later message carried a higher SEQUENCE for the same UID. */
|
|
196
|
+
const supersededIntel: CalendarInviteIntel = {
|
|
197
|
+
...kickoffIntel,
|
|
198
|
+
invite: {
|
|
199
|
+
...kickoffInvite,
|
|
200
|
+
state: "superseded",
|
|
201
|
+
sequence: 1,
|
|
202
|
+
evidence: "invite.ics · METHOD:REQUEST · SEQUENCE:1",
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/** METHOD:CANCEL on something already accepted. It stays until the reader acts. */
|
|
207
|
+
const cancelledIntel: CalendarInviteIntel = {
|
|
208
|
+
...kickoffIntel,
|
|
209
|
+
invite: {
|
|
210
|
+
...kickoffInvite,
|
|
211
|
+
state: "cancelled",
|
|
212
|
+
sequence: 2,
|
|
213
|
+
method: "ics",
|
|
214
|
+
evidence: "cancel.ics · METHOD:CANCEL · STATUS:CANCELLED",
|
|
215
|
+
proposed: { ...proposedKickoff, myRsvp: "accepted", status: "confirmed" },
|
|
216
|
+
},
|
|
217
|
+
rsvp: "accepted",
|
|
218
|
+
clashes: [],
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/* ------------------------------------------------------------------ */
|
|
222
|
+
/* Times named in prose */
|
|
223
|
+
/* ------------------------------------------------------------------ */
|
|
224
|
+
|
|
225
|
+
const thursdayProposals: CalendarProposal[] = [
|
|
226
|
+
{ id: "p1", phrase: "11:00", clashTitle: supportRotation.title },
|
|
227
|
+
{ id: "p2", phrase: "13:30", clashTitle: designReview.title },
|
|
228
|
+
{ id: "p3", phrase: "after 15:00", clashTitle: "" },
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
const THURSDAY = "2026-06-11";
|
|
232
|
+
|
|
233
|
+
function slot(startTime: string, endTime: string): CalendarSlotPick {
|
|
234
|
+
return { date: THURSDAY, startTime, endTime, allDay: false };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const thursdaySlots: CalendarSlotPick[] = [
|
|
238
|
+
slot("10:45", "11:15"),
|
|
239
|
+
slot("11:30", "12:00"),
|
|
240
|
+
slot("12:00", "12:30"),
|
|
241
|
+
slot("15:15", "15:45"),
|
|
242
|
+
slot("16:00", "16:30"),
|
|
243
|
+
];
|
|
244
|
+
|
|
245
|
+
export const thursdayProse: CalendarProseIntel = {
|
|
246
|
+
dayLabel: THURSDAY_LABEL,
|
|
247
|
+
proposals: thursdayProposals,
|
|
248
|
+
slots: thursdaySlots,
|
|
249
|
+
picked: [],
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/* ------------------------------------------------------------------ */
|
|
253
|
+
/* Readings that are not invitations */
|
|
254
|
+
/* ------------------------------------------------------------------ */
|
|
255
|
+
|
|
256
|
+
const flightSuggestion: EventSuggestion = {
|
|
257
|
+
id: "sug_flight",
|
|
258
|
+
title: "KL1693 Amsterdam → Lisbon",
|
|
259
|
+
start: at(19, 18, 40),
|
|
260
|
+
end: at(19, 20, 25),
|
|
261
|
+
allDay: false,
|
|
262
|
+
location: "Schiphol, gate D-pier",
|
|
263
|
+
threadId: flightThreadId,
|
|
264
|
+
threadSubject: "Your booking is confirmed — KL1693 Amsterdam to Lisbon",
|
|
265
|
+
sender: "KLM",
|
|
266
|
+
senderAddress: "noreply@klm.example",
|
|
267
|
+
confidence: 0.88,
|
|
268
|
+
ambiguity:
|
|
269
|
+
"The confirmation prints 20:25 for the arrival and never says whose clock. Lisbon runs an hour behind Amsterdam.",
|
|
270
|
+
suggestedCalendarId: travelCalendarId,
|
|
271
|
+
timeZone: "",
|
|
272
|
+
zoneCertainty: "ambiguous",
|
|
273
|
+
zoneOptions: [
|
|
274
|
+
{
|
|
275
|
+
timeZone: "Europe/Lisbon",
|
|
276
|
+
label: "20:25 in Lisbon",
|
|
277
|
+
note: "21:25 on your own clock. What an airline usually means.",
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
timeZone: HOME_ZONE,
|
|
281
|
+
label: "20:25 in Amsterdam",
|
|
282
|
+
note: "19:25 where the plane lands.",
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const flightIntel: CalendarSuggestionIntel = {
|
|
288
|
+
suggestion: flightSuggestion,
|
|
289
|
+
whenText: "Friday 19 June, 18:40 – 20:25",
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/* ------------------------------------------------------------------ */
|
|
293
|
+
/* The tab, in each state the review is about */
|
|
294
|
+
/* ------------------------------------------------------------------ */
|
|
295
|
+
|
|
296
|
+
export const inviteWithClash: IntelligenceCalendarData = {
|
|
297
|
+
invite: kickoffIntel,
|
|
298
|
+
suggestions: [],
|
|
299
|
+
day: thursdayEntries,
|
|
300
|
+
dayLabel: THURSDAY_LABEL,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
export const inviteWithoutClash: IntelligenceCalendarData = {
|
|
304
|
+
invite: clearIntel,
|
|
305
|
+
suggestions: [],
|
|
306
|
+
day: thursdayEntries,
|
|
307
|
+
dayLabel: THURSDAY_LABEL,
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export const supersededInvite: IntelligenceCalendarData = {
|
|
311
|
+
invite: supersededIntel,
|
|
312
|
+
suggestions: [],
|
|
313
|
+
day: thursdayEntries,
|
|
314
|
+
dayLabel: THURSDAY_LABEL,
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export const cancelledInvite: IntelligenceCalendarData = {
|
|
318
|
+
invite: cancelledIntel,
|
|
319
|
+
suggestions: [],
|
|
320
|
+
day: thursdayEntries,
|
|
321
|
+
dayLabel: THURSDAY_LABEL,
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export const flightConfirmation: IntelligenceCalendarData = {
|
|
325
|
+
suggestions: [flightIntel],
|
|
326
|
+
day: [],
|
|
327
|
+
dayLabel: "Friday 19 June",
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
export const proseTimeThread: IntelligenceCalendarData = {
|
|
331
|
+
prose: thursdayProse,
|
|
332
|
+
suggestions: [],
|
|
333
|
+
day: thursdayEntries,
|
|
334
|
+
dayLabel: THURSDAY_LABEL,
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
export const nothingAboutTime: IntelligenceCalendarData = {
|
|
338
|
+
suggestions: [],
|
|
339
|
+
day: [],
|
|
340
|
+
dayLabel: "",
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
/* ------------------------------------------------------------------ */
|
|
344
|
+
/* The other half of the panel, so the strip has two sides */
|
|
345
|
+
/* ------------------------------------------------------------------ */
|
|
346
|
+
|
|
347
|
+
export const organiserSender: IntelligenceData = {
|
|
348
|
+
sender: {
|
|
349
|
+
name: "Priya Natarajan",
|
|
350
|
+
email: "priya@northwind.example",
|
|
351
|
+
trust: "vip",
|
|
352
|
+
firstSeenLabel: "Mar 2023",
|
|
353
|
+
inboundCount: 214,
|
|
354
|
+
replyCount: 188,
|
|
355
|
+
},
|
|
356
|
+
authenticity: {
|
|
357
|
+
verdict: "aligned",
|
|
358
|
+
fromDomain: "northwind.example",
|
|
359
|
+
dkimDomain: "northwind.example",
|
|
360
|
+
summary: "This message was signed by northwind.example.",
|
|
361
|
+
},
|
|
362
|
+
category: { value: "personal" },
|
|
363
|
+
flags: { vip: true },
|
|
364
|
+
similar: [],
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
export const airlineSender: IntelligenceData = {
|
|
368
|
+
sender: {
|
|
369
|
+
name: "KLM",
|
|
370
|
+
email: "noreply@klm.example",
|
|
371
|
+
trust: "wellknown",
|
|
372
|
+
firstSeenLabel: "Jan 2024",
|
|
373
|
+
inboundCount: 31,
|
|
374
|
+
replyCount: 0,
|
|
375
|
+
},
|
|
376
|
+
authenticity: {
|
|
377
|
+
verdict: "aligned",
|
|
378
|
+
fromDomain: "klm.example",
|
|
379
|
+
dkimDomain: "klm.example",
|
|
380
|
+
summary: "This message was signed by klm.example.",
|
|
381
|
+
},
|
|
382
|
+
category: { value: "transactional" },
|
|
383
|
+
similar: [],
|
|
384
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The zone gate on the deck's swipe. The buttons inside the card are guarded by
|
|
3
|
+
* `event-suggestion-card.zone-gate.test.ts`; the gesture is a second way out of
|
|
4
|
+
* the same card, and it bypassed the card's own refusal entirely — a swipe right
|
|
5
|
+
* booked a zoneless reading on an empty zone.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import "@remit/test-dom";
|
|
9
|
+
import assert from "node:assert/strict";
|
|
10
|
+
import { afterEach, beforeEach, describe, it } from "node:test";
|
|
11
|
+
import { act, createElement } from "react";
|
|
12
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
13
|
+
import { ZONE_UNSETTLED_REASON } from "./event-suggestion-card.js";
|
|
14
|
+
import {
|
|
15
|
+
IntelligenceCalendar,
|
|
16
|
+
type IntelligenceCalendarActions,
|
|
17
|
+
} from "./intelligence-calendar.js";
|
|
18
|
+
import { flightConfirmation } from "./intelligence-calendar-fixtures.js";
|
|
19
|
+
|
|
20
|
+
const LISBON = "Europe/Lisbon";
|
|
21
|
+
const COMMIT_DISTANCE = 96;
|
|
22
|
+
|
|
23
|
+
let container: HTMLElement;
|
|
24
|
+
let root: Root;
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
container = document.getElementById("root") as unknown as HTMLElement;
|
|
28
|
+
container.innerHTML = "";
|
|
29
|
+
root = createRoot(container);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
act(() => {
|
|
34
|
+
root.unmount();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
interface Added {
|
|
39
|
+
id: string;
|
|
40
|
+
timeZone: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function mount(added: Added[]) {
|
|
44
|
+
const actions: IntelligenceCalendarActions = {
|
|
45
|
+
onAddInvite: () => undefined,
|
|
46
|
+
onTentativeInvite: () => undefined,
|
|
47
|
+
onDeclineInvite: () => undefined,
|
|
48
|
+
onReopenInvite: () => undefined,
|
|
49
|
+
onOfferOtherTimes: () => undefined,
|
|
50
|
+
onRemoveInvite: () => undefined,
|
|
51
|
+
onOpenNewerInvite: () => undefined,
|
|
52
|
+
onToggleSlot: () => undefined,
|
|
53
|
+
onAddSuggestion: (id, timeZone) => added.push({ id, timeZone }),
|
|
54
|
+
onReviewSuggestion: () => undefined,
|
|
55
|
+
onDismissSuggestion: () => undefined,
|
|
56
|
+
onOpenThread: () => undefined,
|
|
57
|
+
onSelectEvent: () => undefined,
|
|
58
|
+
};
|
|
59
|
+
act(() => {
|
|
60
|
+
root.render(
|
|
61
|
+
createElement(IntelligenceCalendar, {
|
|
62
|
+
data: flightConfirmation,
|
|
63
|
+
actions,
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The element the deck attaches the gesture to. */
|
|
70
|
+
function deckSurface(): Element {
|
|
71
|
+
const surface = container.querySelector(".touch-pan-y");
|
|
72
|
+
assert.ok(surface, "the deck did not mount its gesture surface");
|
|
73
|
+
return surface;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function pointer(target: Element, type: string, clientX: number) {
|
|
77
|
+
act(() => {
|
|
78
|
+
target.dispatchEvent(
|
|
79
|
+
new PointerEvent(type, {
|
|
80
|
+
bubbles: true,
|
|
81
|
+
pointerType: "touch",
|
|
82
|
+
pointerId: 1,
|
|
83
|
+
clientX,
|
|
84
|
+
clientY: 40,
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function swipeRight() {
|
|
91
|
+
const surface = deckSurface();
|
|
92
|
+
pointer(surface, "pointerdown", 0);
|
|
93
|
+
pointer(surface, "pointermove", COMMIT_DISTANCE + 40);
|
|
94
|
+
pointer(surface, "pointerup", COMMIT_DISTANCE + 40);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function buttonNamed(text: string): Element {
|
|
98
|
+
const found = Array.from(container.querySelectorAll("button")).find(
|
|
99
|
+
(candidate) => candidate.textContent?.includes(text),
|
|
100
|
+
);
|
|
101
|
+
assert.ok(found, `no button reading ${text}`);
|
|
102
|
+
return found;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function press(target: Element) {
|
|
106
|
+
act(() => {
|
|
107
|
+
target.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
describe("swiping a suggestion right in the calendar tab", () => {
|
|
112
|
+
it("books nothing while the mail never said which clock", () => {
|
|
113
|
+
const added: Added[] = [];
|
|
114
|
+
mount(added);
|
|
115
|
+
|
|
116
|
+
swipeRight();
|
|
117
|
+
|
|
118
|
+
assert.deepEqual(added, []);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("says why the swipe will not commit", () => {
|
|
122
|
+
mount([]);
|
|
123
|
+
const surface = deckSurface();
|
|
124
|
+
|
|
125
|
+
pointer(surface, "pointerdown", 0);
|
|
126
|
+
pointer(surface, "pointermove", COMMIT_DISTANCE + 40);
|
|
127
|
+
|
|
128
|
+
assert.ok(container.textContent?.includes(ZONE_UNSETTLED_REASON));
|
|
129
|
+
|
|
130
|
+
pointer(surface, "pointerup", COMMIT_DISTANCE + 40);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("books on the clock that was picked once one is", () => {
|
|
134
|
+
const added: Added[] = [];
|
|
135
|
+
mount(added);
|
|
136
|
+
|
|
137
|
+
press(buttonNamed("20:25 in Lisbon"));
|
|
138
|
+
swipeRight();
|
|
139
|
+
|
|
140
|
+
assert.deepEqual(added, [{ id: "sug_flight", timeZone: LISBON }]);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { createElement } from "react";
|
|
4
|
+
import { renderToString } from "react-dom/server";
|
|
5
|
+
import {
|
|
6
|
+
IntelligenceCalendar,
|
|
7
|
+
type IntelligenceCalendarActions,
|
|
8
|
+
type IntelligenceCalendarData,
|
|
9
|
+
} from "./intelligence-calendar.js";
|
|
10
|
+
import {
|
|
11
|
+
cancelledInvite,
|
|
12
|
+
flightConfirmation,
|
|
13
|
+
inviteWithClash,
|
|
14
|
+
inviteWithoutClash,
|
|
15
|
+
nothingAboutTime,
|
|
16
|
+
proseTimeThread,
|
|
17
|
+
supersededInvite,
|
|
18
|
+
} from "./intelligence-calendar-fixtures.js";
|
|
19
|
+
|
|
20
|
+
const inert: IntelligenceCalendarActions = {
|
|
21
|
+
onAddInvite: () => undefined,
|
|
22
|
+
onTentativeInvite: () => undefined,
|
|
23
|
+
onDeclineInvite: () => undefined,
|
|
24
|
+
onReopenInvite: () => undefined,
|
|
25
|
+
onOfferOtherTimes: () => undefined,
|
|
26
|
+
onRemoveInvite: () => undefined,
|
|
27
|
+
onOpenNewerInvite: () => undefined,
|
|
28
|
+
onToggleSlot: () => undefined,
|
|
29
|
+
onAddSuggestion: () => undefined,
|
|
30
|
+
onReviewSuggestion: () => undefined,
|
|
31
|
+
onDismissSuggestion: () => undefined,
|
|
32
|
+
onOpenThread: () => undefined,
|
|
33
|
+
onSelectEvent: () => undefined,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function render(data: IntelligenceCalendarData): string {
|
|
37
|
+
return renderToString(
|
|
38
|
+
createElement(IntelligenceCalendar, { data, actions: inert }),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe("the calendar tab states the cost before the answer", () => {
|
|
43
|
+
it("names every clash above the button that would accept the invitation", () => {
|
|
44
|
+
const html = render(inviteWithClash);
|
|
45
|
+
const clash = html.indexOf("Dentist");
|
|
46
|
+
const accept = html.indexOf("Add to calendar");
|
|
47
|
+
assert.notEqual(clash, -1, "expected the clashing event to be named");
|
|
48
|
+
assert.notEqual(accept, -1, "expected the accept button");
|
|
49
|
+
assert.ok(clash < accept, "the clash must be stated before the answer");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("says the day is clear rather than saying nothing", () => {
|
|
53
|
+
assert.match(render(inviteWithoutClash), /Nothing else is booked over it/);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("the calendar tab never implies a reply was sent", () => {
|
|
58
|
+
it("states that the organiser is not notified beside the button", () => {
|
|
59
|
+
assert.match(render(inviteWithClash), /is not notified/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("keeps saying so once the event is on the calendar", () => {
|
|
63
|
+
const answered: IntelligenceCalendarData = {
|
|
64
|
+
...inviteWithClash,
|
|
65
|
+
invite: inviteWithClash.invite && {
|
|
66
|
+
...inviteWithClash.invite,
|
|
67
|
+
rsvp: "accepted",
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const html = render(answered);
|
|
71
|
+
assert.match(html, /was not notified/);
|
|
72
|
+
assert.doesNotMatch(html, /Add to calendar/);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("an invitation that has been overtaken", () => {
|
|
77
|
+
it("offers the newer revision instead of an answer to the stale one", () => {
|
|
78
|
+
const html = render(supersededInvite);
|
|
79
|
+
assert.match(html, /has sent a newer version of this/);
|
|
80
|
+
assert.match(html, /Open the newer invitation/);
|
|
81
|
+
assert.doesNotMatch(html, /Add to calendar/);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("leaves a cancellation on the calendar until the reader acts", () => {
|
|
85
|
+
const html = render(cancelledInvite);
|
|
86
|
+
assert.match(html, /cancelled this/);
|
|
87
|
+
assert.match(html, /still on your calendar/);
|
|
88
|
+
assert.match(html, /Remove from calendar/);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("readings that are not invitations", () => {
|
|
93
|
+
it("spells out where the confirming press lands", () => {
|
|
94
|
+
assert.match(render(flightConfirmation), /Add to calendar/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("asks which clock before it will take a zoneless time", () => {
|
|
98
|
+
assert.match(render(flightConfirmation), /Which clock is this on/);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("times named in prose", () => {
|
|
103
|
+
it("marks each named hour against what is already booked", () => {
|
|
104
|
+
const html = render(proseTimeThread);
|
|
105
|
+
assert.match(html, /Support rotation review/);
|
|
106
|
+
assert.match(html, /Design review/);
|
|
107
|
+
assert.match(html, /Nothing booked/);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("offers the free half-hours as things to hand back", () => {
|
|
111
|
+
assert.match(render(proseTimeThread), /15:15/);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("a message with no time in it", () => {
|
|
116
|
+
it("says so rather than rendering an empty frame", () => {
|
|
117
|
+
assert.match(
|
|
118
|
+
render(nothingAboutTime),
|
|
119
|
+
/Nothing in this message is about a time/,
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
});
|