create-ailk 0.46.3 → 0.46.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/component-catalog.json +319 -201
- package/component-catalog.md +8 -9
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +129 -17
- package/templates/apps/web/app/[locale]/layout.tsx +11 -1
- package/templates/apps/web/i18n/request.ts +35 -12
- package/templates/apps/web/lib/__tests__/in-page-blocks.test.ts +261 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +636 -53
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +601 -93
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +18 -1
- package/templates/apps/web/lib/in-page-blocks.ts +175 -0
- package/templates/apps/web/lib/offerings-pricing.ts +300 -102
- package/templates/apps/web/lib/pricing-page.ts +229 -61
- package/templates/apps/web/messages/en.json +20 -1
- package/versions.json +50 -50
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* or price order, so a sort fails AC-1. The labels are sentinels (`⟪`), so
|
|
8
8
|
* any copy the mapper invents shows up in AC-7.
|
|
9
9
|
*/
|
|
10
|
-
import { render } from "@testing-library/react";
|
|
11
|
-
import { Pricing } from "@working-theory/ui/sections";
|
|
10
|
+
import { fireEvent, render, within } from "@testing-library/react";
|
|
11
|
+
import { Pricing, SectionRenderer } from "@working-theory/ui/sections";
|
|
12
12
|
import {
|
|
13
13
|
parseLookupKey,
|
|
14
14
|
PricingSectionDataSchema,
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
workspaceShownSetSchema,
|
|
17
17
|
type OfferingsPrice,
|
|
18
18
|
type OfferingsProduct,
|
|
19
|
+
type PageSection,
|
|
19
20
|
type WorkspaceShownSet,
|
|
20
21
|
} from "@working-theory/validation";
|
|
21
22
|
import React from "react";
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
offeringsBundleHref,
|
|
27
28
|
offeringsCheckoutHref,
|
|
28
29
|
collectionPlans,
|
|
30
|
+
offeringsPlanColumns,
|
|
29
31
|
offeringsPricing,
|
|
30
32
|
type OfferingsPricing,
|
|
31
33
|
type OfferingsPricingLabels,
|
|
@@ -41,6 +43,12 @@ const LABELS: OfferingsPricingLabels = {
|
|
|
41
43
|
depositNote: (deposit) => "D⟪" + deposit,
|
|
42
44
|
billedYearly: (amount) => "B⟪" + amount,
|
|
43
45
|
custom: "C⟪",
|
|
46
|
+
// #12242 D2 — sentinels, so a unit the mapper builds shows where each word came from.
|
|
47
|
+
perMonth: "PM⟪",
|
|
48
|
+
perYear: "PY⟪",
|
|
49
|
+
unitWithLabel: (period, label) => "U⟪" + period + "⟫" + label,
|
|
50
|
+
savings: (percent) => "S⟪" + percent,
|
|
51
|
+
regularPrice: (regular, current) => "R⟪" + regular + "⟫" + current,
|
|
44
52
|
};
|
|
45
53
|
|
|
46
54
|
const OPTIONS = { locale: "en-US", labels: LABELS };
|
|
@@ -180,16 +188,10 @@ function plansOf(result: OfferingsPricing) {
|
|
|
180
188
|
return result.plans.plans;
|
|
181
189
|
}
|
|
182
190
|
|
|
183
|
-
/** The
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
key: string;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
function addonsOf(result: OfferingsPricing): Tile[] {
|
|
191
|
-
if (!result.addons?.addons) throw new Error("expected an add-ons fragment");
|
|
192
|
-
return result.addons.addons as Tile[];
|
|
191
|
+
/** The add-ons fragment's cards (#12241 D3): plan cards, each keyed by its `{plan}`. */
|
|
192
|
+
function addonsOf(result: OfferingsPricing) {
|
|
193
|
+
if (!result.addons) throw new Error("expected an add-ons fragment");
|
|
194
|
+
return result.addons.plans;
|
|
193
195
|
}
|
|
194
196
|
|
|
195
197
|
function card(result: OfferingsPricing, key: string) {
|
|
@@ -198,9 +200,9 @@ function card(result: OfferingsPricing, key: string) {
|
|
|
198
200
|
return found;
|
|
199
201
|
}
|
|
200
202
|
|
|
201
|
-
function
|
|
203
|
+
function addonCard(result: OfferingsPricing, key: string) {
|
|
202
204
|
const found = addonsOf(result).find((t) => t.key === key);
|
|
203
|
-
if (!found) throw new Error(`no
|
|
205
|
+
if (!found) throw new Error(`no add-on card ${key}`);
|
|
204
206
|
return found;
|
|
205
207
|
}
|
|
206
208
|
|
|
@@ -243,7 +245,7 @@ describe("offeringsPricing — one card per Product (AC-1)", () => {
|
|
|
243
245
|
"seo-audit",
|
|
244
246
|
"audit-pack",
|
|
245
247
|
]);
|
|
246
|
-
expect(result.addons
|
|
248
|
+
expect(result.addons).not.toHaveProperty("addons");
|
|
247
249
|
expect(result.plans?.variant).toBe("three-tiers-with-toggle");
|
|
248
250
|
expect(result.plans?.cardLayout).toBe("centered");
|
|
249
251
|
expect(result.addons?.variant).toBe("addons");
|
|
@@ -260,8 +262,9 @@ describe("offeringsPricing — one card per Product (AC-1)", () => {
|
|
|
260
262
|
});
|
|
261
263
|
const flagged = addonsOf(result).filter((t) => t.eyebrow !== undefined);
|
|
262
264
|
expect(flagged.map((t) => t.key)).toEqual(["seo-audit"]);
|
|
263
|
-
expect(flagged[0]).toMatchObject({ eyebrow: "REC⟪"
|
|
264
|
-
|
|
265
|
+
expect(flagged[0]).toMatchObject({ eyebrow: "REC⟪" });
|
|
266
|
+
// #12241 D3 — an add-on card is never highlighted, the recommended one included.
|
|
267
|
+
expect(addonsOf(result).filter((t) => t.highlighted)).toEqual([]);
|
|
265
268
|
});
|
|
266
269
|
|
|
267
270
|
it("highlights only the first recommended Product of a group", () => {
|
|
@@ -392,14 +395,14 @@ describe("offeringsPricing — periods, the switch and the fields (AC-2)", () =>
|
|
|
392
395
|
expect(card(result, "growth").annualCtaHref).toBe(hrefFor("growth_yearly"));
|
|
393
396
|
});
|
|
394
397
|
|
|
395
|
-
it("formats an add-on
|
|
398
|
+
it("formats an add-on card's shown price and links its monthly Price", () => {
|
|
396
399
|
const result = mapped();
|
|
397
|
-
const seo =
|
|
398
|
-
expect(seo.price).
|
|
399
|
-
expect(seo.
|
|
400
|
+
const seo = addonCard(result, "seo-audit");
|
|
401
|
+
expect(seo.price).toEqual({ monthly: "M⟪€19.50" });
|
|
402
|
+
expect(seo.priceUnit).toBe("per site");
|
|
400
403
|
expect(seo.features).toEqual(["Monthly report"]);
|
|
401
404
|
expect(seo.cta?.href).toBe(hrefFor("seo-audit_monthly"));
|
|
402
|
-
expect(
|
|
405
|
+
expect(addonCard(result, "audit-pack").cta?.href).toBe(
|
|
403
406
|
hrefFor("audit-pack_monthly"),
|
|
404
407
|
);
|
|
405
408
|
});
|
|
@@ -469,7 +472,7 @@ describe("offeringsPricing — a bundled plan links its required product (#10028
|
|
|
469
472
|
expect(result.plans!.billingToggle).toBe(false);
|
|
470
473
|
});
|
|
471
474
|
|
|
472
|
-
it("renders no card for the required product itself, and keeps the add-on
|
|
475
|
+
it("renders no card for the required product itself, and keeps the add-on card", () => {
|
|
473
476
|
const result = mapped(bundleSet());
|
|
474
477
|
expect(plansOf(result).map((p) => p.key)).toEqual(["rebuild"]);
|
|
475
478
|
expect(addonsOf(result).map((a) => a.key)).toEqual(["page"]);
|
|
@@ -528,7 +531,7 @@ describe("offeringsPricing — an offer is listed by neither fragment (#11166 AC
|
|
|
528
531
|
edit(set);
|
|
529
532
|
});
|
|
530
533
|
|
|
531
|
-
it("maps the plans and add-ons exactly as without it; the offer gets no card
|
|
534
|
+
it("maps the plans and add-ons exactly as without it; the offer gets no card", () => {
|
|
532
535
|
const result = mapped(withOffer());
|
|
533
536
|
expect(plansOf(result).map((c) => c.key)).toEqual(plansOf(mapped()).map((c) => c.key));
|
|
534
537
|
expect(addonsOf(result).map((t) => t.key)).toEqual(addonsOf(mapped()).map((t) => t.key));
|
|
@@ -594,10 +597,10 @@ describe("offeringsPricing — Stripe text stays text; every link is ours (AC-3)
|
|
|
594
597
|
priceSubhead: "noteone",
|
|
595
598
|
priceFootnote: "Terms",
|
|
596
599
|
});
|
|
597
|
-
expect(
|
|
600
|
+
expect(addonCard(result, "seo-audit")).toMatchObject({
|
|
598
601
|
name: "SEO audit",
|
|
599
602
|
features: ["Monthly report"],
|
|
600
|
-
|
|
603
|
+
priceUnit: "per site",
|
|
601
604
|
});
|
|
602
605
|
});
|
|
603
606
|
|
|
@@ -610,9 +613,11 @@ describe("offeringsPricing — Stripe text stays text; every link is ours (AC-3)
|
|
|
610
613
|
if (plan.annualCtaHref)
|
|
611
614
|
links.push({ plan: plan.key!, href: plan.annualCtaHref });
|
|
612
615
|
}
|
|
613
|
-
for (const t of addonsOf(result))
|
|
614
|
-
links.push({ plan: t.key
|
|
615
|
-
|
|
616
|
+
for (const t of addonsOf(result)) {
|
|
617
|
+
links.push({ plan: t.key!, href: t.cta.href });
|
|
618
|
+
if (t.annualCtaHref) links.push({ plan: t.key!, href: t.annualCtaHref });
|
|
619
|
+
}
|
|
620
|
+
expect(links).toHaveLength(7);
|
|
616
621
|
|
|
617
622
|
for (const { plan, href } of links) {
|
|
618
623
|
const match = /^\/api\/offerings\/checkout\/(.+)$/.exec(href);
|
|
@@ -709,8 +714,12 @@ describe("offeringsPricing — no copy of its own (AC-7)", () => {
|
|
|
709
714
|
if (plan.annualPriceNote) visible.push(plan.annualPriceNote);
|
|
710
715
|
}
|
|
711
716
|
for (const t of addonsOf(result)) {
|
|
712
|
-
visible.push(
|
|
717
|
+
visible.push(
|
|
718
|
+
t.cta.label,
|
|
719
|
+
...Object.values(t.price).filter((p): p is string => p !== undefined),
|
|
720
|
+
);
|
|
713
721
|
if (t.eyebrow) visible.push(t.eyebrow);
|
|
722
|
+
if (t.annualPriceNote) visible.push(t.annualPriceNote);
|
|
714
723
|
}
|
|
715
724
|
for (const text of visible) expect(text).toContain("⟪");
|
|
716
725
|
|
|
@@ -758,7 +767,7 @@ describe("offeringsPricing — an offering page's `plans` (#10044 D4, AC-3)", ()
|
|
|
758
767
|
);
|
|
759
768
|
});
|
|
760
769
|
|
|
761
|
-
it("keeps only the listed plan card and the listed add-on
|
|
770
|
+
it("keeps only the listed plan card and the listed add-on card", () => {
|
|
762
771
|
const result = narrowed(shownSet(), ["growth", "audit-pack"]);
|
|
763
772
|
expect(plansOf(result).map((p) => p.key)).toEqual(["growth"]);
|
|
764
773
|
expect(addonsOf(result).map((a) => a.key)).toEqual(["audit-pack"]);
|
|
@@ -846,7 +855,7 @@ describe("offeringsPricing — the seller's button label (#12103 D1, AC-1)", ()
|
|
|
846
855
|
expect(card(result, "growth").cta?.label).toBe(LABELS.cta);
|
|
847
856
|
});
|
|
848
857
|
|
|
849
|
-
it("labels an add-on
|
|
858
|
+
it("labels an add-on card and a bundle card with their own ctaLabel, the bundle href unchanged", () => {
|
|
850
859
|
const result = mapped(
|
|
851
860
|
set([
|
|
852
861
|
product("retainer", "plan", monthly("retainer")),
|
|
@@ -861,7 +870,7 @@ describe("offeringsPricing — the seller's button label (#12103 D1, AC-1)", ()
|
|
|
861
870
|
label: "Start the bundle",
|
|
862
871
|
href: offeringsBundleHref("setup_once", "retainer_monthly"),
|
|
863
872
|
});
|
|
864
|
-
expect(
|
|
873
|
+
expect(addonCard(result, "seo").cta?.label).toBe("Add it");
|
|
865
874
|
});
|
|
866
875
|
|
|
867
876
|
it("removes a right-to-left override from the label and renders it as the button's text, linking the checkout path", () => {
|
|
@@ -898,18 +907,18 @@ describe("offeringsPricing — the add-on eyebrow and note (#12103 D5, AC-4)", (
|
|
|
898
907
|
});
|
|
899
908
|
}
|
|
900
909
|
|
|
901
|
-
it("maps the eyebrow, the note and the unit label to their own
|
|
902
|
-
expect(
|
|
910
|
+
it("maps the eyebrow, the note and the unit label to their own card fields", () => {
|
|
911
|
+
expect(addonCard(mapped(set([seo({})])), "seo")).toMatchObject({
|
|
903
912
|
eyebrow: "No retainer",
|
|
904
|
-
|
|
905
|
-
|
|
913
|
+
priceSubhead: "Per piece.",
|
|
914
|
+
priceUnit: "piece",
|
|
906
915
|
});
|
|
907
916
|
});
|
|
908
917
|
|
|
909
918
|
it("keeps the Recommended label as the recommended add-on's eyebrow, its note kept", () => {
|
|
910
|
-
expect(
|
|
919
|
+
expect(addonCard(mapped(set([seo({ recommended: true })])), "seo")).toMatchObject({
|
|
911
920
|
eyebrow: LABELS.recommended,
|
|
912
|
-
|
|
921
|
+
priceSubhead: "Per piece.",
|
|
913
922
|
});
|
|
914
923
|
});
|
|
915
924
|
|
|
@@ -919,15 +928,15 @@ describe("offeringsPricing — the add-on eyebrow and note (#12103 D5, AC-4)", (
|
|
|
919
928
|
expect(card(result, "growth")).not.toHaveProperty("note");
|
|
920
929
|
});
|
|
921
930
|
|
|
922
|
-
it("emits neither field on a
|
|
923
|
-
const t =
|
|
931
|
+
it("emits neither field on a card whose product carries none", () => {
|
|
932
|
+
const t = addonCard(mapped(), "audit-pack");
|
|
924
933
|
expect(t).not.toHaveProperty("eyebrow");
|
|
925
|
-
expect(t).not.toHaveProperty("
|
|
934
|
+
expect(t).not.toHaveProperty("priceSubhead");
|
|
926
935
|
});
|
|
927
936
|
});
|
|
928
937
|
|
|
929
938
|
describe("offeringsPricing — exclude (#12103 D2)", () => {
|
|
930
|
-
it("drops the excluded plans' cards and keeps every add-on
|
|
939
|
+
it("drops the excluded plans' cards and keeps every add-on card", () => {
|
|
931
940
|
const result = offeringsPricing(shownSet(), { ...OPTIONS, exclude: ["growth"] })!;
|
|
932
941
|
expect(plansOf(result).map((c) => c.key)).toEqual(["starter", "basic"]);
|
|
933
942
|
expect(addonsOf(result).map((t) => t.key)).toEqual(["seo-audit", "audit-pack"]);
|
|
@@ -1070,7 +1079,6 @@ describe("offeringsPricing — the terms note of a both-prices card is annual-on
|
|
|
1070
1079
|
|
|
1071
1080
|
const LAYOUTS = [
|
|
1072
1081
|
"three-tiers-with-toggle",
|
|
1073
|
-
"with-comparison-table",
|
|
1074
1082
|
"two-tiers-with-extra-tier",
|
|
1075
1083
|
"single-price-with-details",
|
|
1076
1084
|
"features-and-plans",
|
|
@@ -1084,7 +1092,7 @@ describe("offeringsPricing — one mapping per layout (#12140 D3, AC-1)", () =>
|
|
|
1084
1092
|
);
|
|
1085
1093
|
});
|
|
1086
1094
|
|
|
1087
|
-
it.each(["
|
|
1095
|
+
it.each(["two-tiers-with-extra-tier", "band-hero"] as const)(
|
|
1088
1096
|
"%s: centred cards, no billing toggle",
|
|
1089
1097
|
(layout) => {
|
|
1090
1098
|
const result = offeringsPricing(shownSet(), { ...OPTIONS, layout })!;
|
|
@@ -1096,10 +1104,11 @@ describe("offeringsPricing — one mapping per layout (#12140 D3, AC-1)", () =>
|
|
|
1096
1104
|
},
|
|
1097
1105
|
);
|
|
1098
1106
|
|
|
1099
|
-
it("single-price-with-details: the first card only, no card layout and
|
|
1107
|
+
it("single-price-with-details: the first card only, no card layout, and a toggle only when that card has both periods (#12241 D5)", () => {
|
|
1100
1108
|
const result = offeringsPricing(shownSet(), { ...OPTIONS, layout: "single-price-with-details" })!;
|
|
1101
1109
|
expect(result.plans).toStrictEqual({
|
|
1102
1110
|
variant: "single-price-with-details",
|
|
1111
|
+
billingToggle: false,
|
|
1103
1112
|
plans: [plansOf(mapped())[0]],
|
|
1104
1113
|
});
|
|
1105
1114
|
expect(result.plans!.plans[0]!.key).toBe("starter");
|
|
@@ -1198,7 +1207,7 @@ describe("offeringsPricing — no layout names a vendor; every link is ours (#12
|
|
|
1198
1207
|
expect(JSON.stringify(result)).not.toMatch(/stripe/i);
|
|
1199
1208
|
const links = [
|
|
1200
1209
|
...plansOf(result).flatMap((c) => [c.cta.href, ...(c.annualCtaHref ? [c.annualCtaHref] : [])]),
|
|
1201
|
-
...addonsOf(result).
|
|
1210
|
+
...addonsOf(result).flatMap((t) => [t.cta.href, ...(t.annualCtaHref ? [t.annualCtaHref] : [])]),
|
|
1202
1211
|
];
|
|
1203
1212
|
expect(links.length).toBeGreaterThan(0);
|
|
1204
1213
|
for (const href of links) expect(href.startsWith(OFFERINGS_CHECKOUT_PATH)).toBe(true);
|
|
@@ -1459,8 +1468,8 @@ describe("offeringsPricing — ailk_name titles a card (#12193 D5 rule 3, D6, AC
|
|
|
1459
1468
|
expect(offering(set, "essentials").name).toBe("Content Factory - Essentials");
|
|
1460
1469
|
});
|
|
1461
1470
|
|
|
1462
|
-
it("titles an add-on
|
|
1463
|
-
expect(
|
|
1471
|
+
it("titles an add-on card by its short name", () => {
|
|
1472
|
+
expect(addonCard(offeringsPricing(tierSet(), OPTIONS)!, "seo").name).toBe("SEO");
|
|
1464
1473
|
});
|
|
1465
1474
|
});
|
|
1466
1475
|
|
|
@@ -1539,17 +1548,18 @@ describe("offeringsPricing — the contact card (#12193 D5 rule 7, AC-5, AC-6)",
|
|
|
1539
1548
|
});
|
|
1540
1549
|
});
|
|
1541
1550
|
|
|
1542
|
-
describe("offeringsPricing — the add-on contact
|
|
1543
|
-
it("an add-ons collection shows the add-on and the contact
|
|
1551
|
+
describe("offeringsPricing — the add-on contact card (#12193 AC-7, #12241 D3)", () => {
|
|
1552
|
+
it("an add-ons collection shows the add-on and the contact card with its display price, label and link", () => {
|
|
1544
1553
|
const addons = addonsOf(tiers(tierSet(), { collection: "growth-hub" }));
|
|
1545
1554
|
expect(addons.map((t) => t.key)).toEqual(["seo", "commerce"]);
|
|
1546
1555
|
expect(addons[0]!.name).toBe("SEO");
|
|
1547
1556
|
expect(addons[1]).toEqual({
|
|
1548
1557
|
key: "commerce",
|
|
1549
1558
|
name: "Commerce",
|
|
1550
|
-
price: "From 179 USD a month",
|
|
1559
|
+
price: { custom: "From 179 USD a month" },
|
|
1551
1560
|
features: [],
|
|
1552
1561
|
cta: { label: "Talk to us", href: "/contact" },
|
|
1562
|
+
offerPrices: [],
|
|
1553
1563
|
});
|
|
1554
1564
|
});
|
|
1555
1565
|
});
|
|
@@ -1827,12 +1837,13 @@ describe("offeringsPricing — changing points changes the amount and the link o
|
|
|
1827
1837
|
annualCtaHref: _a,
|
|
1828
1838
|
annualPriceNote: _n,
|
|
1829
1839
|
offerPrices: _o,
|
|
1840
|
+
priceParts: _pp,
|
|
1830
1841
|
key: _k,
|
|
1831
1842
|
label: _l,
|
|
1832
1843
|
detail: _d,
|
|
1833
1844
|
cta,
|
|
1834
1845
|
...fields
|
|
1835
|
-
} = level as typeof level & { offerPrices?: unknown };
|
|
1846
|
+
} = level as typeof level & { offerPrices?: unknown; priceParts?: unknown };
|
|
1836
1847
|
return { ...fields, cta: { label: cta.label } };
|
|
1837
1848
|
});
|
|
1838
1849
|
expect(rest[1]).toEqual(rest[0]);
|
|
@@ -2016,3 +2027,575 @@ describe("price points under offeringGroups and in a long tier (#12210 D6 rules
|
|
|
2016
2027
|
expect(card.levelSwitchControl).toBe("select");
|
|
2017
2028
|
});
|
|
2018
2029
|
});
|
|
2030
|
+
|
|
2031
|
+
// ─── #12238 — a collection of contacts, and a contact named by its slug ─────
|
|
2032
|
+
|
|
2033
|
+
describe("offeringsPricing — a collection whose only members are contacts (#12238)", () => {
|
|
2034
|
+
/** `tierSet()` with no priced product: the two contacts alone, both of `growth-hub`. */
|
|
2035
|
+
const contactsOnly = () =>
|
|
2036
|
+
tierSet((o, c) => {
|
|
2037
|
+
o.length = 0;
|
|
2038
|
+
for (const contact of c) contact.collection = "growth-hub";
|
|
2039
|
+
});
|
|
2040
|
+
|
|
2041
|
+
it("maps the plan contact to a card and the add-on contact to a tile, with no priced product shown", () => {
|
|
2042
|
+
const result = tiers(contactsOnly(), { collection: "growth-hub" });
|
|
2043
|
+
expect(plansOf(result).map((c) => c.key)).toEqual(["enterprise"]);
|
|
2044
|
+
expect(card(result, "enterprise")).toMatchObject({ name: "Enterprise", cta: { label: "Book a call", href: "/meet?x=1" } });
|
|
2045
|
+
expect(addonsOf(result).map((t) => t.key)).toEqual(["commerce"]);
|
|
2046
|
+
});
|
|
2047
|
+
|
|
2048
|
+
it("is null for the page-level mapping, which shows no contact", () => {
|
|
2049
|
+
expect(offeringsPricing(contactsOnly(), OPTIONS)).toBeNull();
|
|
2050
|
+
});
|
|
2051
|
+
});
|
|
2052
|
+
|
|
2053
|
+
describe("offeringsPricing — contactPlans names a contact by its slug (#12238, operator 2026-11-23)", () => {
|
|
2054
|
+
it("a named plan contact is a card after the named plans, and a named add-on contact a tile", () => {
|
|
2055
|
+
const result = offeringsPricing(tierSet(), {
|
|
2056
|
+
...OPTIONS,
|
|
2057
|
+
...SITE,
|
|
2058
|
+
plans: ["essentials", "enterprise", "commerce"],
|
|
2059
|
+
contactPlans: ["essentials", "enterprise", "commerce"],
|
|
2060
|
+
})!;
|
|
2061
|
+
expect(plansOf(result).map((c) => c.key)).toEqual(["essentials", "enterprise"]);
|
|
2062
|
+
expect(card(result, "enterprise")).toMatchObject({ name: "Enterprise", price: { custom: "C⟪" }, offerPrices: [] });
|
|
2063
|
+
expect(addonsOf(result).map((t) => t.key)).toEqual(["commerce"]);
|
|
2064
|
+
});
|
|
2065
|
+
|
|
2066
|
+
it("a contact it does not name stays out, and `plans` alone names no contact", () => {
|
|
2067
|
+
const keys = (extra: Record<string, unknown>) =>
|
|
2068
|
+
plansOf(offeringsPricing(tierSet(), { ...OPTIONS, ...SITE, plans: ["essentials", "enterprise"], ...extra })!).map((c) => c.key);
|
|
2069
|
+
expect(keys({ contactPlans: ["essentials"] })).toEqual(["essentials"]);
|
|
2070
|
+
expect(keys({})).toEqual(["essentials"]);
|
|
2071
|
+
});
|
|
2072
|
+
|
|
2073
|
+
it("a collection wins: contactPlans is not read beside it", () => {
|
|
2074
|
+
// `growth-hub` holds no plan, so the named plan contact gives no plans fragment.
|
|
2075
|
+
const result = tiers(tierSet(), { collection: "growth-hub", contactPlans: ["enterprise"] });
|
|
2076
|
+
expect(result.plans).toBeNull();
|
|
2077
|
+
expect(addonsOf(result).map((t) => t.key)).toEqual(["seo", "commerce"]);
|
|
2078
|
+
});
|
|
2079
|
+
});
|
|
2080
|
+
|
|
2081
|
+
describe("offeringsPricing — a plan's footnote and its link (#12243)", () => {
|
|
2082
|
+
const LINK = { label: "Learn more", url: "https://example.com/onboarding?x=1#fee" };
|
|
2083
|
+
const noted = (set: WorkspaceShownSet, plans: string[], link: typeof LINK | undefined = LINK) => {
|
|
2084
|
+
for (const o of set.offerings) {
|
|
2085
|
+
if (!plans.includes(o.plan)) continue;
|
|
2086
|
+
o.footnote = "*Cost shown excludes onboarding.";
|
|
2087
|
+
if (link) o.footnoteLink = link;
|
|
2088
|
+
}
|
|
2089
|
+
return workspaceShownSetSchema.parse(set);
|
|
2090
|
+
};
|
|
2091
|
+
|
|
2092
|
+
it("puts it on the plan's card, its format characters stripped, the link after it", () => {
|
|
2093
|
+
const growth = card(mapped(noted(shownSet(), ["growth"])), "growth");
|
|
2094
|
+
expect(growth.footnote).toBe("*Cost shown excludes onboarding.");
|
|
2095
|
+
expect(growth.footnoteLink).toEqual({ label: "Learn more", href: "https://example.com/onboarding?x=1#fee" });
|
|
2096
|
+
});
|
|
2097
|
+
|
|
2098
|
+
it("a same-origin URL is an internal path, another origin's the full URL", () => {
|
|
2099
|
+
const set = noted(tierSet(), ["team-msg"]);
|
|
2100
|
+
expect(card(tiers(set, { collection: "growth-platform" }), "team-msg").footnoteLink).toEqual({
|
|
2101
|
+
label: "Learn more",
|
|
2102
|
+
href: "/onboarding?x=1#fee",
|
|
2103
|
+
});
|
|
2104
|
+
expect(
|
|
2105
|
+
card(tiers(set, { collection: "growth-platform", siteOrigin: "https://other.test" }), "team-msg").footnoteLink,
|
|
2106
|
+
).toEqual({ label: "Learn more", href: "https://example.com/onboarding?x=1#fee" });
|
|
2107
|
+
});
|
|
2108
|
+
|
|
2109
|
+
it.each([
|
|
2110
|
+
["a same-origin /api/ path", "https://example.com/api/offerings/checkout/a_monthly"],
|
|
2111
|
+
["a percent-encoded /api/ path", "https://example.com/%61pi/offerings/checkout/a_monthly"],
|
|
2112
|
+
["a path that does not percent-decode", "https://example.com/%zz"],
|
|
2113
|
+
])("drops the link for %s and keeps the footnote as text alone", (_label, url) => {
|
|
2114
|
+
const set = noted(tierSet(), ["team-msg"], { label: "Learn more", url });
|
|
2115
|
+
const team = card(tiers(set, { collection: "growth-platform" }), "team-msg");
|
|
2116
|
+
expect(team.footnote).toBe("*Cost shown excludes onboarding.");
|
|
2117
|
+
expect(team).not.toHaveProperty("footnoteLink");
|
|
2118
|
+
});
|
|
2119
|
+
|
|
2120
|
+
it("a card without one keeps exactly its earlier fields", () => {
|
|
2121
|
+
const before = card(mapped(), "growth");
|
|
2122
|
+
expect(before).not.toHaveProperty("footnote");
|
|
2123
|
+
expect(before).not.toHaveProperty("footnoteLink");
|
|
2124
|
+
expect(card(mapped(noted(shownSet(), ["basic"])), "growth")).toEqual(before);
|
|
2125
|
+
});
|
|
2126
|
+
|
|
2127
|
+
it("a tier card takes its first level's footnote, as its other card fields", () => {
|
|
2128
|
+
const set = noted(tierSet(), ["ind-msg"]);
|
|
2129
|
+
const individual = plansOf(tiers(set, { collection: "growth-platform" }))[0]!;
|
|
2130
|
+
expect(individual.footnote).toBe("*Cost shown excludes onboarding.");
|
|
2131
|
+
expect(individual.levels!.some((l) => "footnote" in l)).toBe(false);
|
|
2132
|
+
});
|
|
2133
|
+
|
|
2134
|
+
it("an offeringGroups card takes its first level's footnote", () => {
|
|
2135
|
+
const set = noted(levelSet(), ["ind-msg"]);
|
|
2136
|
+
const grouped0 = plansOf(grouped(set)!)[0]!;
|
|
2137
|
+
expect(grouped0.footnote).toBe("*Cost shown excludes onboarding.");
|
|
2138
|
+
expect(grouped0.levels!.some((l) => "footnote" in l)).toBe(false);
|
|
2139
|
+
});
|
|
2140
|
+
|
|
2141
|
+
it("a bundle card takes the plan's own footnote", () => {
|
|
2142
|
+
const set = shownSet((s) => {
|
|
2143
|
+
s.offerings.push(
|
|
2144
|
+
product("build", "plan", [price("build", "once", 300000, "usd")], {
|
|
2145
|
+
requires: "growth",
|
|
2146
|
+
footnote: "*Balance on delivery.",
|
|
2147
|
+
}),
|
|
2148
|
+
);
|
|
2149
|
+
s.productIds = s.offerings.map((o) => o.productId);
|
|
2150
|
+
});
|
|
2151
|
+
expect(card(mapped(set), "build").footnote).toBe("*Balance on delivery.");
|
|
2152
|
+
});
|
|
2153
|
+
|
|
2154
|
+
it("a plan contact's card carries its footnote", () => {
|
|
2155
|
+
const set = tierSet((_o, c) => {
|
|
2156
|
+
c[0]!.footnote = "*Annual contract.";
|
|
2157
|
+
c[0]!.footnoteLink = { label: "Terms", url: "https://example.com/terms" };
|
|
2158
|
+
});
|
|
2159
|
+
const contact = card(tiers(set, { collection: "growth-platform" }), "enterprise");
|
|
2160
|
+
expect(contact.footnote).toBe("*Annual contract.");
|
|
2161
|
+
expect(contact.footnoteLink).toEqual({ label: "Terms", href: "/terms" });
|
|
2162
|
+
});
|
|
2163
|
+
|
|
2164
|
+
it("the section schema accepts the cards and the tier card renders the footnote and its link", () => {
|
|
2165
|
+
const result = mapped(noted(shownSet(), ["growth"]));
|
|
2166
|
+
expect(PricingSectionDataSchema.safeParse(result.plans).success).toBe(true);
|
|
2167
|
+
const { getByTestId } = render(
|
|
2168
|
+
React.createElement(Pricing, { sectionName: "pricing", data: result.plans! } as Parameters<typeof Pricing>[0]),
|
|
2169
|
+
);
|
|
2170
|
+
expect(getByTestId("tier-footnote")).toHaveTextContent("*Cost shown excludes onboarding. Learn more");
|
|
2171
|
+
});
|
|
2172
|
+
});
|
|
2173
|
+
|
|
2174
|
+
// ─── #12239 — a Stripe price can be marked not public ─────────────────────────
|
|
2175
|
+
//
|
|
2176
|
+
// End-of-chain evidence only: the normalizer leaves a not-public Price out of
|
|
2177
|
+
// the shown set (packages/api's catalog and wire suites), so the mapper — which
|
|
2178
|
+
// is unchanged — sees the one-point product and draws a plain card.
|
|
2179
|
+
|
|
2180
|
+
describe("offeringsPricing — a product left with one public price is a plain card (#12239 AC-1, AC-4)", () => {
|
|
2181
|
+
it("the fixture's Growth card has no levels and no level control", () => {
|
|
2182
|
+
const growth = card(mapped(), "growth");
|
|
2183
|
+
expect(growth).not.toHaveProperty("levels");
|
|
2184
|
+
expect(growth).not.toHaveProperty("levelSwitchControl");
|
|
2185
|
+
});
|
|
2186
|
+
|
|
2187
|
+
it("the shape the pin's normalizer wrote for an unmarked partner Price is a level card, so the plain card is the filter's", () => {
|
|
2188
|
+
const set = shownSet((s) => {
|
|
2189
|
+
const growth = s.offerings.find((o) => o.plan === "growth")!;
|
|
2190
|
+
growth.plan = "growth-partner";
|
|
2191
|
+
growth.prices = [{ ...price("growth-partner", "monthly", 2900, "usd"), label: "Partner" }, ...growth.prices];
|
|
2192
|
+
});
|
|
2193
|
+
const growth = plansOf(mapped(set)).find((c) => c.levels?.some((l) => l.key === "growth-partner"));
|
|
2194
|
+
expect(growth).toBeDefined();
|
|
2195
|
+
expect(growth!.levels!.map((l) => l.key)).toEqual(["growth-partner", "growth"]);
|
|
2196
|
+
});
|
|
2197
|
+
|
|
2198
|
+
it("one public monthly Price, its not-public siblings left out upstream, maps to one plain card", () => {
|
|
2199
|
+
const set = shownSet((s) => {
|
|
2200
|
+
s.offerings = [product("growth", "plan", [price("growth", "monthly", 4900, "usd")])];
|
|
2201
|
+
s.productIds = ["prod_growth"];
|
|
2202
|
+
s.recommended = { plan: null, addon: null };
|
|
2203
|
+
});
|
|
2204
|
+
const cards = plansOf(mapped(set));
|
|
2205
|
+
expect(cards.map((c) => c.key)).toEqual(["growth"]);
|
|
2206
|
+
expect(cards[0]).not.toHaveProperty("levels");
|
|
2207
|
+
expect(cards[0]).not.toHaveProperty("levelSwitchControl");
|
|
2208
|
+
});
|
|
2209
|
+
});
|
|
2210
|
+
|
|
2211
|
+
// ─── #12246 — a comparison table's plan columns (spec 12246 D3, AC-1, AC-4) ──
|
|
2212
|
+
|
|
2213
|
+
describe("offeringsPlanColumns — a plan column's facts, from the shown set (#12246 D3)", () => {
|
|
2214
|
+
const S3_LABELS: OfferingsPricingLabels = {
|
|
2215
|
+
...LABELS,
|
|
2216
|
+
monthly: (amount) => amount + "/mo",
|
|
2217
|
+
annual: (amount) => amount + "/yr",
|
|
2218
|
+
};
|
|
2219
|
+
const S3_OPTIONS = { locale: "en-US", labels: S3_LABELS };
|
|
2220
|
+
const both = (plan: string, monthly: number, yearly: number) => [
|
|
2221
|
+
price(plan, "monthly", monthly, "usd"),
|
|
2222
|
+
price(plan, "yearly", yearly, "usd"),
|
|
2223
|
+
];
|
|
2224
|
+
function s3(edit: (offerings: OfferingsProduct[]) => void = () => {}): WorkspaceShownSet {
|
|
2225
|
+
const offerings = [
|
|
2226
|
+
product("essentials", "plan", both("essentials", 220000, 2376000)),
|
|
2227
|
+
product("growth", "plan", both("growth", 440000, 4752000), {
|
|
2228
|
+
shortName: "Growth",
|
|
2229
|
+
name: "Growth plan",
|
|
2230
|
+
recommended: true,
|
|
2231
|
+
}),
|
|
2232
|
+
product("scale", "plan", both("scale", 650000, 7020000)),
|
|
2233
|
+
product("extra", "addon", [price("extra", "monthly", 9900, "usd")]),
|
|
2234
|
+
];
|
|
2235
|
+
edit(offerings);
|
|
2236
|
+
return shownSet((set) => {
|
|
2237
|
+
set.offerings = offerings;
|
|
2238
|
+
set.productIds = offerings.map((o) => o.productId);
|
|
2239
|
+
set.recommended = { plan: "prod_growth", addon: null };
|
|
2240
|
+
});
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
it("AC-1: maps exactly the shown plan slugs, each as its card would show it", () => {
|
|
2244
|
+
const columns = offeringsPlanColumns(s3(), ["growth", "extra", "ghost"], S3_OPTIONS);
|
|
2245
|
+
expect([...columns.keys()]).toEqual(["growth"]);
|
|
2246
|
+
expect(columns.get("growth")).toEqual({
|
|
2247
|
+
name: "Growth",
|
|
2248
|
+
price: { monthly: "$4,400/mo", annual: "$3,960/mo" },
|
|
2249
|
+
cta: { label: LABELS.cta, href: `${OFFERINGS_CHECKOUT_PATH}/growth_monthly` },
|
|
2250
|
+
annualCtaHref: `${OFFERINGS_CHECKOUT_PATH}/growth_yearly`,
|
|
2251
|
+
recommended: true,
|
|
2252
|
+
});
|
|
2253
|
+
});
|
|
2254
|
+
|
|
2255
|
+
it("marks only the shown set's first Recommended plan, and reads no page plans", () => {
|
|
2256
|
+
const columns = offeringsPlanColumns(s3(), ["essentials", "growth", "scale"], S3_OPTIONS);
|
|
2257
|
+
expect([...columns.keys()]).toEqual(["essentials", "growth", "scale"]);
|
|
2258
|
+
expect([...columns.values()].filter((c) => c.recommended).map((c) => c.name)).toEqual(["Growth"]);
|
|
2259
|
+
expect(columns.get("essentials")).not.toHaveProperty("recommended");
|
|
2260
|
+
});
|
|
2261
|
+
|
|
2262
|
+
it("AC-4: resolves nothing from a set that is not current, or does not parse", () => {
|
|
2263
|
+
const stale = { ...s3(), state: "expired" };
|
|
2264
|
+
expect(offeringsPlanColumns(stale, ["growth"], S3_OPTIONS).size).toBe(0);
|
|
2265
|
+
expect(offeringsPlanColumns({ nope: true }, ["growth"], S3_OPTIONS).size).toBe(0);
|
|
2266
|
+
});
|
|
2267
|
+
|
|
2268
|
+
it("gives a price point its own price, and a bundle its bundle card's", () => {
|
|
2269
|
+
const set = s3((offerings) => {
|
|
2270
|
+
offerings.push(
|
|
2271
|
+
product("writer-4", "plan", [price("writer-4", "monthly", 40000, "usd"), price("writer-8", "monthly", 80000, "usd")], {
|
|
2272
|
+
name: "Writer",
|
|
2273
|
+
}),
|
|
2274
|
+
product("setup", "plan", [price("setup", "once", 50000, "usd")], { name: "Setup", requires: "retainer" }),
|
|
2275
|
+
product("retainer", "plan", [price("retainer", "monthly", 10000, "usd")], { name: "Retainer" }),
|
|
2276
|
+
);
|
|
2277
|
+
});
|
|
2278
|
+
const columns = offeringsPlanColumns(set, ["writer-4", "writer-8", "setup", "retainer"], S3_OPTIONS);
|
|
2279
|
+
expect(columns.get("writer-4")?.price.monthly).toBe("$400/mo");
|
|
2280
|
+
expect(columns.get("writer-8")?.price.monthly).toBe("$800/mo");
|
|
2281
|
+
expect(columns.get("writer-8")?.cta.href).toBe(`${OFFERINGS_CHECKOUT_PATH}/writer-8_monthly`);
|
|
2282
|
+
expect(columns.get("setup")?.cta.href).toBe(offeringsBundleHref("setup_once", "retainer_monthly"));
|
|
2283
|
+
expect(columns.has("retainer")).toBe(false);
|
|
2284
|
+
});
|
|
2285
|
+
});
|
|
2286
|
+
|
|
2287
|
+
// ─── #12241 — one pricing card for plans and add-ons ─────────────────────────
|
|
2288
|
+
|
|
2289
|
+
/** The spec's `ADDON_SET` (§ 5): `seo-audit` with a description and an eyebrow. */
|
|
2290
|
+
function addonSet(): WorkspaceShownSet {
|
|
2291
|
+
return shownSet((set) => {
|
|
2292
|
+
const seo = offering(set, "seo-audit");
|
|
2293
|
+
seo.description = "Audit desc";
|
|
2294
|
+
seo.eyebrow = "New";
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
describe("offeringsPricing — add-ons are cards (#12241 D3, AC-1)", () => {
|
|
2299
|
+
it("AC-1 mapper: one card per add-on, its description kept, and no `addons` key", () => {
|
|
2300
|
+
const addons = offeringsPricing(addonSet(), OPTIONS)!.addons!;
|
|
2301
|
+
expect(addons.plans.map((c) => c.key)).toEqual(["seo-audit", "audit-pack"]);
|
|
2302
|
+
expect(addons.plans.find((c) => c.key === "seo-audit")!.description).toBe("Audit desc");
|
|
2303
|
+
expect(addons).not.toHaveProperty("addons");
|
|
2304
|
+
expect(PricingSectionDataSchema.safeParse(addons).success).toBe(true);
|
|
2305
|
+
});
|
|
2306
|
+
});
|
|
2307
|
+
|
|
2308
|
+
describe("offeringsPricing — a level's detail from its Price (#12241 D6, AC-5)", () => {
|
|
2309
|
+
it("AC-5 mapper: a tier level takes its first monthly Price's detail; the card carries none", () => {
|
|
2310
|
+
const set = shownSet((s) => {
|
|
2311
|
+
s.offerings = [
|
|
2312
|
+
product("duo-a", "plan", [{ ...price("duo-a", "monthly", 1000, "usd"), detail: "Under $2M" }, price("duo-a", "yearly", 9600, "usd")], {
|
|
2313
|
+
tier: "Duo",
|
|
2314
|
+
level: "Early",
|
|
2315
|
+
ailkOrder: 1,
|
|
2316
|
+
}),
|
|
2317
|
+
product("duo-b", "plan", [price("duo-b", "monthly", 2000, "usd")], { tier: "Duo", level: "Growth", ailkOrder: 2 }),
|
|
2318
|
+
];
|
|
2319
|
+
s.productIds = s.offerings.map((o) => o.productId);
|
|
2320
|
+
s.recommended = { plan: null, addon: null };
|
|
2321
|
+
});
|
|
2322
|
+
const duo = plansOf(tiers(set))[0]!;
|
|
2323
|
+
expect(duo.levels!.map((l) => l.label)).toEqual(["Early", "Growth"]);
|
|
2324
|
+
expect(duo.levels![0]!.detail).toBe("Under $2M");
|
|
2325
|
+
expect(duo.levels![1]).not.toHaveProperty("detail");
|
|
2326
|
+
expect(duo).not.toHaveProperty("detail");
|
|
2327
|
+
});
|
|
2328
|
+
|
|
2329
|
+
it("AC-5 mapper: a price point's own Price detail replaces its price phrase", () => {
|
|
2330
|
+
const set = writerSet(([w]) => [
|
|
2331
|
+
{ ...w!, prices: w!.prices.map((p) => (p.plan === "writer-4" ? { ...p, detail: "Early" } : p)) },
|
|
2332
|
+
]);
|
|
2333
|
+
const levels = plansOf(mapped(set))[0]!.levels!;
|
|
2334
|
+
expect(levels[0]!.detail).toBe("Early");
|
|
2335
|
+
expect(levels[1]!.detail).toBe(LABELS.monthly("$4,400"));
|
|
2336
|
+
});
|
|
2337
|
+
});
|
|
2338
|
+
|
|
2339
|
+
describe("offeringsPricing — Stripe's images ride the card (#12241 D8, AC-8)", () => {
|
|
2340
|
+
it("AC-8 mapper: a product's images become the card's images, each described by the card title", () => {
|
|
2341
|
+
const set = shownSet((s) => {
|
|
2342
|
+
const growth = offering(s, "growth");
|
|
2343
|
+
growth.shortName = "Grow";
|
|
2344
|
+
growth.images = ["https://files.example.com/a.png", "https://files.example.com/b.png"];
|
|
2345
|
+
});
|
|
2346
|
+
// A render-time field, outside the stored section type (as `offerPrices` is).
|
|
2347
|
+
expect((card(mapped(set), "growth") as { images?: unknown }).images).toEqual([
|
|
2348
|
+
{ src: "https://files.example.com/a.png", alt: "Grow" },
|
|
2349
|
+
{ src: "https://files.example.com/b.png", alt: "Grow" },
|
|
2350
|
+
]);
|
|
2351
|
+
expect(card(mapped(), "growth")).not.toHaveProperty("images");
|
|
2352
|
+
});
|
|
2353
|
+
});
|
|
2354
|
+
|
|
2355
|
+
describe("offeringsPricing — checkout and the recommended add-on as before (#12241 AC-12)", () => {
|
|
2356
|
+
it("AC-12 mapper: each add-on card links its own checkout; the recommended one keeps its eyebrow and is not highlighted", () => {
|
|
2357
|
+
const result = mapped(shownSet());
|
|
2358
|
+
const seo = addonCard(result, "seo-audit");
|
|
2359
|
+
expect(seo.cta.href).toBe("/api/offerings/checkout/seo-audit_monthly");
|
|
2360
|
+
expect(seo.eyebrow).toBe(LABELS.recommended);
|
|
2361
|
+
expect(seo).not.toHaveProperty("highlighted");
|
|
2362
|
+
const pack = addonCard(result, "audit-pack");
|
|
2363
|
+
expect(pack.cta.href).toBe("/api/offerings/checkout/audit-pack_monthly");
|
|
2364
|
+
expect(pack.annualCtaHref).toBe("/api/offerings/checkout/audit-pack_yearly");
|
|
2365
|
+
});
|
|
2366
|
+
|
|
2367
|
+
it("AC-12 mapper: an add-on contact's card has no checkout link", () => {
|
|
2368
|
+
const commerce = addonCard(tiers(tierSet(), { collection: "growth-hub" }), "commerce");
|
|
2369
|
+
expect(JSON.stringify(commerce)).not.toContain(OFFERINGS_CHECKOUT_PATH);
|
|
2370
|
+
expect(commerce).not.toHaveProperty("annualCtaHref");
|
|
2371
|
+
});
|
|
2372
|
+
});
|
|
2373
|
+
|
|
2374
|
+
describe("offeringsPricing — the single card follows the toggle (#12241 D5, AC-14)", () => {
|
|
2375
|
+
it("AC-14 mapper: single-price-with-details over a both-periods plan carries billingToggle: true", () => {
|
|
2376
|
+
expect(
|
|
2377
|
+
offeringsPricing(shownSet(), { ...OPTIONS, plans: ["growth"], layout: "single-price-with-details" })!.plans,
|
|
2378
|
+
).toHaveProperty("billingToggle", true);
|
|
2379
|
+
});
|
|
2380
|
+
});
|
|
2381
|
+
|
|
2382
|
+
// #12242 — the price on a Stripe-built card: amount and unit as two elements,
|
|
2383
|
+
// the unit joined by the site's one pattern, and the yearly-line and strike
|
|
2384
|
+
// options of a bound section.
|
|
2385
|
+
describe("price parts (#12242)", () => {
|
|
2386
|
+
const messages = jest.requireActual<{ pricingOfferings: Record<string, string> }>("../../messages/en.json");
|
|
2387
|
+
const m = messages.pricingOfferings;
|
|
2388
|
+
/** The shipped English words, built as `offeringsCopy` builds them. */
|
|
2389
|
+
const ENGLISH: OfferingsPricingLabels = {
|
|
2390
|
+
cta: m.cta!,
|
|
2391
|
+
recommended: m.recommended!,
|
|
2392
|
+
monthly: (amount) => m.monthly!.replace("{amount}", () => amount),
|
|
2393
|
+
annual: (amount) => m.annual!.replace("{amount}", () => amount),
|
|
2394
|
+
oneTime: (amount) => m.oneTime!.replace("{amount}", () => amount),
|
|
2395
|
+
withRequired: (plan, required) => m.withRequired!.replace("{plan}", () => plan).replace("{required}", () => required),
|
|
2396
|
+
depositNote: (deposit) => m.depositNote!.replace("{deposit}", () => deposit),
|
|
2397
|
+
billedYearly: (amount) => m.billedYearly!.replace("{amount}", () => amount),
|
|
2398
|
+
custom: m.custom!,
|
|
2399
|
+
perMonth: m.perMonth!,
|
|
2400
|
+
perYear: m.perYear!,
|
|
2401
|
+
unitWithLabel: (period, label) => m.unitWithLabel!.replace("{period}", () => period).replace("{label}", () => label),
|
|
2402
|
+
savings: (percent) => m.savings!.replace("{percent}", () => percent),
|
|
2403
|
+
regularPrice: (regular, current) =>
|
|
2404
|
+
m.regularPrice!.replace("{regular}", () => regular).replace("{current}", () => current),
|
|
2405
|
+
};
|
|
2406
|
+
const seat = (yearly = 20000, extra: Partial<OfferingsProduct> = {}, yearlyCurrency = "usd") =>
|
|
2407
|
+
product(
|
|
2408
|
+
"positionary",
|
|
2409
|
+
"plan",
|
|
2410
|
+
[price("positionary", "monthly", 2000, "usd"), price("positionary", "yearly", yearly, yearlyCurrency)],
|
|
2411
|
+
{ unitLabel: "seat", ...extra },
|
|
2412
|
+
);
|
|
2413
|
+
const SEAT = seat();
|
|
2414
|
+
const SITE = product(
|
|
2415
|
+
"growth-hub",
|
|
2416
|
+
"plan",
|
|
2417
|
+
[price("growth-hub", "monthly", 2000, "usd"), price("growth-hub", "yearly", 20000, "usd")],
|
|
2418
|
+
{ unitLabel: "site" },
|
|
2419
|
+
);
|
|
2420
|
+
const BARE = product(
|
|
2421
|
+
"bare",
|
|
2422
|
+
"plan",
|
|
2423
|
+
[price("bare", "monthly", 2000, "usd"), price("bare", "yearly", 20000, "usd")],
|
|
2424
|
+
);
|
|
2425
|
+
const YEARLY_ONLY = product("positionary", "plan", [price("positionary", "yearly", 20000, "usd")], { unitLabel: "seat" });
|
|
2426
|
+
const setOf = (...offerings: OfferingsProduct[]) =>
|
|
2427
|
+
shownSet((set) => {
|
|
2428
|
+
set.offerings = offerings;
|
|
2429
|
+
set.productIds = offerings.map((o) => o.productId);
|
|
2430
|
+
set.recommended = { plan: null, addon: null };
|
|
2431
|
+
});
|
|
2432
|
+
const cardsOf = (offerings: OfferingsProduct[], extra: Partial<Parameters<typeof offeringsPricing>[1]> = {}) =>
|
|
2433
|
+
plansOf(offeringsPricing(setOf(...offerings), { ...OPTIONS, ...extra })!);
|
|
2434
|
+
const one = (p: OfferingsProduct, extra: Partial<Parameters<typeof offeringsPricing>[1]> = {}) => cardsOf([p], extra)[0]!;
|
|
2435
|
+
type WithParts = { priceParts?: { monthly?: Record<string, string>; annual?: Record<string, string> } };
|
|
2436
|
+
const partsOf = (c: object) => (c as WithParts).priceParts;
|
|
2437
|
+
|
|
2438
|
+
it("AC-1 — a Stripe card keeps its price phrases and gains the amount and unit apart", () => {
|
|
2439
|
+
const c = one(SEAT, { labels: ENGLISH });
|
|
2440
|
+
expect(c.price).toEqual({ monthly: "$20/mo", annual: "$17/mo" });
|
|
2441
|
+
expect(partsOf(c)).toEqual({
|
|
2442
|
+
monthly: { amount: "$20", unit: "/mo/seat" },
|
|
2443
|
+
annual: { amount: "$17", unit: "/mo/seat" },
|
|
2444
|
+
});
|
|
2445
|
+
});
|
|
2446
|
+
|
|
2447
|
+
it("AC-2 — both sides of a monthly-and-yearly product read the per-month unit; a yearly-only one the yearly unit", () => {
|
|
2448
|
+
expect(partsOf(one(SEAT))).toEqual({
|
|
2449
|
+
monthly: { amount: "$20", unit: "U⟪PM⟪⟫seat" },
|
|
2450
|
+
annual: { amount: "$17", unit: "U⟪PM⟪⟫seat" },
|
|
2451
|
+
});
|
|
2452
|
+
expect(partsOf(one(YEARLY_ONLY))).toEqual({ annual: { amount: "$200", unit: "U⟪PY⟪⟫seat" } });
|
|
2453
|
+
});
|
|
2454
|
+
|
|
2455
|
+
it("AC-9 — one pattern joins every product's noun; no noun reads the period alone", () => {
|
|
2456
|
+
const units = (labels: OfferingsPricingLabels) =>
|
|
2457
|
+
cardsOf([SEAT, SITE, BARE], { labels }).map((c) => partsOf(c)!.monthly!.unit);
|
|
2458
|
+
expect(units(ENGLISH)).toEqual(["/mo/seat", "/mo/site", "/mo"]);
|
|
2459
|
+
expect(units({ ...ENGLISH, unitWithLabel: (p, l) => p + " per " + l })).toEqual(["/mo per seat", "/mo per site", "/mo"]);
|
|
2460
|
+
expect(JSON.stringify(messages).match(/"unitWithLabel"/g)).toHaveLength(1);
|
|
2461
|
+
});
|
|
2462
|
+
|
|
2463
|
+
it("AC-10 — the card's priceUnit is the noun as Stripe holds it, and the unit uses it unchanged", () => {
|
|
2464
|
+
const c = one(seat(20000, { unitLabel: "Seat" }), { labels: ENGLISH });
|
|
2465
|
+
expect(c.priceUnit).toBe("Seat");
|
|
2466
|
+
expect(partsOf(c)!.monthly!.unit).toBe("/mo/Seat");
|
|
2467
|
+
const dollar = one(seat(20000, { unitLabel: "$& seat" }), { labels: ENGLISH });
|
|
2468
|
+
expect(partsOf(dollar)!.monthly!.unit).toBe("/mo/$& seat");
|
|
2469
|
+
});
|
|
2470
|
+
|
|
2471
|
+
it("AC-4 — the yearly line: billed by default, a savings percentage, or none", () => {
|
|
2472
|
+
expect(one(SEAT).annualPriceNote).toBe("B⟪$200");
|
|
2473
|
+
expect(one(SEAT, { annualLine: "billed" }).annualPriceNote).toBe("B⟪$200");
|
|
2474
|
+
expect(one(SEAT, { annualLine: "savings" }).annualPriceNote).toBe("S⟪17");
|
|
2475
|
+
expect(one(SEAT, { annualLine: "none" })).not.toHaveProperty("annualPriceNote");
|
|
2476
|
+
expect(one(seat(24000), { annualLine: "savings" })).not.toHaveProperty("annualPriceNote");
|
|
2477
|
+
// 1 − 20280 ÷ 24000 = 15.5 % → 16; the rounded $17 per month would give 15.
|
|
2478
|
+
expect(one(seat(20280), { annualLine: "savings" }).annualPriceNote).toBe("S⟪16");
|
|
2479
|
+
expect(one(seat(25000), { annualLine: "savings" })).not.toHaveProperty("annualPriceNote");
|
|
2480
|
+
expect(one(seat(20000, {}, "eur"), { annualLine: "savings" })).not.toHaveProperty("annualPriceNote");
|
|
2481
|
+
for (const annualLine of [undefined, "billed", "savings", "none"] as const)
|
|
2482
|
+
expect(one(YEARLY_ONLY, { annualLine })).not.toHaveProperty("annualPriceNote");
|
|
2483
|
+
expect(one(SEAT, { labels: ENGLISH, annualLine: "savings" }).annualPriceNote).toBe("Save 17% billed annually");
|
|
2484
|
+
});
|
|
2485
|
+
|
|
2486
|
+
it("AC-5 — the strike: the standard monthly price on the yearly side only, with both prices named", () => {
|
|
2487
|
+
const parts = partsOf(one(SEAT, { labels: ENGLISH, strikeMonthly: true }))!;
|
|
2488
|
+
expect(parts.annual).toEqual({ amount: "$17", unit: "/mo/seat", was: "$20", wasLabel: "Regular price $20, now $17" });
|
|
2489
|
+
expect(parts.monthly).not.toHaveProperty("was");
|
|
2490
|
+
expect(partsOf(one(seat(24000), { strikeMonthly: true }))!.annual).not.toHaveProperty("was");
|
|
2491
|
+
expect(partsOf(one(seat(20000, {}, "eur"), { strikeMonthly: true }))!.annual).not.toHaveProperty("was");
|
|
2492
|
+
expect(partsOf(one(SEAT))!.annual).not.toHaveProperty("was");
|
|
2493
|
+
});
|
|
2494
|
+
|
|
2495
|
+
it("AC-1 — each level carries its own parts", () => {
|
|
2496
|
+
const tier = (plan: string, amount: number, order: number) =>
|
|
2497
|
+
product(plan, "plan", [price(plan, "monthly", amount, "usd")], { tier: "Team", level: plan, ailkOrder: order });
|
|
2498
|
+
const [c] = cardsOf([tier("small", 2000, 1), tier("large", 4000, 2)], { tiers: true });
|
|
2499
|
+
expect(c!.levels!.map((l) => partsOf(l)!.monthly!.amount)).toEqual(["$20", "$40"]);
|
|
2500
|
+
expect(partsOf(c!)!.monthly!.amount).toBe("$20");
|
|
2501
|
+
});
|
|
2502
|
+
|
|
2503
|
+
it("AC-7 — the phrases and notes are today's; bundles, one-time cards and the split blocks carry no parts", () => {
|
|
2504
|
+
// The fixture's cards keep every phrase and note they had (the suite's other cases, unedited).
|
|
2505
|
+
expect(card(mapped(), "growth")).toMatchObject({ priceUnit: "per seat", annualPriceNote: "B⟪$490" });
|
|
2506
|
+
const once = product("build", "plan", [price("build", "once", 300000, "usd")]);
|
|
2507
|
+
expect(one(once)).not.toHaveProperty("priceParts");
|
|
2508
|
+
const bundle = product("rebuild", "plan", [price("rebuild", "once", 250000, "usd")], { requires: "positionary" });
|
|
2509
|
+
const bundleCard = cardsOf([bundle, SEAT]).find((c) => c.key === "rebuild")!;
|
|
2510
|
+
expect(bundleCard).not.toHaveProperty("priceParts");
|
|
2511
|
+
const blocks = offeringsPricing(setOf(SEAT), { ...OPTIONS, layout: "features-and-plans" })!.plans!.plans;
|
|
2512
|
+
for (const block of blocks) expect(block).not.toHaveProperty("priceParts");
|
|
2513
|
+
expect(PricingSectionDataSchema.safeParse(offeringsPricing(setOf(SEAT), OPTIONS)!.plans).success).toBe(true);
|
|
2514
|
+
});
|
|
2515
|
+
|
|
2516
|
+
describe("offeringsPlanColumns — the header price carries the unit (#12280)", () => {
|
|
2517
|
+
const columnsOf = (offerings: OfferingsProduct[], slug: string, labels: OfferingsPricingLabels = ENGLISH) =>
|
|
2518
|
+
offeringsPlanColumns(setOf(...offerings), [slug], { locale: "en-US", labels }).get(slug);
|
|
2519
|
+
|
|
2520
|
+
it("AC-1 — a unit label's column reads the card's amount and unit, joined as the card joins them", () => {
|
|
2521
|
+
expect(columnsOf([SEAT], "positionary")!.price).toEqual({ monthly: "$20 /mo/seat", annual: "$17 /mo/seat" });
|
|
2522
|
+
expect(columnsOf([SEAT], "positionary", { ...ENGLISH, unitWithLabel: (p, l) => p + " per " + l })!.price).toEqual({
|
|
2523
|
+
monthly: "$20 /mo per seat",
|
|
2524
|
+
annual: "$17 /mo per seat",
|
|
2525
|
+
});
|
|
2526
|
+
const yearly = columnsOf([YEARLY_ONLY], "positionary")!.price;
|
|
2527
|
+
expect(yearly.annual).toBe("$200 /yr/seat");
|
|
2528
|
+
const card = partsOf(one(YEARLY_ONLY, { labels: ENGLISH }))!.annual!;
|
|
2529
|
+
expect(yearly.annual).toBe(`${card["amount"]} ${card["unit"]}`);
|
|
2530
|
+
});
|
|
2531
|
+
|
|
2532
|
+
it("AC-2 — no unit label keeps today's header, word for word", () => {
|
|
2533
|
+
expect(columnsOf([BARE], "bare")!.price).toEqual({ monthly: "$20/mo", annual: "$17/mo" });
|
|
2534
|
+
expect(columnsOf([BARE], "bare")!.price).toEqual(one(BARE, { labels: ENGLISH }).price);
|
|
2535
|
+
expect(columnsOf([BARE], "bare", { ...ENGLISH, monthly: (a) => a + " per month" })!.price.monthly).toBe("$20 per month");
|
|
2536
|
+
expect(columnsOf([seat(20000, { unitLabel: "\u200B" })], "positionary")!.price).toEqual({
|
|
2537
|
+
monthly: "$20/mo",
|
|
2538
|
+
annual: "$17/mo",
|
|
2539
|
+
});
|
|
2540
|
+
const setup = product("setup", "plan", [price("setup", "once", 50000, "usd")], {
|
|
2541
|
+
requires: "retainer",
|
|
2542
|
+
unitLabel: "seat",
|
|
2543
|
+
});
|
|
2544
|
+
const retainer = product("retainer", "plan", [price("retainer", "monthly", 10000, "usd")], { unitLabel: "seat" });
|
|
2545
|
+
const bundle = cardsOf([setup, retainer], { labels: ENGLISH }).find((c) => c.key === "setup")!;
|
|
2546
|
+
expect(columnsOf([setup, retainer], "setup")!.price).toEqual({ custom: bundle.price.custom });
|
|
2547
|
+
});
|
|
2548
|
+
|
|
2549
|
+
describe.each(["monthly", "annual"] as const)("AC-1, AC-3 — the rendered card and table (%s)", (period) => {
|
|
2550
|
+
const expected = period === "monthly" ? "$20 /mo/seat" : "$17 /mo/seat";
|
|
2551
|
+
function renderBoth() {
|
|
2552
|
+
const plans = offeringsPricing(setOf(SEAT), { ...OPTIONS, labels: ENGLISH })!.plans!;
|
|
2553
|
+
const card = render(
|
|
2554
|
+
React.createElement(Pricing, {
|
|
2555
|
+
sectionName: "pricing",
|
|
2556
|
+
data: { ...plans, billingPeriod: period },
|
|
2557
|
+
} as Parameters<typeof Pricing>[0]),
|
|
2558
|
+
);
|
|
2559
|
+
const cardLine = card.getByTestId("tier-price-unit").parentElement!.textContent;
|
|
2560
|
+
card.unmount();
|
|
2561
|
+
const offering = columnsOf([SEAT], "positionary")!;
|
|
2562
|
+
// `offering` and `billingPeriod` are render-time fields, as `withPlanColumns` sets them.
|
|
2563
|
+
const section: PageSection = {
|
|
2564
|
+
type: "comparison-table",
|
|
2565
|
+
id: "compare",
|
|
2566
|
+
data: {
|
|
2567
|
+
columns: [
|
|
2568
|
+
{ key: "us", name: "Us" },
|
|
2569
|
+
{ key: "positionary", plan: "positionary", offering },
|
|
2570
|
+
],
|
|
2571
|
+
groups: [{ groupName: "Basics", rows: [{ featureName: "Seats", values: { us: true, positionary: true } }] }],
|
|
2572
|
+
planBar: { pickerLabel: "Plans", price: true },
|
|
2573
|
+
billingPeriod: period,
|
|
2574
|
+
} as Extract<PageSection, { type: "comparison-table" }>["data"],
|
|
2575
|
+
};
|
|
2576
|
+
const table = render(React.createElement(SectionRenderer, { sections: [section] }));
|
|
2577
|
+
return { cardLine, table };
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2580
|
+
it("the desktop header and the phone picker read the card's price line", () => {
|
|
2581
|
+
const { cardLine, table } = renderBoth();
|
|
2582
|
+
expect(cardLine).toBe(expected);
|
|
2583
|
+
const cell = table.getByTestId("plan-bar-cell-positionary");
|
|
2584
|
+
expect(within(cell).getByText(expected).tagName).toBe("SPAN");
|
|
2585
|
+
expect(table.queryByTestId("plan-bar-summary")).toBeNull();
|
|
2586
|
+
const picker = table.getByTestId("plan-bar-picker");
|
|
2587
|
+
fireEvent.click(within(picker).getByRole("radio", { name: "Positionary" }));
|
|
2588
|
+
expect(table.getByTestId("plan-bar-summary").textContent).toBe(cardLine);
|
|
2589
|
+
});
|
|
2590
|
+
|
|
2591
|
+
it("a typed column still shows no price", () => {
|
|
2592
|
+
const { table } = renderBoth();
|
|
2593
|
+
expect(table.getByTestId("plan-bar-cell-us").textContent).toBe("Us");
|
|
2594
|
+
const row = table.getByTestId("plan-bar-row");
|
|
2595
|
+
const seats = within(row).getAllByText(/seat/);
|
|
2596
|
+
const cell = table.getByTestId("plan-bar-cell-positionary");
|
|
2597
|
+
for (const el of seats) expect(cell).toContainElement(el);
|
|
2598
|
+
});
|
|
2599
|
+
});
|
|
2600
|
+
});
|
|
2601
|
+
});
|