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