@meetelise/chat 1.76.0 → 1.77.1

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.
@@ -371,6 +371,27 @@ const bookAndAddLinden = async (scheduler: TourSchedulerV2) => {
371
371
  );
372
372
  };
373
373
 
374
+ /** "Add another stop", then Cedar & Main from the nearby communities. */
375
+ const addCedar = async (
376
+ scheduler: TourSchedulerV2,
377
+ editor: ItineraryEditor
378
+ ) => {
379
+ editor.shadowRoot?.querySelector<HTMLButtonElement>(".add-stop")?.click();
380
+ const picker = await waitFor(() =>
381
+ inScheduler<CommunityPicker>(scheduler, ".add-stop-picker community-picker")
382
+ );
383
+ await picker.updateComplete;
384
+ const cedar = await waitFor(() =>
385
+ Array.from(
386
+ picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
387
+ "button.floorplan-image-card"
388
+ ) ?? []
389
+ ).find((card) => card.textContent?.includes("Cedar & Main"))
390
+ );
391
+ cedar.click();
392
+ await waitFor(() => editor.stops.some((stop) => stop.building_id === CEDAR));
393
+ };
394
+
374
395
  afterEach(() => {
375
396
  restore();
376
397
  document.querySelectorAll("tour-scheduler-v2").forEach((el) => el.remove());
@@ -397,6 +418,7 @@ it("books a tour with the prospect's details, attribution and conversation, and
397
418
  phone_e164: "+13125550142",
398
419
  bedrooms: [1],
399
420
  move_in: null,
421
+ max_budget: null,
400
422
  notes: "",
401
423
  });
402
424
  expect(booking.conversation_tracking_id).to.equal("webchat_lead_test");
@@ -477,6 +499,12 @@ it("moves an added stop to its own day, keeping the booked tour's day, adds the
477
499
  "Change the date or time at The Linden"
478
500
  );
479
501
  edit.click();
502
+ const dateField = await waitFor(() =>
503
+ editor.shadowRoot?.querySelector<HTMLButtonElement>(
504
+ `#stop-date-trigger-${LINDEN}`
505
+ )
506
+ );
507
+ dateField.click();
480
508
  const picker = await waitFor(() =>
481
509
  editor.shadowRoot?.querySelector<HTMLElement & { selectedDate?: Date }>(
482
510
  "date-picker"
@@ -529,6 +557,88 @@ it("moves an added stop to its own day, keeping the booked tour's day, adds the
529
557
  ]);
530
558
  });
531
559
 
