@meetelise/chat 1.72.0 → 1.73.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.
@@ -41,6 +41,9 @@ import {
41
41
  FeatureFlagsShowDropdown,
42
42
  fetchTrackedRolloutCoastalCustomTourTypes,
43
43
  } from "../../fetchFeatureFlag";
44
+ import fetchFloorplanOptions, {
45
+ FloorplanOption,
46
+ } from "../../fetchFloorplanOptions";
44
47
  import {
45
48
  appendParamsToUrl,
46
49
  getUrlQueryParameters,
@@ -284,6 +287,8 @@ export class TourScheduler extends LitElement {
284
287
  selectedLeadSource!: MESelect;
285
288
  @query("me-select#layout")
286
289
  selectedLayoutEl?: MESelect;
290
+ @query("me-select#floorplan")
291
+ selectedFloorplanEl?: MESelect;
287
292
  @query("me-select#unit")
288
293
  selectedUnitEl?: MESelect;
289
294
 
@@ -295,6 +300,11 @@ export class TourScheduler extends LitElement {
295
300
  leadSourceInputValue = "";
296
301
  @state()
297
302
  selectedLayoutValue = "";
303
+ /** Filled when the building is on the WEBCHAT_FLOORPLAN_PREFERENCE switch; the floor plan dropdown then replaces the bedroom one. */
304
+ @state()
305
+ floorplanOptions: FloorplanOption[] = [];
306
+ @state()
307
+ selectedFloorplanName = "";
298
308
  @state()
299
309
  selectedUnitValue = "";
300
310
  @state()
@@ -583,6 +593,7 @@ export class TourScheduler extends LitElement {
583
593
  const useCoastalCustomTourTypes = fetchTrackedRolloutCoastalCustomTourTypes(
584
594
  this.buildingSlug
585
595
  );
596
+ const floorplanOptions = fetchFloorplanOptions(this.buildingSlug);
586
597
  this.tourTypeOrder = tourTypeOrderFor(
587
598
  await getRawAvailabilities(this.buildingId).then(
588
599
  (availabilities) => availabilities.rankOrderedSupportedTourTypes ?? [],
@@ -590,6 +601,7 @@ export class TourScheduler extends LitElement {
590
601
  )
591
602
  );
592
603
  this.useCoastalCustomTourTypes = await useCoastalCustomTourTypes;
604
+ this.floorplanOptions = await floorplanOptions;
593
605
  await Promise.all([
594
606
  this._setAvailabilities().then(async () => {
595
607
  try {
@@ -635,6 +647,8 @@ export class TourScheduler extends LitElement {
635
647
  this.mobilePageIndex = 0;
636
648
  this.units = [];
637
649
  this.selectedLayoutValue = "";
650
+ this.floorplanOptions = [];
651
+ this.selectedFloorplanName = "";
638
652
  this.selectedUnitValue = "";
639
653
 
640
654
  this.buildingId = building.building_id;
@@ -818,7 +832,9 @@ export class TourScheduler extends LitElement {
818
832
  );
819
833
  },
820
834
  layout: (): boolean =>
821
- !this.bedroomPreferenceRequired || !!this.selectedLayoutValue,
835
+ !this.bedroomPreferenceRequired ||
836
+ !!this.selectedLayoutValue ||
837
+ !!this.selectedFloorplanName,
822
838
  broker: (): boolean => {
823
839
  const broker = this.brokerReferral();
824
840
  // The broker's phone is optional, but one that's been typed has to be valid.
@@ -941,6 +957,9 @@ export class TourScheduler extends LitElement {
941
957
  query_params: Object.fromEntries(queryParams.entries()),
942
958
  conversation_tracking_id: this.leadSourceClient?.chatId,
943
959
  layouts: selectedLayout ? [selectedLayout] : undefined,
960
+ floorplans: this.selectedFloorplanName
961
+ ? [this.selectedFloorplanName]
962
+ : undefined,
944
963
  unit_numbers: selectedUnit ? [selectedUnit] : undefined,
945
964
  lead_sources_with_timestamps: (
946
965
  this.leadSourceMultitouchClient?.getSafeLeadSourceTouchpointsWithDefault(
@@ -1544,6 +1563,29 @@ export class TourScheduler extends LitElement {
1544
1563
  );
1545
1564
  }
1546
1565
 
1566
+ /** Sets the canonical layout ("studio", "1br", ...) picked from the bedroom or floor plan dropdown. */
1567
+ private selectLayout = (v: string): void => {
1568
+ this.selectedLayoutValue = v;
1569
+ // Clear unit selection if it no longer matches the new layout.
1570
+ if (v && this.selectedUnitValue) {
1571
+ const unit = this.units.find(
1572
+ (u) => u.unitNumber === this.selectedUnitValue
1573
+ );
1574
+ if (unit && layoutValueToCanonical(unit.numberOfBedrooms * 10) !== v) {
1575
+ this.selectedUnitValue = "";
1576
+ if (this.selectedUnitEl) {
1577
+ this.selectedUnitEl.value = undefined;
1578
+ }
1579
+ }
1580
+ }
1581
+ if (v) {
1582
+ pushGtmEvent("tourLayoutSelected", {
1583
+ layout: v,
1584
+ buildingId: this.buildingId,
1585
+ });
1586
+ }
1587
+ };
1588
+
1547
1589
  userInfoAndLayoutMenu(): TemplateResult {
1548
1590
  const isReferral = this.brokerIntakeEnabled && this.isBrokerReferral;
1549
1591
  return html`<h2 class="journey-header">Your Information</h2>
@@ -1626,7 +1668,30 @@ export class TourScheduler extends LitElement {
1626
1668
  ${this.brokerIntakeEnabled && !isReferral
1627
1669
  ? this.renderBrokerToggle()
1628
1670
  : ""}
1629
- ${this.layoutOptions.length > 0
1671
+ ${this.floorplanOptions.length > 0
1672
+ ? html` <me-select
1673
+ id="floorplan"
1674
+ placeholder=${this.bedroomPreferenceRequired
1675
+ ? "Floor plan preference"
1676
+ : "Floor plan preference (optional)"}
1677
+ .value=${this.selectedFloorplanName}
1678
+ .options="${this.floorplanOptions.map((o) => ({
1679
+ label: o.name,
1680
+ value: o.name,
1681
+ }))}"
1682
+ @change=${() => {
1683
+ const name = this.selectedFloorplanEl?.value || "";
1684
+ const bedrooms = this.floorplanOptions.find(
1685
+ (o) => o.name === name
1686
+ )?.bedrooms;
1687
+ this.selectedFloorplanName = name;
1688
+ this.selectLayout(
1689
+ bedrooms == null ? "" : layoutValueToCanonical(bedrooms * 10)
1690
+ );
1691
+ }}
1692
+ >
1693
+ </me-select>`
1694
+ : this.layoutOptions.length > 0
1630
1695
  ? html` <me-select
1631
1696
  id="layout"
1632
1697
  placeholder=${this.bedroomPreferenceRequired
@@ -1636,31 +1701,8 @@ export class TourScheduler extends LitElement {
1636
1701
  label: o.label,
1637
1702
  value: layoutValueToCanonical(o.value),
1638
1703
  }))}"
1639
- @change=${() => {
1640
- const v = this.selectedLayoutEl?.value || "";
1641
- this.selectedLayoutValue = v;
1642
- // Clear unit selection if it no longer matches the new layout.
1643
- if (v && this.selectedUnitValue) {
1644
- const unit = this.units.find(
1645
- (u) => u.unitNumber === this.selectedUnitValue
1646
- );
1647
- if (
1648
- unit &&
1649
- layoutValueToCanonical(unit.numberOfBedrooms * 10) !== v
1650
- ) {
1651
- this.selectedUnitValue = "";
1652
- if (this.selectedUnitEl) {
1653
- this.selectedUnitEl.value = undefined;
1654
- }
1655
- }
1656
- }
1657
- if (v) {
1658
- pushGtmEvent("tourLayoutSelected", {
1659
- layout: v,
1660
- buildingId: this.buildingId,
1661
- });
1662
- }
1663
- }}
1704
+ @change=${() =>
1705
+ this.selectLayout(this.selectedLayoutEl?.value || "")}
1664
1706
  >
1665
1707
  </me-select>`
1666
1708
  : ""}
@@ -162,9 +162,7 @@ export class MESelect extends LitElement {
162
162
  overflow-y: scroll;
163
163
  position: absolute;
164
164
  min-height: 40px;
165
- min-width: 144px;
166
- max-width: 400px;
167
- width: max-content;
165
+ width: 100%;
168
166
  background-color: white;
169
167
  z-index: 20;
170
168
  margin-top: 4px;
@@ -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
+ });