create-ailk 0.39.0 → 0.40.0

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.
Files changed (187) hide show
  1. package/dist/add-route.js +15 -0
  2. package/dist/body-heading.d.ts +2 -1
  3. package/dist/body-heading.js +31 -3
  4. package/dist/module-architecture.js +0 -3
  5. package/dist/remove-module.js +13 -4
  6. package/dist/routes.d.ts +7 -0
  7. package/dist/routes.js +1 -1
  8. package/dist/site-roster.js +7 -1
  9. package/dist/surfaces.d.ts +2 -0
  10. package/dist/surfaces.js +59 -172
  11. package/package.json +3 -3
  12. package/templates/apps/web/CLAUDE.md +7 -1
  13. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +3 -2
  14. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +3 -2
  15. package/templates/apps/web/app/[locale]/layout.tsx +1 -1
  16. package/templates/apps/web/i18n/request.ts +5 -1
  17. package/templates/apps/web/jest.config.cjs +6 -0
  18. package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
  19. package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
  20. package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
  21. package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
  22. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
  23. package/templates/apps/web/lib/in-page-magnet.ts +2 -2
  24. package/templates/apps/web/lib/pricing-page.ts +3 -3
  25. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +1 -1
  26. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +1 -1
  27. package/templates/apps/web/lib/site-header.ts +1 -1
  28. package/templates/apps/web/messages/en.json +0 -119
  29. package/templates/apps/web/next.config.mjs +7 -0
  30. package/templates/apps/web/package.json +1 -0
  31. package/templates/apps/web/site-pages.config.tsx +85 -0
  32. package/templates/tools/body-heading.ts +30 -3
  33. package/versions.json +50 -49
  34. package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
  35. package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
  36. package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
  37. package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
  38. package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
  39. package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
  40. package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
  41. package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
  42. package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
  43. package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
  44. package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
  45. package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
  46. package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
  47. package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
  48. package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
  49. package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
  50. package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
  51. package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
  52. package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
  53. package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
  54. package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
  55. package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
  56. package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
  57. package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
  58. package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
  59. package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
  60. package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
  61. package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
  62. package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
  63. package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
  64. package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
  65. package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
  66. package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
  67. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
  68. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
  69. package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
  70. package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
  71. package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
  72. package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
  73. package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
  74. package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
  75. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
  76. package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
  77. package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
  78. package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
  79. package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
  80. package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
  81. package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
  82. package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
  83. package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
  84. package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
  85. package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
  86. package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
  87. package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
  88. package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
  89. package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
  90. package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
  91. package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
  92. package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
  93. package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
  94. package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
  95. package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
  96. package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
  97. package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
  98. package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
  99. package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
  100. package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
  101. package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
  102. package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
  103. package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
  104. package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
  105. package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
  106. package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
  107. package/templates/apps/web/app/[locale]/page.tsx +0 -147
  108. package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
  109. package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
  110. package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
  111. package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
  112. package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
  113. package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
  114. package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
  115. package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
  116. package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
  117. package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
  118. package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
  119. package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
  120. package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
  121. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
  122. package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
  123. package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
  124. package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
  125. package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
  126. package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
  127. package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
  128. package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
  129. package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
  130. package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
  131. package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
  132. package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
  133. package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
  134. package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
  135. package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
  136. package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
  137. package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
  138. package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
  139. package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
  140. package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
  141. package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
  142. package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
  143. package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
  144. package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
  145. package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
  146. package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
  147. package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
  148. package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
  149. package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
  150. package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
  151. package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
  152. package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
  153. package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
  154. package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
  155. package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
  156. package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
  157. package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
  158. package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
  159. package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
  160. package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
  161. package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
  162. package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
  163. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
  164. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
  165. package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
  166. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
  167. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
  168. package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
  169. package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
  170. package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
  171. package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
  172. package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
  173. package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
  174. package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
  175. package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
  176. package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
  177. package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
  178. package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
  179. package/templates/apps/web/lib/hub-children.tsx +0 -351
  180. package/templates/apps/web/lib/meet-placeholder.ts +0 -5
  181. package/templates/apps/web/lib/posting-title.ts +0 -39
  182. package/templates/apps/web/lib/route-family.ts +0 -69
  183. package/templates/apps/web/lib/service-listing.ts +0 -89
  184. package/templates/apps/web/lib/template-listing.ts +0 -169
  185. package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
  186. package/templates/apps/web/src/lib/lead-write.ts +0 -90
  187. /package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +0 -0
