create-ailk 0.46.2 → 0.46.4

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.
@@ -10,6 +10,7 @@
10
10
  import {
11
11
  PageSectionsSchema,
12
12
  workspaceShownSetSchema,
13
+ type OfferingsContactProduct,
13
14
  type OfferingsPrice,
14
15
  type OfferingsProduct,
15
16
  type PageSection,
@@ -23,10 +24,13 @@ import {
23
24
  } from "../offerings-pricing";
24
25
  import {
25
26
  offeringPricingPages,
27
+ offeringsCopy,
26
28
  offeringsFragments,
27
29
  pagePlans,
28
30
  PRICING_HUB_SLUG,
29
31
  pricingPageCard,
32
+ pricingPagesHeading,
33
+ pricingPagesSectionEnabled,
30
34
  pricingSections,
31
35
  withContactFallback,
32
36
  withOfferings,
@@ -114,6 +118,26 @@ describe("pagePlans (#10044 D1)", () => {
114
118
  });
115
119
  });
116
120
 
121
+ describe("pricingPagesHeading (#12213 AC-1)", () => {
122
+ it("reads the hub's heading override, or undefined when unset", () => {
123
+ expect(pricingPagesHeading({ pricingPagesHeading: "Pick your plan" })).toBe(
124
+ "Pick your plan",
125
+ );
126
+ expect(pricingPagesHeading({})).toBeUndefined();
127
+ expect(pricingPagesHeading(null)).toBeUndefined();
128
+ expect(pricingPagesHeading({ pricingPagesHeading: 1 })).toBeUndefined();
129
+ });
130
+ });
131
+
132
+ describe("pricingPagesSectionEnabled (#12213 AC-2, AC-3)", () => {
133
+ it("is on by default and off only when the frontmatter sets it false", () => {
134
+ expect(pricingPagesSectionEnabled({})).toBe(true);
135
+ expect(pricingPagesSectionEnabled(null)).toBe(true);
136
+ expect(pricingPagesSectionEnabled({ pricingPagesSection: true })).toBe(true);
137
+ expect(pricingPagesSectionEnabled({ pricingPagesSection: false })).toBe(false);
138
+ });
139
+ });
140
+
117
141
  describe("pricingSections (#10044 AC-4)", () => {
118
142
  const declared: PageSection[] = PageSectionsSchema.parse([
119
143
  {
@@ -169,6 +193,12 @@ const LABELS: OfferingsPricingLabels = {
169
193
  withRequired: (plan, required) => "W⟪" + plan + "⟫" + required,
170
194
  depositNote: (deposit) => "D⟪" + deposit,
171
195
  billedYearly: (amount) => "B⟪" + amount,
196
+ custom: "C⟪",
197
+ perMonth: "PM⟪",
198
+ perYear: "PY⟪",
199
+ unitWithLabel: (period, label) => "U⟪" + period + "⟫" + label,
200
+ savings: (percent) => "S⟪" + percent,
201
+ regularPrice: (regular, current) => "R⟪" + regular + "⟫" + current,
172
202
  };
173
203
  const RECOMMENDED_LABEL = "FOR-YOU⟪";
174
204
  const ADDONS_HEADLINE = "ADDONS⟪";
@@ -303,7 +333,8 @@ describe("plan groups — offeringPlans on a pricing section (#12103 D2, AC-2)",
303
333
  expect(dataOf(placed, "retainers").billingToggle).toBe(false);
304
334
  expect(keysOf(placed, "writing-skills")).toEqual(["writing"]);
305
335
  expect(dataOf(placed, "writing-skills").billingToggle).toBe(true);
306
- expect(dataOf(placed, "extras").addons?.map((t) => t.name)).toEqual(["seo"]);
336
+ expect(keysOf(placed, "extras")).toEqual(["seo"]);
337
+ expect(dataOf(placed, "extras")).not.toHaveProperty("addons");
307
338
  });
308
339
 
309
340
  it("an unlisted plans section shows the page's plans less the listed ones", () => {
@@ -430,7 +461,6 @@ describe("the authored card layout survives (#12103 D6, AC-5)", () => {
430
461
 
431
462
  const PLAN_VARIANTS = [
432
463
  "three-tiers-with-toggle",
433
- "with-comparison-table",
434
464
  "two-tiers-with-extra-tier",
435
465
  "single-price-with-details",
436
466
  "features-and-plans",
@@ -448,7 +478,7 @@ describe("a bound section renders the variant the page sets (#12140 AC-1)", () =
448
478
  expect(placed.map((s) => s.id)).toEqual(["hero", "p"]);
449
479
  expect(dataOf(placed, "p").variant).toBe(variant);
450
480
  expect(dataOf(placed, "p").source).toBe("offerings");
451
- if (variant === "with-comparison-table")
481
+ if (variant === "band-hero")
452
482
  expect(keysOf(placed, "p")).toEqual(ALL_KEYS);
453
483
  if (variant === "single-price-with-details")
454
484
  expect(keysOf(placed, "p")).toEqual(["essentials"]);
@@ -483,14 +513,16 @@ describe("a bound section renders the variant the page sets (#12140 AC-1)", () =
483
513
  expect(keysOf(placed, "p")).toEqual(ALL_KEYS);
484
514
  });
485
515
 
486
- it("a bound add-ons section takes the tiles; a bound plans section beside it takes none", () => {
516
+ it("a bound add-ons section takes the add-on cards; a bound plans section beside it takes none", () => {
487
517
  const { placed } = render([
488
518
  pricingSection("a", { source: "offerings", variant: "addons" }),
489
- pricingSection("c", { source: "offerings", variant: "with-comparison-table" }),
519
+ pricingSection("c", { source: "offerings", variant: "band-hero" }),
490
520
  ]);
491
521
  expect(placed.map((s) => s.id)).toEqual(["a", "c"]);
492
- expect(dataOf(placed, "a").addons?.map((t) => t.name)).toEqual(["seo"]);
522
+ expect(keysOf(placed, "a")).toEqual(["seo"]);
523
+ expect(dataOf(placed, "a")).not.toHaveProperty("addons");
493
524
  expect(dataOf(placed, "a").source).toBe("offerings");
525
+ expect(keysOf(placed, "c")).not.toContain("seo");
494
526
  expect(dataOf(placed, "c")).not.toHaveProperty("addons");
495
527
  });
496
528
  });
@@ -498,8 +530,7 @@ describe("a bound section renders the variant the page sets (#12140 AC-1)", () =
498
530
  describe("a section with no source renders exactly as in 0.74.0 (#12140 AC-2)", () => {
499
531
  const AUTHORED = {
500
532
  headline: "Plans",
501
- variant: "with-comparison-table",
502
- comparisonGroups: [{ groupName: "Core", rows: [{ featureName: "Reports", values: { growth: true } }] }],
533
+ variant: "band-hero",
503
534
  features: [{ title: "Row", description: "One" }],
504
535
  extraTier: { name: "Big", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/contact" } },
505
536
  };
@@ -558,64 +589,11 @@ describe("features-and-plans on one product with two Prices (#12140 AC-3)", () =
558
589
  });
559
590
  });
560
591
 
561
- describe("comparisonGroups survive the swap, matched by plan slug (#12140 AC-4)", () => {
562
- const NAMED = workspaceShownSetSchema.parse({
563
- ...stripeSet(),
564
- offerings: stripeSet().offerings.map((o) => ({
565
- ...o,
566
- name: o.plan.charAt(0).toUpperCase() + o.plan.slice(1),
567
- })),
568
- });
569
- const G = [
570
- { groupName: "Core", rows: [{ featureName: "Reports", values: { essentials: true, growth: "Weekly", absent: true } }] },
571
- ];
572
- const section = (groups: unknown) =>
573
- pricingSection("c", {
574
- source: "offerings",
575
- variant: "with-comparison-table",
576
- offeringPlans: ["essentials", "growth"],
577
- comparisonGroups: groups,
578
- });
579
-
580
- it("keeps the grid and keys the cards by slug, not by name", () => {
581
- const { placed } = render([HERO, section(G)], { set: NAMED });
582
- expect(dataOf(placed, "c").comparisonGroups).toEqual(G);
583
- expect(keysOf(placed, "c")).toEqual(["essentials", "growth"]);
584
- expect(dataOf(placed, "c").plans.map((c) => c.name)).toEqual(["Essentials", "Growth"]);
585
- });
586
-
587
- it("drops a cell's authored link and keeps every other value", () => {
588
- const linked = [
589
- {
590
- groupName: "Core",
591
- rows: [
592
- {
593
- featureName: "Reports",
594
- values: {
595
- essentials: true,
596
- growth: { text: "Weekly", verdict: "yes", link: { label: "See", href: "https://example.com" } },
597
- absent: true,
598
- },
599
- },
600
- ],
601
- },
602
- ];
603
- const { placed } = render([section(linked)], { set: NAMED });
604
- expect(dataOf(placed, "c").comparisonGroups).toEqual([
605
- { groupName: "Core", rows: [{ featureName: "Reports", values: { essentials: true, growth: { text: "Weekly", verdict: "yes" }, absent: true } }] },
606
- ]);
607
- });
608
- });
609
-
610
592
  describe("no vendor, and every price link on a non-written section is a checkout key (#12140 AC-5, NFR-2)", () => {
611
593
  it("holds over a page of every bound variant, a bound add-ons section and an unbound section", () => {
612
- const linkedGrid = [
613
- { groupName: "Core", rows: [{ featureName: "R", values: { growth: { text: "W", link: { label: "See", href: "/elsewhere" } } } }] },
614
- ];
615
594
  const authored = {
616
595
  plans: [{ key: "own", name: "Own", price: { custom: "$1" }, features: [], cta: { label: "Go", href: "/elsewhere" } }],
617
596
  extraTier: { name: "Big", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/elsewhere" } },
618
- comparisonGroups: linkedGrid,
619
597
  };
620
598
  const { placed } = render([
621
599
  HERO,
@@ -635,10 +613,6 @@ describe("no vendor, and every price link on a non-written section is a checkout
635
613
  expect(ours(card.annualCtaHref)).toBe(true);
636
614
  }
637
615
  for (const tile of data.addons ?? []) expect(ours(tile.cta?.href)).toBe(true);
638
- for (const group of data.comparisonGroups ?? [])
639
- for (const row of group.rows)
640
- for (const value of Object.values(row.values))
641
- if (typeof value === "object") expect(value).not.toHaveProperty("link");
642
616
  }
643
617
  });
644
618
  });
@@ -704,31 +678,14 @@ describe("a written section (#12140 AC-6)", () => {
704
678
  expect(keysOf(render([W3, pricingSection("p")]).placed, "w")).toEqual(["custom", "malformed"]);
705
679
  });
706
680
 
707
- it("drops a written add-on tile and a cell link that reach the Offerings checkout", () => {
681
+ it("drops a written add-on tile that reaches the Offerings checkout", () => {
708
682
  const tile = (name: string, href: string) => ({ name, price: "$1", cta: { label: "Add", href } });
709
683
  const W4 = pricingSection("w", {
710
684
  source: "written",
711
685
  addons: [tile("Kept", "/contact"), tile("Sold", "/api/offerings/checkout/rush_once")],
712
- comparisonGroups: [
713
- {
714
- groupName: "G",
715
- rows: [
716
- {
717
- featureName: "Row",
718
- values: {
719
- custom: { text: "Yes", link: { label: "Buy", href: "/api/offerings/checkout/writing_monthly" } },
720
- other: { text: "Ask", link: { label: "Ask", href: "/contact" } },
721
- },
722
- },
723
- ],
724
- },
725
- ],
726
686
  });
727
687
  const data = dataOf(render([W4, pricingSection("p")]).placed, "w");
728
688
  expect(data.addons?.map((a) => a.name)).toEqual(["Kept"]);
729
- const values = data.comparisonGroups?.[0]?.rows[0]?.values ?? {};
730
- expect(values["custom"]).toEqual({ text: "Yes" });
731
- expect(values["other"]).toEqual({ text: "Ask", link: { label: "Ask", href: "/contact" } });
732
689
  });
733
690
 
734
691
  it("drops them through pricingSections for page plans: [] too", async () => {
@@ -802,17 +759,14 @@ describe("a written section (#12140 AC-6)", () => {
802
759
  });
803
760
 
804
761
  describe("the plan bar options survive the Stripe path (#12141 D9, AC-1)", () => {
805
- const REC_GRID = { pickerLabel: "Plan", pinnedGroups: true, groupsOpen: "first" };
762
+ const ALL_CARDS = { price: true, button: true, billingSwitch: true };
806
763
 
807
764
  it.each([
808
765
  ["an unbound plans slot", {}],
809
- ["a bound section", { source: "offerings", variant: "with-comparison-table" }],
810
- ])("%s keeps planBar and comparisonPlanBar over the Offerings cards, deep-equal", (_label, extra) => {
811
- const { placed } = render([
812
- pricingSection("p", { ...extra, planBar: {}, comparisonPlanBar: REC_GRID }),
813
- ]);
814
- expect(dataOf(placed, "p").planBar).toEqual({});
815
- expect(dataOf(placed, "p").comparisonPlanBar).toEqual(REC_GRID);
766
+ ["a bound section", { source: "offerings", variant: "band-hero" }],
767
+ ])("%s keeps planBar over the Offerings cards, deep-equal", (_label, extra) => {
768
+ const { placed } = render([pricingSection("p", { ...extra, planBar: ALL_CARDS })]);
769
+ expect(dataOf(placed, "p").planBar).toEqual(ALL_CARDS);
816
770
  });
817
771
  });
818
772
 
@@ -922,3 +876,833 @@ describe("a bound section's offeringGroups and writtenPlans (#12174 AC-5, AC-7)"
922
876
  expect(p?.type === "pricing" && p.data.plans.map((c) => c.key)).toEqual(["fallback"]);
923
877
  });
924
878
  });
879
+
880
+ // ─── #12193 — cards built from Stripe ───────────────────────────────────────
881
+
882
+ /** `stripeSet()` with `edit` applied to its offerings and these contacts. */
883
+ function stripeSetWith(
884
+ edit: (offerings: OfferingsProduct[]) => void,
885
+ contacts: OfferingsContactProduct[] = [],
886
+ ): WorkspaceShownSet {
887
+ const set = structuredClone(stripeSet());
888
+ edit(set.offerings);
889
+ set.productIds = set.offerings.map((o) => o.productId);
890
+ if (contacts.length > 0) set.contacts = contacts;
891
+ return workspaceShownSetSchema.parse(set);
892
+ }
893
+
894
+ const COMMERCE: OfferingsContactProduct = {
895
+ productId: "prod_commerce",
896
+ plan: "commerce",
897
+ ailkGroup: "addon",
898
+ name: "Growth Hub Commerce",
899
+ description: null,
900
+ marketingFeatures: [],
901
+ ailkOrder: null,
902
+ url: "https://example.com/contact",
903
+ ctaLabel: "Talk to us",
904
+ priceText: "From 179 USD a month",
905
+ shortName: "Commerce",
906
+ collection: "growth-hub",
907
+ };
908
+
909
+ describe("a selecting bound section builds its cards from Stripe (#12193 D5, AC-2, AC-4, AC-7)", () => {
910
+ it("a collection section's tier card takes nothing from the page", () => {
911
+ const set = stripeSetWith((o) => {
912
+ for (const p of o) if (p.plan === "growth" || p.plan === "writing") Object.assign(p, { collection: "c", tier: "Individual" });
913
+ });
914
+ const section = pricingSection("p", {
915
+ source: "offerings",
916
+ offeringCollection: "c",
917
+ plans: [{ name: "Page name", description: "Page desc", price: {}, features: [], cta: { label: "x", href: "/x" } }],
918
+ });
919
+ const { placed } = render([section], { set });
920
+ const card = dataOf(placed, "p").plans[0]!;
921
+ expect(card.name).toBe("Individual");
922
+ expect(card.description).not.toBe("Page desc");
923
+ expect(card.levels!.map((l) => l.key)).toEqual(["growth", "writing"]);
924
+ });
925
+
926
+ it("a collection section shows its collection, matched lowercased; the unbound slot leaves those plans out", () => {
927
+ const tagged = (extra?: OfferingsProduct) =>
928
+ stripeSetWith((o) => {
929
+ for (const p of o) if (p.plan === "growth" || p.plan === "writing") p.collection = "Growth-Platform";
930
+ if (extra) o.push(extra);
931
+ });
932
+ const sections = [
933
+ HERO,
934
+ pricingSection("c", { source: "offerings", offeringCollection: "growth-platform" }),
935
+ pricingSection("rest"),
936
+ ];
937
+ const { placed } = render(sections, { set: tagged(), plans: ["essentials"] });
938
+ expect(keysOf(placed, "c")).toEqual(["growth", "writing"]);
939
+ expect(keysOf(placed, "rest")).toEqual(["essentials"]);
940
+ const pro = stripeProduct("pro", "plan", [stripePrice("pro", "monthly", 5000)], { collection: "growth-platform" });
941
+ expect(keysOf(render(sections, { set: tagged(pro), plans: ["essentials"] }).placed, "c")).toEqual(["growth", "pro", "writing"]);
942
+ });
943
+
944
+ it("an add-ons section selects its collection, the contact card included", () => {
945
+ const set = stripeSetWith((o) => {
946
+ o.find((p) => p.plan === "seo")!.collection = "growth-hub";
947
+ }, [COMMERCE]);
948
+ const { placed } = render(
949
+ [pricingSection("p"), pricingSection("a", { source: "offerings", variant: "addons", offeringCollection: "growth-hub" })],
950
+ { set },
951
+ );
952
+ expect(keysOf(placed, "a")).toEqual(["seo", "commerce"]);
953
+ });
954
+
955
+ it("a section with offeringPlans keeps one card per plan though the plans carry a tier (AC-17)", () => {
956
+ const set = stripeSetWith((o) => {
957
+ for (const p of o) if (p.ailkGroup === "plan") p.tier = "T";
958
+ });
959
+ const { placed } = render([pricingSection("p", { source: "offerings", offeringPlans: ["growth", "writing"] })], { set });
960
+ expect(keysOf(placed, "p")).toEqual(["growth", "writing"]);
961
+ for (const card of dataOf(placed, "p").plans) expect(card).not.toHaveProperty("levels");
962
+ });
963
+
964
+ it("a contact appears in no unbound slot (AC-17)", () => {
965
+ const set = stripeSetWith(() => {}, [{ ...COMMERCE, ailkGroup: "plan", plan: "enterprise", productId: "prod_e" }]);
966
+ expect(allKeys(render([pricingSection("p")], { set }).placed)).not.toContain("enterprise");
967
+ });
968
+ });
969
+
970
+ describe("pricingSections — the toggle field, ?plan= and ?billing=, and the render-time strip (#12193 D7, D9, D11)", () => {
971
+ // Past every earlier suite's mocked clock, so no shared read of theirs is reused.
972
+ let now = Date.now() + 10 ** 12;
973
+ const unconnected = fetchMock.getMockImplementation();
974
+ beforeEach(() => {
975
+ jest.spyOn(Date, "now").mockReturnValue(now);
976
+ });
977
+ afterEach(() => {
978
+ jest.restoreAllMocks();
979
+ fetchMock.mockReset();
980
+ fetchMock.mockImplementation(unconnected);
981
+ });
982
+
983
+ /** Answer every read with `data`, past the shared read's window. */
984
+ const answer = (data: unknown) => {
985
+ now += 16_000;
986
+ jest.spyOn(Date, "now").mockReturnValue(now);
987
+ fetchMock.mockReset();
988
+ fetchMock.mockImplementation(async () => ({
989
+ ok: true,
990
+ status: 200,
991
+ json: async () => ({ ok: true, data }),
992
+ }));
993
+ };
994
+
995
+ it("a stored billingToggle: false hides nothing on a bound section; hideBillingToggle is kept (AC-11)", async () => {
996
+ answer({ status: "shown", shownSet: stripeSet() });
997
+ const off = await pricingSections([pricingSection("p", { source: "offerings", billingToggle: false })], {
998
+ plans: undefined,
999
+ plan: undefined,
1000
+ locale: "en",
1001
+ });
1002
+ expect(dataOf(off, "p").billingToggle).toBe(true);
1003
+ const hidden = await pricingSections(
1004
+ [pricingSection("p", { source: "offerings", billingToggle: false, hideBillingToggle: true })],
1005
+ { plans: undefined, plan: undefined, locale: "en" },
1006
+ );
1007
+ expect(dataOf(hidden, "p").hideBillingToggle).toBe(true);
1008
+ });
1009
+
1010
+ it("sets selectedPlan and billingPeriod on every pricing section, on the shown and unconnected reads (AC-15)", async () => {
1011
+ answer({ status: "shown", shownSet: stripeSet() });
1012
+ const shown = await pricingSections([pricingSection("p")], { plans: undefined, plan: "ind-pb", period: "monthly", locale: "en" });
1013
+ expect(dataOf(shown, "p")).toMatchObject({ selectedPlan: "ind-pb", billingPeriod: "monthly" });
1014
+ const yearly = await pricingSections([pricingSection("p")], { plans: undefined, plan: "ind-pb", period: "yearly", locale: "en" });
1015
+ expect(dataOf(yearly, "p")).not.toHaveProperty("billingPeriod");
1016
+ answer({ status: "unconnected" });
1017
+ const unconnected = await pricingSections([pricingSection("p")], {
1018
+ plans: undefined,
1019
+ plan: "ind-pb",
1020
+ period: "annual",
1021
+ locale: "en",
1022
+ });
1023
+ expect(dataOf(unconnected, "p")).toMatchObject({ selectedPlan: "ind-pb", billingPeriod: "annual" });
1024
+ const badPlan = await pricingSections([pricingSection("p")], { plans: undefined, plan: "IND PB", period: undefined, locale: "en" });
1025
+ expect(dataOf(badPlan, "p")).not.toHaveProperty("selectedPlan");
1026
+ });
1027
+
1028
+ it("strips an authored offerPrices, selectedPlan and billingPeriod on every path (AC-13, security)", async () => {
1029
+ answer({ status: "unconnected" });
1030
+ const offerPrices = [{ amount: "1", currency: "USD", period: "month" }];
1031
+ const plan = { key: "a", name: "A", price: { monthly: "$9" }, features: [], cta: { label: "Go", href: "/go" }, offerPrices };
1032
+ const section = pricingSection("w", {
1033
+ source: "written",
1034
+ selectedPlan: "a",
1035
+ billingPeriod: "annual",
1036
+ plans: [{ ...plan, levels: [{ ...plan, label: "L1" }, { ...plan, label: "L2" }] }],
1037
+ extraTier: plan,
1038
+ });
1039
+ for (const options of [
1040
+ { plans: undefined, plan: undefined, locale: "en" },
1041
+ { plans: [] as string[], plan: undefined, locale: "en" },
1042
+ ]) {
1043
+ const [out] = await pricingSections([section], options);
1044
+ const data = out!.data as Record<string, unknown> & { plans: Array<Record<string, unknown> & { levels: Record<string, unknown>[] }> };
1045
+ expect(data).not.toHaveProperty("selectedPlan");
1046
+ expect(data).not.toHaveProperty("billingPeriod");
1047
+ expect(data.plans[0]).not.toHaveProperty("offerPrices");
1048
+ for (const level of data.plans[0]!.levels) expect(level).not.toHaveProperty("offerPrices");
1049
+ expect(data.extraTier).not.toHaveProperty("offerPrices");
1050
+ }
1051
+ const bound = pricingSection("b", { source: "offerings", writtenPlans: [plan] });
1052
+ answer({ status: "shown", shownSet: stripeSet() });
1053
+ const [placed] = await pricingSections([bound], { plans: undefined, plan: undefined, locale: "en" });
1054
+ const written = (placed!.data as { plans: Array<Record<string, unknown>> }).plans.find((c) => c.key === "a")!;
1055
+ expect(written).not.toHaveProperty("offerPrices");
1056
+ });
1057
+ });
1058
+
1059
+ // ─── #12209 — the level card's settings on a Stripe section ─────────────────
1060
+
1061
+ describe("a bound section keeps the level card's settings (#12209 D2, D8, D11, D12)", () => {
1062
+ const tiered = (n = 2) =>
1063
+ stripeSetWith((o) => {
1064
+ for (const p of o) if (p.plan === "growth" || p.plan === "writing") p.tier = "Individual";
1065
+ for (let i = 1; i <= n - 2; i++) {
1066
+ o.push(stripeProduct(`more-${i}`, "plan", [stripePrice(`more-${i}`, "monthly", 4000 + i)], { tier: "Individual" }));
1067
+ }
1068
+ });
1069
+ const levelOf = (label: string, plan: string) => ({ label, plan });
1070
+
1071
+ it("carries the control, the derived detail and the level heading onto the placed section (AC-1)", () => {
1072
+ const section = pricingSection("p", {
1073
+ source: "offerings",
1074
+ levelSwitchControl: "select",
1075
+ levelSwitchDetail: "price",
1076
+ showLevelHeading: true,
1077
+ });
1078
+ const data = dataOf(render([section], { set: tiered() }).placed, "p");
1079
+ expect(data.levelSwitchControl).toBe("select");
1080
+ expect(data.levelSwitchDetail).toBe("price");
1081
+ expect(data.showLevelHeading).toBe(true);
1082
+ });
1083
+
1084
+ it("an offeringGroups entry's control reaches its placed card, and none when it sets none (AC-1)", () => {
1085
+ const group = { key: "team", name: "Team", levels: [levelOf("Lite", "essentials"), levelOf("Full", "writing")] };
1086
+ const withControl = render([pricingSection("p", { source: "offerings", offeringGroups: [{ ...group, levelSwitchControl: "select" }] })]);
1087
+ expect(dataOf(withControl.placed, "p").plans[0]!.levelSwitchControl).toBe("select");
1088
+ const without = render([pricingSection("p", { source: "offerings", offeringGroups: [group] })]);
1089
+ expect(dataOf(without.placed, "p").plans[0]!).not.toHaveProperty("levelSwitchControl");
1090
+ });
1091
+
1092
+ it("no authored level detail survives onto a bound section's cards (AC-3, SEC-12209-1)", () => {
1093
+ const authored = {
1094
+ name: "Page",
1095
+ price: { monthly: "$1/mo" },
1096
+ features: [],
1097
+ cta: { label: "Go", href: "/go" },
1098
+ levels: [
1099
+ { label: "A", detail: "$1/mo", price: { monthly: "$1/mo" }, features: [], cta: { label: "Go", href: "/a" } },
1100
+ { label: "B", detail: "$1/mo", price: { monthly: "$1/mo" }, features: [], cta: { label: "Go", href: "/b" } },
1101
+ ],
1102
+ };
1103
+ const { placed } = render([pricingSection("p", { source: "offerings", plans: [authored] })], { set: tiered() });
1104
+ for (const card of dataOf(placed, "p").plans) for (const level of card.levels ?? []) expect(level).not.toHaveProperty("detail");
1105
+ expect(JSON.stringify(dataOf(placed, "p").plans)).not.toContain('"detail"');
1106
+ });
1107
+
1108
+ it("a select section places a tier card with up to twenty levels; segments keep four (AC-8)", () => {
1109
+ const set = tiered(22);
1110
+ const select = render([pricingSection("p", { source: "offerings", levelSwitchControl: "select" })], { set });
1111
+ expect(dataOf(select.placed, "p").plans.find((c) => c.name === "Individual")!.levels).toHaveLength(20);
1112
+ const segments = render([pricingSection("p", { source: "offerings" })], { set });
1113
+ expect(dataOf(segments.placed, "p").plans.find((c) => c.name === "Individual")!.levels).toHaveLength(4);
1114
+ });
1115
+
1116
+ it("separateTiers shows the same tier as separate cards, and is not carried into the placed section (AC-9)", () => {
1117
+ const set = tiered();
1118
+ const { placed } = render(
1119
+ [pricingSection("one", { source: "offerings" }), pricingSection("two", { source: "offerings", separateTiers: true })],
1120
+ { set },
1121
+ );
1122
+ const one = dataOf(placed, "one").plans;
1123
+ const two = dataOf(placed, "two").plans;
1124
+ expect(one.filter((c) => (c.levels?.length ?? 0) >= 2).map((c) => c.levels!.map((l) => l.key))).toEqual([["growth", "writing"]]);
1125
+ expect(two.map((c) => c.key)).toEqual(expect.arrayContaining(["growth", "writing"]));
1126
+ for (const c of two) expect(c).not.toHaveProperty("levels");
1127
+ expect(dataOf(placed, "one")).not.toHaveProperty("separateTiers");
1128
+ expect(dataOf(placed, "two")).not.toHaveProperty("separateTiers");
1129
+ });
1130
+ });
1131
+
1132
+ // ─── #12238 — a collection of contacts on a live page ───────────────────────
1133
+
1134
+ /** The report's shape: two plan contacts and one add-on contact of `growth-hub`. */
1135
+ const HUB_CONTACTS: OfferingsContactProduct[] = [
1136
+ { ...COMMERCE, productId: "prod_hub_pro", plan: "growth-hub-pro", ailkGroup: "plan", name: "Growth Hub Pro", ailkOrder: 10 },
1137
+ { ...COMMERCE, productId: "prod_hub_pro_plus", plan: "growth-hub-pro-plus", ailkGroup: "plan", name: "Growth Hub Pro Plus", ailkOrder: 20 },
1138
+ { ...COMMERCE, productId: "prod_hub_commerce", plan: "growth-hub-commerce", ailkGroup: "addon", name: "AI-Native Commerce", ailkOrder: 30 },
1139
+ ];
1140
+ const HUB_PLANS = HUB_CONTACTS.map((c) => c.plan);
1141
+
1142
+ /** A shown set whose only members are the report's contacts: no priced product at all. */
1143
+ function contactsOnlySet(): WorkspaceShownSet {
1144
+ return workspaceShownSetSchema.parse({
1145
+ ...stripeSet(),
1146
+ productIds: [],
1147
+ recommended: { plan: null, addon: null },
1148
+ offerings: [],
1149
+ contacts: HUB_CONTACTS,
1150
+ });
1151
+ }
1152
+
1153
+ describe("a collection of contacts renders on the live page (#12238)", () => {
1154
+ // Past every earlier suite's mocked clock (#12193's is 10 ** 12 ahead), so
1155
+ // no shared read of theirs is reused.
1156
+ let now = Date.now() + 2 * 10 ** 12;
1157
+ beforeEach(() => {
1158
+ now += 16_000;
1159
+ jest.spyOn(Date, "now").mockReturnValue(now);
1160
+ });
1161
+ afterEach(() => jest.restoreAllMocks());
1162
+
1163
+ const answer = (shownSet: unknown) =>
1164
+ fetchMock.mockImplementation(async () => ({
1165
+ ok: true,
1166
+ status: 200,
1167
+ json: async () => ({ ok: true, data: { status: "shown", shownSet } }),
1168
+ }));
1169
+ const bound = (id: string, data: Record<string, unknown> = {}) =>
1170
+ pricingSection(id, {
1171
+ source: "offerings",
1172
+ offeringCollection: "growth-hub",
1173
+ variant: "three-tiers-with-toggle",
1174
+ billingToggle: false,
1175
+ ...data,
1176
+ });
1177
+ // #12241 D3 — an add-on, its contact included, is a card in the section's plans.
1178
+ const tileKeys = (placed: PageSection[], id: string) => keysOf(placed, id);
1179
+
1180
+ it("the cause: a page whose own `plans` is [] never reads the shown set, so its bound section keeps no card", async () => {
1181
+ answer(contactsOnlySet());
1182
+ const sections = await pricingSections([HERO, bound("plans")], { plans: [], plan: undefined, locale: "en" });
1183
+ expect(fetchMock).not.toHaveBeenCalled();
1184
+ expect(keysOf(sections, "plans")).toEqual([]);
1185
+ });
1186
+
1187
+ it("a shown set of contacts only: the plan contacts are cards and the add-on contact a tile, never the contact email", async () => {
1188
+ answer(contactsOnlySet());
1189
+ const sections = await pricingSections(
1190
+ [HERO, bound("plans"), bound("extras", { variant: "addons" })],
1191
+ { plans: HUB_PLANS, plan: undefined, locale: "en" },
1192
+ );
1193
+ expect(sections.map((s) => s.id)).toEqual(["hero", "plans", "extras"]);
1194
+ expect(keysOf(sections, "plans")).toEqual(["growth-hub-pro", "growth-hub-pro-plus"]);
1195
+ expect(dataOf(sections, "plans").plans[0]).toMatchObject({ price: { custom: "From 179 USD a month" }, offerPrices: [] });
1196
+ expect(tileKeys(sections, "extras")).toEqual(["growth-hub-commerce"]);
1197
+ });
1198
+
1199
+ it("the report's page — one bound plans section on a page listing the slugs — shows both plan contacts", async () => {
1200
+ answer(contactsOnlySet());
1201
+ const sections = await pricingSections([HERO, bound("plans")], { plans: HUB_PLANS, plan: undefined, locale: "en" });
1202
+ expect(keysOf(sections, "plans")).toEqual(["growth-hub-pro", "growth-hub-pro-plus"]);
1203
+ });
1204
+
1205
+ it("an expired shown set takes the contact email, even beside a bound section's written cards", async () => {
1206
+ const written = { key: "written", name: "Written", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/contact" } };
1207
+ answer(workspaceShownSetSchema.parse({ ...stripeSet(), state: "expired" }));
1208
+ const sections = await pricingSections([HERO, bound("plans", { writtenPlans: [written] })], { plans: HUB_PLANS, plan: undefined, locale: "en" });
1209
+ expect(sections.map((s) => s.id)).toEqual(["hero", "offerings-contact"]);
1210
+ });
1211
+
1212
+ it("a shown set with no priced product and no contact of the collection still takes the contact email", async () => {
1213
+ answer(workspaceShownSetSchema.parse({ ...contactsOnlySet(), contacts: [{ ...HUB_CONTACTS[0]!, collection: "other" }] }));
1214
+ const sections = await pricingSections([HERO, bound("plans")], { plans: HUB_PLANS, plan: undefined, locale: "en" });
1215
+ expect(sections.map((s) => s.id)).toEqual(["hero", "offerings-contact"]);
1216
+ });
1217
+ });
1218
+
1219
+ describe("offeringPlans may name a contact by its slug (#12238, operator 2026-11-23)", () => {
1220
+ const set = () =>
1221
+ stripeSetWith(() => {}, [
1222
+ { ...COMMERCE, productId: "prod_e", plan: "enterprise", ailkGroup: "plan", name: "Enterprise", shortName: "Enterprise", collection: "growth-platform" },
1223
+ COMMERCE,
1224
+ ]);
1225
+
1226
+ it("a bound section naming a plan contact renders its card beside the named plans", () => {
1227
+ const { placed } = render([pricingSection("p", { source: "offerings", offeringPlans: ["growth", "enterprise"] })], { set: set() });
1228
+ expect(keysOf(placed, "p")).toEqual(["growth", "enterprise"]);
1229
+ expect(dataOf(placed, "p").plans[1]).toMatchObject({ name: "Enterprise", price: { custom: "From 179 USD a month" } });
1230
+ });
1231
+
1232
+ it("a bound section naming only a contact renders that contact's card", () => {
1233
+ const { placed } = render([pricingSection("p", { source: "offerings", offeringPlans: ["enterprise"] })], { set: set() });
1234
+ expect(keysOf(placed, "p")).toEqual(["enterprise"]);
1235
+ });
1236
+
1237
+ it("a plan group with no source (#12103) naming a contact renders its card", () => {
1238
+ const { placed } = render([pricingSection("p", { offeringPlans: ["enterprise", "writing"] })], { set: set() });
1239
+ expect(keysOf(placed, "p")).toEqual(["writing", "enterprise"]);
1240
+ });
1241
+
1242
+ it("a bound add-ons section naming an add-on contact renders its tile", () => {
1243
+ const { placed } = render(
1244
+ [pricingSection("p"), pricingSection("a", { source: "offerings", variant: "addons", offeringPlans: ["seo", "commerce"] })],
1245
+ { set: set() },
1246
+ );
1247
+ // #12241 D3 — the add-ons, the contact included, are cards in the section's plans.
1248
+ expect(keysOf(placed, "a")).toEqual(["seo", "commerce"]);
1249
+ });
1250
+
1251
+ it("the page's own `plans` naming a contact still shows it in no unbound slot", () => {
1252
+ const { placed } = render([pricingSection("p")], { set: set(), plans: ["growth", "enterprise"] });
1253
+ expect(allKeys(placed)).toEqual(["growth"]);
1254
+ });
1255
+ });
1256
+
1257
+ describe("a contact offeringPlans names keeps the same-origin link rule (#12238)", () => {
1258
+ const base = process.env["NEXT_PUBLIC_BASE_URL"];
1259
+ beforeEach(() => {
1260
+ process.env["NEXT_PUBLIC_BASE_URL"] = "https://example.com";
1261
+ });
1262
+ afterEach(() => {
1263
+ if (base === undefined) delete process.env["NEXT_PUBLIC_BASE_URL"];
1264
+ else process.env["NEXT_PUBLIC_BASE_URL"] = base;
1265
+ });
1266
+ const setWithUrl = (url: string) =>
1267
+ stripeSetWith(() => {}, [{ ...COMMERCE, productId: "prod_e", plan: "enterprise", ailkGroup: "plan", name: "Enterprise", url }]);
1268
+
1269
+ it.each([
1270
+ ["a bound section", { source: "offerings", offeringPlans: ["enterprise"] }],
1271
+ ["a plan group with no source", { offeringPlans: ["growth", "enterprise"] }],
1272
+ ])("%s gives no card for a named contact linking the site's own /api/", (_label, data) => {
1273
+ const { placed } = render([pricingSection("p", data)], { set: setWithUrl("https://example.com/api/offerings/checkout/growth_monthly") });
1274
+ expect(allKeys(placed)).not.toContain("enterprise");
1275
+ });
1276
+
1277
+ it.each([
1278
+ ["a bound section", { source: "offerings", offeringPlans: ["enterprise"] }],
1279
+ ["a plan group with no source", { offeringPlans: ["growth", "enterprise"] }],
1280
+ ])("%s links a named contact's same-origin page internally", (_label, data) => {
1281
+ const { placed } = render([pricingSection("p", data)], { set: setWithUrl("https://example.com/contact") });
1282
+ const card = dataOf(placed, "p").plans.find((c) => c.key === "enterprise");
1283
+ expect(card?.cta).toEqual({ label: "Talk to us", href: "/contact" });
1284
+ });
1285
+ });
1286
+
1287
+ // ─── #12246 — a comparison table's plan columns on a pricing page ───────────
1288
+
1289
+ describe("pricingSections — comparison tables with plan columns (#12246 D3, D4, D7)", () => {
1290
+ // Past every other suite's clock (#12238's is 2 * 10 ** 12 ahead), so no earlier shared read is reused.
1291
+ let now = Date.now() + 3 * 10 ** 12;
1292
+ beforeEach(() => {
1293
+ now += 16_000;
1294
+ jest.spyOn(Date, "now").mockReturnValue(now);
1295
+ });
1296
+ afterEach(() => jest.restoreAllMocks());
1297
+
1298
+ const answer = (data: unknown) =>
1299
+ fetchMock.mockImplementation(async () => ({
1300
+ ok: true,
1301
+ status: 200,
1302
+ json: async () => ({ ok: true, data }),
1303
+ }));
1304
+
1305
+ const both = (plan: string, monthly: number, yearly: number) => [
1306
+ stripePrice(plan, "monthly", monthly),
1307
+ stripePrice(plan, "yearly", yearly),
1308
+ ];
1309
+ /** S3: three plans priced both ways, `growth` titled "Growth" and Recommended, and an add-on. */
1310
+ function s3(): WorkspaceShownSet {
1311
+ const offerings = [
1312
+ stripeProduct("essentials", "plan", both("essentials", 220000, 2376000), { name: "Essentials" }),
1313
+ stripeProduct("growth", "plan", both("growth", 440000, 4752000), {
1314
+ shortName: "Growth",
1315
+ name: "Growth plan",
1316
+ recommended: true,
1317
+ }),
1318
+ stripeProduct("scale", "plan", both("scale", 650000, 7020000), { name: "Scale" }),
1319
+ stripeProduct("extra", "addon", [stripePrice("extra", "monthly", 9900)]),
1320
+ ];
1321
+ return workspaceShownSetSchema.parse({
1322
+ workspaceId: "wksp_01890a5d-ac96-774b-bcce-b302099a8057",
1323
+ organizationId: "org_01890a5d-ac96-774b-bcce-b302099a8058",
1324
+ productIds: offerings.map((o) => o.productId),
1325
+ recommended: { plan: "prod_growth", addon: null },
1326
+ offerings,
1327
+ state: "current",
1328
+ snapshotAt: "2026-11-20T00:00:00.000Z",
1329
+ });
1330
+ }
1331
+
1332
+ type Table = Extract<PageSection, { type: "comparison-table" }>;
1333
+ type Column = Table["data"]["columns"][number] & { offering?: { name: string; cta: { href: string } } };
1334
+ const GROUPS = [{ groupName: "Writing", rows: [{ featureName: "Pieces", values: { growth: "8", us: true } }] }];
1335
+ const table = (id: string, columns: unknown[], groups: unknown = GROUPS, extra: Record<string, unknown> = {}) =>
1336
+ ({ id, type: "comparison-table", data: { columns, groups, ...extra } }) as PageSection;
1337
+ const MIXED = [{ key: "us", name: "Us" }, { key: "growth", plan: "growth" }, { key: "them", name: "Them" }];
1338
+ const PLAN3 = ["essentials", "growth", "scale"].map((key) => ({ key, plan: key }));
1339
+ const tableOf = (sections: PageSection[], id = "t") => {
1340
+ const found = sections.find((s) => s.id === id);
1341
+ if (!found || found.type !== "comparison-table") throw new Error(`no table ${id}`);
1342
+ return found.data as Omit<Table["data"], "columns"> & { billingPeriod?: string; columns: Column[] };
1343
+ };
1344
+ const options = (extra: Partial<Parameters<typeof pricingSections>[1]> = {}) => ({
1345
+ plans: undefined,
1346
+ plan: undefined,
1347
+ locale: "en",
1348
+ ...extra,
1349
+ });
1350
+
1351
+ it("AC-1: a plan column takes its plan from the shown set, whatever the page's plans list", async () => {
1352
+ answer({ status: "shown", shownSet: s3() });
1353
+ const sections = await pricingSections([HERO, table("t", MIXED)], options({ plans: ["scale"] }));
1354
+ const columns = tableOf(sections).columns;
1355
+ expect(columns.map((c) => c.offering?.name)).toEqual([undefined, "Growth", undefined]);
1356
+ expect(columns[1]!.offering?.cta.href).toBe(`${OFFERINGS_CHECKOUT_PATH}/growth_monthly`);
1357
+ });
1358
+
1359
+ it("AC-2: an authored offering never reaches a column, typed or plan", async () => {
1360
+ answer({ status: "shown", shownSet: s3() });
1361
+ const forged = { name: "Free", price: { monthly: "$0" }, cta: { label: "Take", href: "https://evil.example" } };
1362
+ const sections = await pricingSections(
1363
+ [
1364
+ HERO,
1365
+ table("t", [
1366
+ { key: "us", name: "Us", offering: forged },
1367
+ { key: "ghost", plan: "ghost", offering: forged },
1368
+ { key: "growth", plan: "growth", offering: forged },
1369
+ ]),
1370
+ ],
1371
+ options(),
1372
+ );
1373
+ const columns = tableOf(sections).columns;
1374
+ expect(columns[0]).not.toHaveProperty("offering");
1375
+ expect(columns[1]).not.toHaveProperty("offering");
1376
+ expect(columns[2]!.offering?.cta.href).toBe(`${OFFERINGS_CHECKOUT_PATH}/growth_monthly`);
1377
+ });
1378
+
1379
+ describe("AC-3: the table opens on the period the page's cards open on", () => {
1380
+ beforeEach(() => answer({ status: "unconnected" }));
1381
+ const cards = (data: Record<string, unknown>) =>
1382
+ pricingSection("p", { plans: [{ key: "a", name: "A", price: { monthly: "$1", annual: "$10" }, features: [], cta: { label: "Go", href: "/a" } }], ...data });
1383
+
1384
+ it("annual with a toggle, monthly without, and ?billing= over both", async () => {
1385
+ const period = async (data: Record<string, unknown>, extra = {}) =>
1386
+ tableOf(await pricingSections([cards(data), table("t", PLAN3)], options(extra))).billingPeriod;
1387
+ expect(await period({ billingToggle: true })).toBe("annual");
1388
+ expect(await period({ hideBillingToggle: true })).toBe("annual");
1389
+ expect(await period({})).toBe("monthly");
1390
+ expect(await period({ billingToggle: true }, { period: "monthly" })).toBe("monthly");
1391
+ expect(await period({}, { period: "annual" })).toBe("annual");
1392
+ expect(await period({ billingToggle: true }, { period: "weekly" })).toBe("annual");
1393
+ });
1394
+
1395
+ it("monthly beside a layout that shows monthly prices only, whatever its stored toggle", async () => {
1396
+ const period = async (variant: string) =>
1397
+ tableOf(await pricingSections([cards({ variant, billingToggle: true }), table("t", PLAN3)], options())).billingPeriod;
1398
+ for (const variant of ["two-tiers-with-extra-tier", "band-hero", "single-price-with-details", "features-and-plans"])
1399
+ expect(await period(variant)).toBe("monthly");
1400
+ expect(await period("three-tiers-with-toggle")).toBe("annual");
1401
+ });
1402
+
1403
+ it("annual on the shown path, where the mapper turns the toggle on", async () => {
1404
+ answer({ status: "shown", shownSet: s3() });
1405
+ const sections = await pricingSections([cards({}), table("t", PLAN3)], options());
1406
+ expect(tableOf(sections).billingPeriod).toBe("annual");
1407
+ });
1408
+
1409
+ it("an authored billingPeriod never reaches the table, and a typed table takes none", async () => {
1410
+ const sections = await pricingSections(
1411
+ [cards({}), table("t", PLAN3, GROUPS, { billingPeriod: "annual" }), table("u", MIXED.filter((c) => !("plan" in c)))],
1412
+ options(),
1413
+ );
1414
+ expect(tableOf(sections).billingPeriod).toBe("monthly");
1415
+ expect(tableOf(sections, "u")).not.toHaveProperty("billingPeriod");
1416
+ });
1417
+ });
1418
+
1419
+ it("AC-4: a slug the shown set lacks stays unresolved", async () => {
1420
+ answer({ status: "shown", shownSet: s3() });
1421
+ const GHOST = { key: "ghost", plan: "ghost" };
1422
+ const shown = await pricingSections([HERO, table("t", [GHOST, { key: "growth", plan: "growth" }])], options());
1423
+ expect(tableOf(shown).columns.map((c) => c.offering?.name)).toEqual([undefined, "Growth"]);
1424
+ });
1425
+
1426
+ it("AC-4: every plan column stays unresolved on the contact path", async () => {
1427
+ answer({ status: "empty" });
1428
+ const contact = await pricingSections([HERO, pricingSection("p"), table("t", PLAN3)], options());
1429
+ expect(contact.map((s) => s.id)).toEqual(["hero", "offerings-contact", "t"]);
1430
+ expect(tableOf(contact).columns.every((c) => c.offering === undefined)).toBe(true);
1431
+ });
1432
+
1433
+ it("AC-6: a stored with-comparison-table page reads as cards and a table of three resolved plan columns", async () => {
1434
+ answer({ status: "shown", shownSet: s3() });
1435
+ const stored = PageSectionsSchema.parse([
1436
+ HERO,
1437
+ {
1438
+ id: "plans",
1439
+ type: "pricing",
1440
+ data: {
1441
+ variant: "with-comparison-table",
1442
+ source: "offerings",
1443
+ offeringPlans: ["essentials", "growth", "scale"],
1444
+ plans: [],
1445
+ comparisonGroups: [
1446
+ {
1447
+ groupName: "Writing",
1448
+ rows: [{ featureName: "Samples", values: { essentials: { text: "See", link: { label: "Samples", href: "/samples" } } } }],
1449
+ },
1450
+ ],
1451
+ },
1452
+ },
1453
+ ]);
1454
+ const sections = await pricingSections(stored, options());
1455
+ expect(sections.map((s) => [s.id, s.type])).toEqual([
1456
+ ["hero", "hero"],
1457
+ ["plans", "pricing"],
1458
+ ["plans-comparison", "comparison-table"],
1459
+ ]);
1460
+ expect(keysOf(sections, "plans")).toEqual(["essentials", "growth", "scale"]);
1461
+ const data = tableOf(sections, "plans-comparison");
1462
+ expect(data.columns.map((c) => c.offering?.name)).toEqual(["Essentials", "Growth", "Scale"]);
1463
+ expect(data.groups[0]!.rows[0]!.values).toEqual({ essentials: { text: "See" } });
1464
+ });
1465
+
1466
+ it("AC-6: a written table cell that links the Offerings checkout loses its link, in any URL form", async () => {
1467
+ answer({ status: "unconnected" });
1468
+ const cell = (href: string) => ({ text: "Buy", link: { label: "Buy", href } });
1469
+ const groups = [
1470
+ {
1471
+ groupName: "G",
1472
+ rows: [
1473
+ {
1474
+ featureName: "Row",
1475
+ values: {
1476
+ a: cell("/api/offerings/checkout/x"),
1477
+ b: cell("/api/%6Ffferings/checkout/x"),
1478
+ c: cell("/contact"),
1479
+ d: cell("/api//offerings/checkout/x"),
1480
+ e: cell("/api/offerings//checkout/x"),
1481
+ f: cell("/api/\\offerings/checkout/x"),
1482
+ g: cell("/api/%2Fofferings/checkout/x"),
1483
+ },
1484
+ },
1485
+ ],
1486
+ },
1487
+ ];
1488
+ const sections = await pricingSections([table("t", [{ key: "a", name: "A" }], groups)], options());
1489
+ expect(tableOf(sections).groups[0]!.rows[0]!.values).toEqual({
1490
+ a: { text: "Buy" },
1491
+ b: { text: "Buy" },
1492
+ c: cell("/contact"),
1493
+ d: { text: "Buy" },
1494
+ e: { text: "Buy" },
1495
+ f: { text: "Buy" },
1496
+ g: { text: "Buy" },
1497
+ });
1498
+ });
1499
+
1500
+ it("returns a typed table with no checkout link as the same object", async () => {
1501
+ answer({ status: "unconnected" });
1502
+ const typed = table("t", [{ key: "us", name: "Us" }]);
1503
+ const sections = await pricingSections([HERO, typed], options());
1504
+ expect(sections[1]).toBe(typed);
1505
+ });
1506
+ });
1507
+
1508
+ // ─── #12242 — the price unit on a Stripe section ────────────────────────────
1509
+
1510
+ describe("the price unit's words and a bound section's options (#12242)", () => {
1511
+ const seatSet = () => {
1512
+ const set = structuredClone(stripeSet());
1513
+ set.offerings.find((o) => o.plan === "writing")!.unitLabel = "seat";
1514
+ set.offerings.push(
1515
+ stripeProduct("hub", "plan", [stripePrice("hub", "monthly", 3000), stripePrice("hub", "yearly", 30000)], {
1516
+ unitLabel: "site",
1517
+ }),
1518
+ );
1519
+ set.productIds = set.offerings.map((o) => o.productId);
1520
+ return set;
1521
+ };
1522
+ type Card = { key?: string; annualPriceNote?: string; priceParts?: { monthly?: { unit: string }; annual?: { was?: string } } };
1523
+ const cardIn = (placed: PageSection[], key: string) =>
1524
+ (dataOf(placed, "p").plans as Card[]).find((c) => c.key === key)!;
1525
+
1526
+ it("AC-2, AC-9 — the shipped catalog gives /mo, /yr and the one join", async () => {
1527
+ const { labels } = await offeringsCopy("en");
1528
+ expect(labels.perMonth).toBe("/mo");
1529
+ expect(labels.perYear).toBe("/yr");
1530
+ expect(labels.unitWithLabel("/mo", "seat")).toBe("/mo/seat");
1531
+ expect(labels.unitWithLabel("/mo", "site")).toBe("/mo/site");
1532
+ expect(labels.unitWithLabel("/mo", "$& $1")).toBe("/mo/$& $1");
1533
+ expect(labels.savings("17")).toBe("Save 17% billed annually");
1534
+ expect(labels.regularPrice("$20", "$17")).toBe("Regular price $20, now $17");
1535
+ });
1536
+
1537
+ it("AC-4, AC-5 — a bound section's yearly line and strike reach its mapping, and are not placed", () => {
1538
+ const { placed } = render([pricingSection("p", { source: "offerings", annualPriceLine: "savings", annualStrikePrice: true })], {
1539
+ set: seatSet(),
1540
+ });
1541
+ expect(cardIn(placed, "writing").annualPriceNote).toBe("S⟪17");
1542
+ expect(cardIn(placed, "writing").priceParts?.annual?.was).toBe("$30");
1543
+ expect(cardIn(placed, "writing").priceParts?.monthly?.unit).toBe("U⟪PM⟪⟫seat");
1544
+ expect(cardIn(placed, "hub").priceParts?.monthly?.unit).toBe("U⟪PM⟪⟫site");
1545
+ const unset = render([pricingSection("p", { source: "offerings" })], { set: seatSet() }).placed;
1546
+ expect(cardIn(unset, "writing").annualPriceNote).toBe("B⟪$300");
1547
+ expect(cardIn(unset, "writing").priceParts?.annual).not.toHaveProperty("was");
1548
+ });
1549
+
1550
+ it("AC-6 — a bound section keeps its price size and tone", () => {
1551
+ const { placed } = render([pricingSection("p", { source: "offerings", priceAmountSize: "xl", priceUnitTone: "muted" })]);
1552
+ expect(dataOf(placed, "p")).toMatchObject({ priceAmountSize: "xl", priceUnitTone: "muted" });
1553
+ });
1554
+
1555
+ it("AC-7 — an unbound page keeps the billed line; an authored priceParts never reaches a section", async () => {
1556
+ const { placed } = render([pricingSection("p")], { set: seatSet() });
1557
+ expect(cardIn(placed, "writing").annualPriceNote).toBe("B⟪$300");
1558
+ fetchMock.mockImplementation(async () => ({
1559
+ ok: true,
1560
+ status: 200,
1561
+ json: async () => ({ ok: true, data: { status: "unconnected" } }),
1562
+ }));
1563
+ const priceParts = { monthly: { amount: "$1", unit: "/forged" } };
1564
+ const plan = { key: "a", name: "A", price: { monthly: "$9" }, features: [], cta: { label: "Go", href: "/go" }, priceParts };
1565
+ const section = pricingSection("w", {
1566
+ source: "written",
1567
+ plans: [{ ...plan, levels: [{ ...plan, label: "L1" }, { ...plan, label: "L2" }] }],
1568
+ extraTier: plan,
1569
+ });
1570
+ const [out] = await pricingSections([section], { plans: undefined, plan: undefined, locale: "en" });
1571
+ const data = out!.data as Record<string, unknown> & { plans: Array<Record<string, unknown> & { levels: Record<string, unknown>[] }> };
1572
+ expect(data.plans[0]).not.toHaveProperty("priceParts");
1573
+ for (const level of data.plans[0]!.levels) expect(level).not.toHaveProperty("priceParts");
1574
+ expect(data.extraTier).not.toHaveProperty("priceParts");
1575
+ });
1576
+ });
1577
+
1578
+ // SOFT_LOCK_OK: #12243 AC-6 — every section reads the site's origin, so a
1579
+ // same-origin footnote link is an internal path whichever way the section
1580
+ // picks its plans, not only in tier mode.
1581
+ describe("a card footnote's link on the site's own origin (#12243 AC-6)", () => {
1582
+ const ORIGIN_ENV = process.env["NEXT_PUBLIC_BASE_URL"];
1583
+ beforeAll(() => {
1584
+ process.env["NEXT_PUBLIC_BASE_URL"] = "https://site.test";
1585
+ });
1586
+ afterAll(() => {
1587
+ if (ORIGIN_ENV === undefined) delete process.env["NEXT_PUBLIC_BASE_URL"];
1588
+ else process.env["NEXT_PUBLIC_BASE_URL"] = ORIGIN_ENV;
1589
+ });
1590
+
1591
+ function footnoted(): WorkspaceShownSet {
1592
+ const set = stripeSet();
1593
+ for (const o of set.offerings) {
1594
+ if (o.plan !== "growth") continue;
1595
+ o.footnote = "*Plus onboarding.";
1596
+ o.footnoteLink = { label: "Learn more", url: "https://site.test/onboarding#fee" };
1597
+ }
1598
+ return set;
1599
+ }
1600
+ const growthLink = (placed: PageSection[], id: string) =>
1601
+ dataOf(placed, id).plans.find((card) => card.key === "growth")?.footnoteLink;
1602
+
1603
+ it.each([
1604
+ ["a bound section that names its plans", pricingSection("p", { source: "offerings", offeringPlans: ["essentials", "growth"] })],
1605
+ ["a bound section that builds its cards from Stripe", pricingSection("p", { source: "offerings" })],
1606
+ ["a listed plan group", pricingSection("p", { offeringPlans: ["essentials", "growth"] })],
1607
+ ["the page's plans section", pricingSection("p")],
1608
+ ])("%s links it as an internal path", (_label, section) => {
1609
+ const { placed } = render([HERO, section], { set: footnoted() });
1610
+ expect(growthLink(placed, "p")).toEqual({ label: "Learn more", href: "/onboarding#fee" });
1611
+ });
1612
+ });
1613
+
1614
+ // ─── #12241 — one pricing card for plans and add-ons ─────────────────────────
1615
+
1616
+ describe("a bound section keeps the card settings (#12241 D1, D9)", () => {
1617
+ it("AC-2 page: a bound addons section keeps cardLayout, featureListStyle, levelSwitchControl and levelSwitchPlacement", () => {
1618
+ const settings = {
1619
+ cardLayout: "centered",
1620
+ featureListStyle: "included-dots",
1621
+ levelSwitchControl: "select",
1622
+ levelSwitchPlacement: "above-button",
1623
+ } as const;
1624
+ const { placed } = render([pricingSection("a", { source: "offerings", variant: "addons", ...settings })]);
1625
+ expect(dataOf(placed, "a")).toMatchObject({ variant: "addons", ...settings });
1626
+ expect(keysOf(placed, "a")).toEqual(["seo"]);
1627
+ });
1628
+
1629
+ const LOOK = {
1630
+ featureDetails: [{ feature: "timeline", detail: "Six weeks", plan: "writing" }, { feature: "Support", detail: "Weekdays" }],
1631
+ featureRowStyle: "opens",
1632
+ loneCard: "column",
1633
+ wideSide: {
1634
+ media: "rotate",
1635
+ images: [{ src: "/a.png", alt: "A" }, { src: "/b.png", alt: "B" }],
1636
+ quote: { quote: "Q", author: "A" },
1637
+ },
1638
+ } as const;
1639
+
1640
+ it.each([
1641
+ ["a bound plans section", pricingSection("p", { source: "offerings", offeringPlans: ["writing"], ...LOOK })],
1642
+ ["a bound addons section", pricingSection("p", { source: "offerings", variant: "addons", ...LOOK })],
1643
+ ["the page's plans section", pricingSection("p", LOOK)],
1644
+ ])("AC-6 / AC-17 page: %s keeps featureDetails, featureRowStyle, loneCard and wideSide", (_label, section) => {
1645
+ const data = dataOf(render([section]).placed, "p");
1646
+ expect(data.featureDetails).toEqual(LOOK.featureDetails);
1647
+ expect(data.featureRowStyle).toBe("opens");
1648
+ expect(data.loneCard).toBe("column");
1649
+ expect(data.wideSide).toEqual(LOOK.wideSide);
1650
+ });
1651
+
1652
+ it("AC-14 page: a bound single-price-with-details section over a both-periods plan places billingToggle: true", () => {
1653
+ const { placed } = render([
1654
+ pricingSection("s", { source: "offerings", variant: "single-price-with-details", offeringPlans: ["writing"] }),
1655
+ ]);
1656
+ expect(dataOf(placed, "s")).toMatchObject({ variant: "single-price-with-details", billingToggle: true });
1657
+ expect(keysOf(placed, "s")).toEqual(["writing"]);
1658
+ });
1659
+ });
1660
+
1661
+ describe("an authored card's images never reach the page (#12241 D8, security)", () => {
1662
+ // Past every earlier suite's mocked clock (#12246's is 3 × 10 ** 12 ahead),
1663
+ // so no shared read of theirs is reused.
1664
+ let now = Date.now() + 4 * 10 ** 12;
1665
+ beforeEach(() => {
1666
+ now += 16_000;
1667
+ jest.spyOn(Date, "now").mockReturnValue(now);
1668
+ });
1669
+ afterEach(() => jest.restoreAllMocks());
1670
+ const answer = (data: unknown) => {
1671
+ fetchMock.mockImplementation(async () => ({
1672
+ ok: true,
1673
+ status: 200,
1674
+ json: async () => ({ ok: true, data }),
1675
+ }));
1676
+ };
1677
+ const images = [{ src: "https://evil.example/x.png", alt: "X" }];
1678
+ const plan = { key: "a", name: "A", price: { monthly: "$9" }, features: [], cta: { label: "Go", href: "/go" }, images };
1679
+
1680
+ it("AC-8 page: an authored images on a written card, its levels, its extra tier or a bound section's written card is stripped", async () => {
1681
+ answer({ status: "unconnected" });
1682
+ const section = pricingSection("w", {
1683
+ source: "written",
1684
+ plans: [{ ...plan, levels: [{ ...plan, label: "L1" }, { ...plan, label: "L2" }] }],
1685
+ extraTier: plan,
1686
+ });
1687
+ for (const options of [
1688
+ { plans: undefined, plan: undefined, locale: "en" },
1689
+ { plans: [] as string[], plan: undefined, locale: "en" },
1690
+ ]) {
1691
+ const [out] = await pricingSections([section], options);
1692
+ expect(JSON.stringify(out!.data)).not.toContain("evil.example");
1693
+ const data = out!.data as { plans: Array<Record<string, unknown> & { levels: Record<string, unknown>[] }> };
1694
+ expect(data.plans[0]).not.toHaveProperty("images");
1695
+ for (const level of data.plans[0]!.levels) expect(level).not.toHaveProperty("images");
1696
+ }
1697
+ answer({ status: "shown", shownSet: stripeSet() });
1698
+ const [placed] = await pricingSections([pricingSection("b", { source: "offerings", writtenPlans: [plan] })], {
1699
+ plans: undefined,
1700
+ plan: undefined,
1701
+ locale: "en",
1702
+ });
1703
+ const written = (placed!.data as { plans: Array<Record<string, unknown>> }).plans.find((c) => c.key === "a")!;
1704
+ expect(written).toBeDefined();
1705
+ expect(written).not.toHaveProperty("images");
1706
+ expect(JSON.stringify(placed!.data)).not.toContain("evil.example");
1707
+ });
1708
+ });