@meetelise/chat 1.73.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.
@@ -35,6 +35,7 @@ import mapValues from "lodash/mapValues";
35
35
  import classnames from "classnames";
36
36
  import parseISO from "date-fns/parseISO";
37
37
  import compareAsc from "date-fns/compareAsc";
38
+ import isValid from "date-fns/isValid";
38
39
  import { InputStyles } from "../actions/InputStyles";
39
40
  import { classMap } from "lit/directives/class-map.js";
40
41
  import {
@@ -230,6 +231,12 @@ export class TourScheduler extends LitElement {
230
231
  private promptForReschedule = false;
231
232
  @state()
232
233
  private canceledReschedule = false;
234
+ /** The existing tour's community, from the "already has a tour" 409. */
235
+ @state()
236
+ private existingTourBuildingName?: string;
237
+ /** The existing tour's readable time, in its own UTC offset, from the same 409. */
238
+ @state()
239
+ private existingTourStartTime?: string;
233
240
  @state()
234
241
  isBrokerReferral = false;
235
242
  @state()
@@ -1026,6 +1033,13 @@ export class TourScheduler extends LitElement {
1026
1033
  !this.promptForReschedule &&
1027
1034
  message === "User already has a tour scheduled for this building"
1028
1035
  ) {
1036
+ const headers = typedError.response.headers;
1037
+ this.existingTourBuildingName = decodedHeader(
1038
+ headers["existing-tour-building-name"]
1039
+ );
1040
+ this.existingTourStartTime = readableTimeAtOwnOffset(
1041
+ headers["existing-tour-start-time"]
1042
+ );
1029
1043
  this.promptForReschedule = true;
1030
1044
  this.isSubmitting = false;
1031
1045
  this.tourIsBooked = false;
@@ -1752,11 +1766,9 @@ export class TourScheduler extends LitElement {
1752
1766
  confirmationMessage(): TemplateResult {
1753
1767
  if (!this.selectedDate || !this.selectedTime || this.tourType === null)
1754
1768
  return html``;
1755
- // format example: "November 9th, 2022 at 11:00pm"
1756
- const readableDateAndTime = formatInTimeZone(
1757
- parseISO(`${this.selectedTime.datetime}${this.selectedTime.offset}`),
1758
- this.calendarTimeZone,
1759
- "MMM d 'at' h:mmaaa"
1769
+ const readableDateAndTime = readableTourTime(
1770
+ `${this.selectedTime.datetime}${this.selectedTime.offset}`,
1771
+ this.calendarTimeZone
1760
1772
  );
1761
1773
 
1762
1774
  if (this.canceledReschedule) {
@@ -1818,6 +1830,16 @@ export class TourScheduler extends LitElement {
1818
1830
  `;
1819
1831
  }
1820
1832
 
1833
+ /** Names the existing tour's community and time when the 409 sent both. */
1834
+ rescheduleExplanation(): TemplateResult {
1835
+ if (this.existingTourBuildingName && this.existingTourStartTime) {
1836
+ return html`You already have a tour scheduled at one of our communities,
1837
+ ${this.existingTourBuildingName}, on ${this.existingTourStartTime}. Would
1838
+ you like to reschedule?`;
1839
+ }
1840
+ return html`You already have a tour scheduled. Would you like to reschedule?`;
1841
+ }
1842
+
1821
1843
  /** The broker isn't the one touring: the client gets the confirmation email. */
1822
1844
  private referralConfirmation(readableDateAndTime: string): TemplateResult {
1823
1845
  if (this.tourType === null) return html``;
@@ -2006,8 +2028,7 @@ export class TourScheduler extends LitElement {
2006
2028
  <div>
2007
2029
  <h2 class="journey-header">Reschedule Tour</h2>
2008
2030
  <div class="explanation">
2009
- You already have a tour scheduled. Would you like to
2010
- reschedule?
2031
+ ${this.rescheduleExplanation()}
2011
2032
  </div>
2012
2033
  </div>
2013
2034
  </div>
@@ -2149,8 +2170,7 @@ export class TourScheduler extends LitElement {
2149
2170
  <div>
2150
2171
  <h2 class="journey-header">Reschedule Tour</h2>
2151
2172
  <div class="explanation">
2152
- You already have a tour scheduled. Would you like to
2153
- reschedule?
2173
+ ${this.rescheduleExplanation()}
2154
2174
  </div>
2155
2175
  </div>
2156
2176
  </div>
@@ -2268,6 +2288,37 @@ const tourTypeForSubmission = {
2268
2288
  [TourType.Virtual]: "live-virtual-tour",
2269
2289
  };
2270
2290
 
2291
+ // format example: "Nov 9 at 11:00pm"
2292
+ function readableTourTime(isoDateTime: string, timeZone: string): string {
2293
+ return formatInTimeZone(
2294
+ parseISO(isoDateTime),
2295
+ timeZone,
2296
+ "MMM d 'at' h:mmaaa"
2297
+ );
2298
+ }
2299
+
2300
+ /**
2301
+ * An ISO 8601 time such as "2026-11-16T15:15:00-05:00", read in its own UTC
2302
+ * offset rather than the viewer's time zone. Undefined when absent or unreadable.
2303
+ */
2304
+ function readableTimeAtOwnOffset(
2305
+ value: string | undefined
2306
+ ): string | undefined {
2307
+ const offset = value?.match(/(Z|[+-]\d{2}:\d{2})$/)?.[1];
2308
+ if (!value || !offset || !isValid(parseISO(value))) return undefined;
2309
+ return readableTourTime(value, offset);
2310
+ }
2311
+
2312
+ /** A percent-encoded UTF-8 header value, or undefined when absent or malformed. */
2313
+ function decodedHeader(value: string | undefined): string | undefined {
2314
+ if (!value) return undefined;
2315
+ try {
2316
+ return decodeURIComponent(value) || undefined;
2317
+ } catch {
2318
+ return undefined;
2319
+ }
2320
+ }
2321
+
2271
2322
  // LayoutOption.value is bedrooms * 10; EliseAI classifier expects `studio` / `Nbr`.
2272
2323
  function layoutValueToCanonical(value: number): string {
2273
2324
  const bedrooms = Math.round(value / 10);
@@ -225,7 +225,7 @@ export class CommunityPicker extends LitElement {
225
225
  type="date"
226
226
  .value=${f.moveIn ?? ""}
227
227
  @change=${(e: Event) => {
228
- this.openFilter = null;
228
+ void this.closeCommittedFilter("moveIn");
229
229
  this.setFilters({
230
230
  moveIn: (e.target as HTMLInputElement).value || null,
231
231
  });
@@ -244,7 +244,7 @@ export class CommunityPicker extends LitElement {
244
244
  .value=${f.maxBudget === null ? "" : String(f.maxBudget)}
245
245
  @change=${(e: Event) => {
246
246
  const value = parseInt((e.target as HTMLInputElement).value, 10);
247
- this.openFilter = null;
247
+ void this.closeCommittedFilter("budget");
248
248
  this.setFilters({
249
249
  maxBudget: Number.isFinite(value) && value > 0 ? value : null,
250
250
  });
@@ -253,6 +253,23 @@ export class CommunityPicker extends LitElement {
253
253
  </div>`;
254
254
  }
255
255
 
256
+ /**
257
+ * A move-in date or budget, once set, closes its panel and so removes the
258
+ * input that had focus. Focus goes back to the chip, as on Escape, rather
259
+ * than out of the dialog, unless the prospect already moved it elsewhere.
260
+ */
261
+ private async closeCommittedFilter(id: FilterId): Promise<void> {
262
+ this.openFilter = null;
263
+ await this.updateComplete;
264
+ // A Tab that set it moves focus on after this event; let it land first.
265
+ await new Promise((resolve) => setTimeout(resolve));
266
+ if (!document.activeElement || document.activeElement === document.body) {
267
+ this.shadowRoot
268
+ ?.querySelector<HTMLElement>(`[aria-controls="filter-${id}"]`)
269
+ ?.focus();
270
+ }
271
+ }
272
+
256
273
  private renderFilters(): TemplateResult {
257
274
  const open = this.openFilter;
258
275
  return html`<div class="picker-toolbar" role="group" aria-label="Filters">
@@ -7,6 +7,7 @@ import "../me-select";
7
7
  import type { MESelect } from "../me-select";
8
8
  import { tourSchedulerStyles } from "../Scheduler/tourSchedulerStyles";
9
9
  import { InputStyles } from "../actions/InputStyles";
10
+ import floorPlanSelectorStyles from "../FeeCalculator/components/floor-plan-selector/floor-plan-selector-styles";
10
11
  import type { LayoutOption } from "../../fetchBuildingWebchatView";
11
12
  import { isValidEmail } from "../../utils";
12
13
 
@@ -17,8 +18,8 @@ export interface ContactValues {
17
18
  phone: string;
18
19
  phoneE164: string | null;
19
20
  phoneCountry: string | null;
20
- /** The building's layout option value picked, or null. */
21
- layout: number | null;
21
+ /** The building's layout option values picked, in the options' order. */
22
+ layouts: number[];
22
23
  moveIn: string;
23
24
  notes: string;
24
25
  /** Picked in "How did you hear about us?", when that is shown. */
@@ -32,7 +33,7 @@ export const EMPTY_CONTACT: ContactValues = {
32
33
  phone: "",
33
34
  phoneE164: null,
34
35
  phoneCountry: null,
35
- layout: null,
36
+ layouts: [],
36
37
  moveIn: "",
37
38
  notes: "",
38
39
  leadSource: null,
@@ -40,7 +41,7 @@ export const EMPTY_CONTACT: ContactValues = {
40
41
 
41
42
  /**
42
43
  * Today's scheduler's rules: a first or last name, a valid email and phone,
43
- * and a bedroom preference only where the building requires one.
44
+ * and at least one bedroom preference only where the building requires one.
44
45
  */
45
46
  export const contactIsValid = (
46
47
  values: ContactValues,
@@ -49,7 +50,7 @@ export const contactIsValid = (
49
50
  (!!values.firstName.trim() || !!values.lastName.trim()) &&
50
51
  isValidEmail(values.email.trim()) &&
51
52
  !!values.phoneE164 &&
52
- (!bedroomsRequired || values.layout !== null);
53
+ (!bedroomsRequired || values.layouts.length > 0);
53
54
 
54
55
  /**
55
56
  * The prospect's details, in today's scheduler's "Your Information" column
@@ -104,6 +105,44 @@ export class ContactForm extends LitElement {
104
105
  });
105
106
  }
106
107
 
108
+ /**
109
+ * The bedroom preferences as the filters' chips: each tap picks or clears
110
+ * one, as the Bedrooms filter does.
111
+ */
112
+ private renderLayouts(): TemplateResult {
113
+ const picked = this.values.layouts;
114
+ return html`<div class="inputContainer">
115
+ <span class="section-label" id="layout-label">
116
+ Bedroom preferences${this.bedroomsRequired ? "" : " (optional)"}
117
+ </span>
118
+ <div
119
+ id="layout"
120
+ class="floor-plan-selector-badges"
121
+ role="group"
122
+ aria-labelledby="layout-label"
123
+ >
124
+ ${this.layoutOptions.map((o) => {
125
+ const selected = picked.includes(o.value);
126
+ return html`<button
127
+ type="button"
128
+ class=${classMap({ "floor-plan-badge": true, selected })}
129
+ aria-pressed=${String(selected)}
130
+ @click=${() =>
131
+ this.setValues({
132
+ layouts: this.layoutOptions
133
+ .map((option) => option.value)
134
+ .filter((value) =>
135
+ value === o.value ? !selected : picked.includes(value)
136
+ ),
137
+ })}
138
+ >
139
+ ${o.label}
140
+ </button>`;
141
+ })}
142
+ </div>
143
+ </div>`;
144
+ }
145
+
107
146
  render(): TemplateResult {
108
147
  const v = this.values;
109
148
  const emailInvalid = !!v.email && !isValidEmail(v.email.trim());
@@ -174,23 +213,7 @@ export class ContactForm extends LitElement {
174
213
  ? html`<p class="error-message">Invalid phone number</p>`
175
214
  : ""}
176
215
  </div>
177
- ${this.layoutOptions.length > 0
178
- ? html`<me-select
179
- id="layout"
180
- placeholder=${this.bedroomsRequired
181
- ? "Bedroom preference"
182
- : "Bedroom preference (optional)"}
183
- value=${v.layout === null ? "" : String(v.layout)}
184
- .options=${this.layoutOptions.map((o) => ({
185
- label: o.label,
186
- value: String(o.value),
187
- }))}
188
- @change=${(e: Event) => {
189
- const value = (e.target as MESelect).value;
190
- this.setValues({ layout: value ? Number(value) : null });
191
- }}
192
- ></me-select>`
193
- : ""}
216
+ ${this.layoutOptions.length > 0 ? this.renderLayouts() : ""}
194
217
  <div class="inputContainer">
195
218
  <label class="section-label" for="move-in">
196
219
  Move-in date (optional)
@@ -243,6 +266,7 @@ export class ContactForm extends LitElement {
243
266
  static styles = [
244
267
  tourSchedulerStyles,
245
268
  InputStyles,
269
+ floorPlanSelectorStyles,
246
270
  css`
247
271
  :host {
248
272
  display: contents;
@@ -254,6 +278,14 @@ export class ContactForm extends LitElement {
254
278
  gap: 4px;
255
279
  }
256
280
 
281
+ /* The filters' chips, wrapping in the column rather than scrolling. */
282
+ #layout {
283
+ flex-wrap: wrap;
284
+ margin: 0;
285
+ max-width: none;
286
+ overflow: visible;
287
+ }
288
+
257
289
  textarea {
258
290
  resize: vertical;
259
291
  width: 100%;
@@ -4,7 +4,9 @@ import { customElement, property } from "lit/decorators.js";
4
4
  /**
5
5
  * A trigger and the small panel it opens, for the v2 scheduler's secondary
6
6
  * choices. The panel floats under the trigger with `me-select`'s list surface
7
- * and closes, as that list does, on a click outside it, or on Escape. With
7
+ * and closes, as that list does, on a click outside it, or on Escape, and
8
+ * when focus moves out of it, so a later Escape closes the scheduler only
9
+ * once no panel is open. With
8
10
  * `inline` (phones) it opens in place instead, after its siblings in the
9
11
  * parent's flex row, as the filter row always did there.
10
12
  *
@@ -24,11 +26,13 @@ export class SchedulerPopover extends LitElement {
24
26
  super.connectedCallback();
25
27
  document.addEventListener("click", this.onDocumentClick);
26
28
  this.addEventListener("keydown", this.onKeydown);
29
+ this.addEventListener("focusout", this.onFocusout);
27
30
  }
28
31
 
29
32
  disconnectedCallback(): void {
30
33
  document.removeEventListener("click", this.onDocumentClick);
31
34
  this.removeEventListener("keydown", this.onKeydown);
35
+ this.removeEventListener("focusout", this.onFocusout);
32
36
  super.disconnectedCallback();
33
37
  }
34
38
 
@@ -43,6 +47,18 @@ export class SchedulerPopover extends LitElement {
43
47
  }
44
48
  };
45
49
 
50
+ /**
51
+ * Tabbing on to another control. Not when focus goes nowhere (a click on
52
+ * the panel's own text), nor inline, where closing would move what is
53
+ * being tapped.
54
+ */
55
+ private onFocusout = (e: FocusEvent): void => {
56
+ const to = e.relatedTarget;
57
+ if (this.open && !this.inline && to instanceof Node && !this.contains(to)) {
58
+ this.requestClose();
59
+ }
60
+ };
61
+
46
62
  private onKeydown = (e: KeyboardEvent): void => {
47
63
  if (!this.open || e.key !== "Escape" || e.isComposing) return;
48
64
  // The scheduler closes on Escape; here it only closes the panel.
@@ -81,6 +81,11 @@ const EMPTY_FILTERS: CommunityFilters = {
81
81
  maxBudget: null,
82
82
  };
83
83
 
84
+ /** The bedroom counts of layouts, once each. */
85
+ const bedroomsOf = (layouts: number[]): number[] => [
86
+ ...new Set(layouts.map(layoutToBedrooms)),
87
+ ];
88
+
84
89
  /** The building config value each tour type is offered under. */
85
90
  const TOUR_TYPE_OPTION_VALUE: Record<TourTypeId, string> = {
86
91
  "escorted-tour": "WITH_AGENT",
@@ -657,8 +662,7 @@ export class TourSchedulerV2 extends LitElement {
657
662
  last_name: values.lastName.trim(),
658
663
  email: values.email.trim(),
659
664
  phone_e164: values.phoneE164 ?? "",
660
- bedrooms:
661
- values.layout === null ? [] : [layoutToBedrooms(values.layout)],
665
+ bedrooms: bedroomsOf(values.layouts),
662
666
  move_in: values.moveIn || null,
663
667
  notes: values.notes.trim(),
664
668
  },
@@ -970,22 +974,20 @@ export class TourSchedulerV2 extends LitElement {
970
974
  : this.layoutOptions;
971
975
  }
972
976
 
973
- /**
974
- * The form's bedroom preference, from the shared bedrooms: the one offered
975
- * option they name, or none when they name no offered option or several.
976
- */
977
- private get preferredLayout(): number | null {
978
- const named = this.bedroomOptions.filter((option) =>
979
- this.preferences.bedrooms.includes(layoutToBedrooms(option.value))
980
- );
981
- return named.length === 1 ? named[0].value : null;
977
+ /** The form's bedroom preferences: every offered option the shared bedrooms name. */
978
+ private get preferredLayouts(): number[] {
979
+ return this.bedroomOptions
980
+ .map((option) => option.value)
981
+ .filter((value) =>
982
+ this.preferences.bedrooms.includes(layoutToBedrooms(value))
983
+ );
982
984
  }
983
985
 
984
986
  /** The form's values, with bedrooms and move-in from the shared preferences. */
985
987
  private get formValues(): ContactValues {
986
988
  return {
987
989
  ...this.contact,
988
- layout: this.preferredLayout,
990
+ layouts: this.preferredLayouts,
989
991
  moveIn: this.preferences.moveIn ?? "",
990
992
  };
991
993
  }
@@ -995,11 +997,23 @@ export class TourSchedulerV2 extends LitElement {
995
997
  // Every edit sends the whole form: only a field the prospect changed replaces
996
998
  // the shared value, so typing a name keeps bedrooms the form can't show.
997
999
  const shown = this.formValues;
998
- if (values.layout !== shown.layout) {
1000
+ // A chip picks or clears its bedroom count, so bedrooms the form doesn't
1001
+ // offer stay picked, and layouts sharing a count go on and off together.
1002
+ const cleared = bedroomsOf(
1003
+ shown.layouts.filter((layout) => !values.layouts.includes(layout))
1004
+ );
1005
+ const picked = bedroomsOf(
1006
+ values.layouts.filter((layout) => !shown.layouts.includes(layout))
1007
+ );
1008
+ if (cleared.length > 0 || picked.length > 0) {
999
1009
  this.preferences = {
1000
1010
  ...this.preferences,
1001
- bedrooms:
1002
- values.layout === null ? [] : [layoutToBedrooms(values.layout)],
1011
+ bedrooms: [
1012
+ ...new Set([
1013
+ ...this.preferences.bedrooms.filter((b) => !cleared.includes(b)),
1014
+ ...picked,
1015
+ ]),
1016
+ ].sort((a, b) => a - b),
1003
1017
  };
1004
1018
  }
1005
1019
  if (values.moveIn !== shown.moveIn) {
@@ -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
+ });
@@ -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();