560
+ it("opens a stop's date and time panel from its pencil, closes it on Escape or a picked time, and returns focus to the pencil", async () => {
561
+ const { plans } = fakeBackend();
562
+ const scheduler = mount();
563
+ await bookAndAddLinden(scheduler);
564
+ const editor = await waitFor(() =>
565
+ inScheduler<ItineraryEditor>(scheduler, "itinerary-editor")
566
+ );
567
+ const inEditor = <T extends Element>(selector: string) =>
568
+ editor.shadowRoot?.querySelector<T>(selector) ?? null;
569
+ const pencil = await waitFor(() =>
570
+ inEditor<HTMLButtonElement>(`.edit-time[data-building-id="${LINDEN}"]`)
571
+ );
572
+ const popover = pencil.closest<HTMLElement & { open: boolean }>(
573
+ "scheduler-popover"
574
+ );
575
+ // The booked stop has no pencil.
576
+ expect(editor.shadowRoot?.querySelectorAll(".edit-time").length).to.equal(1);
577
+
578
+ pencil.click();
579
+ await editor.updateComplete;
580
+ expect(popover?.open).to.equal(true);
581
+ expect(pencil.getAttribute("aria-expanded")).to.equal("true");
582
+ const panel = inEditor(`#${pencil.getAttribute("aria-controls")}`);
583
+ expect(panel?.getAttribute("aria-label")).to.equal(
584
+ "Date and time at The Linden"
585
+ );
586
+ // Another time than the stop's, once the picker has marked the stop's.
587
+ const laterTime = () =>
588
+ waitFor(() => {
589
+ const options = panel
590
+ ?.querySelector("time-picker")
591
+ ?.shadowRoot?.querySelectorAll<HTMLButtonElement>(".option");
592
+ return (
593
+ options &&
594
+ Array.from(options).some((o) => o.classList.contains("selected")) &&
595
+ Array.from(options).find((o) => !o.classList.contains("selected"))
596
+ );
597
+ });
598
+ const later = await laterTime();
599
+
600
+ later.dispatchEvent(
601
+ new KeyboardEvent("keydown", {
602
+ key: "Escape",
603
+ bubbles: true,
604
+ composed: true,
605
+ })
606
+ );
607
+ await editor.updateComplete;
608
+ expect(popover?.open).to.equal(false);
609
+ expect(editor.shadowRoot?.activeElement).to.equal(pencil);
610
+
611
+ pencil.click();
612
+ await editor.updateComplete;
613
+ const planned = plans.length;
614
+ (await laterTime()).click();
615
+ await editor.updateComplete;
616
+ expect(popover?.open).to.equal(false);
617
+ expect(editor.shadowRoot?.activeElement).to.equal(pencil);
618
+ await waitFor(() => plans.length > planned);
619
+ // The first new stop's time leads the plan.
620
+ expect(plans[plans.length - 1].start_time).to.equal("10:45");
621
+
622
+ // With a panel open, another stop's pencil opens that stop's panel instead.
623
+ await waitFor(() => editor.canAddStop);
624
+ await addCedar(scheduler, editor);
625
+ const cedarPencil = await waitFor(
626
+ () =>
627
+ !editor.loading &&
628
+ inEditor<HTMLButtonElement>(`.edit-time[data-building-id="${CEDAR}"]`)
629
+ );
630
+ pencil.click();
631
+ await editor.updateComplete;
632
+ expect(popover?.open).to.equal(true);
633
+ cedarPencil.click();
634
+ await editor.updateComplete;
635
+ expect(popover?.open).to.equal(false);
636
+ expect(
637
+ cedarPencil.closest<HTMLElement & { open: boolean }>("scheduler-popover")
638
+ ?.open
639
+ ).to.equal(true);
640
+ });
641
+
532
642
  it("picks one community at a time: a pick replaces the community and opens its schedule", async () => {
533
643
  fakeBackend();
534
644
  const scheduler = mount();
@@ -873,6 +983,7 @@ it("carries bedrooms, move-in and budget between the picker's filters, the form
873
983
  await waitFor(() => bookings.length === 1);
874
984
  expect(bookings[0].contact?.bedrooms).to.deep.equal([1]);
875
985
  expect(bookings[0].contact?.move_in).to.equal("2027-01-15");
986
+ expect(bookings[0].contact?.max_budget).to.equal(2500);
876
987
 
877
988
  const extendQuery = await waitFor(() =>
878
989
  communityQueries.find((q) => q.has("available_after") && q.has("bedrooms"))
@@ -986,20 +1097,7 @@ it("adds stops one at a time after a booking, offering each next stop after the
986
1097
  const editor = await waitFor(() =>
987
1098
  inScheduler<ItineraryEditor>(scheduler, "itinerary-editor")
988
1099
  );
989
- editor.shadowRoot?.querySelector<HTMLButtonElement>(".add-stop")?.click();
990
- const picker = await waitFor(() =>
991
- inScheduler<CommunityPicker>(scheduler, ".add-stop-picker community-picker")
992
- );
993
- await picker.updateComplete;
994
- const cedar = await waitFor(() =>
995
- Array.from(
996
- picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
997
- "button.floorplan-image-card"
998
- ) ?? []
999
- ).find((card) => card.textContent?.includes("Cedar & Main"))
1000
- );
1001
- cedar.click();
1002
- await waitFor(() => editor.stops.some((stop) => stop.building_id === CEDAR));
1100
+ await addCedar(scheduler, editor);
1003
1101
  expect(inScheduler(scheduler, ".add-stop-picker")).to.equal(null);
1004
1102
 
1005
1103
  // Its communities were asked for after The Linden, without either community.
@@ -1088,3 +1186,32 @@ it("closes the date calendar when the prospect picks the day already chosen", as
1088
1186
  await editor.updateComplete;
1089
1187
  expect(popover.open).to.equal(false);
1090
1188
  });
1189
+
1190
+ it("shows distances only on communities near a booked stop, not on the first page", async () => {
1191
+ const distances = async (variant: "select" | "extend") => {
1192
+ const picker = document.createElement(
1193
+ "community-picker"
1194
+ ) as CommunityPicker;
1195
+ Object.assign(picker, {
1196
+ variant,
1197
+ initial: {
1198
+ anchor: {
1199
+ building_id: ANCHOR,
1200
+ name: "Parkside",
1201
+ is_general_building: true,
1202
+ },
1203
+ communities: [community(LINDEN, "The Linden")],
1204
+ },
1205
+ });
1206
+ document.body.appendChild(picker);
1207
+ await picker.updateComplete;
1208
+ const shown = Array.from(
1209
+ picker.shadowRoot?.querySelectorAll(".distance") ?? []
1210
+ ).map((d) => d.textContent?.trim());
1211
+ picker.remove();
1212
+ return shown;
1213
+ };
1214
+
1215
+ expect(await distances("select")).to.deep.equal([]);
1216
+ expect(await distances("extend")).to.deep.equal(["1.8 mi"]);
1217
+ });
package/src/utils.ts CHANGED
@@ -95,8 +95,12 @@ export const isValidPhoneNumber = (phoneNumber: string): boolean => {
95
95
  return phoneNumberRegex.test(phoneNumber);
96
96
  };
97
97
 
98
+ /**
99
+ * Something@domain.tld, where the top-level domain is two or more letters
100
+ * (any script) or an IDN's punycode form, so a typo such as "x@y.c" is caught.
101
+ */
98
102
  export const isValidEmail = (email: string): boolean => {
99
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
103
+ const emailRegex = /^[^\s@]+@[^\s@]+\.(?:\p{L}{2,}|xn--[a-z\d-]+)$/iu;
100
104
  return emailRegex.test(email);
101
105
  };
102
106