create-ailk 0.46.4 → 0.46.6
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 +99 -8
- package/package.json +3 -3
- package/templates/apps/api/CLAUDE.md +6 -2
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +15 -0
- package/templates/apps/web/CLAUDE.md +28 -4
- package/templates/apps/web/app/[locale]/layout.tsx +4 -0
- package/templates/apps/web/lib/__tests__/grid-read.test.ts +212 -0
- package/templates/apps/web/lib/__tests__/hub-read.test.ts +90 -0
- package/templates/apps/web/lib/__tests__/in-page-blocks.test.ts +261 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +89 -2
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +210 -0
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +18 -1
- package/templates/apps/web/lib/grid-read.ts +115 -0
- package/templates/apps/web/lib/hub-read.ts +35 -0
- package/templates/apps/web/lib/in-page-blocks.ts +119 -0
- package/templates/apps/web/lib/in-page-magnet.ts +5 -24
- package/templates/apps/web/lib/offerings-pricing.ts +12 -1
- package/templates/apps/web/lib/pricing-page.ts +33 -2
- package/templates/apps/web/messages/en.json +14 -0
- package/versions.json +50 -50
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/hub-read.ts — the shared hub read (#8731), a leaf module since #12385.
|
|
3
|
+
*
|
|
4
|
+
* `grid-read.ts` once imported `sharedHubRead` from `in-page-magnet.ts`, and
|
|
5
|
+
* `pricing-page.ts` → `grid-read.ts` → `in-page-magnet.ts` →
|
|
6
|
+
* `contact.actions.ts` → `site-pages.config.tsx` → `pricing-page.ts` closed a
|
|
7
|
+
* cycle that stopped `next build` collecting page data. The read now lives
|
|
8
|
+
* here, importing no other apps/web module, and `in-page-magnet.ts`
|
|
9
|
+
* re-exports it under the same names.
|
|
10
|
+
*/
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
|
|
14
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
15
|
+
flows: { get: jest.fn() },
|
|
16
|
+
leads: { captureStatus: jest.fn() },
|
|
17
|
+
}));
|
|
18
|
+
jest.mock("@working-theory/site-pages/pages/contact/contact.actions", () => ({
|
|
19
|
+
captureLeadAction: jest.fn(),
|
|
20
|
+
}));
|
|
21
|
+
// eslint-disable-next-line no-restricted-syntax -- test-seam mock: a "use server" boundary in-page-magnet only binds
|
|
22
|
+
jest.mock("../newsletter.actions", () => ({
|
|
23
|
+
subscribeNewsletterAction: jest.fn(),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
import { HUB_READ_TTL_MS, sharedHubRead } from "../hub-read";
|
|
27
|
+
import * as inPageMagnet from "../in-page-magnet";
|
|
28
|
+
|
|
29
|
+
/** Every module specifier a source file names: static and dynamic imports, re-exports and requires. */
|
|
30
|
+
function specifiers(file: string): string[] {
|
|
31
|
+
const source = readFileSync(path.join(__dirname, "..", file), "utf8");
|
|
32
|
+
const found: string[] = [];
|
|
33
|
+
for (const match of source.matchAll(/(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)(["'`])([^"'`]+)\1/g)) {
|
|
34
|
+
found.push(match[2]!);
|
|
35
|
+
}
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe("hub-read.ts is a leaf (#12385)", () => {
|
|
40
|
+
// No package import either: the #12385 cycle ran through one
|
|
41
|
+
// (`@working-theory/site-pages`' contact actions read `site-pages.config.tsx`).
|
|
42
|
+
it("imports nothing at all", () => {
|
|
43
|
+
expect(specifiers("hub-read.ts")).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("in-page-magnet.ts re-exports the shared hub read under the same names (#12385)", () => {
|
|
48
|
+
it("exports the very same sharedHubRead and HUB_READ_TTL_MS", () => {
|
|
49
|
+
expect(inPageMagnet.sharedHubRead).toBe(sharedHubRead);
|
|
50
|
+
expect(inPageMagnet.HUB_READ_TTL_MS).toBe(HUB_READ_TTL_MS);
|
|
51
|
+
expect(HUB_READ_TTL_MS).toBe(15_000);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("sharedHubRead (#8731)", () => {
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
jest.useRealTimers();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("shares one in-flight read between concurrent calls", async () => {
|
|
61
|
+
const read = jest.fn(async () => "answer");
|
|
62
|
+
const [a, b] = await Promise.all([sharedHubRead("hub-read:concurrent", read), sharedHubRead("hub-read:concurrent", read)]);
|
|
63
|
+
expect([a, b]).toEqual(["answer", "answer"]);
|
|
64
|
+
expect(read).toHaveBeenCalledTimes(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("shares a null answer too, so a burst against an unreachable hub is one read", async () => {
|
|
68
|
+
const read = jest.fn(async () => null);
|
|
69
|
+
await sharedHubRead("hub-read:null", read);
|
|
70
|
+
await expect(sharedHubRead("hub-read:null", read)).resolves.toBeNull();
|
|
71
|
+
expect(read).toHaveBeenCalledTimes(1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("keeps each key's read apart", async () => {
|
|
75
|
+
await expect(sharedHubRead("hub-read:a", async () => "a")).resolves.toBe("a");
|
|
76
|
+
await expect(sharedHubRead("hub-read:b", async () => "b")).resolves.toBe("b");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("reads afresh once HUB_READ_TTL_MS has passed, and not before", async () => {
|
|
80
|
+
jest.useFakeTimers({ now: 1_000_000 });
|
|
81
|
+
const read = jest.fn(async () => "fresh");
|
|
82
|
+
await sharedHubRead("hub-read:ttl", read);
|
|
83
|
+
jest.setSystemTime(1_000_000 + HUB_READ_TTL_MS - 1);
|
|
84
|
+
await sharedHubRead("hub-read:ttl", read);
|
|
85
|
+
expect(read).toHaveBeenCalledTimes(1);
|
|
86
|
+
jest.setSystemTime(1_000_000 + HUB_READ_TTL_MS);
|
|
87
|
+
await sharedHubRead("hub-read:ttl", read);
|
|
88
|
+
expect(read).toHaveBeenCalledTimes(2);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/in-page-blocks.ts — the site's renderer for a body's block lines
|
|
3
|
+
* (#12222, spec docs/specs/12222-capabilities-and-alternatives-what-a-spec.md
|
|
4
|
+
* D13, D18; B4 #12293): AC-13, AC-14.
|
|
5
|
+
*
|
|
6
|
+
* The grid read is mocked at `@working-theory/api-client`, the locale's words
|
|
7
|
+
* at `next-intl/server`, and `pricingSections` (the shared Pricing render,
|
|
8
|
+
* whose own suite covers it) at `../pricing-page`, so this suite pins what the
|
|
9
|
+
* renderer asks for and draws.
|
|
10
|
+
*/
|
|
11
|
+
import type { GridAnswer, PageSection } from "@working-theory/validation";
|
|
12
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
13
|
+
|
|
14
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
15
|
+
content: { grid: jest.fn() },
|
|
16
|
+
flows: { get: jest.fn() },
|
|
17
|
+
leads: { captureStatus: jest.fn() },
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
jest.mock("@working-theory/site-pages/pages/contact/contact.actions", () => ({
|
|
21
|
+
captureLeadAction: jest.fn(),
|
|
22
|
+
}));
|
|
23
|
+
// eslint-disable-next-line no-restricted-syntax -- test-seam mock: a "use server" boundary the module only binds
|
|
24
|
+
jest.mock("../newsletter.actions", () => ({
|
|
25
|
+
subscribeNewsletterAction: jest.fn(),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
/** The `grids` messages; a case may replace one word. */
|
|
29
|
+
const mockGrids: Record<string, string> = {
|
|
30
|
+
fromLevel: "From {level}",
|
|
31
|
+
addon: "Add-on",
|
|
32
|
+
ourAssessment: "Our assessment",
|
|
33
|
+
checked: "Checked {date}",
|
|
34
|
+
factsAsOf: "Facts as of {date}",
|
|
35
|
+
countOf: "{yes} of {of}",
|
|
36
|
+
capabilities: "Capabilities",
|
|
37
|
+
labelHeader: "What you get",
|
|
38
|
+
planPicker: "Plan",
|
|
39
|
+
};
|
|
40
|
+
jest.mock("next-intl/server", () => ({
|
|
41
|
+
getTranslations: jest.fn(async () => (key: string, values: Record<string, unknown> = {}) =>
|
|
42
|
+
Object.entries(values).reduce(
|
|
43
|
+
(text, [name, value]) => text.replace(`{${name}}`, String(value)),
|
|
44
|
+
mockGrids[key] ?? key,
|
|
45
|
+
),
|
|
46
|
+
),
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
const mockPricingSections = jest.fn();
|
|
50
|
+
// eslint-disable-next-line no-restricted-syntax -- the shared Pricing render is its own suite's subject; this suite pins only what the renderer hands it
|
|
51
|
+
jest.mock("../pricing-page", () => ({
|
|
52
|
+
pricingSections: (...args: unknown[]) => mockPricingSections(...args),
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
import { content } from "@working-theory/api-client";
|
|
56
|
+
import { parseBlockLine, type BlockLine } from "@working-theory/validation";
|
|
57
|
+
|
|
58
|
+
import { renderBodyBlock, renderGrid } from "../in-page-blocks";
|
|
59
|
+
|
|
60
|
+
const grid = jest.mocked(content.grid);
|
|
61
|
+
|
|
62
|
+
const line = (text: string): BlockLine => {
|
|
63
|
+
const parsed = parseBlockLine(text);
|
|
64
|
+
if (parsed === null) throw new Error(`not a block line: ${text}`);
|
|
65
|
+
return parsed;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** `publicGrid`'s answer for `R` and `S` on Website platform, by feature. */
|
|
69
|
+
const ANSWER: GridAnswer = {
|
|
70
|
+
kind: "alternatives",
|
|
71
|
+
columns: [
|
|
72
|
+
{ key: "ours", ours: true, name: "Growth Hub" },
|
|
73
|
+
{ key: "wix", ours: false, name: "Wix", what: "A website builder", source: { url: "https://wix.com/pricing" }, checkedOn: "2026-11-01" },
|
|
74
|
+
],
|
|
75
|
+
groups: [
|
|
76
|
+
{
|
|
77
|
+
id: "build",
|
|
78
|
+
name: "Build",
|
|
79
|
+
rows: [
|
|
80
|
+
{ id: "r1", name: "Pages", cells: { ours: { verdict: "yes" }, wix: { verdict: "yes" } } },
|
|
81
|
+
{
|
|
82
|
+
id: "r2",
|
|
83
|
+
name: "Drafts",
|
|
84
|
+
cells: {
|
|
85
|
+
ours: { verdict: "yes", note: { code: "from-level", level: "Pro Plus" } },
|
|
86
|
+
wix: { verdict: "partial", words: "Blog only" },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
summaries: {},
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
factsAsOf: "2026-11-01",
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
let keySeq = 0;
|
|
97
|
+
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
grid.mockReset();
|
|
100
|
+
mockPricingSections.mockReset();
|
|
101
|
+
mockGrids.fromLevel = "From {level}";
|
|
102
|
+
mockGrids.labelHeader = "What you get";
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/** Each case reads a line no other case read, so the 15 s share never answers from another case. */
|
|
106
|
+
function uniqueGridLine(): string {
|
|
107
|
+
keySeq += 1;
|
|
108
|
+
return `<Grid kind="alternatives" category="website-platform-${keySeq}" show="features" />`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function html(text: string, locale = "en"): Promise<string | null> {
|
|
112
|
+
const node = await renderBodyBlock({ block: line(text), locale });
|
|
113
|
+
return node === null || node === undefined ? null : renderToStaticMarkup(node as React.ReactElement);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
describe("a grid block renders the published answer through the comparison table (AC-14)", () => {
|
|
117
|
+
it("reads the grid once, by kind and slug, and draws its rows and columns", async () => {
|
|
118
|
+
grid.mockResolvedValue({ ok: true, body: ANSWER });
|
|
119
|
+
const text = uniqueGridLine();
|
|
120
|
+
const out = await html(text);
|
|
121
|
+
expect(grid).toHaveBeenCalledTimes(1);
|
|
122
|
+
expect(grid.mock.calls[0]![0]).toEqual({
|
|
123
|
+
kind: "alternatives",
|
|
124
|
+
slug: `website-platform-${keySeq}`,
|
|
125
|
+
show: "features",
|
|
126
|
+
locale: "en",
|
|
127
|
+
});
|
|
128
|
+
expect(out).toContain("Pages");
|
|
129
|
+
expect(out).toContain("Drafts");
|
|
130
|
+
expect(out).toContain("Wix");
|
|
131
|
+
expect(out).toContain("Blog only");
|
|
132
|
+
expect(out).toContain("From Pro Plus");
|
|
133
|
+
// A grid without price or button needs no shown-set read.
|
|
134
|
+
expect(mockPricingSections).not.toHaveBeenCalled();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("draws an alternative's Yes in dark ink and its Partial mid grey, so the column scans (#12222 decision 3)", async () => {
|
|
138
|
+
grid.mockResolvedValue({ ok: true, body: ANSWER });
|
|
139
|
+
const out = (await html(uniqueGridLine())) ?? "";
|
|
140
|
+
const marks = (label: string) =>
|
|
141
|
+
(out.match(/<svg[^>]*>/g) ?? []).filter((tag) => tag.includes(`aria-label="${label}"`) && !tag.includes("lucide-check"));
|
|
142
|
+
// Wix's Yes on Pages: the circle-dot, in the foreground ink.
|
|
143
|
+
expect(marks("Included").length).toBeGreaterThan(0);
|
|
144
|
+
for (const tag of marks("Included")) expect(tag).toContain("text-(--color-fg)");
|
|
145
|
+
// Wix's Partial on Drafts stays muted.
|
|
146
|
+
expect(marks("Partially included").length).toBeGreaterThan(0);
|
|
147
|
+
for (const tag of marks("Partially included")) expect(tag).toContain("text-(--color-text-muted)");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("words every fixed word from the locale's messages: fromLevel \"Ab {level}\" reads \"Ab Pro Plus\"", async () => {
|
|
151
|
+
mockGrids.fromLevel = "Ab {level}";
|
|
152
|
+
grid.mockResolvedValue({ ok: true, body: ANSWER });
|
|
153
|
+
const out = await html(uniqueGridLine(), "de");
|
|
154
|
+
expect(out).toContain("Ab Pro Plus");
|
|
155
|
+
expect(out).not.toContain("From Pro Plus");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("names the row-name column from the locale's messages, never the table's English default (D18)", async () => {
|
|
159
|
+
mockGrids.labelHeader = "Was Sie bekommen";
|
|
160
|
+
grid.mockResolvedValue({ ok: true, body: ANSWER });
|
|
161
|
+
const out = await html(uniqueGridLine(), "de");
|
|
162
|
+
expect(out).toContain("Was Sie bekommen");
|
|
163
|
+
expect(out).not.toContain("Capability");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it.each<[string, () => void]>([
|
|
167
|
+
["a refusal", () => grid.mockResolvedValue({ ok: false, status: 400, body: {} })],
|
|
168
|
+
["a throw", () => grid.mockRejectedValue(new Error("hub down"))],
|
|
169
|
+
["an answer that does not parse", () => grid.mockResolvedValue({ ok: true, body: { kind: "alternatives" } as never })],
|
|
170
|
+
[
|
|
171
|
+
"an empty grid",
|
|
172
|
+
() => grid.mockResolvedValue({ ok: true, body: { kind: "alternatives", columns: [], groups: [], factsAsOf: null } }),
|
|
173
|
+
],
|
|
174
|
+
])("renders nothing for %s", async (_label, stub) => {
|
|
175
|
+
stub();
|
|
176
|
+
await expect(html(uniqueGridLine())).resolves.toBeNull();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("refuses an answer whose own note carries free text (GridAnswerSchema)", async () => {
|
|
180
|
+
const free: { groups: Array<{ rows: Array<{ cells: Record<string, unknown> }> }> } = structuredClone(ANSWER);
|
|
181
|
+
free.groups[0]!.rows[1]!.cells.ours = { verdict: "yes", note: { code: "from-level", level: "Pro", text: "Ab Pro" } };
|
|
182
|
+
grid.mockResolvedValue({ ok: true, body: free as never });
|
|
183
|
+
await expect(html(uniqueGridLine())).resolves.toBeNull();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("with price on a Capabilities grid, resolves its plan columns beside a bound pricing section it never draws", async () => {
|
|
187
|
+
grid.mockResolvedValue({
|
|
188
|
+
ok: true,
|
|
189
|
+
body: {
|
|
190
|
+
kind: "capabilities",
|
|
191
|
+
columns: [
|
|
192
|
+
{ key: "pro", ours: true, plan: "pro", name: "Pro" },
|
|
193
|
+
{ key: "pro-plus", ours: true, plan: "pro-plus", name: "Pro Plus" },
|
|
194
|
+
],
|
|
195
|
+
groups: [{ id: "site", name: "Site", rows: [{ id: "pages", name: "Pages", cells: { pro: true, "pro-plus": true } }], summaries: {} }],
|
|
196
|
+
factsAsOf: null,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
// The shared render places a Stripe card in the bound section, as a connected site would.
|
|
200
|
+
mockPricingSections.mockImplementation(async (sections: PageSection[]) =>
|
|
201
|
+
sections.map((section) =>
|
|
202
|
+
section.type === "pricing"
|
|
203
|
+
? ({
|
|
204
|
+
...section,
|
|
205
|
+
data: {
|
|
206
|
+
...section.data,
|
|
207
|
+
plans: [{ name: "Growth", price: { monthly: "$49" }, features: [], cta: { label: "Buy", href: "/buy" } }],
|
|
208
|
+
},
|
|
209
|
+
} as PageSection)
|
|
210
|
+
: section,
|
|
211
|
+
),
|
|
212
|
+
);
|
|
213
|
+
const block = line(`<Grid kind="capabilities" products="growth-hub-${(keySeq += 1)}" show="features" price="true" />`);
|
|
214
|
+
if (block.tag !== "Grid") throw new Error("not a grid");
|
|
215
|
+
const node = await renderGrid(block.block, "en");
|
|
216
|
+
const [sections] = mockPricingSections.mock.calls[0] as [PageSection[]];
|
|
217
|
+
expect(sections.map((s) => s.type)).toEqual(["pricing", "comparison-table"]);
|
|
218
|
+
expect((sections[0]!.data as { offeringPlans: string[] }).offeringPlans).toEqual(["pro", "pro-plus"]);
|
|
219
|
+
const out = renderToStaticMarkup(node!);
|
|
220
|
+
expect(out).toContain("Pages");
|
|
221
|
+
// The pricing section is read for the plan columns, never drawn.
|
|
222
|
+
expect(out).not.toContain("pricing-tier-card");
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe("an offer block renders today's Stripe cards (AC-13)", () => {
|
|
227
|
+
// eslint-disable-next-line no-restricted-syntax -- a minimal placed Stripe card; the full PricingPlan shape is pricingSections' own suite's subject
|
|
228
|
+
const cards = { type: "pricing", id: "x", data: { plans: [{ name: "Growth", price: "$49", features: [] }] } } as unknown as PageSection;
|
|
229
|
+
|
|
230
|
+
it("one plan: a bound section for that plan, the page's ?plan= left alone", async () => {
|
|
231
|
+
mockPricingSections.mockResolvedValue([cards]);
|
|
232
|
+
await html('<Offer slug="growth" />');
|
|
233
|
+
const [sections, options] = mockPricingSections.mock.calls[0] as [PageSection[], Record<string, unknown>];
|
|
234
|
+
expect(sections).toEqual([
|
|
235
|
+
{ type: "pricing", id: "offer-growth", data: { plans: [], source: "offerings", offeringPlans: ["growth"] } },
|
|
236
|
+
]);
|
|
237
|
+
expect(options).toEqual({ plans: undefined, plan: undefined, locale: "en" });
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("several plans: one bound section, yearly as its toggle, recommended as the page's ?plan=", async () => {
|
|
241
|
+
mockPricingSections.mockResolvedValue([cards]);
|
|
242
|
+
await html('<Offer plans="essentials growth scale" yearly="true" recommended="growth" />');
|
|
243
|
+
const [sections, options] = mockPricingSections.mock.calls[0] as [PageSection[], Record<string, unknown>];
|
|
244
|
+
expect(sections).toHaveLength(1);
|
|
245
|
+
expect(sections[0]!.data).toEqual({
|
|
246
|
+
plans: [],
|
|
247
|
+
source: "offerings",
|
|
248
|
+
offeringPlans: ["essentials", "growth", "scale"],
|
|
249
|
+
billingToggle: true,
|
|
250
|
+
});
|
|
251
|
+
expect(options).toMatchObject({ plan: "growth" });
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("renders nothing when the shown set gives no Stripe cards (the contact path, an unconnected site)", async () => {
|
|
255
|
+
mockPricingSections.mockResolvedValue([
|
|
256
|
+
{ type: "contact-form", id: "offerings-contact", data: { fields: [] } },
|
|
257
|
+
{ type: "pricing", id: "offer-growth", data: { plans: [] } },
|
|
258
|
+
]);
|
|
259
|
+
await expect(html('<Offer slug="growth" />')).resolves.toBeNull();
|
|
260
|
+
});
|
|
261
|
+
});
|
|
@@ -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";
|
|
@@ -2511,4 +2512,90 @@ describe("price parts (#12242)", () => {
|
|
|
2511
2512
|
for (const block of blocks) expect(block).not.toHaveProperty("priceParts");
|
|
2512
2513
|
expect(PricingSectionDataSchema.safeParse(offeringsPricing(setOf(SEAT), OPTIONS)!.plans).success).toBe(true);
|
|
2513
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
|
+
});
|
|
2514
2601
|
});
|
|
@@ -1706,3 +1706,213 @@ describe("an authored card's images never reach the page (#12241 D8, security)",
|
|
|
1706
1706
|
expect(JSON.stringify(placed!.data)).not.toContain("evil.example");
|
|
1707
1707
|
});
|
|
1708
1708
|
});
|
|
1709
|
+
|
|
1710
|
+
// ─── #12370 — a comparison table that reads its rows from an Offerings grid ──
|
|
1711
|
+
|
|
1712
|
+
describe("pricingSections — a grid-bound comparison table (#12370 D3, D4)", () => {
|
|
1713
|
+
// Past every other suite's clock, so no earlier shared read is reused.
|
|
1714
|
+
let now = Date.now() + 5 * 10 ** 12;
|
|
1715
|
+
let seq = 0;
|
|
1716
|
+
beforeEach(() => {
|
|
1717
|
+
now += 16_000;
|
|
1718
|
+
seq += 1;
|
|
1719
|
+
jest.spyOn(Date, "now").mockReturnValue(now);
|
|
1720
|
+
});
|
|
1721
|
+
afterEach(() => {
|
|
1722
|
+
jest.useRealTimers();
|
|
1723
|
+
jest.restoreAllMocks();
|
|
1724
|
+
});
|
|
1725
|
+
|
|
1726
|
+
/** `publicGrid`'s answer for a Capabilities grid of two levels, by feature. */
|
|
1727
|
+
const C = {
|
|
1728
|
+
kind: "capabilities",
|
|
1729
|
+
columns: [
|
|
1730
|
+
{ key: "pro", ours: true, plan: "pro", name: "Pro" },
|
|
1731
|
+
{ key: "pro-plus", ours: true, plan: "pro-plus", name: "Pro Plus" },
|
|
1732
|
+
],
|
|
1733
|
+
groups: [
|
|
1734
|
+
{
|
|
1735
|
+
id: "site",
|
|
1736
|
+
name: "Site",
|
|
1737
|
+
rows: [
|
|
1738
|
+
// A Capabilities cell is what Stripe grants (`true` / `false`) or a typed value.
|
|
1739
|
+
{ id: "pages", name: "Pages", cells: { pro: true, "pro-plus": true } },
|
|
1740
|
+
{ id: "drafts", name: "Drafts", cells: { pro: false, "pro-plus": { value: "8" } } },
|
|
1741
|
+
],
|
|
1742
|
+
summaries: {},
|
|
1743
|
+
},
|
|
1744
|
+
],
|
|
1745
|
+
factsAsOf: null,
|
|
1746
|
+
};
|
|
1747
|
+
/** `publicGrid`'s answer for an Alternatives grid: ours, then one approved alternative. */
|
|
1748
|
+
const A = {
|
|
1749
|
+
kind: "alternatives",
|
|
1750
|
+
columns: [
|
|
1751
|
+
{ key: "ours", ours: true, name: "Growth Hub" },
|
|
1752
|
+
{ key: "wix", ours: false, name: "Wix", what: "A website builder", source: { url: "https://wix.com/pricing" }, checkedOn: "2026-11-01" },
|
|
1753
|
+
],
|
|
1754
|
+
groups: [
|
|
1755
|
+
{
|
|
1756
|
+
id: "build",
|
|
1757
|
+
name: "Build",
|
|
1758
|
+
rows: [{ id: "r1", name: "Pages", cells: { ours: { verdict: "yes" }, wix: { verdict: "partial", words: "Blog only" } } }],
|
|
1759
|
+
summaries: {},
|
|
1760
|
+
},
|
|
1761
|
+
],
|
|
1762
|
+
factsAsOf: "2026-11-01",
|
|
1763
|
+
};
|
|
1764
|
+
|
|
1765
|
+
const ok = (data: unknown) => ({ ok: true, status: 200, json: async () => ({ ok: true, data }) });
|
|
1766
|
+
/** The site's two reads: the shown set, and the public grid read. */
|
|
1767
|
+
function serve(grid: unknown | (() => Promise<unknown>), shown: unknown = { status: "unconnected" }): void {
|
|
1768
|
+
fetchMock.mockImplementation(async (url: unknown) => {
|
|
1769
|
+
if (!String(url).includes("/v1/content/grids/")) return ok(shown);
|
|
1770
|
+
return typeof grid === "function" ? (grid as () => Promise<unknown>)() : ok(grid);
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
const gridCalls = () => fetchMock.mock.calls.map(([url]) => String(url)).filter((url) => url.includes("/v1/content/grids/"));
|
|
1774
|
+
|
|
1775
|
+
type Table = Extract<PageSection, { type: "comparison-table" }>;
|
|
1776
|
+
/** A grid-bound section as a page stores it, parsed as the site parses a page's sections. */
|
|
1777
|
+
const bound = (grid: Record<string, unknown>, own: Record<string, unknown> = {}): PageSection =>
|
|
1778
|
+
PageSectionsSchema.parse([{ id: "t", type: "comparison-table", data: { grid, ...own } }])[0]!;
|
|
1779
|
+
const capabilities = (extra: Record<string, unknown> = {}) => ({
|
|
1780
|
+
kind: "capabilities",
|
|
1781
|
+
products: [`growth-hub-${seq}`],
|
|
1782
|
+
show: "features",
|
|
1783
|
+
...extra,
|
|
1784
|
+
});
|
|
1785
|
+
const alternatives = (extra: Record<string, unknown> = {}) => ({
|
|
1786
|
+
kind: "alternatives",
|
|
1787
|
+
category: `website-platform-${seq}`,
|
|
1788
|
+
show: "features",
|
|
1789
|
+
...extra,
|
|
1790
|
+
});
|
|
1791
|
+
const tableOf = (sections: PageSection[]) => {
|
|
1792
|
+
const found = sections.find((s) => s.id === "t");
|
|
1793
|
+
if (!found || found.type !== "comparison-table") throw new Error("no table");
|
|
1794
|
+
return found.data as Table["data"] & { billingPeriod?: string };
|
|
1795
|
+
};
|
|
1796
|
+
const options = { plans: undefined, plan: undefined, locale: "en" };
|
|
1797
|
+
|
|
1798
|
+
it("AC-1: a capabilities grid draws its features under their capability, one column per named level", async () => {
|
|
1799
|
+
serve(C);
|
|
1800
|
+
const sections = await pricingSections([HERO, bound(capabilities({ levels: ["pro", "pro-plus"] }), { headline: "Compare" })], options);
|
|
1801
|
+
const table = tableOf(sections);
|
|
1802
|
+
expect(table.columns.map((c) => [c.key, c.plan, c.name])).toEqual([
|
|
1803
|
+
["pro", "pro", "Pro"],
|
|
1804
|
+
["pro-plus", "pro-plus", "Pro Plus"],
|
|
1805
|
+
]);
|
|
1806
|
+
expect(table.groups.map((g) => [g.groupName, g.rows.map((r) => r.featureName)])).toEqual([["Site", ["Pages", "Drafts"]]]);
|
|
1807
|
+
expect(table.groups[0]!.rows.map((r) => r.values)).toEqual([
|
|
1808
|
+
{ pro: true, "pro-plus": true },
|
|
1809
|
+
{ pro: false, "pro-plus": "8" },
|
|
1810
|
+
]);
|
|
1811
|
+
expect(table.headline).toBe("Compare");
|
|
1812
|
+
expect(table).not.toHaveProperty("grid");
|
|
1813
|
+
// One read, of the public grid route, naming the product, the levels and the page's locale.
|
|
1814
|
+
const [url] = gridCalls();
|
|
1815
|
+
expect(gridCalls()).toHaveLength(1);
|
|
1816
|
+
expect(url).toContain(`/v1/content/grids/capabilities/growth-hub-${seq}?`);
|
|
1817
|
+
expect(new URL(url!, "http://x").searchParams.get("levels")).toBe("pro pro-plus");
|
|
1818
|
+
expect(new URL(url!, "http://x").searchParams.get("locale")).toBe("en");
|
|
1819
|
+
});
|
|
1820
|
+
|
|
1821
|
+
it("AC-2: an alternatives grid draws ours first and highlighted, then the answer's alternatives, as answered", async () => {
|
|
1822
|
+
serve(A);
|
|
1823
|
+
const grid = alternatives({ ours: "growth-hub", columns: ["wix"], source: true });
|
|
1824
|
+
const table = tableOf(await pricingSections([HERO, bound(grid)], options));
|
|
1825
|
+
expect(table.columns).toEqual([
|
|
1826
|
+
{ key: "ours", name: "Growth Hub", highlighted: true },
|
|
1827
|
+
{ key: "wix", name: "Wix" },
|
|
1828
|
+
]);
|
|
1829
|
+
expect(table.groups[0]!.rows[0]!.values).toEqual({ ours: { text: "", verdict: "yes" }, wix: { text: "Blog only", verdict: "partial" } });
|
|
1830
|
+
// The grid's own look and footnote show, since the section sets none.
|
|
1831
|
+
expect(table).toMatchObject({ variant: "detailed", yesMark: "ink" });
|
|
1832
|
+
expect(table.footnote).toContain("https://wix.com/pricing");
|
|
1833
|
+
const query = new URL(gridCalls()[0]!, "http://x").searchParams;
|
|
1834
|
+
expect([query.get("ours"), query.get("columns")]).toEqual(["growth-hub", "wix"]);
|
|
1835
|
+
});
|
|
1836
|
+
|
|
1837
|
+
it("the section's own fields win over the grid's, and the rest of its settings pass through", async () => {
|
|
1838
|
+
serve(A);
|
|
1839
|
+
const own = { eyebrow: "E", description: "D", footnote: "Mine", variant: "default", labelHeader: "Feature", yesMark: "muted", longCells: "clamp", checkStyle: "inverted" };
|
|
1840
|
+
const table = tableOf(await pricingSections([bound(alternatives(), own)], options));
|
|
1841
|
+
expect(table).toMatchObject(own);
|
|
1842
|
+
expect(table.columns).toHaveLength(2);
|
|
1843
|
+
});
|
|
1844
|
+
|
|
1845
|
+
it("AC-8: the section's planBar gives a grid's plan columns their price and button from the shown set", async () => {
|
|
1846
|
+
const both = (plan: string, monthly: number, yearly: number) => [stripePrice(plan, "monthly", monthly), stripePrice(plan, "yearly", yearly)];
|
|
1847
|
+
const offerings = [
|
|
1848
|
+
stripeProduct("pro", "plan", both("pro", 4900, 49000), { name: "Pro" }),
|
|
1849
|
+
stripeProduct("pro-plus", "plan", both("pro-plus", 9900, 99000), { name: "Pro Plus" }),
|
|
1850
|
+
];
|
|
1851
|
+
const shownSet = workspaceShownSetSchema.parse({
|
|
1852
|
+
workspaceId: "wksp_01890a5d-ac96-774b-bcce-b302099a8057",
|
|
1853
|
+
organizationId: "org_01890a5d-ac96-774b-bcce-b302099a8058",
|
|
1854
|
+
productIds: offerings.map((o) => o.productId),
|
|
1855
|
+
recommended: { plan: null, addon: null },
|
|
1856
|
+
offerings,
|
|
1857
|
+
state: "current",
|
|
1858
|
+
snapshotAt: "2026-11-20T00:00:00.000Z",
|
|
1859
|
+
});
|
|
1860
|
+
serve(C, { status: "shown", shownSet });
|
|
1861
|
+
const planBar = { pickerLabel: "Plan", price: true, button: true };
|
|
1862
|
+
const cards = pricingSection("p", { source: "offerings", offeringPlans: ["pro", "pro-plus"] });
|
|
1863
|
+
const sections = await pricingSections([cards, bound(capabilities(), { planBar })], options);
|
|
1864
|
+
const table = tableOf(sections);
|
|
1865
|
+
expect(table.planBar).toEqual(planBar);
|
|
1866
|
+
const columns = table.columns as Array<Table["data"]["columns"][number] & { offering?: { cta: { href: string } } }>;
|
|
1867
|
+
expect(columns.map((c) => c.offering?.cta.href)).toEqual([
|
|
1868
|
+
`${OFFERINGS_CHECKOUT_PATH}/pro_monthly`,
|
|
1869
|
+
`${OFFERINGS_CHECKOUT_PATH}/pro-plus_monthly`,
|
|
1870
|
+
]);
|
|
1871
|
+
// The table opens on the period the page's cards open on, as a typed table's plan columns do.
|
|
1872
|
+
expect(table.billingPeriod).toBe("annual");
|
|
1873
|
+
});
|
|
1874
|
+
|
|
1875
|
+
it.each<[string, unknown]>([
|
|
1876
|
+
["a refused read", { ok: false, status: 404, json: async () => ({ ok: false, error: { code: "not_found", message: "No grid" } }) }],
|
|
1877
|
+
["an answer that does not parse", ok({ kind: "capabilities", columns: "x" })],
|
|
1878
|
+
["a grid with no row", ok({ ...C, groups: [] })],
|
|
1879
|
+
["a grid with no column", ok({ ...C, columns: [] })],
|
|
1880
|
+
])("AC-7: %s draws no table, and the page's other sections render", async (_label, response) => {
|
|
1881
|
+
serve(async () => response);
|
|
1882
|
+
const sections = await pricingSections([HERO, bound(capabilities()), EXTRAS], options);
|
|
1883
|
+
expect(sections.map((s) => s.id)).toEqual(["hero", "extras"]);
|
|
1884
|
+
});
|
|
1885
|
+
|
|
1886
|
+
it("AC-7: a read that throws draws no table, and one failed grid leaves another grid's table drawn", async () => {
|
|
1887
|
+
fetchMock.mockImplementation(async (url: unknown) => {
|
|
1888
|
+
if (String(url).includes("/grids/capabilities/")) throw new Error("hub down");
|
|
1889
|
+
return String(url).includes("/grids/alternatives/") ? ok(A) : ok({ status: "unconnected" });
|
|
1890
|
+
});
|
|
1891
|
+
const other = { ...bound(alternatives()), id: "alt" } as PageSection;
|
|
1892
|
+
const sections = await pricingSections([HERO, bound(capabilities()), other], options);
|
|
1893
|
+
expect(sections.map((s) => s.id)).toEqual(["hero", "alt"]);
|
|
1894
|
+
});
|
|
1895
|
+
|
|
1896
|
+
it("AC-7: a read that has not answered in 3,000 ms draws no table", async () => {
|
|
1897
|
+
jest.useFakeTimers({ doNotFake: ["Date"] });
|
|
1898
|
+
serve(() => new Promise(() => undefined));
|
|
1899
|
+
const pending = pricingSections([HERO, bound(capabilities())], options);
|
|
1900
|
+
await jest.advanceTimersByTimeAsync(2_999);
|
|
1901
|
+
let settled = false;
|
|
1902
|
+
void pending.then(() => (settled = true));
|
|
1903
|
+
await jest.advanceTimersByTimeAsync(0);
|
|
1904
|
+
expect(settled).toBe(false);
|
|
1905
|
+
await jest.advanceTimersByTimeAsync(1);
|
|
1906
|
+
expect((await pending).map((s) => s.id)).toEqual(["hero"]);
|
|
1907
|
+
});
|
|
1908
|
+
|
|
1909
|
+
it("AC-9: a typed table, and a page with no grid, makes no grid read and comes back unchanged", async () => {
|
|
1910
|
+
serve(C);
|
|
1911
|
+
const typed = PageSectionsSchema.parse([
|
|
1912
|
+
{ id: "t", type: "comparison-table", data: { columns: [{ key: "us", name: "Us" }], groups: [{ groupName: "G", rows: [{ featureName: "F", values: { us: true } }] }] } },
|
|
1913
|
+
])[0]!;
|
|
1914
|
+
const sections = await pricingSections([HERO, typed], options);
|
|
1915
|
+
expect(gridCalls()).toEqual([]);
|
|
1916
|
+
expect(sections[1]).toBe(typed);
|
|
1917
|
+
});
|
|
1918
|
+
});
|