@@ -1,136 +0,0 @@
1
- /**
2
- * Tests for the ThankYouPage detail route (#3960 D6, AC3).
3
- *
4
- * - Populated: getMdxSource returns a real source → renderPage sections mode
5
- * composes the page (JSON-LD + SectionRenderer), no notFound() call.
6
- * - Unknown slug: getMdxSource returns null → renderPage's own detail-route
7
- * branch (no translationsNamespace passed) calls notFound().
8
- */
9
- import React from "react";
10
- import { render } from "@testing-library/react";
11
-
12
- jest.mock("next/navigation", () => ({
13
- __esModule: true,
14
- notFound: jest.fn(() => {
15
- throw new Error("NEXT_NOT_FOUND");
16
- }),
17
- }));
18
-
19
- jest.mock("@working-theory/ui", () => ({
20
- // #7789: renderPage's fallback page head renders inside the section Container.
21
- Container: ({ children }: { children?: React.ReactNode }) =>
22
- React.createElement("div", null, children),
23
- // #4446/#4447: renderPage's own fallback/empty-state title now composes
24
- // Heading (mobile type-budget classes, #4417) instead of a bare <h1>.
25
- Heading: ({
26
- children,
27
- level,
28
- }: {
29
- children: React.ReactNode;
30
- level: number;
31
- }): React.ReactElement =>
32
- React.createElement(`h${level}`, null, children),
33
- SectionRenderer: ({ sections }: { sections: unknown[] }) =>
34
- React.createElement("div", {
35
- "data-testid": "section-renderer",
36
- "data-section-count": String(sections.length),
37
- }),
38
- }));
39
-
40
-
41
- import { existsSync, readFileSync } from "node:fs";
42
- import { join } from "node:path";
43
- import { notFound } from "next/navigation";
44
- import ThankYouSlugPage, { generateMetadata } from "../page";
45
-
46
- const mockNotFound = notFound as jest.MockedFunction<typeof notFound>;
47
-
48
- function makeThankYouSource(slug: string) {
49
- return {
50
- frontmatter: {
51
- type: "ThankYouPage" as const,
52
- slug,
53
- title: "You're all set",
54
- description: "Thanks — we'll be in touch shortly.",
55
- sections: [],
56
- },
57
- body: "",
58
- };
59
- }
60
-
61
- describe("ThankYouSlugPage — detail route", () => {
62
- beforeEach(() => {
63
- mockNotFound.mockClear();
64
- });
65
-
66
- it("renders a seed page through renderPage sections mode", async () => {
67
- const source = makeThankYouSource("flow-thanks");
68
- const getMdxSourcePopulated = jest.fn().mockResolvedValue(source);
69
-
70
- const element = await ThankYouSlugPage({
71
- params: Promise.resolve({ locale: "en", slug: "flow-thanks" }),
72
- getMdxSource: getMdxSourcePopulated,
73
- });
74
- const { container } = render(element);
75
-
76
- expect(getMdxSourcePopulated).toHaveBeenCalledWith(
77
- "ThankYouPage",
78
- "flow-thanks",
79
- "en",
80
- );
81
- expect(mockNotFound).not.toHaveBeenCalled();
82
- expect(
83
- container.querySelector('[data-testid="section-renderer"]'),
84
- ).not.toBeNull();
85
- expect(container.querySelector('[data-testid="json-ld"]')).not.toBeNull();
86
- });
87
-
88
- it("unknown slug calls notFound()", async () => {
89
- const getMdxSourceNull = jest.fn().mockResolvedValue(null);
90
-
91
- await expect(
92
- ThankYouSlugPage({
93
- params: Promise.resolve({ locale: "en", slug: "unknown-slug" }),
94
- getMdxSource: getMdxSourceNull,
95
- }),
96
- ).rejects.toThrow("NEXT_NOT_FOUND");
97
- expect(mockNotFound).toHaveBeenCalled();
98
- });
99
-
100
- it("renders no account hand-off: a user magnet's walk lands on sign-up itself (#10826 D6)", async () => {
101
- const getMdxSource = jest.fn().mockResolvedValue(makeThankYouSource("flow-thanks"));
102
-
103
- const element = await ThankYouSlugPage({
104
- params: Promise.resolve({ locale: "en", slug: "flow-thanks" }),
105
- getMdxSource,
106
- });
107
- const { container } = render(element);
108
-
109
- expect(container.querySelector('[data-testid="account-invite-link"]')).toBeNull();
110
- expect(existsSync(join(__dirname, "..", "AccountInviteLink.tsx"))).toBe(false);
111
- });
112
-
113
- it("stays a server page: the module has no client directive (#8771)", () => {
114
- const source = readFileSync(join(__dirname, "..", "page.tsx"), "utf8");
115
- expect(source).not.toMatch(/["']use client["']/);
116
- });
117
- });
118
-
119
- // #10617 AC-1 — the route's own metadata, read from the real seed, carries
120
- // the noindex directive the page-renderer gives every ThankYouPage.
121
- // The scaffold matrix runs this suite inside a scaffold that ships no
122
- // flow-thanks seed (#10763), so the test skips where the seed does not exist.
123
- const SEED = join(
124
- __dirname, "..", "..", "..", "..", "..", "..", "..",
125
- "content", "en", "ThankYouPage", "flow-thanks.mdx",
126
- );
127
- const itWithSeed = existsSync(SEED) ? it : it.skip;
128
-
129
- describe("ThankYouSlugPage — generateMetadata (#10617)", () => {
130
- itWithSeed("carries robots noindex, follow", async () => {
131
- const metadata = await generateMetadata({
132
- params: Promise.resolve({ locale: "en", slug: "flow-thanks" }),
133
- });
134
- expect(metadata.robots).toEqual({ index: false, follow: true });
135
- });
136
- });
@@ -1,39 +0,0 @@
1
- // ThankYouPage detail page (#3960 D6) — the segment-keyed flow-completion
2
- // redirect target. Sections-mode renderPage (the ContactPage pattern),
3
- // rendered on request under the cookie-reading locale layout; [slug]/page.tsx's
4
- // header says why there is no static-params export (#7379). Unknown slugs 404
5
- // via renderPage's own detail-route branch (no translationsNamespace passed
6
- // — renderPage calls notFound() itself when getMdxSource resolves null).
7
- // `renderPageMetadata` makes every ThankYouPage `noindex, follow` (#10617).
8
- import type { getMdxSource as defaultGetMdxSource } from "@working-theory/page-renderer";
9
- import { renderPage, renderPageMetadata } from "@working-theory/page-renderer";
10
- import type { Metadata } from "next";
11
- import type { ReactElement } from "react";
12
-
13
- interface Props {
14
- params: Promise<{ locale: string; slug: string }>;
15
- getMdxSource?: typeof defaultGetMdxSource;
16
- }
17
-
18
- export async function generateMetadata({
19
- params,
20
- }: Pick<Props, "params">): Promise<Metadata> {
21
- const { locale, slug } = await params;
22
- return renderPageMetadata({ type: "ThankYouPage", slug, locale });
23
- }
24
-
25
- export default async function Page({
26
- params,
27
- getMdxSource,
28
- }: Props): Promise<ReactElement> {
29
- const { locale, slug } = await params;
30
- // #10826 D6 — no account hand-off: a `user` magnet's walk lands on sign-up
31
- // itself, so the walk writes no `/thanks` link any more.
32
- return renderPage({
33
- type: "ThankYouPage",
34
- slug,
35
- locale,
36
- populatedDescriptionTestId: "thank-you-description",
37
- ...(getMdxSource !== undefined && { getMdxSource }),
38
- });
39
- }
@@ -1,226 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- * @jest-environment-options {"customExportConditions": ["react-server", "node", "require", "default"]}
4
- */
5
- // /[locale]/unsubscribe → real RSC render regression test (#8438 D17, the
6
- // #7402 class).
7
- //
8
- // The create-ailk scaffold matrix's `organization-product · Free` leg answered
9
- // `GET /unsubscribe` with a 500: `page.tsx` (a Server Component) handed
10
- // `UnsubscribeButton` ("use client") a `labels.done` FUNCTION, and React
11
- // refuses to serialize a function into the Flight payload ("Functions cannot
12
- // be passed directly to Client Components"). `unsubscribe.test.tsx` renders
13
- // the island in the same jsdom process, so it never crosses the boundary and
14
- // stayed green while the real page crashed.
15
- //
16
- // This suite runs the page through React's own Flight serializer — the same
17
- // `react-server-dom-webpack` server Next uses — under the `react-server`
18
- // export condition, with every `"use client"` module in the render graph
19
- // replaced by a real client reference, exactly as
20
- // `apps/web/__tests__/signed-in-nav-rsc-boundary.test.tsx` does for the
21
- // layout. A function crossing any server→client edge throws the production
22
- // error here.
23
-
24
- import fs from "node:fs";
25
- import path from "node:path";
26
- import { Writable } from "node:stream";
27
-
28
- import type { ReactElement, ReactNode } from "react";
29
-
30
- // Next's compiled Flight server ships no types; it is the renderer Next itself runs.
31
- const flight =
32
- require("next/dist/compiled/react-server-dom-webpack/server.node") as {
33
- createClientModuleProxy: (moduleId: string) => Record<string, unknown>;
34
- renderToPipeableStream: (
35
- model: ReactNode,
36
- manifest: unknown,
37
- options: { onError: (error: unknown) => void },
38
- ) => { pipe: (destination: Writable) => void };
39
- };
40
-
41
- // ── The "use client" boundary ────────────────────────────────────────────────
42
-
43
- const REPO_ROOT = path.resolve(__dirname, "../../../../../..");
44
-
45
- /** This app and every workspace package its imports can resolve into. */
46
- const WORKSPACE_DIRS = [
47
- path.join(REPO_ROOT, "apps/web"),
48
- // `packages-paid` is absent from the public tree the strip derives.
49
- ...["packages", "packages-paid"]
50
- .map((dir) => path.join(REPO_ROOT, dir))
51
- .filter((dir) => fs.existsSync(dir))
52
- .flatMap((dir) => fs.readdirSync(dir).map((pkg) => path.join(dir, pkg))),
53
- ];
54
-
55
- /** A file's directive prologue opens with "use client" (comments may precede it). */
56
- const USE_CLIENT = /^(?:\s|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)*["']use client["']/;
57
-
58
- /**
59
- * Every source module that marks itself `"use client"` in the trees jest maps
60
- * this app's imports onto: the app itself and the workspace packages' `src/`.
61
- */
62
- function clientModules(): string[] {
63
- const roots = WORKSPACE_DIRS.map((dir) =>
64
- dir.endsWith(path.join("apps", "web")) ? dir : path.join(dir, "src"),
65
- );
66
- const found: string[] = [];
67
- const walk = (dir: string): void => {
68
- if (!fs.existsSync(dir)) return;
69
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
70
- if (["node_modules", ".next", "__tests__", "dist"].includes(entry.name))
71
- continue;
72
- const full = path.join(dir, entry.name);
73
- if (entry.isDirectory()) walk(full);
74
- else if (
75
- /\.tsx?$/.test(entry.name) &&
76
- !/\.(stories|test)\.tsx?$/.test(entry.name)
77
- ) {
78
- if (USE_CLIENT.test(fs.readFileSync(full, "utf8"))) found.push(full);
79
- }
80
- }
81
- };
82
- roots.forEach(walk);
83
- return found;
84
- }
85
-
86
- /**
87
- * The installed `@working-theory/*` packages' built `dist/` trees — the shape a
88
- * create-ailk scaffold runs this test in (#8557). There jest maps nothing onto
89
- * `src/`: `@working-theory/ui` is a tarball under `node_modules`, and its
90
- * Radix-backed primitives carry the directive in their built files. Unmocked,
91
- * they load as server code under the `react-server` condition and throw
92
- * (`React.createContext is not a function`). In the monorepo the symlinked
93
- * workspace package's `dist/` (when built) is walked too; those files are never
94
- * reached, since jest maps the imports onto `src/`, so the extra mocks are inert.
95
- */
96
- function installedClientModules(): string[] {
97
- const scope = path.join(REPO_ROOT, "apps/web/node_modules/@working-theory");
98
- if (!fs.existsSync(scope)) return [];
99
- const found: string[] = [];
100
- const walk = (dir: string): void => {
101
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
102
- const full = path.join(dir, entry.name);
103
- if (entry.isDirectory()) walk(full);
104
- else if (/\.(?:m|c)?js$/.test(entry.name)) {
105
- if (USE_CLIENT.test(fs.readFileSync(full, "utf8"))) found.push(full);
106
- }
107
- }
108
- };
109
- for (const pkg of fs.readdirSync(scope)) {
110
- let dist: string;
111
- try {
112
- dist = path.join(fs.realpathSync(path.join(scope, pkg)), "dist");
113
- } catch {
114
- continue;
115
- }
116
- if (fs.existsSync(dist)) walk(dist);
117
- }
118
- return found;
119
- }
120
-
121
- for (const file of [...clientModules(), ...installedClientModules()]) {
122
- jest.doMock(file, () => flight.createClientModuleProxy(file));
123
- }
124
- // Third-party client entries the primitives barrel reaches (`next/image` via
125
- // `Image.tsx`). pnpm can link a physically distinct `next` per workspace, so
126
- // each entry is mocked at every copy a workspace resolves.
127
- for (const specifier of ["next/link", "next/image", "next/script"]) {
128
- const copies = new Set<string>();
129
- for (const dir of WORKSPACE_DIRS) {
130
- try {
131
- copies.add(require.resolve(specifier, { paths: [dir] }));
132
- } catch {
133
- // This workspace does not depend on `next`.
134
- }
135
- }
136
- for (const file of copies) {
137
- jest.doMock(file, () => flight.createClientModuleProxy(specifier));
138
- }
139
- }
140
- // `next-intl` is path-independent: jest.config.cjs maps every copy onto one stub.
141
- jest.doMock("next-intl", () => flight.createClientModuleProxy("next-intl"));
142
- // #8847 D12 — the page reads the newsletter magnet through
143
- // `lib/in-page-magnet`, whose module graph reaches `contact.actions`' import
144
- // of `next/navigation`. Next serves server code that entry's react-server
145
- // build; under jest it is the client build, which needs a React context, so
146
- // it is stubbed as `signed-in-nav-rsc-boundary.test.tsx` stubs it.
147
- jest.doMock("next/navigation", () => ({
148
- redirect: () => {
149
- throw new Error("redirect");
150
- },
151
- notFound: () => {
152
- throw new Error("NEXT_NOT_FOUND");
153
- },
154
- }));
155
-
156
- // ── Render ───────────────────────────────────────────────────────────────────
157
-
158
- /** Any client-reference id resolves to a chunk-less manifest entry. */
159
- const CLIENT_MANIFEST = new Proxy(
160
- {},
161
- { get: (_target, id) => ({ id: String(id), chunks: [], name: "*" }) },
162
- );
163
-
164
- interface FlightResult {
165
- errors: string[];
166
- payload: string;
167
- }
168
-
169
- /** Serialize the unsubscribe page to a Flight payload, collecting render errors. */
170
- async function renderPageToFlight(
171
- token: string | undefined,
172
- ): Promise<FlightResult> {
173
- // Required, not imported: an `import` would be hoisted above the doMock calls.
174
- const { default: UnsubscribePage } = require("../page") as {
175
- default: (props: {
176
- params: Promise<{ locale: string }>;
177
- searchParams: Promise<{ t?: string }>;
178
- }) => Promise<ReactElement>;
179
- };
180
-
181
- const errors: string[] = [];
182
- const chunks: string[] = [];
183
- await new Promise<void>((resolve, reject) => {
184
- const destination = new Writable({
185
- write(chunk: Buffer, _encoding, done) {
186
- chunks.push(chunk.toString());
187
- done();
188
- },
189
- final(done) {
190
- done();
191
- resolve();
192
- },
193
- });
194
- destination.on("error", reject);
195
- flight
196
- .renderToPipeableStream(
197
- <UnsubscribePage
198
- params={Promise.resolve({ locale: "en" })}
199
- searchParams={Promise.resolve(
200
- token === undefined ? {} : { t: token },
201
- )}
202
- />,
203
- CLIENT_MANIFEST,
204
- { onError: (error) => void errors.push(String(error)) },
205
- )
206
- .pipe(destination);
207
- });
208
- return { errors, payload: chunks.join("") };
209
- }
210
-
211
- describe("/[locale]/unsubscribe crosses the RSC → client boundary cleanly", () => {
212
- it("serializes with a token: nothing callable is handed to the island", async () => {
213
- const { errors, payload } = await renderPageToFlight("tok_1");
214
- expect(errors).toEqual([]);
215
- expect(payload).toContain("unsubscribe-page");
216
- // #8847 D12 — the island gets the token and the magnet's copy as strings.
217
- const props = /"token":"tok_1"[^}]*}/.exec(payload)?.[0] ?? "";
218
- expect(props).toContain('"cta":"Unsubscribe"');
219
- expect(props).toContain('"doneHeadline":"You\'re unsubscribed."');
220
- });
221
-
222
- it("serializes with no token", async () => {
223
- const { errors } = await renderPageToFlight(undefined);
224
- expect(errors).toEqual([]);
225
- });
226
- });
@@ -1,217 +0,0 @@
1
- /**
2
- * Tests for /[locale]/unsubscribe (#8438 D17, AC-3 unsubscribe).
3
- */
4
- import { render, screen, waitFor } from "@testing-library/react";
5
- import userEvent from "@testing-library/user-event";
6
-
7
- /**
8
- * One interpolating translator for both halves of the page: the server half
9
- * (`getTranslations`, the heading and lead) and the client island
10
- * (`useTranslations`, whose done line formats `{description}` in). The
11
- * workspace's mapped `next-intl` stub ignores ICU values, so it is replaced
12
- * here, the way this file already replaces `next-intl/server`.
13
- */
14
- function mockTranslator(ns: string): (key: string, values?: Record<string, unknown>) => string {
15
- const msgs: unknown = require("../../../../messages/en.json");
16
- const dig = (obj: unknown, path: string): unknown =>
17
- path.split(".").reduce<unknown>(
18
- (acc, k) => (acc !== null && typeof acc === "object" ? (acc as Record<string, unknown>)[k] : undefined),
19
- obj,
20
- );
21
- const messages = dig(msgs, ns);
22
- return (key, values) => {
23
- const value = dig(messages, key);
24
- if (typeof value !== "string") return `${ns}.${key}`;
25
- return value.replace(/\{(\w+)\}/g, (m, name: string) =>
26
- values && name in values ? String(values[name]) : m,
27
- );
28
- };
29
- }
30
-
31
- jest.mock("next-intl/server", () => ({
32
- __esModule: true,
33
- getTranslations: async (arg: string | { namespace?: string; locale?: string }) =>
34
- mockTranslator(typeof arg === "string" ? arg : (arg.namespace ?? "")),
35
- }));
36
-
37
- jest.mock("next-intl", () => ({
38
- __esModule: true,
39
- useTranslations: (ns: string) => mockTranslator(ns),
40
- }));
41
-
42
- const mockUnsubscribe = jest.fn();
43
- const mockFlowsGet = jest.fn();
44
- jest.mock("@working-theory/api-client", () => ({
45
- __esModule: true,
46
- consent: { unsubscribe: (...args: unknown[]) => mockUnsubscribe(...args) },
47
- flows: { get: (...args: unknown[]) => mockFlowsGet(...args) },
48
- visitorForwardHeaders: () => undefined,
49
- }));
50
-
51
- jest.mock("next/headers", () => ({
52
- __esModule: true,
53
- headers: jest.fn().mockResolvedValue(new Headers()),
54
- }));
55
-
56
- import Page, { generateMetadata } from "../page";
57
-
58
- const ok = <T,>(body: T) => ({ ok: true, body });
59
- const refusal = (status: number) => ({ ok: false, status, body: null });
60
-
61
- // #8847 D12 — the page's newsletter-magnet read is shared for a few seconds
62
- // per module instance; each test starts an hour later so none sees another's.
63
- let clock = 1_900_000_000_000;
64
- jest.spyOn(Date, "now").mockImplementation(() => clock);
65
-
66
- beforeEach(() => {
67
- clock += 60 * 60 * 1000;
68
- mockUnsubscribe.mockReset();
69
- // The hub unreadable: the seeded newsletterFlowConfig's unsubscribe copy.
70
- mockFlowsGet.mockReset().mockRejectedValue(new Error("hub down"));
71
- });
72
-
73
- async function renderPage(token: string | undefined): Promise<void> {
74
- render(
75
- await Page({
76
- params: Promise.resolve({ locale: "en" }),
77
- searchParams: Promise.resolve(token === undefined ? {} : { t: token }),
78
- }),
79
- );
80
- }
81
-
82
- describe("metadata — noindex, no-referrer (D17, SEC-8438-9)", () => {
83
- it("is noindex and sends no-referrer", async () => {
84
- const meta = await generateMetadata({
85
- params: Promise.resolve({ locale: "en" }),
86
- searchParams: Promise.resolve({}),
87
- });
88
- expect(meta.robots).toEqual({ index: false, follow: true });
89
- expect(meta.referrer).toBe("no-referrer");
90
- });
91
- });
92
-
93
- describe("the page performs no write on GET", () => {
94
- it("renders with no call to unsubscribeAction", async () => {
95
- await renderPage("tok_1");
96
- expect(mockUnsubscribe).not.toHaveBeenCalled();
97
- expect(screen.getByTestId("unsubscribe-page")).toBeInTheDocument();
98
- expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Unsubscribe");
99
- expect(screen.getByText("Stop getting the newsletter by email?")).toBeInTheDocument();
100
- });
101
- });
102
-
103
- describe("with no token", () => {
104
- it("shows the invalid-link line and no button", async () => {
105
- await renderPage(undefined);
106
- expect(screen.getByTestId("unsubscribe-invalid")).toHaveTextContent("This link isn't valid.");
107
- expect(screen.queryByTestId("unsubscribe-button")).not.toBeInTheDocument();
108
- expect(mockUnsubscribe).not.toHaveBeenCalled();
109
- });
110
- });
111
-
112
- describe("clicking Unsubscribe", () => {
113
- it("a changed answer shows the magnet's done message (#8847 D12)", async () => {
114
- mockUnsubscribe.mockResolvedValue(
115
- ok({ purpose: { id: "marketing_email", description: "product news and offers" }, changed: true }),
116
- );
117
- await renderPage("tok_1");
118
- await userEvent.click(screen.getByTestId("unsubscribe-button"));
119
- expect(mockUnsubscribe).toHaveBeenCalledWith({ token: "tok_1" });
120
- expect(await screen.findByTestId("unsubscribe-done")).toHaveTextContent(
121
- "You're unsubscribed.You won't get the newsletter any more.",
122
- );
123
- });
124
-
125
- it("changed: false shows the already-unsubscribed line, with no second write implied", async () => {
126
- mockUnsubscribe.mockResolvedValue(
127
- ok({ purpose: { id: "marketing_email", description: "product news and offers" }, changed: false }),
128
- );
129
- await renderPage("tok_1");
130
- await userEvent.click(screen.getByTestId("unsubscribe-button"));
131
- expect(await screen.findByTestId("unsubscribe-already")).toHaveTextContent(
132
- "You were already unsubscribed.",
133
- );
134
- });
135
-
136
- it("any 400 shows the invalid-link line", async () => {
137
- mockUnsubscribe.mockResolvedValue(refusal(400));
138
- await renderPage("tok_1");
139
- await userEvent.click(screen.getByTestId("unsubscribe-button"));
140
- expect(await screen.findByTestId("unsubscribe-invalid")).toHaveTextContent("This link isn't valid.");
141
- });
142
-
143
- it("a 429 (rate-limited) shows the unavailable line, never the invalid-link line", async () => {
144
- mockUnsubscribe.mockResolvedValue(refusal(429));
145
- await renderPage("tok_1");
146
- await userEvent.click(screen.getByTestId("unsubscribe-button"));
147
- expect(await screen.findByTestId("unsubscribe-unavailable")).toHaveTextContent(
148
- "Unsubscribing isn't available right now.",
149
- );
150
- expect(screen.queryByTestId("unsubscribe-invalid")).not.toBeInTheDocument();
151
- });
152
-
153
- it("a 5xx shows the unavailable line", async () => {
154
- mockUnsubscribe.mockResolvedValue(refusal(503));
155
- await renderPage("tok_1");
156
- await userEvent.click(screen.getByTestId("unsubscribe-button"));
157
- expect(await screen.findByTestId("unsubscribe-unavailable")).toHaveTextContent(
158
- "Unsubscribing isn't available right now.",
159
- );
160
- });
161
-
162
- it("a thrown error shows the unavailable line, never a crash", async () => {
163
- mockUnsubscribe.mockRejectedValue(new TypeError("fetch failed"));
164
- await renderPage("tok_1");
165
- await userEvent.click(screen.getByTestId("unsubscribe-button"));
166
- expect(await screen.findByTestId("unsubscribe-unavailable")).toBeInTheDocument();
167
- });
168
- });
169
-
170
- describe("the copy comes from the newsletter magnet (#8847 D12, AC-7)", () => {
171
- const unsubscribe = {
172
- title: { en: "Leave" },
173
- body: { en: "Sure?" },
174
- cta: { en: "Leave now" },
175
- done: { headline: { en: "Gone." } },
176
- };
177
-
178
- beforeEach(() => {
179
- const { newsletterFlowConfig } = jest.requireActual("@working-theory/validation") as {
180
- newsletterFlowConfig: Record<string, unknown>;
181
- };
182
- const { completionEmail: _omitted, ...body } = newsletterFlowConfig;
183
- mockFlowsGet.mockReset().mockResolvedValue({ ok: true, status: 200, body: { ...body, unsubscribe } });
184
- });
185
-
186
- it("the title, line and button are the served block's, and so is the done message", async () => {
187
- mockUnsubscribe.mockResolvedValue(
188
- ok({ purpose: { id: "newsletter", description: "This site's newsletter by email" }, changed: true }),
189
- );
190
- await renderPage("tok_1");
191
- expect(mockFlowsGet).toHaveBeenCalledWith("newsletter");
192
- expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Leave");
193
- expect(screen.getByText("Sure?")).toBeInTheDocument();
194
- expect(screen.getByTestId("unsubscribe-button")).toHaveTextContent("Leave now");
195
- await userEvent.click(screen.getByTestId("unsubscribe-button"));
196
- expect(await screen.findByTestId("unsubscribe-done")).toHaveTextContent("Gone.");
197
- });
198
-
199
- it("generateMetadata's title is the served block's", async () => {
200
- const meta = await generateMetadata({
201
- params: Promise.resolve({ locale: "en" }),
202
- searchParams: Promise.resolve({}),
203
- });
204
- expect(meta.title).toBe("Leave");
205
- });
206
-
207
- it("already still shows the catalog's line", async () => {
208
- mockUnsubscribe.mockResolvedValue(
209
- ok({ purpose: { id: "newsletter", description: "This site's newsletter by email" }, changed: false }),
210
- );
211
- await renderPage("tok_1");
212
- await userEvent.click(screen.getByTestId("unsubscribe-button"));
213
- expect(await screen.findByTestId("unsubscribe-already")).toHaveTextContent(
214
- "You were already unsubscribed.",
215
- );
216
- });
217
- });