@meetelise/chat 1.68.0 → 1.69.1
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/dist/src/MyPubnub.d.ts +2 -0
- package/dist/src/WebComponent/SchedulerV2/tourItineraryApi.d.ts +2 -1
- package/dist/src/WebComponent/launcher/Launcher.d.ts +11 -0
- package/dist/src/WebComponent/me-chat.d.ts +4 -0
- package/dist/src/fetchFeatureFlag.d.ts +2 -0
- package/package.json +1 -1
- package/public/dist/index.js +2077 -912
- package/src/MyPubnub.ts +5 -0
- package/src/WebComponent/SchedulerV2/schedulerRequests.ts +1 -1
- package/src/WebComponent/SchedulerV2/tourItineraryApi.ts +2 -1
- package/src/WebComponent/launcher/Launcher.ts +63 -3
- package/src/WebComponent/me-chat.ts +13 -0
- package/src/fetchFeatureFlag.ts +20 -0
- package/src/tourSchedulerV2Booking.test.ts +480 -0
- package/src/tourSchedulerV2Rollout.test.ts +190 -0
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
import { expect } from "@esm-bundle/chai";
|
|
2
|
+
import { restore, useFakeXMLHttpRequest } from "sinon/pkg/sinon-esm";
|
|
3
|
+
import "../public/dist/index";
|
|
4
|
+
import type { TourSchedulerV2 } from "./WebComponent/SchedulerV2/tour-scheduler-v2";
|
|
5
|
+
import type { ContactForm } from "./WebComponent/SchedulerV2/contact-form";
|
|
6
|
+
import type { CommunityPicker } from "./WebComponent/SchedulerV2/community-picker";
|
|
7
|
+
import type {
|
|
8
|
+
BookingRequest,
|
|
9
|
+
BookingResponse,
|
|
10
|
+
Community,
|
|
11
|
+
CommunitiesResponse,
|
|
12
|
+
PlanRequest,
|
|
13
|
+
PlanResponse,
|
|
14
|
+
PlanStop,
|
|
15
|
+
TourTypeId,
|
|
16
|
+
} from "./WebComponent/SchedulerV2/tourItineraryApi";
|
|
17
|
+
|
|
18
|
+
declare const afterEach: (callback: () => void) => void;
|
|
19
|
+
declare const it: (name: string, callback: () => Promise<void>) => void;
|
|
20
|
+
|
|
21
|
+
// The v2 scheduler driven through its own UI, with its real API client, against
|
|
22
|
+
// a fake of the three endpoints: checks what it sends to the booking endpoint
|
|
23
|
+
// and what it pushes to the dataLayer. Every request is answered by the fake.
|
|
24
|
+
|
|
25
|
+
type FakeRequest = XMLHttpRequest & {
|
|
26
|
+
url: string;
|
|
27
|
+
requestBody?: string;
|
|
28
|
+
requestHeaders: Record<string, string>;
|
|
29
|
+
respond: (
|
|
30
|
+
status: number,
|
|
31
|
+
headers?: Record<string, string>,
|
|
32
|
+
body?: string
|
|
33
|
+
) => void;
|
|
34
|
+
error: () => void;
|
|
35
|
+
onSend?: () => void;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const header = (request: FakeRequest, name: string): string | undefined =>
|
|
39
|
+
Object.entries(request.requestHeaders).find(
|
|
40
|
+
([key]) => key.toLowerCase() === name.toLowerCase()
|
|
41
|
+
)?.[1];
|
|
42
|
+
|
|
43
|
+
const DATE = "2026-10-30";
|
|
44
|
+
const ANCHOR = 12;
|
|
45
|
+
const LINDEN = 40;
|
|
46
|
+
|
|
47
|
+
const community = (building_id: number, name: string): Community => ({
|
|
48
|
+
building_id,
|
|
49
|
+
name,
|
|
50
|
+
address: { line1: "1 Main St", city: "Chicago", state: "IL" },
|
|
51
|
+
timezone: "America/Chicago",
|
|
52
|
+
distance_mi: building_id === ANCHOR ? 0 : 1.8,
|
|
53
|
+
price_from: null,
|
|
54
|
+
next_available: { date: DATE, time: "10:00" },
|
|
55
|
+
best_match: false,
|
|
56
|
+
image_url: null,
|
|
57
|
+
tourable: true,
|
|
58
|
+
unavailable_reason: null,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const isoMinutes = (iso: string) =>
|
|
62
|
+
parseInt(iso.slice(11, 13), 10) * 60 + parseInt(iso.slice(14, 16), 10);
|
|
63
|
+
|
|
64
|
+
const at = (minutes: number) =>
|
|
65
|
+
`${DATE}T${String(Math.floor(minutes / 60)).padStart(2, "0")}:${String(
|
|
66
|
+
minutes % 60
|
|
67
|
+
).padStart(2, "0")}:00-05:00`;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A central group of two, chaining 30-minute tours from 10:00, served on the
|
|
71
|
+
* widget's tour endpoints. Records what the scheduler sent.
|
|
72
|
+
*/
|
|
73
|
+
const fakeBackend = ({
|
|
74
|
+
tourTypes = ["escorted-tour"],
|
|
75
|
+
dropFirstBooking = false,
|
|
76
|
+
}: {
|
|
77
|
+
/** The tour types the building offers. */
|
|
78
|
+
tourTypes?: TourTypeId[];
|
|
79
|
+
/** Drops the first booking's connection, as a timeout would. */
|
|
80
|
+
dropFirstBooking?: boolean;
|
|
81
|
+
} = {}): {
|
|
82
|
+
bookings: BookingRequest[];
|
|
83
|
+
keys: string[];
|
|
84
|
+
sessionTokens: string[];
|
|
85
|
+
communityQueries: URLSearchParams[];
|
|
86
|
+
plannedTourTypes: TourTypeId[];
|
|
87
|
+
} => {
|
|
88
|
+
const bookings: BookingRequest[] = [];
|
|
89
|
+
const keys: string[] = [];
|
|
90
|
+
const sessionTokens: string[] = [];
|
|
91
|
+
const communityQueries: URLSearchParams[] = [];
|
|
92
|
+
const plannedTourTypes: TourTypeId[] = [];
|
|
93
|
+
let nextEventId = 990;
|
|
94
|
+
let dropped = false;
|
|
95
|
+
const group = (extend: boolean): CommunitiesResponse => ({
|
|
96
|
+
anchor: {
|
|
97
|
+
building_id: ANCHOR,
|
|
98
|
+
name: "Parkside Commons",
|
|
99
|
+
is_general_building: false,
|
|
100
|
+
},
|
|
101
|
+
communities: extend
|
|
102
|
+
? [community(LINDEN, "The Linden")]
|
|
103
|
+
: [
|
|
104
|
+
community(ANCHOR, "Parkside Commons"),
|
|
105
|
+
community(LINDEN, "The Linden"),
|
|
106
|
+
],
|
|
107
|
+
});
|
|
108
|
+
const plan = (request: PlanRequest): PlanResponse => {
|
|
109
|
+
const stops: PlanStop[] = [];
|
|
110
|
+
let start = 10 * 60;
|
|
111
|
+
if (request.fixed_first) {
|
|
112
|
+
stops.push({
|
|
113
|
+
building_id: ANCHOR,
|
|
114
|
+
start: at(start),
|
|
115
|
+
end: at(start + 30),
|
|
116
|
+
timezone: "America/Chicago",
|
|
117
|
+
distance_from_prev_mi: null,
|
|
118
|
+
alternatives: [],
|
|
119
|
+
fixed: true,
|
|
120
|
+
});
|
|
121
|
+
start += 30;
|
|
122
|
+
}
|
|
123
|
+
request.building_ids.forEach((building_id) => {
|
|
124
|
+
stops.push({
|
|
125
|
+
building_id,
|
|
126
|
+
start: at(start),
|
|
127
|
+
end: at(start + 30),
|
|
128
|
+
timezone: "America/Chicago",
|
|
129
|
+
distance_from_prev_mi: stops.length > 0 ? 1.8 : null,
|
|
130
|
+
alternatives: [at(start + 15)],
|
|
131
|
+
fixed: false,
|
|
132
|
+
});
|
|
133
|
+
start += 30;
|
|
134
|
+
});
|
|
135
|
+
// As /plan does: dates and times only for a tour type the building offers.
|
|
136
|
+
const offered = tourTypes.includes(request.tour_type);
|
|
137
|
+
return {
|
|
138
|
+
bookable_dates: offered ? [DATE] : [],
|
|
139
|
+
tour_types: tourTypes,
|
|
140
|
+
stops: offered ? stops : [],
|
|
141
|
+
changed: [],
|
|
142
|
+
unchainable: [],
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
const book = (request: BookingRequest): BookingResponse => {
|
|
146
|
+
return {
|
|
147
|
+
itinerary_id: request.stops.length > 1 ? "itinerary" : null,
|
|
148
|
+
stops: request.stops.map((stop) =>
|
|
149
|
+
"existing_calendar_event_id" in stop
|
|
150
|
+
? {
|
|
151
|
+
building_id: ANCHOR,
|
|
152
|
+
calendar_event_id: stop.existing_calendar_event_id,
|
|
153
|
+
start: at(600),
|
|
154
|
+
end: at(630),
|
|
155
|
+
status: "existing" as const,
|
|
156
|
+
error: null,
|
|
157
|
+
}
|
|
158
|
+
: {
|
|
159
|
+
building_id: stop.building_id,
|
|
160
|
+
calendar_event_id: nextEventId++,
|
|
161
|
+
start: stop.start,
|
|
162
|
+
end: at(isoMinutes(stop.start) + 30),
|
|
163
|
+
status: "booked" as const,
|
|
164
|
+
error: null,
|
|
165
|
+
}
|
|
166
|
+
),
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const fakeXhr = useFakeXMLHttpRequest();
|
|
171
|
+
fakeXhr.onCreate = (request: FakeRequest) => {
|
|
172
|
+
request.onSend = () =>
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
const json = (status: number, data: unknown) =>
|
|
175
|
+
request.respond(
|
|
176
|
+
status,
|
|
177
|
+
{ "Content-Type": "application/json" },
|
|
178
|
+
JSON.stringify(data)
|
|
179
|
+
);
|
|
180
|
+
const { pathname, searchParams } = new URL(request.url);
|
|
181
|
+
const body = request.requestBody
|
|
182
|
+
? JSON.parse(request.requestBody)
|
|
183
|
+
: null;
|
|
184
|
+
if (!pathname.startsWith("/platformApi/webchat/tour-")) {
|
|
185
|
+
return json(200, null);
|
|
186
|
+
}
|
|
187
|
+
sessionTokens.push(header(request, "X-Session-Token") ?? "");
|
|
188
|
+
if (pathname === "/platformApi/webchat/tour-communities") {
|
|
189
|
+
communityQueries.push(searchParams);
|
|
190
|
+
return json(200, group(searchParams.has("available_after")));
|
|
191
|
+
}
|
|
192
|
+
if (pathname === "/platformApi/webchat/tour-itineraries/plan") {
|
|
193
|
+
// As the server's request model does: stop_starts may be empty, not null.
|
|
194
|
+
if (body.stop_starts === null) return json(422, null);
|
|
195
|
+
plannedTourTypes.push(body.tour_type);
|
|
196
|
+
return json(200, plan(body));
|
|
197
|
+
}
|
|
198
|
+
if (pathname === "/platformApi/webchat/tour-itineraries") {
|
|
199
|
+
keys.push(header(request, "Idempotency-Key") ?? "");
|
|
200
|
+
if (dropFirstBooking && !dropped) {
|
|
201
|
+
dropped = true;
|
|
202
|
+
return request.error();
|
|
203
|
+
}
|
|
204
|
+
bookings.push(body);
|
|
205
|
+
return json(200, book(body));
|
|
206
|
+
}
|
|
207
|
+
return json(404, null);
|
|
208
|
+
}, 0);
|
|
209
|
+
};
|
|
210
|
+
return { bookings, keys, sessionTokens, communityQueries, plannedTourTypes };
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const waitFor = async <T>(
|
|
214
|
+
find: () => T | null | undefined | false
|
|
215
|
+
): Promise<T> => {
|
|
216
|
+
for (let i = 0; i < 300; i++) {
|
|
217
|
+
const found = find();
|
|
218
|
+
if (found) return found;
|
|
219
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
220
|
+
}
|
|
221
|
+
throw new Error("Timed out waiting for the scheduler");
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const mount = (): TourSchedulerV2 => {
|
|
225
|
+
const scheduler = document.createElement(
|
|
226
|
+
"tour-scheduler-v2"
|
|
227
|
+
) as TourSchedulerV2;
|
|
228
|
+
Object.assign(scheduler, {
|
|
229
|
+
getSessionToken: () => "session-from-init",
|
|
230
|
+
orgSlug: "test-org",
|
|
231
|
+
buildingSlug: "parkside-commons",
|
|
232
|
+
buildingId: ANCHOR,
|
|
233
|
+
buildingName: "Parkside Commons",
|
|
234
|
+
currentLeadSource: "google",
|
|
235
|
+
leadSourceClient: {
|
|
236
|
+
chatId: "webchat_lead_test",
|
|
237
|
+
checkAndHandleForLogLeadSource: () => Promise.resolve(),
|
|
238
|
+
resetLeadSource: () => true,
|
|
239
|
+
},
|
|
240
|
+
leadSourceMultitouchClient: {
|
|
241
|
+
getSafeLeadSourceTouchpointsWithDefault: () => [
|
|
242
|
+
{
|
|
243
|
+
timestampInitiallyLogged: "2026-10-29T10:00:00Z",
|
|
244
|
+
leadSourceValue: "google",
|
|
245
|
+
type: "touchpoint",
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
resetLeadSourceTouchpoints: () => undefined,
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
document.body.appendChild(scheduler);
|
|
252
|
+
return scheduler;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const inScheduler = <T extends Element>(
|
|
256
|
+
scheduler: TourSchedulerV2,
|
|
257
|
+
selector: string
|
|
258
|
+
): T | null => scheduler.shadowRoot?.querySelector<T>(selector) ?? null;
|
|
259
|
+
|
|
260
|
+
const clickButton = (button: Element | null | undefined) =>
|
|
261
|
+
button?.shadowRoot?.querySelector<HTMLButtonElement>("button")?.click();
|
|
262
|
+
|
|
263
|
+
const fillContactAndSubmit = async (scheduler: TourSchedulerV2) => {
|
|
264
|
+
const form = await waitFor(() =>
|
|
265
|
+
inScheduler<ContactForm>(scheduler, "contact-form")
|
|
266
|
+
);
|
|
267
|
+
form.dispatchEvent(
|
|
268
|
+
new CustomEvent("contact-change", {
|
|
269
|
+
detail: {
|
|
270
|
+
values: {
|
|
271
|
+
...form.values,
|
|
272
|
+
firstName: "Jane",
|
|
273
|
+
lastName: "Doe",
|
|
274
|
+
email: "jane@example.com",
|
|
275
|
+
phone: "(312) 555-0142",
|
|
276
|
+
phoneE164: "+13125550142",
|
|
277
|
+
layout: 10,
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
bubbles: true,
|
|
281
|
+
composed: true,
|
|
282
|
+
})
|
|
283
|
+
);
|
|
284
|
+
const submit = await waitFor(() => {
|
|
285
|
+
const button = inScheduler<HTMLElement & { disabled: boolean }>(
|
|
286
|
+
scheduler,
|
|
287
|
+
"#schedule-bttn"
|
|
288
|
+
);
|
|
289
|
+
return button && !button.disabled ? button : null;
|
|
290
|
+
});
|
|
291
|
+
clickButton(submit);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
afterEach(() => {
|
|
295
|
+
restore();
|
|
296
|
+
document.querySelectorAll("tour-scheduler-v2").forEach((el) => el.remove());
|
|
297
|
+
window.dataLayer = [];
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("books a tour with the prospect's details, attribution and conversation, and keeps them out of the dataLayer", async () => {
|
|
301
|
+
window.dataLayer = [];
|
|
302
|
+
const { bookings, keys, sessionTokens } = fakeBackend();
|
|
303
|
+
const scheduler = mount();
|
|
304
|
+
|
|
305
|
+
await fillContactAndSubmit(scheduler);
|
|
306
|
+
await waitFor(() => inScheduler(scheduler, "booking-confirmation"));
|
|
307
|
+
|
|
308
|
+
expect(bookings).to.have.length(1);
|
|
309
|
+
const [booking] = bookings;
|
|
310
|
+
expect(booking.stops).to.deep.equal([
|
|
311
|
+
{ building_id: ANCHOR, start: at(600) },
|
|
312
|
+
]);
|
|
313
|
+
expect(booking.contact).to.deep.equal({
|
|
314
|
+
first_name: "Jane",
|
|
315
|
+
last_name: "Doe",
|
|
316
|
+
email: "jane@example.com",
|
|
317
|
+
phone_e164: "+13125550142",
|
|
318
|
+
bedrooms: [1],
|
|
319
|
+
move_in: null,
|
|
320
|
+
notes: "",
|
|
321
|
+
});
|
|
322
|
+
expect(booking.conversation_tracking_id).to.equal("webchat_lead_test");
|
|
323
|
+
expect(booking.cancel_existing_tours).to.equal(false);
|
|
324
|
+
expect(booking.lead_sources.lead_sources).to.deep.equal([
|
|
325
|
+
"google",
|
|
326
|
+
"property-website",
|
|
327
|
+
]);
|
|
328
|
+
expect(booking.lead_sources.lead_sources_with_timestamps).to.deep.equal([
|
|
329
|
+
{
|
|
330
|
+
timestamp_initially_logged: "2026-10-29T10:00:00Z",
|
|
331
|
+
lead_source_value: "google",
|
|
332
|
+
type: "touchpoint",
|
|
333
|
+
},
|
|
334
|
+
]);
|
|
335
|
+
expect(keys[0]).to.match(/^[0-9a-f-]{36}$/);
|
|
336
|
+
expect(sessionTokens).to.not.be.empty;
|
|
337
|
+
expect(new Set(sessionTokens)).to.deep.equal(new Set(["session-from-init"]));
|
|
338
|
+
|
|
339
|
+
const pushed = JSON.stringify(window.dataLayer);
|
|
340
|
+
expect(pushed).to.contain("scheduleTourSubmitted");
|
|
341
|
+
for (const pii of [
|
|
342
|
+
"Jane",
|
|
343
|
+
"Doe",
|
|
344
|
+
"jane@example.com",
|
|
345
|
+
"3125550142",
|
|
346
|
+
"webchat_lead_test",
|
|
347
|
+
]) {
|
|
348
|
+
expect(pushed, `dataLayer leaks ${pii}`).not.to.contain(pii);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("extends a booking by sending the booked tour as an existing stop and only the new community as a new one", async () => {
|
|
353
|
+
const { bookings, communityQueries } = fakeBackend();
|
|
354
|
+
const scheduler = mount();
|
|
355
|
+
|
|
356
|
+
await fillContactAndSubmit(scheduler);
|
|
357
|
+
const picker = await waitFor(() =>
|
|
358
|
+
inScheduler<CommunityPicker>(
|
|
359
|
+
scheduler,
|
|
360
|
+
"booking-confirmation community-picker"
|
|
361
|
+
)
|
|
362
|
+
);
|
|
363
|
+
await picker.updateComplete;
|
|
364
|
+
picker.shadowRoot
|
|
365
|
+
?.querySelector<HTMLButtonElement>("button.floorplan-image-card")
|
|
366
|
+
?.click();
|
|
367
|
+
clickButton(await waitFor(() => inScheduler(scheduler, "#continue-bttn")));
|
|
368
|
+
|
|
369
|
+
await waitFor(
|
|
370
|
+
() => bookings.length === 1 && inScheduler(scheduler, "itinerary-editor")
|
|
371
|
+
);
|
|
372
|
+
await fillContactAndSubmit(scheduler);
|
|
373
|
+
await waitFor(() => bookings.length === 2);
|
|
374
|
+
|
|
375
|
+
expect(bookings[1].stops).to.deep.equal([
|
|
376
|
+
{ existing_calendar_event_id: 990 },
|
|
377
|
+
{ building_id: LINDEN, start: at(630) },
|
|
378
|
+
]);
|
|
379
|
+
expect(bookings[1].tour_type).to.equal(bookings[0].tour_type);
|
|
380
|
+
// The extension was offered from what the first booking returned.
|
|
381
|
+
const extend = communityQueries.find((q) => q.has("available_after"));
|
|
382
|
+
expect({
|
|
383
|
+
available_after: extend?.get("available_after"),
|
|
384
|
+
tour_type: extend?.get("tour_type"),
|
|
385
|
+
near_building_id: extend?.get("near_building_id"),
|
|
386
|
+
exclude_building_ids: extend?.getAll("exclude_building_ids"),
|
|
387
|
+
}).to.deep.equal({
|
|
388
|
+
available_after: at(630),
|
|
389
|
+
tour_type: "escorted-tour",
|
|
390
|
+
near_building_id: String(ANCHOR),
|
|
391
|
+
exclude_building_ids: [String(ANCHOR)],
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("keeps the prospect's picks when they filter after picking", async () => {
|
|
396
|
+
fakeBackend();
|
|
397
|
+
const scheduler = mount();
|
|
398
|
+
|
|
399
|
+
const editor = await waitFor(() =>
|
|
400
|
+
inScheduler<HTMLElement>(scheduler, "itinerary-editor")
|
|
401
|
+
);
|
|
402
|
+
editor.dispatchEvent(
|
|
403
|
+
new CustomEvent("edit-communities", { bubbles: true, composed: true })
|
|
404
|
+
);
|
|
405
|
+
const picker = await waitFor(() =>
|
|
406
|
+
inScheduler<CommunityPicker>(scheduler, "community-picker")
|
|
407
|
+
);
|
|
408
|
+
await picker.updateComplete;
|
|
409
|
+
const cards = () =>
|
|
410
|
+
Array.from(
|
|
411
|
+
picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
|
|
412
|
+
"button.floorplan-image-card"
|
|
413
|
+
) ?? []
|
|
414
|
+
);
|
|
415
|
+
cards()
|
|
416
|
+
.find((card) => card.textContent?.includes("The Linden"))
|
|
417
|
+
?.click();
|
|
418
|
+
await picker.updateComplete;
|
|
419
|
+
|
|
420
|
+
Array.from(
|
|
421
|
+
picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
|
|
422
|
+
"#picker-filters .floor-plan-badge"
|
|
423
|
+
) ?? []
|
|
424
|
+
)
|
|
425
|
+
.find((badge) => badge.textContent?.trim() === "1 bd")
|
|
426
|
+
?.click();
|
|
427
|
+
// The filter reloads the list, and the scheduler renders again.
|
|
428
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
429
|
+
await picker.updateComplete;
|
|
430
|
+
|
|
431
|
+
await scheduler.updateComplete;
|
|
432
|
+
const picked = Array.from(
|
|
433
|
+
scheduler.shadowRoot?.querySelectorAll(".tray .floor-plan-badge") ?? []
|
|
434
|
+
).map((chip) => chip.textContent?.trim());
|
|
435
|
+
expect(picked).to.deep.equal(["Parkside Commons", "The Linden"]);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("retries a failed booking with the same idempotency key, though attribution is stamped anew", async () => {
|
|
439
|
+
const { bookings, keys } = fakeBackend({ dropFirstBooking: true });
|
|
440
|
+
const scheduler = mount();
|
|
441
|
+
// As LeadSourceMultitouchClient does for a picked lead source: each call stamps now.
|
|
442
|
+
let calls = 0;
|
|
443
|
+
scheduler.leadSourceMultitouchClient = {
|
|
444
|
+
getSafeLeadSourceTouchpointsWithDefault: () => [
|
|
445
|
+
{
|
|
446
|
+
timestampInitiallyLogged: `2026-10-29T10:00:0${calls++}Z`,
|
|
447
|
+
leadSourceValue: "google",
|
|
448
|
+
type: "user-selected",
|
|
449
|
+
},
|
|
450
|
+
],
|
|
451
|
+
resetLeadSourceTouchpoints: () => true,
|
|
452
|
+
} as unknown as TourSchedulerV2["leadSourceMultitouchClient"];
|
|
453
|
+
|
|
454
|
+
await fillContactAndSubmit(scheduler);
|
|
455
|
+
await waitFor(() => keys.length === 1 && !bookings.length);
|
|
456
|
+
await fillContactAndSubmit(scheduler);
|
|
457
|
+
await waitFor(() => inScheduler(scheduler, "booking-confirmation"));
|
|
458
|
+
|
|
459
|
+
expect(bookings).to.have.length(1);
|
|
460
|
+
expect(keys).to.have.length(2);
|
|
461
|
+
expect(keys[1]).to.equal(keys[0]);
|
|
462
|
+
expect(calls).to.equal(2);
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it("moves to the server's first tour type when escorted tours aren't offered", async () => {
|
|
466
|
+
// A building that only offers self-guided tours.
|
|
467
|
+
const { bookings, plannedTourTypes } = fakeBackend({
|
|
468
|
+
tourTypes: ["self-guided-tour"],
|
|
469
|
+
});
|
|
470
|
+
const scheduler = mount();
|
|
471
|
+
|
|
472
|
+
await fillContactAndSubmit(scheduler);
|
|
473
|
+
await waitFor(() => bookings.length === 1);
|
|
474
|
+
|
|
475
|
+
expect(plannedTourTypes.slice(0, 2)).to.deep.equal([
|
|
476
|
+
"escorted-tour",
|
|
477
|
+
"self-guided-tour",
|
|
478
|
+
]);
|
|
479
|
+
expect(bookings[0].tour_type).to.equal("self-guided-tour");
|
|
480
|
+
});
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { expect } from "@esm-bundle/chai";
|
|
2
|
+
import { restore, stub, useFakeXMLHttpRequest } from "sinon/pkg/sinon-esm";
|
|
3
|
+
import "../public/dist/index";
|
|
4
|
+
|
|
5
|
+
declare const afterEach: (callback: () => void) => void;
|
|
6
|
+
declare const beforeEach: (callback: () => void) => void;
|
|
7
|
+
declare const it: (name: string, callback: () => Promise<void>) => void;
|
|
8
|
+
|
|
9
|
+
// Which tour scheduler a building gets, end to end through the built widget.
|
|
10
|
+
// Every request is answered by a fake: nothing reaches EliseAI.
|
|
11
|
+
|
|
12
|
+
type FakeRequest = XMLHttpRequest & {
|
|
13
|
+
url: string;
|
|
14
|
+
requestHeaders: Record<string, string>;
|
|
15
|
+
respond: (
|
|
16
|
+
status: number,
|
|
17
|
+
headers?: Record<string, string>,
|
|
18
|
+
body?: string
|
|
19
|
+
) => void;
|
|
20
|
+
onSend?: () => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type Launcher = HTMLElement & {
|
|
24
|
+
updateComplete: Promise<boolean>;
|
|
25
|
+
isSSTWindowOpen: boolean;
|
|
26
|
+
tourSchedulerV2: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type MeChat = HTMLElement & {
|
|
30
|
+
isLoading: boolean;
|
|
31
|
+
updateComplete: Promise<boolean>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const fakeBackend = (rolloutOn: boolean): FakeRequest[] => {
|
|
35
|
+
const requests: FakeRequest[] = [];
|
|
36
|
+
const fakeXhr = useFakeXMLHttpRequest();
|
|
37
|
+
fakeXhr.onCreate = (request: FakeRequest) => {
|
|
38
|
+
requests.push(request);
|
|
39
|
+
request.onSend = () =>
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
const json = (status: number, body: unknown) =>
|
|
42
|
+
request.respond(
|
|
43
|
+
status,
|
|
44
|
+
{ "Content-Type": "application/json" },
|
|
45
|
+
JSON.stringify(body)
|
|
46
|
+
);
|
|
47
|
+
const { url } = request;
|
|
48
|
+
if (url.includes("/organization/test-org/building/test-building/v2")) {
|
|
49
|
+
return json(200, {
|
|
50
|
+
id: 445038,
|
|
51
|
+
orgId: 53,
|
|
52
|
+
name: "Test Building",
|
|
53
|
+
userId: 7,
|
|
54
|
+
active: 1,
|
|
55
|
+
launchedDateTime: "2024-01-01T00:00:00Z",
|
|
56
|
+
webchatScopeConfigured: true,
|
|
57
|
+
displayStyle: "pills",
|
|
58
|
+
shouldShowChatDesktop: true,
|
|
59
|
+
shouldShowSstDesktop: true,
|
|
60
|
+
shouldShowSstMobile: true,
|
|
61
|
+
layoutOptions: [],
|
|
62
|
+
tourTypeOptions: [],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (url.endsWith("/webchat/init")) {
|
|
66
|
+
return json(200, {
|
|
67
|
+
session_token: "session-from-init",
|
|
68
|
+
lead_id: "lead_test",
|
|
69
|
+
channel: "webchat_lead_test",
|
|
70
|
+
expires_in_seconds: 3600,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (url.includes("/tracked-rollout")) {
|
|
74
|
+
const rollout = new URL(url).searchParams.get("rollout_name");
|
|
75
|
+
return json(
|
|
76
|
+
200,
|
|
77
|
+
rolloutOn && rollout === "webchat_tour_scheduler_v2"
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
// Today's scheduler, when it opens, asks for its availabilities.
|
|
81
|
+
if (url.includes("/tour/availabilities")) {
|
|
82
|
+
return json(200, {
|
|
83
|
+
availability: {},
|
|
84
|
+
rankOrderedSupportedTourTypes: [],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
// Outside a central group, as the v2 endpoints answer for one.
|
|
88
|
+
if (url.includes("/tour-communities")) {
|
|
89
|
+
return json(404, {
|
|
90
|
+
error: { code: "NOT_IN_GROUP", message: "Not in a central group" },
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (url.includes("chat-ui-feature-flag")) return json(200, false);
|
|
94
|
+
return json(200, null);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
return requests;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const openTourScheduler = async (): Promise<ShadowRoot> => {
|
|
101
|
+
const meChat = document.createElement("me-chat") as MeChat;
|
|
102
|
+
meChat.setAttribute("orgslug", "test-org");
|
|
103
|
+
meChat.setAttribute("buildingslug", "test-building");
|
|
104
|
+
document.body.appendChild(meChat);
|
|
105
|
+
for (let i = 0; i < 200 && meChat.isLoading; i++) {
|
|
106
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
107
|
+
}
|
|
108
|
+
await meChat.updateComplete;
|
|
109
|
+
const launcher = meChat.shadowRoot?.querySelector(
|
|
110
|
+
"meetelise-launcher"
|
|
111
|
+
) as Launcher;
|
|
112
|
+
launcher.isSSTWindowOpen = true;
|
|
113
|
+
await launcher.updateComplete;
|
|
114
|
+
return launcher.shadowRoot as ShadowRoot;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
localStorage.clear();
|
|
119
|
+
(window as unknown as { eliseAi: unknown }).eliseAi = {};
|
|
120
|
+
stub(window, "fetch").resolves(new Response("{}"));
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
afterEach(() => {
|
|
124
|
+
document.querySelectorAll("me-chat").forEach((el) => el.remove());
|
|
125
|
+
restore();
|
|
126
|
+
localStorage.clear();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("shows today's tour scheduler when the building is off the rollout", async () => {
|
|
130
|
+
const requests = fakeBackend(false);
|
|
131
|
+
const launcher = await openTourScheduler();
|
|
132
|
+
|
|
133
|
+
expect(launcher.querySelector("tour-scheduler#tour-scheduler-window")).to
|
|
134
|
+
.exist;
|
|
135
|
+
expect(launcher.querySelector("tour-scheduler-v2")).to.equal(null);
|
|
136
|
+
expect(requests.some((r) => r.url.includes("/tour-communities"))).to.equal(
|
|
137
|
+
false
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("shows the v2 scheduler on the rollout, calling its endpoints with the /init session", async () => {
|
|
142
|
+
const requests = fakeBackend(true);
|
|
143
|
+
const launcher = await openTourScheduler();
|
|
144
|
+
|
|
145
|
+
expect(launcher.querySelector("tour-scheduler-v2#tour-scheduler-window")).to
|
|
146
|
+
.exist;
|
|
147
|
+
expect(launcher.querySelector("tour-scheduler")).to.equal(null);
|
|
148
|
+
for (let i = 0; i < 100; i++) {
|
|
149
|
+
if (requests.some((r) => r.url.includes("/tour-communities"))) break;
|
|
150
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
151
|
+
}
|
|
152
|
+
const communities = requests.find((r) => r.url.includes("/tour-communities"));
|
|
153
|
+
expect(communities?.requestHeaders["X-Session-Token"]).to.equal(
|
|
154
|
+
"session-from-init"
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("keeps the scheduler a visitor already opened when the rollout answer changes", async () => {
|
|
159
|
+
fakeBackend(false);
|
|
160
|
+
const launcherRoot = await openTourScheduler();
|
|
161
|
+
const launcher = launcherRoot.host as Launcher;
|
|
162
|
+
|
|
163
|
+
launcher.tourSchedulerV2 = true;
|
|
164
|
+
await launcher.updateComplete;
|
|
165
|
+
|
|
166
|
+
expect(launcherRoot.querySelector("tour-scheduler")).to.exist;
|
|
167
|
+
expect(launcherRoot.querySelector("tour-scheduler-v2")).to.equal(null);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("opens the v2 scheduler from the ?elise_open=tour deep link on a rollout building", async () => {
|
|
171
|
+
fakeBackend(true);
|
|
172
|
+
const meChat = document.createElement("me-chat") as MeChat;
|
|
173
|
+
meChat.setAttribute("orgslug", "test-org");
|
|
174
|
+
meChat.setAttribute("buildingslug", "test-building");
|
|
175
|
+
document.body.appendChild(meChat);
|
|
176
|
+
for (let i = 0; i < 200 && meChat.isLoading; i++) {
|
|
177
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
178
|
+
}
|
|
179
|
+
const launcher = meChat.shadowRoot?.querySelector(
|
|
180
|
+
"meetelise-launcher"
|
|
181
|
+
) as Launcher & { openSSTWindowOnLoad: boolean };
|
|
182
|
+
await launcher.updateComplete;
|
|
183
|
+
|
|
184
|
+
// What me-chat sets when the page URL has ?elise_open=tour.
|
|
185
|
+
launcher.openSSTWindowOnLoad = true;
|
|
186
|
+
await launcher.updateComplete;
|
|
187
|
+
|
|
188
|
+
expect(launcher.shadowRoot?.querySelector("tour-scheduler-v2")).to.exist;
|
|
189
|
+
expect(launcher.shadowRoot?.querySelector("tour-scheduler")).to.equal(null);
|
|
190
|
+
});
|