@meetelise/chat 1.72.0 → 1.74.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.
@@ -0,0 +1,97 @@
1
+ import { expect } from "@esm-bundle/chai";
2
+ import { render } from "lit";
3
+ import { useFakeXMLHttpRequest } from "sinon/pkg/sinon-esm";
4
+ import "../public/dist/index";
5
+ import type {
6
+ TourScheduler,
7
+ TourType,
8
+ } from "./WebComponent/Scheduler/tour-scheduler";
9
+
10
+ type FakeRequest = XMLHttpRequest & {
11
+ respond: (
12
+ status: number,
13
+ headers?: Record<string, string>,
14
+ body?: string
15
+ ) => void;
16
+ };
17
+
18
+ afterEach(() => {
19
+ window.dataLayer = [];
20
+ });
21
+
22
+ /** Submits a tour, answers "already has a tour" with these headers, and reads the prompt. */
23
+ const promptAfterConflict = async (
24
+ headers: Record<string, string>
25
+ ): Promise<string> => {
26
+ const fakeXhr = useFakeXMLHttpRequest();
27
+ const requests: FakeRequest[] = [];
28
+ fakeXhr.onCreate = (request: FakeRequest) => requests.push(request);
29
+ const tour = document.createElement("tour-scheduler") as TourScheduler;
30
+ Object.assign(tour, {
31
+ tourType: "guided" as TourType,
32
+ selectedDate: new Date("2030-01-15T00:00:00Z"),
33
+ selectedTime: { datetime: "2030-01-15T10:00:00", offset: "-06:00" },
34
+ phoneNumber: "(312) 555-0100",
35
+ phoneNumberE164: "+13125550100",
36
+ email: "cora@example.com",
37
+ buildingId: 445038,
38
+ buildingSlug: "test-building",
39
+ orgSlug: "test-org",
40
+ firstNameInputValue: "Cora",
41
+ lastNameInputValue: "Client",
42
+ });
43
+
44
+ try {
45
+ const submission = tour.submit();
46
+ requests[0].respond(
47
+ 409,
48
+ { "Content-Type": "application/json", ...headers },
49
+ JSON.stringify({
50
+ detail: "User already has a tour scheduled for this building",
51
+ })
52
+ );
53
+ await submission;
54
+ } finally {
55
+ // Each call fakes XHR afresh, so put the real one back before the next.
56
+ fakeXhr.restore();
57
+ }
58
+
59
+ const container = document.createElement("div");
60
+ render(tour.rescheduleExplanation(), container);
61
+ return (container.textContent ?? "").replace(/\s+/g, " ").trim();
62
+ };
63
+
64
+ it("names the existing tour's community and time, in the tour's own offset", async () => {
65
+ expect(
66
+ await promptAfterConflict({
67
+ "Existing-Tour-Building-Name": encodeURIComponent("Maple Court – North"),
68
+ "Existing-Tour-Start-Time": "2026-11-17T05:15:00+09:00",
69
+ })
70
+ ).to.equal(
71
+ "You already have a tour scheduled at one of our communities, Maple Court – North, on Nov 17 at 5:15am. Would you like to reschedule?"
72
+ );
73
+ });
74
+
75
+ it("keeps the general prompt when either header is missing or unreadable", async () => {
76
+ const general =
77
+ "You already have a tour scheduled. Would you like to reschedule?";
78
+
79
+ expect(await promptAfterConflict({})).to.equal(general);
80
+ expect(
81
+ await promptAfterConflict({
82
+ "Existing-Tour-Building-Name": "Maple%20Court",
83
+ })
84
+ ).to.equal(general);
85
+ expect(
86
+ await promptAfterConflict({
87
+ "Existing-Tour-Building-Name": "Maple%E0%A4%A",
88
+ "Existing-Tour-Start-Time": "2026-11-16T15:15:00-05:00",
89
+ })
90
+ ).to.equal(general);
91
+ expect(
92
+ await promptAfterConflict({
93
+ "Existing-Tour-Building-Name": "Maple%20Court",
94
+ "Existing-Tour-Start-Time": "2026-11-16T15:15:00",
95
+ })
96
+ ).to.equal(general);
97
+ });
@@ -0,0 +1,38 @@
1
+ import axios from "axios";
2
+ import { LogType, sendLoggingEvent } from "./analytics";
3
+ import { BASE_DOMAIN } from "./globals";
4
+
5
+ export type FloorplanOption = {
6
+ name: string;
7
+ bedrooms: number | null;
8
+ };
9
+
10
+ /**
11
+ * The building's unit-editor floor plans that have an active unit. Empty when the building is off the
12
+ * WEBCHAT_FLOORPLAN_PREFERENCE switch, or when they can't be read.
13
+ */
14
+ const fetchFloorplanOptions = async (
15
+ buildingSlug: string
16
+ ): Promise<FloorplanOption[]> => {
17
+ if (!buildingSlug) return [];
18
+ try {
19
+ const response = await axios.get<FloorplanOption[]>(
20
+ `${BASE_DOMAIN}/platformApi/webchat/${buildingSlug}/floorplan-options`,
21
+ { timeout: 3000 }
22
+ );
23
+ return Array.isArray(response.data)
24
+ ? response.data.filter((option) => !!option?.name)
25
+ : [];
26
+ } catch (error) {
27
+ sendLoggingEvent({
28
+ logType: LogType.error,
29
+ buildingSlug,
30
+ logTitle: "[ERROR_GETTING_FLOORPLAN_OPTIONS]",
31
+ logData: { error },
32
+ error,
33
+ });
34
+ return [];
35
+ }
36
+ };
37
+
38
+ export default fetchFloorplanOptions;
@@ -0,0 +1,51 @@
1
+ import { expect } from "@esm-bundle/chai";
2
+ import "../public/dist/index";
3
+ import type { MESelect } from "./WebComponent/me-select";
4
+
5
+ declare const it: (name: string, callback: () => Promise<void>) => void;
6
+
7
+ const FIELD_WIDTH = 315;
8
+ const LONG_FLOORPLAN_NAME =
9
+ "370-414 - 1 Bedroom + Den Penthouse (With Rooftop Terrace) - Over 890 Sqft!";
10
+
11
+ const openMenu = async (
12
+ labels: string[]
13
+ ): Promise<{ field: DOMRect; menu: DOMRect }> => {
14
+ const container = document.createElement("div");
15
+ container.style.width = `${FIELD_WIDTH}px`;
16
+ const select = document.createElement("me-select") as MESelect & {
17
+ updateComplete: Promise<boolean>;
18
+ };
19
+ select.options = labels.map((label) => ({ label, value: label }));
20
+ container.append(select);
21
+ document.body.append(container);
22
+ await select.updateComplete;
23
+
24
+ select.toggleSelect();
25
+ await select.updateComplete;
26
+
27
+ const root = select.shadowRoot as ShadowRoot;
28
+ const field = (
29
+ root.querySelector("#select") as HTMLElement
30
+ ).getBoundingClientRect();
31
+ const menu = (
32
+ root.querySelector('[role="listbox"]') as HTMLElement
33
+ ).getBoundingClientRect();
34
+ container.remove();
35
+ return { field, menu };
36
+ };
37
+
38
+ it("opens a menu as wide as the field when every label is short", async () => {
39
+ const { field, menu } = await openMenu(["Studio", "One bedroom"]);
40
+
41
+ expect(field.width).to.be.closeTo(FIELD_WIDTH, 0.5);
42
+ expect(menu.left).to.be.closeTo(field.left, 0.5);
43
+ expect(menu.right).to.be.closeTo(field.right, 0.5);
44
+ });
45
+
46
+ it("wraps a label longer than the field instead of widening the menu", async () => {
47
+ const { field, menu } = await openMenu(["Studio", LONG_FLOORPLAN_NAME]);
48
+
49
+ expect(menu.left).to.be.closeTo(field.left, 0.5);
50
+ expect(menu.right).to.be.closeTo(field.right, 0.5);
51
+ });
@@ -0,0 +1,208 @@
1
+ import { expect } from "@esm-bundle/chai";
2
+ import { restore, stub, useFakeXMLHttpRequest } from "sinon/pkg/sinon-esm";
3
+ import "../public/dist/index";
4
+ import type { MESelect } from "./WebComponent/me-select";
5
+ import type {
6
+ TourScheduler,
7
+ TourType,
8
+ } from "./WebComponent/Scheduler/tour-scheduler";
9
+
10
+ declare const afterEach: (callback: () => void) => void;
11
+ declare const beforeEach: (callback: () => void) => void;
12
+ declare const it: (name: string, callback: () => Promise<void>) => void;
13
+
14
+ // Today's tour scheduler for buildings on and off the WEBCHAT_FLOORPLAN_PREFERENCE switch. The backend
15
+ // answers /floorplan-options with [] for a building off the switch.
16
+ // Every request is answered by a fake: nothing reaches EliseAI.
17
+
18
+ type FakeRequest = XMLHttpRequest & {
19
+ url: string;
20
+ requestBody?: string;
21
+ respond: (
22
+ status: number,
23
+ headers?: Record<string, string>,
24
+ body?: string
25
+ ) => void;
26
+ onSend?: () => void;
27
+ };
28
+
29
+ type TourSubmissionHarness = {
30
+ tourType: TourType;
31
+ selectedDate: Date;
32
+ selectedTime: { datetime: string; offset: string };
33
+ phoneNumber: string;
34
+ phoneNumberE164: string;
35
+ email: string;
36
+ };
37
+
38
+ const floorplans = [
39
+ { name: "Studio Loft", bedrooms: 0 },
40
+ { name: "1 Bedroom", bedrooms: 1 },
41
+ { name: "1 Bedroom + Den", bedrooms: 1 },
42
+ ];
43
+
44
+ const fakeBackend = (floorplanOptions: {
45
+ status: number;
46
+ body: unknown;
47
+ }): FakeRequest[] => {
48
+ const requests: FakeRequest[] = [];
49
+ const fakeXhr = useFakeXMLHttpRequest();
50
+ fakeXhr.onCreate = (request: FakeRequest) => {
51
+ requests.push(request);
52
+ request.onSend = () =>
53
+ setTimeout(() => {
54
+ const json = (status: number, body: unknown) =>
55
+ request.respond(
56
+ status,
57
+ { "Content-Type": "application/json" },
58
+ JSON.stringify(body)
59
+ );
60
+ const { url } = request;
61
+ if (url.includes("/tracked-rollout")) return json(200, false);
62
+ if (url.includes("/floorplan-options")) {
63
+ return json(floorplanOptions.status, floorplanOptions.body);
64
+ }
65
+ if (url.includes("/tour/availabilities")) {
66
+ return json(200, {
67
+ availability: {
68
+ WITH_AGENT: { availableTourStartTimes: ["2030-01-15T10:00:00Z"] },
69
+ },
70
+ rankOrderedSupportedTourTypes: ["WITH_AGENT"],
71
+ });
72
+ }
73
+ if (url.includes("/scheduling_status")) {
74
+ return json(200, { is_enabled: true });
75
+ }
76
+ if (url.includes("/central-convo-buildings")) {
77
+ return json(200, { buildings: [], is_general_building: false });
78
+ }
79
+ if (url.includes("/units/summary")) return json(200, []);
80
+ return json(200, null);
81
+ });
82
+ };
83
+ return requests;
84
+ };
85
+
86
+ const openScheduler = async (
87
+ fields: Record<string, unknown> = {}
88
+ ): Promise<TourScheduler> => {
89
+ const tour = document.createElement("tour-scheduler") as TourScheduler;
90
+ Object.assign(tour, {
91
+ buildingId: 445038,
92
+ buildingSlug: "test-building",
93
+ orgSlug: "test-org",
94
+ tourTypeOptions: [{ label: "Guided tour", value: "WITH_AGENT" }],
95
+ layoutOptions: [
96
+ { label: "Studio", value: 0 },
97
+ { label: "One bedroom", value: 10 },
98
+ ],
99
+ ...fields,
100
+ });
101
+ document.body.appendChild(tour);
102
+ for (let i = 0; i < 300 && !preferenceSelect(tour); i++) {
103
+ await new Promise((resolve) => setTimeout(resolve, 10));
104
+ }
105
+ await tour.updateComplete;
106
+ return tour;
107
+ };
108
+
109
+ const preferenceSelect = (tour: TourScheduler): MESelect | null =>
110
+ tour.shadowRoot?.querySelector("me-select#floorplan, me-select#layout") ??
111
+ null;
112
+
113
+ const choose = async (
114
+ tour: TourScheduler,
115
+ select: MESelect,
116
+ label: string
117
+ ): Promise<void> => {
118
+ await select.updateComplete;
119
+ const option = select.options.find((o) => o.label === label);
120
+ if (!option) throw new Error(`No option labeled ${label}`);
121
+ select.setSelectedOption(option);
122
+ await tour.updateComplete;
123
+ };
124
+
125
+ const book = async (
126
+ tour: TourScheduler,
127
+ requests: FakeRequest[]
128
+ ): Promise<Record<string, unknown>> => {
129
+ Object.assign(tour as unknown as TourSubmissionHarness, {
130
+ tourType: "guided",
131
+ selectedDate: new Date("2030-01-15T00:00:00Z"),
132
+ selectedTime: { datetime: "2030-01-15T10:00:00", offset: "-05:00" },
133
+ phoneNumber: "(312) 555-0100",
134
+ phoneNumberE164: "+13125550100",
135
+ email: "cora@example.com",
136
+ });
137
+ await tour.submit();
138
+ const booking = requests.find((r) => r.url.endsWith("/v2/scheduleMe"));
139
+ return JSON.parse(booking?.requestBody ?? "{}");
140
+ };
141
+
142
+ beforeEach(() => {
143
+ stub(window, "fetch").resolves(new Response("{}"));
144
+ });
145
+
146
+ afterEach(() => {
147
+ document.querySelectorAll("tour-scheduler").forEach((el) => el.remove());
148
+ restore();
149
+ window.dataLayer = [];
150
+ });
151
+
152
+ it("lists the floor plans by name and books the chosen one with its bedroom layout", async () => {
153
+ const requests = fakeBackend({ status: 200, body: floorplans });
154
+ const tour = await openScheduler();
155
+
156
+ const select = preferenceSelect(tour) as MESelect;
157
+ expect(select.id).to.equal("floorplan");
158
+ expect(select.placeholder).to.equal("Floor plan preference (optional)");
159
+ expect(select.options.map((o) => o.label)).to.deep.equal([
160
+ "Studio Loft",
161
+ "1 Bedroom",
162
+ "1 Bedroom + Den",
163
+ ]);
164
+
165
+ await choose(tour, select, "1 Bedroom + Den");
166
+ expect(tour.selectedLayoutValue).to.equal("1br");
167
+
168
+ const body = await book(tour, requests);
169
+ expect(body.layouts).to.deep.equal(["1br"]);
170
+ expect(body.floorplans).to.deep.equal(["1 Bedroom + Den"]);
171
+ });
172
+
173
+ it("requires a floor plan when the building requires a bedroom preference", async () => {
174
+ fakeBackend({ status: 200, body: floorplans });
175
+ const tour = await openScheduler({ bedroomPreferenceRequired: true });
176
+
177
+ const select = preferenceSelect(tour) as MESelect;
178
+ expect(select.placeholder).to.equal("Floor plan preference");
179
+ expect(tour.validators.layout()).to.equal(false);
180
+
181
+ await choose(tour, select, "Studio Loft");
182
+ expect(tour.validators.layout()).to.equal(true);
183
+ expect(tour.selectedLayoutValue).to.equal("studio");
184
+ });
185
+
186
+ it("keeps the bedroom dropdown and books without floor plans when the building is off the switch", async () => {
187
+ const requests = fakeBackend({ status: 200, body: [] });
188
+ const tour = await openScheduler();
189
+
190
+ const select = preferenceSelect(tour) as MESelect;
191
+ expect(select.id).to.equal("layout");
192
+ expect(select.placeholder).to.equal("Bedroom preference (optional)");
193
+ expect(
194
+ requests.some((r) => r.url.includes("webchat_floorplan_preference"))
195
+ ).to.equal(false);
196
+
197
+ await choose(tour, select, "One bedroom");
198
+ const body = await book(tour, requests);
199
+ expect(body.layouts).to.deep.equal(["1br"]);
200
+ expect(body).not.to.have.property("floorplans");
201
+ });
202
+
203
+ it("falls back to the bedroom dropdown when the floor plans fail to load", async () => {
204
+ fakeBackend({ status: 500, body: { detail: "error" } });
205
+ const tour = await openScheduler();
206
+
207
+ expect(preferenceSelect(tour)?.id).to.equal("layout");
208
+ });
@@ -305,7 +305,7 @@ const fillContactAndSubmit = async (
305
305
  email: "jane@example.com",
306
306
  phone: "(312) 555-0142",
307
307
  phoneE164: "+13125550142",
308
- layout: 10,
308
+ layouts: [10],
309
309
  ...overrides,
310
310
  },
