@meetelise/chat 1.70.1 → 1.72.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.
@@ -44,6 +44,7 @@ const header = (request: FakeRequest, name: string): string | undefined =>
44
44
  const DATE = "2026-10-30";
45
45
  const ANCHOR = 12;
46
46
  const LINDEN = 40;
47
+ const CEDAR = 7;
47
48
 
48
49
  const community = (
49
50
  building_id: number,
@@ -81,6 +82,7 @@ const fakeBackend = ({
81
82
  dropFirstBooking = false,
82
83
  failPlan = false,
83
84
  bedrooms,
85
+ extensionError,
84
86
  }: {
85
87
  /** The tour types the building offers. */
86
88
  tourTypes?: TourTypeId[];
@@ -90,6 +92,8 @@ const fakeBackend = ({
90
92
  dropFirstBooking?: boolean;
91
93
  /** Fails every plan request, as an outage would. */
92
94
  failPlan?: boolean;
95
+ /** Refuses bookings that add stops, unless they replace existing tours. */
96
+ extensionError?: { status: number; code: string; message: string };
93
97
  } = {}): {
94
98
  bookings: BookingRequest[];
95
99
  keys: string[];
@@ -111,7 +115,10 @@ const fakeBackend = ({
111
115
  is_general_building: false,
112
116
  },
113
117
  communities: extend
114
- ? [community(LINDEN, "The Linden", bedrooms)]
118
+ ? [
119
+ community(LINDEN, "The Linden", bedrooms),
120
+ community(CEDAR, "Cedar & Main", bedrooms),
121
+ ]
115
122
  : [
116
123
  community(ANCHOR, "Parkside Commons", bedrooms),
117
124
  community(LINDEN, "The Linden", bedrooms),
@@ -215,6 +222,13 @@ const fakeBackend = ({
215
222
  return request.error();
216
223
  }
217
224
  bookings.push(body);
225
+ const addsStops = (body as BookingRequest).stops.some(
226
+ (stop) => "existing_calendar_event_id" in stop
227
+ );
228
+ if (extensionError && addsStops && !body.cancel_existing_tours) {
229
+ const { status, code, message } = extensionError;
230
+ return json(status, { error: { code, message } });
231
+ }
218
232
  return json(200, book(body));
219
233
  }
220
234
  return json(404, null);
@@ -299,6 +313,10 @@ const fillContactAndSubmit = async (
299
313
  composed: true,
300
314
  })
301
315
  );
316
+ await submitWhenReady(scheduler);
317
+ };
318
+
319
+ const submitWhenReady = async (scheduler: TourSchedulerV2) => {
302
320
  const submit = await waitFor(() => {
303
321
  const button = inScheduler<HTMLElement & { disabled: boolean }>(
304
322
  scheduler,
@@ -309,6 +327,31 @@ const fillContactAndSubmit = async (
309
327
  clickButton(submit);
310
328
  };
311
329
 
330
+ /** Books the anchor, then taps The Linden, which joins the itinerary. */
331
+ const bookAndAddLinden = async (scheduler: TourSchedulerV2) => {
332
+ await fillContactAndSubmit(scheduler);
333
+ const picker = await waitFor(() =>
334
+ inScheduler<CommunityPicker>(
335
+ scheduler,
336
+ "booking-confirmation community-picker"
337
+ )
338
+ );
339
+ await picker.updateComplete;
340
+ const linden = await waitFor(() =>
341
+ Array.from(
342
+ picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
343
+ "button.floorplan-image-card"
344
+ ) ?? []
345
+ ).find((card) => card.textContent?.includes("The Linden"))
346
+ );
347
+ linden.click();
348
+ await waitFor(() =>
349
+ inScheduler<ItineraryEditor>(scheduler, "itinerary-editor")?.stops.some(
350
+ (stop) => stop.building_id === LINDEN
351
+ )
352
+ );
353
+ };
354
+
312
355
  afterEach(() => {
313
356
  restore();
314
357
  document.querySelectorAll("tour-scheduler-v2").forEach((el) => el.remove());
@@ -367,29 +410,17 @@ it("books a tour with the prospect's details, attribution and conversation, and
367
410
  }
368
411
  });
369
412
 
370
- it("extends a booking by sending the booked tour as an existing stop and only the new community as a new one", async () => {
413
+ it("extends a booking without asking for contact details again, sending the booked tour as an existing stop and only the new community as a new one", async () => {
371
414
  const { bookings, communityQueries } = fakeBackend();
372
415
  const scheduler = mount();
373
416
 
374
- await fillContactAndSubmit(scheduler);
375
- const picker = await waitFor(() =>
376
- inScheduler<CommunityPicker>(
377
- scheduler,
378
- "booking-confirmation community-picker"
379
- )
380
- );
381
- await picker.updateComplete;
382
- picker.shadowRoot
383
- ?.querySelector<HTMLButtonElement>("button.floorplan-image-card")
384
- ?.click();
385
- clickButton(await waitFor(() => inScheduler(scheduler, "#continue-bttn")));
386
-
387
- await waitFor(
388
- () => bookings.length === 1 && inScheduler(scheduler, "itinerary-editor")
389
- );
390
- await fillContactAndSubmit(scheduler);
417
+ await bookAndAddLinden(scheduler);
418
+ expect(inScheduler(scheduler, "contact-form")).to.equal(null);
419
+ await submitWhenReady(scheduler);
391
420
  await waitFor(() => bookings.length === 2);
392
421
 
422
+ // The server books an extension into the first booking's conversation.
423
+ expect(bookings[1]).not.to.have.property("contact");
393
424
  expect(bookings[1].stops).to.deep.equal([
394
425
  { existing_calendar_event_id: 990 },
395
426
  { building_id: LINDEN, start: at(630) },
@@ -529,7 +560,7 @@ it("offers the toured communities' bedroom counts where this building has no lay
529
560
  await fillContactAndSubmit(scheduler, { layout: 20 });
530
561
  await waitFor(() => bookings.length === 1);
531
562
 
532
- expect(bookings[0].contact.bedrooms).to.deep.equal([2]);
563
+ expect(bookings[0].contact?.bedrooms).to.deep.equal([2]);
533
564
  });
534
565
 
535
566
  it("books without a bedroom preference where one is required but there are no layouts to offer", async () => {
@@ -541,7 +572,7 @@ it("books without a bedroom preference where one is required but there are no la
541
572
  await fillContactAndSubmit(scheduler, { layout: null });
542
573
  await waitFor(() => bookings.length === 1);
543
574
 
544
- expect(bookings[0].contact.bedrooms).to.deep.equal([]);
575
+ expect(bookings[0].contact?.bedrooms).to.deep.equal([]);
545
576
  });
546
577
 
547
578
  it("still asks for a bedroom preference where one is required and the building has layouts", async () => {
@@ -585,3 +616,257 @@ it("still asks for a bedroom preference where one is required and the building h
585
616
  );
586
617
  expect(button?.disabled).to.equal(true);
587
618
  });
619
+
620
+ it("asks to reschedule an added stop that clashes with a tour, and resends it without contact details", async () => {
621
+ const { bookings } = fakeBackend({
622
+ extensionError: {
623
+ status: 409,
624
+ code: "EXISTING_TOUR",
625
+ message: "You already have a tour at The Linden.",
626
+ },
627
+ });
628
+ const scheduler = mount();
629
+
630
+ await bookAndAddLinden(scheduler);
631
+ await submitWhenReady(scheduler);
632
+ await waitFor(() =>
633
+ inScheduler(scheduler, ".explanation")?.textContent?.includes(
634
+ "You already have a tour at The Linden."
635
+ )
636
+ );
637
+ clickButton(inScheduler(scheduler, "#reschedule-button"));
638
+ await waitFor(() => bookings.length === 3);
639
+
640
+ expect(bookings[2].cancel_existing_tours).to.equal(true);
641
+ expect(bookings[2]).not.to.have.property("contact");
642
+ await waitFor(() => inScheduler(scheduler, "booking-confirmation"));
643
+ });
644
+
645
+ for (const { code, status, message, shownIn } of [
646
+ {
647
+ code: "SLOT_TAKEN",
648
+ status: 409,
649
+ message: "The 10:30 AM tour at The Linden was just booked.",
650
+ shownIn: ".notice",
651
+ },
652
+ {
653
+ code: "INVALID_STOPS",
654
+ status: 404,
655
+ message: "Booked tour not found",
656
+ shownIn: "#tour-scheduler-footer .error-message",
657
+ },
658
+ ]) {
659
+ it(`explains a ${code} on an added stop and stays on its schedule without the form`, async () => {
660
+ fakeBackend({ extensionError: { status, code, message } });
661
+ const scheduler = mount();
662
+
663
+ await bookAndAddLinden(scheduler);
664
+ await submitWhenReady(scheduler);
665
+
666
+ await waitFor(() =>
667
+ inScheduler(scheduler, shownIn)?.textContent?.includes(message)
668
+ );
669
+ expect(inScheduler(scheduler, "itinerary-editor")).not.to.equal(null);
670
+ expect(inScheduler(scheduler, "contact-form")).to.equal(null);
671
+ });
672
+ }
673
+
674
+ it("carries bedrooms, move-in and budget between the picker's filters, the form and the extension's filters", async () => {
675
+ const { bookings, communityQueries } = fakeBackend({ bedrooms: [1, 2] });
676
+ const scheduler = mount();
677
+
678
+ // The picker's filters: 2 bedrooms, a move-in date and a budget.
679
+ const editor = await waitFor(() =>
680
+ inScheduler<HTMLElement>(scheduler, "itinerary-editor")
681
+ );
682
+ editor.dispatchEvent(
683
+ new CustomEvent("edit-communities", { bubbles: true, composed: true })
684
+ );
685
+ const picker = await waitFor(() =>
686
+ inScheduler<CommunityPicker>(scheduler, "community-picker")
687
+ );
688
+ await picker.updateComplete;
689
+ const inPicker = <T extends Element>(selector: string) =>
690
+ picker.shadowRoot?.querySelector<T>(selector) ?? null;
691
+ const setInput = async (selector: string, value: string) => {
692
+ const input = inPicker<HTMLInputElement>(selector);
693
+ if (!input) throw new Error(`No ${selector}`);
694
+ input.value = value;
695
+ input.dispatchEvent(new Event("change"));
696
+ await picker.updateComplete;
697
+ };
698
+ // Each chip opens its own panel.
699
+ const openFilter = async (id: string) => {
700
+ inPicker<HTMLButtonElement>(`[aria-controls="filter-${id}"]`)?.click();
701
+ await picker.updateComplete;
702
+ };
703
+ await openFilter("bedrooms");
704
+ Array.from(
705
+ picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
706
+ "#filter-bedrooms button"
707
+ ) ?? []
708
+ )
709
+ .find((badge) => badge.textContent?.trim() === "2 bd")
710
+ ?.click();
711
+ await picker.updateComplete;
712
+ await openFilter("moveIn");
713
+ await setInput("#move-in", "2026-12-01");
714
+ await openFilter("budget");
715
+ await setInput("#max-budget", "2500");
716
+ const linden = await waitFor(() =>
717
+ Array.from(
718
+ picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
719
+ "button.floorplan-image-card"
720
+ ) ?? []
721
+ ).find((card) => card.textContent?.includes("The Linden"))
722
+ );
723
+ linden.click();
724
+
725
+ // The form starts from them.
726
+ const form = await waitFor(() =>
727
+ inScheduler<ContactForm>(scheduler, "contact-form")
728
+ );
729
+ expect({
730
+ layout: form.values.layout,
731
+ moveIn: form.values.moveIn,
732
+ }).to.deep.equal({ layout: 20, moveIn: "2026-12-01" });
733
+
734
+ // 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" });
736
+ await waitFor(() => bookings.length === 1);
737
+ expect(bookings[0].contact?.bedrooms).to.deep.equal([1]);
738
+ expect(bookings[0].contact?.move_in).to.equal("2027-01-15");
739
+
740
+ const extendQuery = await waitFor(() =>
741
+ communityQueries.find((q) => q.has("available_after") && q.has("bedrooms"))
742
+ );
743
+ expect({
744
+ bedrooms: extendQuery.getAll("bedrooms"),
745
+ move_in: extendQuery.get("move_in"),
746
+ max_budget: extendQuery.get("max_budget"),
747
+ }).to.deep.equal({
748
+ bedrooms: ["1"],
749
+ move_in: "2027-01-15",
750
+ max_budget: "2500",
751
+ });
752
+ const selectQuery = communityQueries.find(
753
+ (q) => !q.has("available_after") && q.has("max_budget")
754
+ );
755
+ expect(selectQuery?.getAll("bedrooms")).to.deep.equal(["2"]);
756
+ });
757
+
758
+ it("closes only a filter's panel on Escape, leaving the scheduler open", async () => {
759
+ fakeBackend();
760
+ let closed = false;
761
+ const scheduler = mount();
762
+ scheduler.onCloseClicked = () => (closed = true);
763
+ const editor = await waitFor(() =>
764
+ inScheduler<HTMLElement>(scheduler, "itinerary-editor")
765
+ );
766
+ editor.dispatchEvent(
767
+ new CustomEvent("edit-communities", { bubbles: true, composed: true })
768
+ );
769
+ const picker = await waitFor(() =>
770
+ inScheduler<CommunityPicker>(scheduler, "community-picker")
771
+ );
772
+ await picker.updateComplete;
773
+ const chip = picker.shadowRoot?.querySelector<HTMLButtonElement>(
774
+ '[aria-controls="filter-budget"]'
775
+ );
776
+ chip?.click();
777
+ await picker.updateComplete;
778
+ const input = await waitFor(() =>
779
+ picker.shadowRoot?.querySelector<HTMLInputElement>("#max-budget")
780
+ );
781
+
782
+ input.dispatchEvent(
783
+ new KeyboardEvent("keydown", {
784
+ key: "Escape",
785
+ bubbles: true,
786
+ composed: true,
787
+ })
788
+ );
789
+ await picker.updateComplete;
790
+
791
+ expect(picker.shadowRoot?.querySelector("#max-budget")).to.equal(null);
792
+ expect(chip?.getAttribute("aria-expanded")).to.equal("false");
793
+ expect(closed).to.equal(false);
794
+ });
795
+
796
+ it("adds stops one at a time after a booking, offering each next stop after the one before it", async () => {
797
+ const { bookings, communityQueries } = fakeBackend();
798
+ const scheduler = mount();
799
+ await bookAndAddLinden(scheduler);
800
+
801
+ // "Add another stop" opens the nearby communities under the itinerary.
802
+ const editor = await waitFor(() =>
803
+ inScheduler<ItineraryEditor>(scheduler, "itinerary-editor")
804
+ );
805
+ editor.shadowRoot?.querySelector<HTMLButtonElement>(".add-stop")?.click();
806
+ const picker = await waitFor(() =>
807
+ inScheduler<CommunityPicker>(scheduler, ".add-stop-picker community-picker")
808
+ );
809
+ await picker.updateComplete;
810
+ const cedar = await waitFor(() =>
811
+ Array.from(
812
+ picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
813
+ "button.floorplan-image-card"
814
+ ) ?? []
815
+ ).find((card) => card.textContent?.includes("Cedar & Main"))
816
+ );
817
+ cedar.click();
818
+ await waitFor(() => editor.stops.some((stop) => stop.building_id === CEDAR));
819
+ expect(inScheduler(scheduler, ".add-stop-picker")).to.equal(null);
820
+
821
+ // Its communities were asked for after The Linden, without either community.
822
+ const added = communityQueries.filter((q) => q.has("available_after")).pop();
823
+ expect({
824
+ available_after: added?.get("available_after"),
825
+ near_building_id: added?.get("near_building_id"),
826
+ exclude_building_ids: added?.getAll("exclude_building_ids"),
827
+ }).to.deep.equal({
828
+ available_after: at(660),
829
+ near_building_id: String(LINDEN),
830
+ exclude_building_ids: [String(ANCHOR), String(LINDEN)],
831
+ });
832
+
833
+ await submitWhenReady(scheduler);
834
+ await waitFor(() => bookings.length === 2);
835
+ expect(bookings[1].stops).to.deep.equal([
836
+ { existing_calendar_event_id: 990 },
837
+ { building_id: LINDEN, start: at(630) },
838
+ { building_id: CEDAR, start: at(660) },
839
+ ]);
840
+ });
841
+
842
+ it("closes the nearby list when the itinerary changes, and offers it again once the new plan is in", async () => {
843
+ fakeBackend();
844
+ const scheduler = mount();
845
+ await bookAndAddLinden(scheduler);
846
+ const editor = await waitFor(() =>
847
+ inScheduler<ItineraryEditor>(scheduler, "itinerary-editor")
848
+ );
849
+ await waitFor(() => editor.canAddStop);
850
+ editor.shadowRoot?.querySelector<HTMLButtonElement>(".add-stop")?.click();
851
+ await waitFor(() => inScheduler(scheduler, ".add-stop-picker"));
852
+
853
+ // A new time moves The Linden, so the list fetched after its old end goes.
854
+ editor.dispatchEvent(
855
+ new CustomEvent("stop-time-change", {
856
+ detail: { buildingId: LINDEN, start: at(645) },
857
+ })
858
+ );
859
+ await scheduler.updateComplete;
860
+ expect(!!inScheduler(scheduler, ".add-stop-picker")).to.equal(false);
861
+ expect(editor.canAddStop).to.equal(false);
862
+
863
+ // Once /plan answers, the list can open again, fetched after the new plan.
864
+ await waitFor(() => editor.canAddStop);
865
+ editor.shadowRoot?.querySelector<HTMLButtonElement>(".add-stop")?.click();
866
+ const picker = await waitFor(() =>
867
+ inScheduler<CommunityPicker>(scheduler, ".add-stop-picker community-picker")
868
+ );
869
+ await waitFor(() =>
870
+ picker.shadowRoot?.querySelector("button.floorplan-image-card")
871
+ );
872
+ });