@meetelise/chat 1.51.0 → 1.51.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.
@@ -0,0 +1,145 @@
1
+ import { expect } from "@esm-bundle/chai";
2
+ import { restore, useFakeXMLHttpRequest } from "sinon/pkg/sinon-esm";
3
+ import "../public/dist/index";
4
+ import type { EmailUsWindow } from "./WebComponent/actions/email-us-window";
5
+ import type {
6
+ TourScheduler,
7
+ TourType,
8
+ } from "./WebComponent/Scheduler/tour-scheduler";
9
+
10
+ type TourSubmissionHarness = {
11
+ tourType: TourType;
12
+ selectedDate: Date;
13
+ selectedTime: { datetime: string; offset: string };
14
+ phoneNumber: string;
15
+ phoneNumberE164: string | null;
16
+ email: string;
17
+ };
18
+
19
+ type FakeRequest = XMLHttpRequest & {
20
+ requestBody?: string;
21
+ respond: (
22
+ status: number,
23
+ headers?: Record<string, string>,
24
+ body?: string
25
+ ) => void;
26
+ url: string;
27
+ };
28
+
29
+ const guidedTour = "guided" as TourType;
30
+
31
+ afterEach(() => {
32
+ restore();
33
+ window.dataLayer = [];
34
+ });
35
+
36
+ it("submits the canonical international number in the Email Us request", async () => {
37
+ const fakeXhr = useFakeXMLHttpRequest();
38
+ const requests: FakeRequest[] = [];
39
+ fakeXhr.onCreate = (request: FakeRequest) => requests.push(request);
40
+ const emailUs = document.createElement("email-us-window") as EmailUsWindow;
41
+ Object.assign(emailUs, {
42
+ firstName: "Local",
43
+ lastName: "Test",
44
+ email: "local.test@example.com",
45
+ phoneNumber: "07400 123456",
46
+ phoneNumberE164: "+447400123456",
47
+ message: "I would like more information.",
48
+ buildingId: 3660,
49
+ buildingSlug: "test-building",
50
+ orgSlug: "test-org",
51
+ });
52
+
53
+ const submission = emailUs.onClick();
54
+
55
+ expect(requests).to.have.length(1);
56
+ expect(requests[0].url).to.equal(
57
+ "https://app.meetelise.com/platformApi/state/create/emailMe"
58
+ );
59
+ expect(JSON.parse(requests[0].requestBody ?? "{}")).to.include({
60
+ phone_number: "+447400123456",
61
+ email_address: "local.test@example.com",
62
+ });
63
+ requests[0].respond(200, { "Content-Type": "application/json" }, "{}");
64
+ await submission;
65
+
66
+ expect(window.dataLayer[window.dataLayer.length - 1]).to.include({
67
+ event: "emailUsSubmitted",
68
+ phone: "+447400123456",
69
+ });
70
+ });
71
+
72
+ it("submits the canonical international number in the Tour request", async () => {
73
+ const fakeXhr = useFakeXMLHttpRequest();
74
+ const requests: FakeRequest[] = [];
75
+ fakeXhr.onCreate = (request: FakeRequest) => requests.push(request);
76
+ const tour = document.createElement("tour-scheduler") as TourScheduler;
77
+ Object.assign(tour as unknown as TourSubmissionHarness, {
78
+ tourType: guidedTour,
79
+ selectedDate: new Date("2030-01-15T00:00:00Z"),
80
+ selectedTime: {
81
+ datetime: "2030-01-15T10:00:00",
82
+ offset: "+01:00",
83
+ },
84
+ phoneNumber: "02 1234 5678",
85
+ phoneNumberE164: "+390212345678",
86
+ email: "local.test@example.com",
87
+ });
88
+ Object.assign(tour, {
89
+ buildingId: 3660,
90
+ buildingSlug: "test-building",
91
+ orgSlug: "test-org",
92
+ firstNameInputValue: "Local",
93
+ lastNameInputValue: "Test",
94
+ });
95
+
96
+ const submission = tour.submit();
97
+
98
+ expect(requests).to.have.length(1);
99
+ expect(requests[0].url).to.equal(
100
+ "https://app.meetelise.com/platformApi/state/create/v2/scheduleMe"
101
+ );
102
+ expect(JSON.parse(requests[0].requestBody ?? "{}")).to.include({
103
+ phone_number: "+390212345678",
104
+ email_address: "local.test@example.com",
105
+ });
106
+ requests[0].respond(200, { "Content-Type": "application/json" }, "{}");
107
+ await submission;
108
+
109
+ expect(window.dataLayer[window.dataLayer.length - 1]).to.include({
110
+ event: "scheduleTourSubmitted",
111
+ phone: "+390212345678",
112
+ });
113
+ });
114
+
115
+ it("does not submit either form without a canonical phone number", async () => {
116
+ const fakeXhr = useFakeXMLHttpRequest();
117
+ const requests: FakeRequest[] = [];
118
+ fakeXhr.onCreate = (request: FakeRequest) => requests.push(request);
119
+ const emailUs = document.createElement("email-us-window") as EmailUsWindow;
120
+ Object.assign(emailUs, {
121
+ firstName: "Local",
122
+ lastName: "Test",
123
+ email: "local.test@example.com",
124
+ phoneNumber: "123",
125
+ phoneNumberE164: null,
126
+ });
127
+ await emailUs.onClick();
128
+
129
+ const tour = document.createElement("tour-scheduler") as TourScheduler;
130
+ Object.assign(tour as unknown as TourSubmissionHarness, {
131
+ tourType: guidedTour,
132
+ selectedDate: new Date("2030-01-15T00:00:00Z"),
133
+ selectedTime: {
134
+ datetime: "2030-01-15T10:00:00",
135
+ offset: "+01:00",
136
+ },
137
+ phoneNumber: "123",
138
+ phoneNumberE164: null,
139
+ email: "local.test@example.com",
140
+ });
141
+ await tour.submit();
142
+
143
+ expect(requests).to.have.length(0);
144
+ expect(emailUs.hasPhoneNumberError).to.equal(true);
145
+ });