@meetelise/chat 1.71.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.
- package/dist/src/WebComponent/Scheduler/tour-scheduler.d.ts +7 -0
- package/dist/src/WebComponent/SchedulerV2/community-picker.d.ts +5 -24
- package/dist/src/WebComponent/SchedulerV2/itinerary-editor.d.ts +5 -0
- package/dist/src/WebComponent/SchedulerV2/tour-scheduler-v2.d.ts +21 -3
- package/dist/src/fetchFloorplanOptions.d.ts +10 -0
- package/package.json +1 -1
- package/public/dist/index.js +486 -468
- package/src/WebComponent/Scheduler/tour-scheduler.ts +69 -27
- package/src/WebComponent/SchedulerV2/community-picker.ts +56 -175
- package/src/WebComponent/SchedulerV2/itinerary-editor.ts +41 -7
- package/src/WebComponent/SchedulerV2/tour-scheduler-v2.ts +151 -25
- package/src/WebComponent/me-select.ts +1 -3
- package/src/fetchFloorplanOptions.ts +38 -0
- package/src/meSelectMenuWidth.test.ts +51 -0
- package/src/tourSchedulerFloorplanPreference.test.ts +208 -0
- package/src/tourSchedulerV2Booking.test.ts +84 -3
|
@@ -8,6 +8,7 @@ import "./contact-form";
|
|
|
8
8
|
import "./booking-confirmation";
|
|
9
9
|
import "../actions/action-confirm-button";
|
|
10
10
|
import "../loaders/mega-loader";
|
|
11
|
+
import "../mini-loader";
|
|
11
12
|
import { tourSchedulerStyles } from "../Scheduler/tourSchedulerStyles";
|
|
12
13
|
import { InputStyles } from "../actions/InputStyles";
|
|
13
14
|
import { ChevronLeftIcon } from "../icons/ChevronLeftIcon";
|
|
@@ -28,7 +29,6 @@ import {
|
|
|
28
29
|
toCommunitySummary,
|
|
29
30
|
TourTypeId,
|
|
30
31
|
} from "./tourItineraryApi";
|
|
31
|
-
import { renderSelectionTray, selectionTrayStyles } from "./community-picker";
|
|
32
32
|
import type { TourTypeChoice, StopProblem } from "./itinerary-editor";
|
|
33
33
|
import { contactIsValid, ContactValues, EMPTY_CONTACT } from "./contact-form";
|
|
34
34
|
import type { ConfirmedStop } from "./booking-confirmation";
|
|
@@ -139,8 +139,10 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
139
139
|
@state() private group: CommunitiesResponse | null = null;
|
|
140
140
|
@state() private communities = new Map<number, CommunitySummary>();
|
|
141
141
|
@state() private selectedIds: number[] = [];
|
|
142
|
-
/** The
|
|
142
|
+
/** The picker's pick, marked when the prospect goes back to it. */
|
|
143
143
|
@state() private picks: CommunitySummary[] = [];
|
|
144
|
+
/** Adding stops: the nearby communities are open under the itinerary. */
|
|
145
|
+
@state() private addingStop = false;
|
|
144
146
|
@state() private existingEventIds: number[] = [];
|
|
145
147
|
@state() private tourType: TourTypeId = "escorted-tour";
|
|
146
148
|
/** A tour type this building books on its own page, once picked. */
|
|
@@ -373,6 +375,9 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
373
375
|
* type or date isn't offered, moves to the first one it offers and asks again.
|
|
374
376
|
*/
|
|
375
377
|
private async runPlan(keepNotice = false): Promise<void> {
|
|
378
|
+
// The nearby list was fetched after the old last stop, without the old
|
|
379
|
+
// stops; "Add another stop" offers it again once this plan is in.
|
|
380
|
+
this.addingStop = false;
|
|
376
381
|
if (this.selectedIds.length === 0) return;
|
|
377
382
|
const requestId = ++this.planRequestId;
|
|
378
383
|
this.planLoading = true;
|
|
@@ -786,6 +791,62 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
786
791
|
return MAX_ITINERARY_STOPS - this.bookedEventIds.length;
|
|
787
792
|
}
|
|
788
793
|
|
|
794
|
+
/**
|
|
795
|
+
* Another stop fits after the booked ones and those added so far, and the
|
|
796
|
+
* plan shown is for these stops, so the list can start after its last one.
|
|
797
|
+
*/
|
|
798
|
+
private get canAddStop(): boolean {
|
|
799
|
+
return (
|
|
800
|
+
!this.planLoading &&
|
|
801
|
+
!this.planError &&
|
|
802
|
+
this.stopsRemaining() > this.selectedIds.length &&
|
|
803
|
+
(this.plan?.stops.length ?? 0) > 0
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* As `extendQueryFromBooking`, from the itinerary being added: times after
|
|
809
|
+
* its last planned stop, near it, without any community already in it.
|
|
810
|
+
*/
|
|
811
|
+
private extendQueryFromPlan(): ExtendQuery | null {
|
|
812
|
+
const stops = this.plan?.stops ?? [];
|
|
813
|
+
const last = stops[stops.length - 1];
|
|
814
|
+
if (!last || !this.extendFrom) return null;
|
|
815
|
+
return {
|
|
816
|
+
...this.extendFrom,
|
|
817
|
+
availableAfter: last.end,
|
|
818
|
+
nearBuildingId: last.building_id,
|
|
819
|
+
excludeBuildingIds: [
|
|
820
|
+
...this.extendFrom.excludeBuildingIds,
|
|
821
|
+
...this.selectedIds,
|
|
822
|
+
],
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
private loadAddStopCommunities = (
|
|
827
|
+
filters: CommunityFilters
|
|
828
|
+
): Promise<CommunitiesResponse> => {
|
|
829
|
+
const extend = this.extendQueryFromPlan();
|
|
830
|
+
if (!extend) return Promise.reject(new Error("No stop to add after"));
|
|
831
|
+
return this.client
|
|
832
|
+
.getCommunities({ ...filters, extend })
|
|
833
|
+
.then(this.rememberPage);
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
/** One more community joins the itinerary, after the stops already in it. */
|
|
837
|
+
private onStopAdded(picked: CommunitySummary[]): void {
|
|
838
|
+
const community = picked[0];
|
|
839
|
+
if (!community) return;
|
|
840
|
+
this.rememberOne(community);
|
|
841
|
+
pushGtmEvent("tourCommunitiesSelected", {
|
|
842
|
+
buildingId: this.buildingId,
|
|
843
|
+
count: 1,
|
|
844
|
+
mode: "extend",
|
|
845
|
+
});
|
|
846
|
+
this.selectedIds = [...this.selectedIds, community.building_id];
|
|
847
|
+
void this.runPlan();
|
|
848
|
+
}
|
|
849
|
+
|
|
789
850
|
/** Offers more communities while the itinerary has stops left. */
|
|
790
851
|
private async loadExtension(): Promise<void> {
|
|
791
852
|
const extend = this.extendQueryFromBooking();
|
|
@@ -989,7 +1050,6 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
989
1050
|
.load=${this.loadSelectCommunities}
|
|
990
1051
|
.initial=${this.group}
|
|
991
1052
|
.filters=${this.preferences}
|
|
992
|
-
.maxSelectable=${1}
|
|
993
1053
|
.selected=${this.picks}
|
|
994
1054
|
@filters-change=${this.onFiltersChange}
|
|
995
1055
|
@selection-change=${(
|
|
@@ -998,20 +1058,37 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
998
1058
|
></community-picker>`);
|
|
999
1059
|
}
|
|
1000
1060
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1061
|
+
/** Adding stops to a booking: the design's itinerary heading. */
|
|
1062
|
+
private renderItineraryHeading(): TemplateResult {
|
|
1063
|
+
return html`<div class="itinerary-heading">
|
|
1064
|
+
<h2>
|
|
1065
|
+
Create Your Tour Itinerary
|
|
1066
|
+
${this.planLoading ? html`<mini-loader></mini-loader>` : ""}
|
|
1067
|
+
</h2>
|
|
1068
|
+
<p class="explanation">Add up to ${MAX_ITINERARY_STOPS} communities</p>
|
|
1069
|
+
</div>`;
|
|
1070
|
+
}
|
|
1006
1071
|
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1072
|
+
/** "Add another stop": the nearby communities, under the itinerary. */
|
|
1073
|
+
private renderAddStop(): TemplateResult {
|
|
1074
|
+
return html`<div class="add-stop-picker">
|
|
1075
|
+
<button
|
|
1076
|
+
class="close-add-stop"
|
|
1077
|
+
aria-label="Close nearby communities"
|
|
1078
|
+
@click=${() => (this.addingStop = false)}
|
|
1079
|
+
>
|
|
1080
|
+
${XOutlineIcon("#737373")}
|
|
1081
|
+
</button>
|
|
1082
|
+
<community-picker
|
|
1083
|
+
variant="extend"
|
|
1084
|
+
.load=${this.loadAddStopCommunities}
|
|
1085
|
+
.filters=${this.preferences}
|
|
1086
|
+
@filters-change=${this.onFiltersChange}
|
|
1087
|
+
@selection-change=${(
|
|
1088
|
+
e: CustomEvent<{ communities: CommunitySummary[] }>
|
|
1089
|
+
) => this.onStopAdded(e.detail.communities)}
|
|
1090
|
+
></community-picker>
|
|
1091
|
+
</div>`;
|
|
1015
1092
|
}
|
|
1016
1093
|
|
|
1017
1094
|
private renderSchedule(): TemplateResult {
|
|
@@ -1026,10 +1103,14 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
1026
1103
|
</button>
|
|
1027
1104
|
</p>`
|
|
1028
1105
|
: ""}
|
|
1106
|
+
${this.extending ? this.renderItineraryHeading() : ""}
|
|
1029
1107
|
${this.notice
|
|
1030
1108
|
? html`<p class="explanation notice" role="status">${this.notice}</p>`
|
|
1031
1109
|
: ""}
|
|
1032
|
-
<div
|
|
1110
|
+
<div
|
|
1111
|
+
id="book-tour-journey-items"
|
|
1112
|
+
class=${classMap({ itinerary: this.extending })}
|
|
1113
|
+
>
|
|
1033
1114
|
<itinerary-editor
|
|
1034
1115
|
.stops=${plan?.stops ?? []}
|
|
1035
1116
|
.communities=${this.communities}
|
|
@@ -1039,6 +1120,8 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
1039
1120
|
.bookableDates=${plan?.bookable_dates ?? []}
|
|
1040
1121
|
.date=${this.date}
|
|
1041
1122
|
?single=${!this.isMultiStop()}
|
|
1123
|
+
?stopsOnly=${this.extending}
|
|
1124
|
+
?canAddStop=${this.extending && !this.addingStop && this.canAddStop}
|
|
1042
1125
|
?canEditCommunities=${this.group !== null && !this.extending}
|
|
1043
1126
|
?loading=${this.planLoading}
|
|
1044
1127
|
?planned=${plan !== null}
|
|
@@ -1057,6 +1140,7 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
1057
1140
|
@stop-remove=${(e: CustomEvent<{ buildingId: number }>) =>
|
|
1058
1141
|
this.onRemove(e.detail.buildingId)}
|
|
1059
1142
|
@edit-communities=${() => this.onEditCommunities()}
|
|
1143
|
+
@add-stop=${() => (this.addingStop = true)}
|
|
1060
1144
|
@open-tour-link=${() =>
|
|
1061
1145
|
this.activeLinkType && this.openTourLink(this.activeLinkType)}
|
|
1062
1146
|
></itinerary-editor>
|
|
@@ -1082,6 +1166,7 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
1082
1166
|
})}
|
|
1083
1167
|
></contact-form>`}
|
|
1084
1168
|
</div>
|
|
1169
|
+
${this.extending && this.addingStop ? this.renderAddStop() : ""}
|
|
1085
1170
|
`)}
|
|
1086
1171
|
<div
|
|
1087
1172
|
id="tour-scheduler-footer"
|
|
@@ -1102,8 +1187,12 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
1102
1187
|
.onClick=${() => this.submit()}
|
|
1103
1188
|
.isLoading=${this.submitting}
|
|
1104
1189
|
height="50px"
|
|
1105
|
-
width=${this.mobile ? "100%" : "145px"}
|
|
1106
|
-
text=${this.
|
|
1190
|
+
width=${this.mobile ? "100%" : this.extending ? "200px" : "145px"}
|
|
1191
|
+
text=${this.extending
|
|
1192
|
+
? "Confirm tour itinerary"
|
|
1193
|
+
: this.isMultiStop()
|
|
1194
|
+
? "Schedule tours"
|
|
1195
|
+
: "Schedule tour"}
|
|
1107
1196
|
?disabled=${!this.canSubmit()}
|
|
1108
1197
|
></action-confirm-button>
|
|
1109
1198
|
</div>`;
|
|
@@ -1165,14 +1254,13 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
1165
1254
|
.load=${this.loadExtendCommunities}
|
|
1166
1255
|
.initial=${this.extendInitial}
|
|
1167
1256
|
.filters=${this.preferences}
|
|
1168
|
-
.maxSelectable=${this.stopsRemaining()}
|
|
1169
|
-
.selected=${this.picks}
|
|
1170
1257
|
@filters-change=${this.onFiltersChange}
|
|
1171
|
-
@selection-change=${
|
|
1258
|
+
@selection-change=${(
|
|
1259
|
+
e: CustomEvent<{ communities: CommunitySummary[] }>
|
|
1260
|
+
) => this.onCommunitiesSelected(e.detail.communities, "extend")}
|
|
1172
1261
|
></community-picker>`
|
|
1173
1262
|
: ""}
|
|
1174
|
-
</booking-confirmation>`)}
|
|
1175
|
-
${this.extendInitial ? this.renderTray() : ""}`;
|
|
1263
|
+
</booking-confirmation>`)}`;
|
|
1176
1264
|
}
|
|
1177
1265
|
|
|
1178
1266
|
private renderBody(): TemplateResult {
|
|
@@ -1240,7 +1328,6 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
1240
1328
|
static styles = [
|
|
1241
1329
|
tourSchedulerStyles,
|
|
1242
1330
|
InputStyles,
|
|
1243
|
-
selectionTrayStyles,
|
|
1244
1331
|
css`
|
|
1245
1332
|
/* New layout only: the back button beside the title. */
|
|
1246
1333
|
.title {
|
|
@@ -1270,6 +1357,45 @@ export class TourSchedulerV2 extends LitElement {
|
|
|
1270
1357
|
margin: 0 0 16px;
|
|
1271
1358
|
}
|
|
1272
1359
|
|
|
1360
|
+
/* Adding stops: the design's one centred column of stops. */
|
|
1361
|
+
#book-tour-journey-items.itinerary {
|
|
1362
|
+
display: block;
|
|
1363
|
+
margin: 0 auto;
|
|
1364
|
+
max-width: 30rem;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
.itinerary-heading {
|
|
1368
|
+
margin-bottom: 16px;
|
|
1369
|
+
text-align: center;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
/* The pickers' heading size. */
|
|
1373
|
+
.itinerary-heading h2 {
|
|
1374
|
+
align-items: center;
|
|
1375
|
+
display: flex;
|
|
1376
|
+
font-size: 20px;
|
|
1377
|
+
font-weight: 400;
|
|
1378
|
+
gap: 8px;
|
|
1379
|
+
justify-content: center;
|
|
1380
|
+
margin: 0;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
.add-stop-picker {
|
|
1384
|
+
margin-top: 24px;
|
|
1385
|
+
position: relative;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
/* The extend picker's top rule and padding put its heading 24px down. */
|
|
1389
|
+
.close-add-stop {
|
|
1390
|
+
background: none;
|
|
1391
|
+
border: none;
|
|
1392
|
+
cursor: pointer;
|
|
1393
|
+
padding: 4px;
|
|
1394
|
+
position: absolute;
|
|
1395
|
+
right: 0;
|
|
1396
|
+
top: 24px;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1273
1399
|
.link-button {
|
|
1274
1400
|
background: none;
|
|
1275
1401
|
border: none;
|
|
@@ -162,9 +162,7 @@ export class MESelect extends LitElement {
|
|
|
162
162
|
overflow-y: scroll;
|
|
163
163
|
position: absolute;
|
|
164
164
|
min-height: 40px;
|
|
165
|
-
|
|
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
|
+
});
|