@meetelise/chat 1.68.0 → 1.69.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.
- package/dist/src/MyPubnub.d.ts +2 -0
- 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/launcher/Launcher.ts +63 -3
- package/src/WebComponent/me-chat.ts +13 -0
- package/src/fetchFeatureFlag.ts +20 -0
- package/src/tourSchedulerV2Booking.test.ts +478 -0
- package/src/tourSchedulerV2Rollout.test.ts +190 -0
|
@@ -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
|
+
});
|