311
311
  },
@@ -557,7 +557,7 @@ it("offers the toured communities' bedroom counts where this building has no lay
557
557
  ]);
558
558
  expect(form.bedroomsRequired).to.equal(true);
559
559
 
560
- await fillContactAndSubmit(scheduler, { layout: 20 });
560
+ await fillContactAndSubmit(scheduler, { layouts: [20] });
561
561
  await waitFor(() => bookings.length === 1);
562
562
 
563
563
  expect(bookings[0].contact?.bedrooms).to.deep.equal([2]);
@@ -569,7 +569,7 @@ it("books without a bedroom preference where one is required but there are no la
569
569
  scheduler.layoutOptions = [];
570
570
  scheduler.bedroomPreferenceRequired = true;
571
571
 
572
- await fillContactAndSubmit(scheduler, { layout: null });
572
+ await fillContactAndSubmit(scheduler, { layouts: [] });
573
573
  await waitFor(() => bookings.length === 1);
574
574
 
575
575
  expect(bookings[0].contact?.bedrooms).to.deep.equal([]);
@@ -593,7 +593,7 @@ it("still asks for a bedroom preference where one is required and the building h
593
593
  email: "jane@example.com",
594
594
  phone: "(312) 555-0142",
595
595
  phoneE164: "+13125550142",
596
- layout: null,
596
+ layouts: [],
597
597
  },
598
598
  },
