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.
@@ -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
+ });