create-ailk 0.46.2 → 0.46.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/component-catalog.json +413 -205
- package/component-catalog.md +12 -12
- package/dist/surfaces.js +1 -1
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +248 -16
- package/templates/apps/web/app/[locale]/layout.tsx +7 -1
- package/templates/apps/web/app/globals.css +12 -0
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +4 -0
- package/templates/apps/web/app/llms.txt/route.ts +22 -0
- package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +4 -0
- package/templates/apps/web/app/sitemap.xml/route.ts +43 -0
- package/templates/apps/web/i18n/request.ts +35 -12
- package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +170 -1
- package/templates/apps/web/lib/__tests__/magnet-addresses.test.ts +406 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +1245 -49
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +875 -91
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +44 -0
- package/templates/apps/web/lib/in-page-magnet.ts +86 -9
- package/templates/apps/web/lib/magnet-addresses.ts +317 -0
- package/templates/apps/web/lib/offerings-pricing.ts +645 -97
- package/templates/apps/web/lib/paid-section-contracts.ts +41 -1
- package/templates/apps/web/lib/pricing-page.ts +375 -50
- package/templates/apps/web/lib/served-pages.ts +38 -1
- package/templates/apps/web/messages/en.json +7 -1
- package/templates/apps/web/site-pages.config.tsx +9 -0
- package/versions.json +50 -50
|
@@ -24,6 +24,10 @@ jest.mock("../../../lib/modules.generated", () => ({
|
|
|
24
24
|
// eslint-disable-next-line no-restricted-syntax -- #507: a per-site generated or site-owned file; this suite pins the value it tests (#11246)
|
|
25
25
|
jest.mock("../../../lib/site-listing", () => ({ __esModule: true, SITE_LISTING: {} }));
|
|
26
26
|
|
|
27
|
+
// #12204 D8 — no magnet address, so no hub read and the bodies are unchanged.
|
|
28
|
+
// eslint-disable-next-line no-restricted-syntax -- #507: the address table's one reader; mocked so no case reads a hub or loads the paid package (#12204)
|
|
29
|
+
jest.mock("../../../lib/magnet-addresses", () => ({ servedAddresses: async () => [] }));
|
|
30
|
+
|
|
27
31
|
import { createSitemapHandler } from "../route";
|
|
28
32
|
|
|
29
33
|
const BASE = "https://example.com";
|
|
@@ -35,6 +35,12 @@
|
|
|
35
35
|
* `DocsDetail` rows, so those rows are listed at the docs path; otherwise
|
|
36
36
|
* those rows are skipped (the MDX docs route never serves them) and the docs
|
|
37
37
|
* directory is listed instead (`getDocsPages`, default `listDocsPages`).
|
|
38
|
+
*
|
|
39
|
+
* Magnet addresses (#12204 D8): after the content pages, one entry per
|
|
40
|
+
* (enabled locale, address the site serves in that locale) — only addresses
|
|
41
|
+
* the hub lists (`listed`), never `/flows/<slug>` — with alternates over the
|
|
42
|
+
* locales it is served in and `lastmod` the magnet's last change
|
|
43
|
+
* (`getMagnetAddresses`, default `servedAddresses`).
|
|
38
44
|
*/
|
|
39
45
|
|
|
40
46
|
import {
|
|
@@ -47,6 +53,7 @@ import {
|
|
|
47
53
|
listedPath,
|
|
48
54
|
type SiteListing,
|
|
49
55
|
} from "@working-theory/page-renderer";
|
|
56
|
+
import type { FlowAddressItem } from "@working-theory/validation";
|
|
50
57
|
|
|
51
58
|
import {
|
|
52
59
|
adapterDocsUrl,
|
|
@@ -54,6 +61,7 @@ import {
|
|
|
54
61
|
listDocsPages,
|
|
55
62
|
type DocsIndexPage,
|
|
56
63
|
} from "../../lib/docs-index";
|
|
64
|
+
import { servedAddresses } from "../../lib/magnet-addresses";
|
|
57
65
|
import { PUBLIC_PAGES } from "../../lib/modules.generated";
|
|
58
66
|
import { SITE_LISTING } from "../../lib/site-listing";
|
|
59
67
|
import { siteLive } from "../../lib/site-visibility";
|
|
@@ -75,6 +83,8 @@ export interface SitemapHandlerDeps {
|
|
|
75
83
|
discoverable?: () => Promise<boolean>;
|
|
76
84
|
/** The site's own listing (#10940 D3). Defaults to `SITE_LISTING`. */
|
|
77
85
|
getSiteListing?: () => SiteListing;
|
|
86
|
+
/** The magnet addresses served in a locale (#12204 D8). Defaults to `servedAddresses`. */
|
|
87
|
+
getMagnetAddresses?: (locale: string) => Promise<readonly FlowAddressItem[]>;
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
function escapeXml(value: string): string {
|
|
@@ -112,6 +122,7 @@ export function createSitemapHandler(deps: SitemapHandlerDeps = {}) {
|
|
|
112
122
|
const resolveDocsPages = deps.getDocsPages ?? listDocsPages;
|
|
113
123
|
const isDiscoverable = deps.discoverable ?? siteLive;
|
|
114
124
|
const resolveSiteListing = deps.getSiteListing ?? (() => SITE_LISTING);
|
|
125
|
+
const resolveMagnetAddresses = deps.getMagnetAddresses ?? servedAddresses;
|
|
115
126
|
return async function sitemapGET(): Promise<Response> {
|
|
116
127
|
// #10040 decision 7 — no public page, no sitemap: 404 before the adapter.
|
|
117
128
|
if (!PUBLIC_PAGES) return new Response(null, { status: 404 });
|
|
@@ -188,6 +199,38 @@ export function createSitemapHandler(deps: SitemapHandlerDeps = {}) {
|
|
|
188
199
|
}
|
|
189
200
|
}
|
|
190
201
|
|
|
202
|
+
// #12204 D8 — the magnet addresses: listed ones only, each at the one URL
|
|
203
|
+
// per locale it is served at.
|
|
204
|
+
const addressLists = await Promise.all(
|
|
205
|
+
locales.map((locale) => resolveMagnetAddresses(locale).catch(() => [])),
|
|
206
|
+
);
|
|
207
|
+
const servedIn = new Map<string, string[]>();
|
|
208
|
+
for (let i = 0; i < locales.length; i++) {
|
|
209
|
+
for (const item of addressLists[i]!) {
|
|
210
|
+
if (item.listed) servedIn.set(item.path, [...(servedIn.get(item.path) ?? []), locales[i]!]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (let i = 0; i < locales.length; i++) {
|
|
214
|
+
const locale = locales[i]!;
|
|
215
|
+
for (const item of addressLists[i]!) {
|
|
216
|
+
if (!item.listed) continue;
|
|
217
|
+
const path = item.path;
|
|
218
|
+
const alternates = (servedIn.get(path) ?? [])
|
|
219
|
+
.map(
|
|
220
|
+
(alt) =>
|
|
221
|
+
` <xhtml:link rel="alternate" hreflang="${escapeXml(alt)}" href="${escapeXml(buildLocaleUrl(baseUrl, alt, defaultLocale, path))}"/>`,
|
|
222
|
+
)
|
|
223
|
+
.join("\n");
|
|
224
|
+
// x-default names the default-locale URL, so only where it is served.
|
|
225
|
+
const xDefault = (servedIn.get(path) ?? []).includes(defaultLocale)
|
|
226
|
+
? `\n <xhtml:link rel="alternate" hreflang="x-default" href="${escapeXml(buildLocaleUrl(baseUrl, defaultLocale, defaultLocale, path))}"/>`
|
|
227
|
+
: "";
|
|
228
|
+
urlEntries.push(
|
|
229
|
+
` <url>\n <loc>${escapeXml(buildLocaleUrl(baseUrl, locale, defaultLocale, path))}</loc>\n <lastmod>${item.updatedAt.slice(0, 10)}</lastmod>\n${alternates}${xDefault}\n </url>`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
191
234
|
if (!databaseDocs) {
|
|
192
235
|
for (const doc of resolveDocsPages()) pushDocsEntry(doc.url, today);
|
|
193
236
|
}
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
// has keeps the template's value. The merge builds new objects, descends only
|
|
12
12
|
// into plain objects, takes only string leaves and skips prototype keys, so
|
|
13
13
|
// it can neither mutate the imported catalog nor pollute `Object.prototype`.
|
|
14
|
+
// One namespace is the exception (#12242 D3): in `SITE_OVERRIDE_NAMESPACES`
|
|
15
|
+
// (`pricingOfferings`) a string leaf of the locale's OWN overlay replaces the
|
|
16
|
+
// catalog's, so a site rewords its pricing cards from its own file; the
|
|
17
|
+
// English fallback overlay stays add-only there too.
|
|
14
18
|
//
|
|
15
19
|
// A page package's catalog (#11219, ADR 0040 rule 5) is added the same way,
|
|
16
20
|
// before the overlay: `@working-theory/account` ships the `account` keys its
|
|
@@ -51,34 +55,53 @@ const UNSAFE_KEYS: ReadonlySet<string> = new Set([
|
|
|
51
55
|
"prototype",
|
|
52
56
|
]);
|
|
53
57
|
|
|
58
|
+
/** The namespaces a site's own-locale overlay may reword (#12242 D3). */
|
|
59
|
+
const SITE_OVERRIDE_NAMESPACES: ReadonlySet<string> = new Set(["pricingOfferings"]);
|
|
60
|
+
|
|
54
61
|
type Catalog = Record<string, unknown>;
|
|
55
62
|
|
|
56
63
|
function isCatalog(value: unknown): value is Catalog {
|
|
57
64
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
58
65
|
}
|
|
59
66
|
|
|
60
|
-
/**
|
|
61
|
-
|
|
67
|
+
/**
|
|
68
|
+
* `base` with every key of `overlay` it lacks added — new objects, never a
|
|
69
|
+
* mutation. With `replace`, a string leaf also replaces a string leaf `base`
|
|
70
|
+
* already has (#12242 D3).
|
|
71
|
+
*/
|
|
72
|
+
function mergeAddOnly(base: Catalog, overlay: Catalog, replace = false): Catalog {
|
|
62
73
|
const out: Catalog = { ...base };
|
|
63
74
|
for (const [key, value] of Object.entries(overlay)) {
|
|
64
75
|
if (UNSAFE_KEYS.has(key)) continue;
|
|
65
76
|
const has = Object.prototype.hasOwnProperty.call(base, key);
|
|
66
77
|
if (typeof value === "string") {
|
|
67
|
-
if (!has) out[key] = value;
|
|
78
|
+
if (!has || (replace && typeof base[key] === "string")) out[key] = value;
|
|
68
79
|
} else if (isCatalog(value)) {
|
|
69
|
-
if (!has) out[key] = mergeAddOnly({}, value);
|
|
70
|
-
else if (isCatalog(base[key])) out[key] = mergeAddOnly(base[key], value);
|
|
80
|
+
if (!has) out[key] = mergeAddOnly({}, value, replace);
|
|
81
|
+
else if (isCatalog(base[key])) out[key] = mergeAddOnly(base[key], value, replace);
|
|
71
82
|
}
|
|
72
83
|
}
|
|
73
84
|
return out;
|
|
74
85
|
}
|
|
75
86
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
/** The site overlay merged over `base`: add-only, but `own` rewords the override namespaces (#12242 D3). */
|
|
88
|
+
function mergeSiteOverlay(base: Catalog, overlay: Catalog, own: boolean): Catalog {
|
|
89
|
+
const out = mergeAddOnly(base, overlay);
|
|
90
|
+
if (!own) return out;
|
|
91
|
+
for (const namespace of SITE_OVERRIDE_NAMESPACES) {
|
|
92
|
+
const words = Object.prototype.hasOwnProperty.call(overlay, namespace) ? overlay[namespace] : undefined;
|
|
93
|
+
const catalog = base[namespace];
|
|
94
|
+
if (isCatalog(words) && isCatalog(catalog)) out[namespace] = mergeAddOnly(catalog, words, true);
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The locale's own overlay (`own`), else the English one, else nothing. */
|
|
100
|
+
async function loadSiteOverlay(locale: string): Promise<{ overlay: Catalog; own: boolean }> {
|
|
101
|
+
const mine = await import(`../messages/site/${locale}.json`).catch(() => null);
|
|
102
|
+
const mod = mine ?? (await import(`../messages/site/${DEFAULT_LOCALE}.json`).catch(() => null));
|
|
80
103
|
const overlay: unknown = mod ? (mod.default ?? mod) : null;
|
|
81
|
-
return isCatalog(overlay) ? overlay : {};
|
|
104
|
+
return isCatalog(overlay) ? { overlay, own: mine !== null } : { overlay: {}, own: false };
|
|
82
105
|
}
|
|
83
106
|
|
|
84
107
|
export default getRequestConfig(async ({ requestLocale }) => {
|
|
@@ -130,9 +153,9 @@ export default getRequestConfig(async ({ requestLocale }) => {
|
|
|
130
153
|
docsAndBlog,
|
|
131
154
|
);
|
|
132
155
|
|
|
133
|
-
const overlay = await loadSiteOverlay(locale);
|
|
156
|
+
const { overlay, own } = await loadSiteOverlay(locale);
|
|
134
157
|
return {
|
|
135
158
|
locale,
|
|
136
|
-
messages:
|
|
159
|
+
messages: mergeSiteOverlay(withPackages, overlay, own) as AbstractIntlMessages,
|
|
137
160
|
};
|
|
138
161
|
});
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { LeadCaptureForm } from "@working-theory/ui";
|
|
9
9
|
import {
|
|
10
10
|
contactFormFlowConfig,
|
|
11
|
+
flowConfigSchema,
|
|
11
12
|
newsletterFlowConfig,
|
|
12
13
|
type FlowConfig,
|
|
13
14
|
} from "@working-theory/validation";
|
|
@@ -17,7 +18,6 @@ jest.mock("@working-theory/api-client", () => ({
|
|
|
17
18
|
leads: { captureStatus: jest.fn() },
|
|
18
19
|
}));
|
|
19
20
|
|
|
20
|
-
// eslint-disable-next-line no-restricted-syntax -- test-seam mock: a "use server" boundary the module only binds
|
|
21
21
|
jest.mock("@working-theory/site-pages/pages/contact/contact.actions", () => ({
|
|
22
22
|
captureLeadAction: jest.fn(),
|
|
23
23
|
}));
|
|
@@ -263,3 +263,172 @@ describe("readServedMagnet", () => {
|
|
|
263
263
|
expect(await readServedMagnet("down")).toBeNull();
|
|
264
264
|
});
|
|
265
265
|
});
|
|
266
|
+
|
|
267
|
+
// ─── The magnet section's renderer (#12205 D4; AC-4, AC-5) ────────────────────
|
|
268
|
+
|
|
269
|
+
describe("renderMagnetSection", () => {
|
|
270
|
+
type Module = typeof import("../in-page-magnet");
|
|
271
|
+
|
|
272
|
+
const FIVE_TYPES: FlowConfig = flowConfigSchema.parse({
|
|
273
|
+
slug: "five-types",
|
|
274
|
+
defaultLocale: "en",
|
|
275
|
+
steps: [
|
|
276
|
+
{
|
|
277
|
+
key: "about",
|
|
278
|
+
type: "field",
|
|
279
|
+
copy: { title: { en: "About you" } },
|
|
280
|
+
fields: [
|
|
281
|
+
{ name: "email", inputType: "email", required: true, mapsTo: "email", copy: { label: { en: "Email" } } },
|
|
282
|
+
{ name: "site", inputType: "url", copy: { label: { en: "Site" } } },
|
|
283
|
+
],
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
key: "pace",
|
|
287
|
+
type: "segmentation",
|
|
288
|
+
copy: { title: { en: "Pace?" } },
|
|
289
|
+
questions: [{ name: "pace", options: [{ value: "fast", label: { en: "Fast" } }, { value: "slow", label: { en: "Slow" } }] }],
|
|
290
|
+
},
|
|
291
|
+
{ key: "note", type: "message", copy: { title: { en: "A note" } } },
|
|
292
|
+
{ key: "score", type: "aeo_score", copy: { title: { en: "Your score" } }, urlField: "site" },
|
|
293
|
+
{ key: "extra", type: "custom", copy: { title: { en: "Extra" } }, renderer: "extra" },
|
|
294
|
+
],
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
function StubLauncher(): null {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* A fresh copy of the module (its package load is memoized per process),
|
|
303
|
+
* with the site's package answering `ui`, and the registration spied.
|
|
304
|
+
*/
|
|
305
|
+
function load(ui: unknown): {
|
|
306
|
+
mod: Module;
|
|
307
|
+
get: jest.Mock;
|
|
308
|
+
loadUi: jest.Mock;
|
|
309
|
+
register: jest.Mock;
|
|
310
|
+
} {
|
|
311
|
+
jest.resetModules();
|
|
312
|
+
const loadUi = jest.fn(async () => ui);
|
|
313
|
+
const register = jest.fn();
|
|
314
|
+
jest.doMock("../paid-sections.generated", () => ({
|
|
315
|
+
...jest.requireActual("../paid-sections.generated"),
|
|
316
|
+
loadUiSignalCollectors: loadUi,
|
|
317
|
+
}));
|
|
318
|
+
jest.doMock("@working-theory/page-renderer", () => ({
|
|
319
|
+
...jest.requireActual("@working-theory/page-renderer"),
|
|
320
|
+
setMagnetSectionRenderer: register,
|
|
321
|
+
}));
|
|
322
|
+
const mod = require("../in-page-magnet") as Module;
|
|
323
|
+
const get = (require("@working-theory/api-client") as { flows: { get: jest.Mock } }).flows.get;
|
|
324
|
+
return { mod, get, loadUi, register };
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
let warn: jest.SpyInstance;
|
|
328
|
+
beforeEach(() => {
|
|
329
|
+
warn = jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
330
|
+
});
|
|
331
|
+
afterEach(() => {
|
|
332
|
+
warn.mockRestore();
|
|
333
|
+
jest.useRealTimers();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it("registers itself with page-renderer at module load", () => {
|
|
337
|
+
const { mod, register } = load(null);
|
|
338
|
+
expect(register).toHaveBeenCalledWith(mod.renderMagnetSection);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it.each([
|
|
342
|
+
["absent or a draft (404)", (get: jest.Mock) => get.mockResolvedValueOnce({ ok: false, status: 404, body: {} })],
|
|
343
|
+
["a rejected read", (get: jest.Mock) => get.mockRejectedValueOnce(new Error("hub down"))],
|
|
344
|
+
["a 2xx that is not a served flow", (get: jest.Mock) => get.mockResolvedValueOnce({ ok: true, status: 200, body: { slug: "x" } })],
|
|
345
|
+
])("answers null for %s, and never loads the package", async (_name, arrange) => {
|
|
346
|
+
const { mod, get, loadUi } = load({ MagnetSectionClient: StubLauncher });
|
|
347
|
+
arrange(get);
|
|
348
|
+
expect(await mod.renderMagnetSection({ slug: "x", locale: "en" })).toBeNull();
|
|
349
|
+
expect(loadUi).not.toHaveBeenCalled();
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("answers null for a read that never settles, after 2,000 ms", async () => {
|
|
353
|
+
const { mod, get, loadUi } = load({ MagnetSectionClient: StubLauncher });
|
|
354
|
+
jest.useFakeTimers();
|
|
355
|
+
get.mockReturnValueOnce(new Promise(() => undefined));
|
|
356
|
+
const pending = mod.renderMagnetSection({ slug: "stalled", locale: "en" });
|
|
357
|
+
await jest.advanceTimersByTimeAsync(2_000);
|
|
358
|
+
expect(await pending).toBeNull();
|
|
359
|
+
expect(loadUi).not.toHaveBeenCalled();
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it("answers null for a deliverable magnet (its one route is /reports/<slug>)", async () => {
|
|
363
|
+
const { mod, get, loadUi } = load({ MagnetSectionClient: StubLauncher });
|
|
364
|
+
get.mockResolvedValueOnce({
|
|
365
|
+
ok: true,
|
|
366
|
+
status: 200,
|
|
367
|
+
body: { ...FIVE_TYPES, deliverable: { kind: "file", gated: true, copy: { title: { en: "Report" } } } },
|
|
368
|
+
});
|
|
369
|
+
expect(await mod.renderMagnetSection({ slug: "five-types", locale: "en" })).toBeNull();
|
|
370
|
+
expect(loadUi).not.toHaveBeenCalled();
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it.each([
|
|
374
|
+
["no package", null],
|
|
375
|
+
["a package without MagnetSectionClient", { flowsMessages: () => ({}) }],
|
|
376
|
+
])("answers null with %s", async (_name, ui) => {
|
|
377
|
+
const { mod, get } = load(ui);
|
|
378
|
+
get.mockResolvedValueOnce({ ok: true, status: 200, body: FIVE_TYPES });
|
|
379
|
+
expect(await mod.renderMagnetSection({ slug: "five-types", locale: "en" })).toBeNull();
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("answers the package's launcher over the whole served config", async () => {
|
|
383
|
+
const { mod, get } = load({ MagnetSectionClient: StubLauncher });
|
|
384
|
+
get.mockResolvedValueOnce({ ok: true, status: 200, body: FIVE_TYPES });
|
|
385
|
+
const element = (await mod.renderMagnetSection({ slug: "five-types", locale: "fr" }))!;
|
|
386
|
+
expect(element.type).toBe(StubLauncher);
|
|
387
|
+
const props = element.props as Record<string, unknown>;
|
|
388
|
+
expect(props["config"]).toBe(FIVE_TYPES);
|
|
389
|
+
expect(props["slug"]).toBe("five-types");
|
|
390
|
+
expect(props["locale"]).toBe("fr");
|
|
391
|
+
expect(props["consentPolicies"]).toEqual(expect.any(Object));
|
|
392
|
+
expect(props["brand"]).toEqual({ logomark: expect.anything(), wordmark: expect.anything() });
|
|
393
|
+
expect(props).not.toHaveProperty("bookingStep");
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("passes the booking step's calendar the package builds, when there is one", async () => {
|
|
397
|
+
const calendar = { type: "div", props: {} };
|
|
398
|
+
const bookingStepElement = jest.fn(async () => calendar);
|
|
399
|
+
const { mod, get } = load({ MagnetSectionClient: StubLauncher, bookingStepElement });
|
|
400
|
+
get.mockResolvedValueOnce({ ok: true, status: 200, body: FIVE_TYPES });
|
|
401
|
+
const element = (await mod.renderMagnetSection({ slug: "five-types", locale: "en" }))!;
|
|
402
|
+
expect(bookingStepElement).toHaveBeenCalledWith(FIVE_TYPES);
|
|
403
|
+
expect((element.props as Record<string, unknown>)["bookingStep"]).toBe(calendar);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("a throw past the read answers null with one warning that names nothing read", async () => {
|
|
407
|
+
const bookingStepElement = jest.fn(async () => {
|
|
408
|
+
throw new Error("five-types exploded");
|
|
409
|
+
});
|
|
410
|
+
const { mod, get } = load({ MagnetSectionClient: StubLauncher, bookingStepElement });
|
|
411
|
+
get.mockResolvedValueOnce({ ok: true, status: 200, body: FIVE_TYPES });
|
|
412
|
+
expect(await mod.renderMagnetSection({ slug: "five-types", locale: "en" })).toBeNull();
|
|
413
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
414
|
+
expect(warn).toHaveBeenCalledWith("[magnet-section] render failed; the section is removed");
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it("rethrows Next's control flow", async () => {
|
|
418
|
+
const { redirect } = jest.requireActual("next/navigation") as typeof import("next/navigation");
|
|
419
|
+
let signal: unknown;
|
|
420
|
+
try {
|
|
421
|
+
redirect("/elsewhere");
|
|
422
|
+
} catch (err) {
|
|
423
|
+
signal = err;
|
|
424
|
+
}
|
|
425
|
+
const { mod, get } = load({
|
|
426
|
+
MagnetSectionClient: StubLauncher,
|
|
427
|
+
bookingStepElement: jest.fn(async () => {
|
|
428
|
+
throw signal;
|
|
429
|
+
}),
|
|
430
|
+
});
|
|
431
|
+
get.mockResolvedValueOnce({ ok: true, status: 200, body: FIVE_TYPES });
|
|
432
|
+
await expect(mod.renderMagnetSection({ slug: "five-types", locale: "en" })).rejects.toBe(signal);
|
|
433
|
+
});
|
|
434
|
+
});
|