599
599
  bubbles: true,
@@ -617,6 +617,52 @@ it("still asks for a bedroom preference where one is required and the building h
617
617
  expect(button?.disabled).to.equal(true);
618
618
  });
619
619
 
620
+ it("picks several bedroom preferences, a layout sharing a count going on and off with it", async () => {
621
+ const { bookings } = fakeBackend();
622
+ const scheduler = mount();
623
+ scheduler.layoutOptions = [
624
+ { value: 10, label: "One bedroom" },
625
+ { value: 11, label: "One bedroom + den" },
626
+ { value: 20, label: "Two bedroom" },
627
+ ];
628
+
629
+ const form = await waitFor(() =>
630
+ inScheduler<ContactForm>(scheduler, "contact-form")
631
+ );
632
+ const chip = (label: string) =>
633
+ Array.from(
634
+ form.shadowRoot?.querySelectorAll<HTMLButtonElement>("#layout button") ??
635
+ []
636
+ ).find((b) => b.textContent?.trim() === label);
637
+ const tap = async (label: string) => {
638
+ chip(label)?.click();
639
+ await scheduler.updateComplete;
640
+ await form.updateComplete;
641
+ };
642
+ const pressed = () =>
643
+ Array.from(
644
+ form.shadowRoot?.querySelectorAll<HTMLButtonElement>(
645
+ '#layout button[aria-pressed="true"]'
646
+ ) ?? []
647
+ ).map((b) => b.textContent?.trim());
648
+
649
+ await tap("One bedroom");
650
+ expect(pressed()).to.deep.equal(["One bedroom", "One bedroom + den"]);
651
+ await tap("Two bedroom");
652
+ expect(pressed()).to.deep.equal([
653
+ "One bedroom",
654
+ "One bedroom + den",
655
+ "Two bedroom",
656
+ ]);
657
+ await tap("One bedroom + den");
658
+ expect(pressed()).to.deep.equal(["Two bedroom"]);
659
+ await tap("One bedroom");
660
+
661
+ await fillContactAndSubmit(scheduler, { layouts: form.values.layouts });
662
+ await waitFor(() => bookings.length === 1);
663
+ expect(bookings[0].contact?.bedrooms).to.deep.equal([1, 2]);
664
+ });
665
+
620
666
  it("asks to reschedule an added stop that clashes with a tour, and resends it without contact details", async () => {
621
667
  const { bookings } = fakeBackend({
622
668
  extensionError: {
@@ -727,12 +773,15 @@ it("carries bedrooms, move-in and budget between the picker's filters, the form
727
773
  inScheduler<ContactForm>(scheduler, "contact-form")
728
774
  );
729
775
  expect({
730
- layout: form.values.layout,
776
+ layouts: form.values.layouts,
731
777
  moveIn: form.values.moveIn,
732
- }).to.deep.equal({ layout: 20, moveIn: "2026-12-01" });
778
+ }).to.deep.equal({ layouts: [20], moveIn: "2026-12-01" });
733
779
 
734
780
  // Edited on the form, they carry on to the extension's filters, with the budget.
735
- await fillContactAndSubmit(scheduler, { layout: 10, moveIn: "2027-01-15" });
781
+ await fillContactAndSubmit(scheduler, {
782
+ layouts: [10],
783
+ moveIn: "2027-01-15",
784
+ });
736
785
  await waitFor(() => bookings.length === 1);
737
786
  expect(bookings[0].contact?.bedrooms).to.deep.equal([1]);
738
787
  expect(bookings[0].contact?.move_in).to.equal("2027-01-15");
@@ -793,6 +842,53 @@ it("closes only a filter's panel on Escape, leaving the scheduler open", async (
793
842
  expect(closed).to.equal(false);
794
843
  });
795
844
 
845
+ it("closes a filter's panel when focus moves on, so Escape is not pressed outside it", async () => {
846
+ fakeBackend();
847
+ const scheduler = mount();
848
+ const editor = await waitFor(() =>
849
+ inScheduler<HTMLElement>(scheduler, "itinerary-editor")
850
+ );
851
+ editor.dispatchEvent(
852
+ new CustomEvent("edit-communities", { bubbles: true, composed: true })
853
+ );
854
+ const picker = await waitFor(() =>
855
+ inScheduler<CommunityPicker>(scheduler, "community-picker")
856
+ );
857
+ await picker.updateComplete;
858
+ const chip = (id: string) =>
859
+ picker.shadowRoot?.querySelector<HTMLButtonElement>(
860
+ `[aria-controls="filter-${id}"]`
861
+ );
862
+ chip("bedrooms")?.click();
863
+ await picker.updateComplete;
864
+ const bedroom = await waitFor(() =>
865
+ picker.shadowRoot?.querySelector<HTMLButtonElement>(
866
+ "#filter-bedrooms button"
867
+ )
868
+ );
869
+
870
+ // Picking bedrooms keeps the panel open; tabbing on to the next chip doesn't.
871
+ // (Other test files' pages hold real focus, so the move is dispatched.)
872
+ const moveFocus = (from: HTMLElement, to: HTMLElement | undefined | null) =>
873
+ from.dispatchEvent(
874
+ new FocusEvent("focusout", {
875
+ relatedTarget: to ?? null,
876
+ bubbles: true,
877
+ composed: true,
878
+ })
879
+ );
880
+ bedroom.click();
881
+ const others = picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
882
+ "#filter-bedrooms button"
883
+ );
884
+ moveFocus(bedroom, others?.[1]);
885
+ await picker.updateComplete;
886
+ expect(chip("bedrooms")?.getAttribute("aria-expanded")).to.equal("true");
887
+ moveFocus(bedroom, chip("moveIn"));
888
+ await picker.updateComplete;
889
+ expect(chip("bedrooms")?.getAttribute("aria-expanded")).to.equal("false");
890
+ });
891
+
796
892
  it("adds stops one at a time after a booking, offering each next stop after the one before it", async () => {
797
893
  const { bookings, communityQueries } = fakeBackend();
798
894
  const scheduler = mount();