create-ailk 0.39.0 → 0.40.1

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 (203) hide show
  1. package/component-catalog.json +1 -1
  2. package/component-catalog.md +1 -1
  3. package/dist/add-route.js +15 -0
  4. package/dist/body-heading.d.ts +2 -1
  5. package/dist/body-heading.js +31 -3
  6. package/dist/module-architecture.js +0 -3
  7. package/dist/remove-module.js +13 -4
  8. package/dist/routes.d.ts +7 -0
  9. package/dist/routes.js +1 -1
  10. package/dist/site-roster.js +7 -1
  11. package/dist/surfaces.d.ts +2 -0
  12. package/dist/surfaces.js +59 -172
  13. package/package.json +3 -3
  14. package/templates/apps/web/CLAUDE.md +19 -2
  15. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +3 -2
  16. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +3 -2
  17. package/templates/apps/web/app/[locale]/layout.tsx +42 -25
  18. package/templates/apps/web/app/api/revalidate/__tests__/route.test.ts +56 -1
  19. package/templates/apps/web/app/api/revalidate/route.ts +45 -4
  20. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +53 -0
  21. package/templates/apps/web/app/llms.txt/route.ts +5 -2
  22. package/templates/apps/web/i18n/request.ts +5 -1
  23. package/templates/apps/web/jest.config.cjs +6 -0
  24. package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
  25. package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +239 -0
  26. package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
  27. package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
  28. package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
  29. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +58 -0
  30. package/templates/apps/web/lib/__tests__/served-pages.test.ts +163 -20
  31. package/templates/apps/web/lib/__tests__/site-brand.test.ts +77 -0
  32. package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +64 -0
  33. package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +115 -3
  34. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
  35. package/templates/apps/web/lib/hub-site-config.ts +151 -0
  36. package/templates/apps/web/lib/in-page-magnet.ts +2 -2
  37. package/templates/apps/web/lib/pricing-page.ts +3 -3
  38. package/templates/apps/web/lib/profile-back-link.ts +49 -12
  39. package/templates/apps/web/lib/served-pages.ts +144 -39
  40. package/templates/apps/web/lib/site-brand.tsx +66 -0
  41. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +25 -5
  42. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +21 -5
  43. package/templates/apps/web/lib/site-header.ts +1 -1
  44. package/templates/apps/web/lib/site-identity.ts +38 -2
  45. package/templates/apps/web/messages/en.json +3 -119
  46. package/templates/apps/web/next.config.mjs +7 -0
  47. package/templates/apps/web/package.json +1 -0
  48. package/templates/apps/web/site-pages.config.tsx +85 -0
  49. package/templates/tools/body-heading.ts +30 -3
  50. package/versions.json +50 -49
  51. package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
  52. package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
  53. package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
  54. package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
  55. package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
  56. package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
  57. package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
  58. package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
  59. package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
  60. package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
  61. package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
  62. package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
  63. package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
  64. package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
  65. package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
  66. package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
  67. package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
  68. package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
  69. package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
  70. package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
  71. package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
  72. package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
  73. package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
  74. package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
  75. package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
  76. package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
  77. package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
  78. package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
  79. package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
  80. package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
  81. package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
  82. package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
  83. package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
  84. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
  85. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
  86. package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
  87. package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
  88. package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
  89. package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
  90. package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
  91. package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
  92. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
  93. package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
  94. package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
  95. package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
  96. package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
  97. package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
  98. package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
  99. package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
  100. package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
  101. package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
  102. package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
  103. package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
  104. package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
  105. package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
  106. package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
  107. package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
  108. package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
  109. package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
  110. package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
  111. package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
  112. package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
  113. package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
  114. package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
  115. package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
  116. package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
  117. package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
  118. package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
  119. package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
  120. package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
  121. package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
  122. package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
  123. package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
  124. package/templates/apps/web/app/[locale]/page.tsx +0 -147
  125. package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
  126. package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
  127. package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
  128. package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
  129. package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
  130. package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
  131. package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
  132. package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
  133. package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
  134. package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
  135. package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
  136. package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
  137. package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
  138. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
  139. package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
  140. package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
  141. package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
  142. package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
  143. package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
  144. package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
  145. package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
  146. package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
  147. package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
  148. package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
  149. package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
  150. package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
  151. package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
  152. package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
  153. package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
  154. package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
  155. package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
  156. package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
  157. package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
  158. package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
  159. package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
  160. package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
  161. package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
  162. package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
  163. package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
  164. package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
  165. package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
  166. package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
  167. package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
  168. package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
  169. package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
  170. package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
  171. package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
  172. package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
  173. package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
  174. package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
  175. package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
  176. package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
  177. package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
  178. package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
  179. package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
  180. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
  181. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
  182. package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
  183. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
  184. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
  185. package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
  186. package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
  187. package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
  188. package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
  189. package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
  190. package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
  191. package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
  192. package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
  193. package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
  194. package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
  195. package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
  196. package/templates/apps/web/lib/hub-children.tsx +0 -351
  197. package/templates/apps/web/lib/meet-placeholder.ts +0 -5
  198. package/templates/apps/web/lib/posting-title.ts +0 -39
  199. package/templates/apps/web/lib/route-family.ts +0 -69
  200. package/templates/apps/web/lib/service-listing.ts +0 -89
  201. package/templates/apps/web/lib/template-listing.ts +0 -169
  202. package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
  203. package/templates/apps/web/src/lib/lead-write.ts +0 -90
@@ -1,51 +0,0 @@
1
- /**
2
- * Tests for intake-analytics.ts's recordIntakeTurn (#4534, epic #4521's
3
- * integration leg).
4
- *
5
- * Acceptance criteria verified here:
6
- * - recordIntakeTurn calls track() with the turn index + status + locale.
7
- * - Never leaks answer text (PII-free per AC3).
8
- */
9
-
10
- jest.mock("@working-theory/analytics/server", () => ({
11
- track: jest.fn().mockResolvedValue(undefined),
12
- }));
13
-
14
- import { track } from "@working-theory/analytics/server";
15
-
16
- import { recordIntakeTurn } from "../intake-analytics.js";
17
-
18
- const mockTrack = track as jest.Mock;
19
-
20
- afterEach(() => {
21
- jest.clearAllMocks();
22
- });
23
-
24
- describe("recordIntakeTurn", () => {
25
- it("reports the turn index, status, and locale — nothing else", async () => {
26
- await recordIntakeTurn({
27
- turnIndex: 2,
28
- status: "in_progress",
29
- locale: "en",
30
- });
31
-
32
- expect(mockTrack).toHaveBeenCalledWith("intake-turn-abandonment", {
33
- turnIndex: 2,
34
- status: "in_progress",
35
- locale: "en",
36
- });
37
- });
38
-
39
- it("never receives answer text (PII-free)", async () => {
40
- await recordIntakeTurn({
41
- turnIndex: 3,
42
- status: "completed",
43
- locale: "en",
44
- });
45
-
46
- const props = mockTrack.mock.calls[0][1] as Record<string, unknown>;
47
- expect(Object.keys(props).sort()).toEqual(
48
- ["turnIndex", "status", "locale"].sort(),
49
- );
50
- });
51
- });
@@ -1,319 +0,0 @@
1
- /**
2
- * contact/page.tsx — render regression + the #6730 D8 contract.
3
- *
4
- * Contact uses sections mode (not bodyMode: "mdx-body"). Since #6730 the page
5
- * places ONE contact surface, first match wins: into the page's first
6
- * `contact-form` section; else into a leading split hero; else after the
7
- * page. The surface is the shared `LeadCaptureForm` block — or, when the API
8
- * says this deployment accepts no contact message, `ContactFallback` with the
9
- * site's contact email and NO form. A failed status read (unreachable API)
10
- * renders the form: its submit then reports honestly.
11
- *
12
- * Boundaries mocked: `@working-theory/ui` (the renderer's section tree is a
13
- * stub that renders each section's slotted node, so placement is visible),
14
- * `@working-theory/api-client` (`leads.captureStatus`), `next-intl/server`,
15
- * the `_site.mdx` contact-email read, and the Server Action module.
16
- */
17
- import React from "react";
18
- import { render, screen } from "@testing-library/react";
19
-
20
- // ── @working-theory/ui mock ─────────────────────────────────────────────────
21
- jest.mock("@working-theory/ui", () => ({
22
- // #7789: renderPage's fallback page head renders inside the section Container.
23
- Container: ({ children }: { children?: React.ReactNode }) =>
24
- React.createElement("div", null, children),
25
- // #4446/#4447: renderPage's own fallback/empty-state title composes Heading.
26
- Heading: ({
27
- children,
28
- level,
29
- }: {
30
- children: React.ReactNode;
31
- level: number;
32
- }): React.ReactElement => React.createElement(`h${level}`, null, children),
33
- SectionRenderer: ({
34
- sections,
35
- sectionSlots,
36
- }: {
37
- sections: Array<{ id: string }>;
38
- sectionSlots?: Record<string, React.ReactNode>;
39
- }) =>
40
- React.createElement(
41
- "div",
42
- {
43
- "data-testid": "section-renderer",
44
- "data-section-count": String(sections.length),
45
- },
46
- sections.map((s) =>
47
- React.createElement(
48
- "div",
49
- { key: s.id, "data-section-id": s.id },
50
- sectionSlots?.[s.id],
51
- ),
52
- ),
53
- ),
54
- localeHref: (locale: string, path: string) => `/${locale}${path}`,
55
- LeadCaptureForm: (props: {
56
- fields?: Array<{ name: string }>;
57
- submitLabel?: string;
58
- text?: { submit?: string };
59
- fallbackEmail?: string;
60
- termsHref: string;
61
- }) =>
62
- React.createElement(
63
- "div",
64
- {
65
- "data-testid": "lead-capture-form",
66
- "data-fields": (props.fields ?? []).map((f) => f.name).join(","),
67
- "data-fallback-email": props.fallbackEmail ?? "",
68
- "data-terms-href": props.termsHref,
69
- },
70
- React.createElement(
71
- "button",
72
- { "data-testid": "contact-submit" },
73
- // The real block falls back to its copy's submit label.
74
- props.submitLabel ?? props.text?.submit ?? "Send",
75
- ),
76
- ),
77
- ContactFallback: (props: { email?: string; text?: { noEmail?: string } }) =>
78
- React.createElement(
79
- "div",
80
- { "data-testid": "contact-fallback" },
81
- props.email
82
- ? React.createElement(
83
- "a",
84
- { href: `mailto:${props.email}` },
85
- props.email,
86
- )
87
- : props.text?.noEmail,
88
- ),
89
- }));
90
-
91
- jest.mock("@working-theory/api-client", () => ({
92
- leads: { captureStatus: jest.fn(), submit: jest.fn() },
93
- }));
94
-
95
- // The real English catalog, so renderPage's own strings render as they ship.
96
- jest.mock("next-intl/server", () => {
97
- const messages = jest.requireActual("../../../../messages/en.json") as Record<
98
- string,
99
- Record<string, unknown>
100
- >;
101
- return {
102
- getTranslations: async (arg: string | { namespace: string }) => {
103
- const ns = messages[typeof arg === "string" ? arg : arg.namespace] ?? {};
104
- return (key: string) => (ns[key] ?? key) as string;
105
- },
106
- };
107
- });
108
-
109
- // eslint-disable-next-line no-restricted-syntax -- test-seam mock: the real read is a node:fs frontmatter parse of content/_site.mdx; narrowest possible scope
110
- jest.mock("../site-contact-email", () => ({
111
- readSiteContactEmail: jest.fn(),
112
- }));
113
-
114
- // eslint-disable-next-line no-restricted-syntax -- test-seam mock: the Server Action module is a "use server" boundary; the page only passes it through
115
- jest.mock("../contact.actions", () => ({
116
- captureLeadAction: jest.fn(),
117
- }));
118
-
119
- import { leads } from "@working-theory/api-client";
120
-
121
- import ContactPage from "../page";
122
- import { readSiteContactEmail } from "../site-contact-email";
123
-
124
- const mockCaptureStatus = leads.captureStatus as jest.Mock;
125
- const mockContactEmail = readSiteContactEmail as jest.Mock;
126
-
127
- const ACCEPTING = {
128
- ok: true,
129
- status: 200,
130
- body: { ok: true, data: { contact: true, newsletter: false } },
131
- };
132
- const REFUSING = {
133
- ok: true,
134
- status: 200,
135
- body: { ok: true, data: { contact: false, newsletter: false } },
136
- };
137
-
138
- const source = {
139
- frontmatter: {
140
- type: "ContactPage" as const,
141
- slug: "contact",
142
- title: "Contact Us",
143
- description: "Get in touch.",
144
- },
145
- body: "",
146
- };
147
-
148
- const splitHero = {
149
- id: "hero",
150
- type: "hero",
151
- data: { variant: "split", headline: "Hi" },
152
- };
153
- const contactFormSection = {
154
- id: "contact-form",
155
- type: "contact-form",
156
- data: {
157
- fields: [
158
- { name: "email", label: "Email", type: "email" },
159
- { name: "plan", label: "Plan", type: "select", options: ["free", "pro"] },
160
- ],
161
- submitLabel: "Request a demo",
162
- },
163
- };
164
-
165
- async function renderWith(sections: unknown[] | null) {
166
- const element = await ContactPage({
167
- params: Promise.resolve({ locale: "en" }),
168
- getMdxSource: jest
169
- .fn()
170
- .mockResolvedValue(sections === null ? null : source),
171
- getPageSections: jest.fn().mockResolvedValue(sections ?? []),
172
- });
173
- return render(element);
174
- }
175
-
176
- // #8731 — the page shares its two hub reads for a few seconds, per module
177
- // instance. Each test starts an hour later so none sees another's read.
178
- let clock = 1_800_000_000_000;
179
- const nowSpy = jest.spyOn(Date, "now");
180
-
181
- beforeEach(() => {
182
- jest.clearAllMocks();
183
- clock += 60 * 60 * 1000;
184
- nowSpy.mockImplementation(() => clock);
185
- mockCaptureStatus.mockResolvedValue(ACCEPTING);
186
- mockContactEmail.mockReturnValue(undefined);
187
- });
188
-
189
- describe("ContactPage — snapshot regression", () => {
190
- it("empty state renders deterministic HTML (renderPage empty-state + the form after it)", async () => {
191
- const { container } = await renderWith(null);
192
- expect(container.innerHTML).toMatchInlineSnapshot(
193
- `"<main id="main"><h1>Contact</h1><p data-testid="section-empty-state">Contact page content coming soon.</p></main><div data-testid="lead-capture-form" data-fields="name,email,subject,message" data-fallback-email="" data-terms-href="/en/terms"><button data-testid="contact-submit">Send message</button></div>"`,
194
- );
195
- });
196
-
197
- it("populated state renders deterministic HTML (renderPage sections + the form after it)", async () => {
198
- const { container } = await renderWith([]);
199
- expect(container.innerHTML).toMatchInlineSnapshot(
200
- `"<script type="application/ld+json" data-testid="json-ld">{"@context":"https://schema.org","@type":"ContactPage","inLanguage":"en","name":"Contact Us","description":"Get in touch.","mainEntity":{"@type":"ContactPoint","contactType":"customer support"}}</script><main id="main"><div><h1>Contact Us</h1><p data-testid="contact-description" class="mt-block-tight text-lead">Get in touch.</p></div><div data-testid="section-renderer" data-section-count="0"></div></main><div data-testid="lead-capture-form" data-fields="name,email,subject,message" data-fallback-email="" data-terms-href="/en/terms"><button data-testid="contact-submit">Send message</button></div>"`,
201
- );
202
- });
203
- });
204
-
205
- describe("ContactPage — placement (#6730 D8)", () => {
206
- it("a contact-form section hosts the form, with that section's fields and label", async () => {
207
- const { container } = await renderWith([splitHero, contactFormSection]);
208
-
209
- const slot = container.querySelector("[data-section-id='contact-form']")!;
210
- const form = slot.querySelector("[data-testid='lead-capture-form']");
211
- expect(form).not.toBeNull();
212
- expect(form).toHaveAttribute("data-fields", "email,plan");
213
- expect(slot).toHaveTextContent("Request a demo");
214
- expect(screen.getAllByTestId("lead-capture-form")).toHaveLength(1);
215
- });
216
-
217
- it("no contact-form section + a leading split hero → inside the hero", async () => {
218
- const { container } = await renderWith([splitHero]);
219
-
220
- expect(
221
- container.querySelector(
222
- "[data-section-id='hero'] [data-testid='lead-capture-form']",
223
- ),
224
- ).not.toBeNull();
225
- expect(screen.getAllByTestId("lead-capture-form")).toHaveLength(1);
226
- });
227
-
228
- it("neither → after the page", async () => {
229
- const { container } = await renderWith([
230
- { id: "faq", type: "faq", data: { items: [] } },
231
- ]);
232
-
233
- expect(
234
- container.querySelector("main [data-testid='lead-capture-form']"),
235
- ).toBeNull();
236
- expect(screen.getAllByTestId("lead-capture-form")).toHaveLength(1);
237
- });
238
-
239
- it("passes the site's contact email to the form's unavailable state", async () => {
240
- mockContactEmail.mockReturnValue("hi@example.com");
241
- await renderWith([]);
242
- expect(screen.getByTestId("lead-capture-form")).toHaveAttribute(
243
- "data-fallback-email",
244
- "hi@example.com",
245
- );
246
- });
247
- });
248
-
249
- describe("ContactPage — no lead destination (#6730 D8)", () => {
250
- it("status contact:false + a contactEmail → the fallback with a mailto link, and no form", async () => {
251
- mockCaptureStatus.mockResolvedValue(REFUSING);
252
- mockContactEmail.mockReturnValue("hi@example.com");
253
-
254
- await renderWith([]);
255
-
256
- const fallback = screen.getByTestId("contact-fallback");
257
- expect(
258
- fallback.querySelector("a[href='mailto:hi@example.com']"),
259
- ).not.toBeNull();
260
- expect(screen.queryByTestId("contact-submit")).toBeNull();
261
- expect(screen.queryByTestId("lead-capture-form")).toBeNull();
262
- });
263
-
264
- it("status contact:false + no contactEmail → the no-email copy, and no form", async () => {
265
- mockCaptureStatus.mockResolvedValue(REFUSING);
266
-
267
- await renderWith([]);
268
-
269
- expect(screen.getByTestId("contact-fallback")).toHaveTextContent(
270
- "Contact details for this site haven't been published yet.",
271
- );
272
- expect(screen.queryByTestId("contact-submit")).toBeNull();
273
- });
274
-
275
- it("the fallback takes the contact-form section's place too", async () => {
276
- mockCaptureStatus.mockResolvedValue(REFUSING);
277
- mockContactEmail.mockReturnValue("hi@example.com");
278
-
279
- const { container } = await renderWith([contactFormSection]);
280
-
281
- expect(
282
- container.querySelector(
283
- "[data-section-id='contact-form'] [data-testid='contact-fallback']",
284
- ),
285
- ).not.toBeNull();
286
- });
287
-
288
- it.each([
289
- [
290
- "rejects (unreachable API)",
291
- () => mockCaptureStatus.mockRejectedValue(new Error("ECONNREFUSED")),
292
- ],
293
- [
294
- "404 (older API)",
295
- () =>
296
- mockCaptureStatus.mockResolvedValue({
297
- ok: false,
298
- status: 404,
299
- body: {},
300
- }),
301
- ],
302
- [
303
- "5xx",
304
- () =>
305
- mockCaptureStatus.mockResolvedValue({
306
- ok: false,
307
- status: 503,
308
- body: {},
309
- }),
310
- ],
311
- ])("status %s → the form renders", async (_label, arrange) => {
312
- arrange();
313
-
314
- await renderWith([]);
315
-
316
- expect(screen.getByTestId("contact-submit")).toBeInTheDocument();
317
- expect(screen.queryByTestId("contact-fallback")).toBeNull();
318
- });
319
- });
@@ -1,77 +0,0 @@
1
- /**
2
- * contactFormFromConfig — a Contact form magnet's config, as the shared
3
- * `LeadCaptureForm` block renders it (#8661 D6).
4
- *
5
- * Reads the config's first step, which must be a `field` step (a config that
6
- * opens with any other step is not a contact form). Answers `null` unless that
7
- * step holds fields named `name` and `email`, because `captureLeadAction` needs both;
8
- * the page then falls back (section fields, else the built-in config).
9
- *
10
- * Each `text`, `email`, `tel`, `url`, `textarea` or `select` field is mapped,
11
- * in order. `name` and `email` sit side by side (`colSpan: 1`, the built-in
12
- * pairing); every other field runs full width. The step's first `consent`
13
- * field is the terms statement (its label), and its `copy.cta` the submit
14
- * label. Other `consent` fields and `address` fields are not rendered.
15
- *
16
- * Copy resolves with the one LocalizedString rule every flow surface shares
17
- * (`resolveLocalizedString`). Pure: no fetch, no React.
18
- */
19
- import type { ContactFormField } from "@working-theory/ui";
20
- import { resolveLocalizedString, type FlowConfig } from "@working-theory/validation";
21
-
22
- export interface ContactFormView {
23
- fields: ContactFormField[];
24
- /** The step's first consent field's label — `[Label](key)` tokens intact. */
25
- consentStatement?: string;
26
- /** The step's `copy.cta`. */
27
- submitLabel?: string;
28
- }
29
-
30
- type FieldStep = Extract<FlowConfig["steps"][number], { type: "field" }>;
31
- type FieldDef = FieldStep["fields"][number];
32
-
33
- const RENDERED_TYPES = ["text", "email", "tel", "url", "textarea", "select"] as const;
34
- type RenderedType = (typeof RENDERED_TYPES)[number];
35
-
36
- function isRendered(type: FieldDef["inputType"]): type is RenderedType {
37
- return (RENDERED_TYPES as readonly string[]).includes(type);
38
- }
39
-
40
- export function contactFormFromConfig(
41
- config: FlowConfig,
42
- locale: string,
43
- ): ContactFormView | null {
44
- const step = config.steps[0];
45
- if (step?.type !== "field") return null;
46
- const names = new Set(step.fields.map((f) => f.name));
47
- if (!names.has("name") || !names.has("email")) return null;
48
-
49
- const resolve = (value: Record<string, string>): string =>
50
- resolveLocalizedString(value, locale, config.defaultLocale);
51
-
52
- const fields: ContactFormField[] = [];
53
- for (const field of step.fields) {
54
- if (!isRendered(field.inputType)) continue;
55
- fields.push({
56
- name: field.name,
57
- type: field.inputType,
58
- label: resolve(field.copy.label),
59
- required: field.required ?? false,
60
- ...(field.copy.placeholder !== undefined && {
61
- placeholder: resolve(field.copy.placeholder),
62
- }),
63
- ...(field.copy.help !== undefined && { helpText: resolve(field.copy.help) }),
64
- ...(field.options !== undefined && {
65
- options: field.options.map((o) => ({ value: o.value, label: resolve(o.label) })),
66
- }),
67
- colSpan: field.name === "name" || field.name === "email" ? 1 : 2,
68
- });
69
- }
70
-
71
- const consent = step.fields.find((f) => f.inputType === "consent");
72
- return {
73
- fields,
74
- ...(consent !== undefined && { consentStatement: resolve(consent.copy.label) }),
75
- ...(step.copy.cta !== undefined && { submitLabel: resolve(step.copy.cta) }),
76
- };
77
- }
@@ -1,52 +0,0 @@
1
- /**
2
- * contactFormText — the `contact` message namespace mapped onto the shared
3
- * `LeadCaptureForm` block's copy (#6730 D8).
4
- *
5
- * One pure mapping, shared by the RSC page (`getTranslations`) and the client
6
- * `ConversationalIntakeWrapper` (`useTranslations`), so the two surfaces that
7
- * render the form can never label it differently. `unavailableBody` keeps
8
- * its `{email}` placeholder (interpolated back to itself): the block fills
9
- * it, since only the block knows the address it is showing.
10
- */
11
-
12
- import type { LeadCaptureFormText } from "@working-theory/ui";
13
-
14
- type ContactTextKey =
15
- | "nameLabel"
16
- | "emailLabel"
17
- | "messageLabel"
18
- | "sendMessage"
19
- | "sending"
20
- | "successMessage"
21
- | "genericError"
22
- | "consentStatement"
23
- | "consentRequired"
24
- | "unavailableHeading"
25
- | "unavailableBody"
26
- | "unavailableNoEmail";
27
-
28
- /** The subset of a `contact`-namespace translator this mapping reads. */
29
- export type ContactTranslator = (
30
- key: ContactTextKey,
31
- values?: { email: string },
32
- ) => string;
33
-
34
- /** Keeps the `{email}` placeholder for the block to fill. */
35
- const KEEP_EMAIL_PLACEHOLDER = { email: "{email}" };
36
-
37
- export function contactFormText(t: ContactTranslator): LeadCaptureFormText {
38
- return {
39
- nameLabel: t("nameLabel"),
40
- emailLabel: t("emailLabel"),
41
- messageLabel: t("messageLabel"),
42
- submit: t("sendMessage"),
43
- sending: t("sending"),
44
- success: t("successMessage"),
45
- genericError: t("genericError"),
46
- consentStatement: t("consentStatement"),
47
- consentRequired: t("consentRequired"),
48
- unavailableHeading: t("unavailableHeading"),
49
- unavailableBody: t("unavailableBody", KEEP_EMAIL_PLACEHOLDER),
50
- unavailableNoEmail: t("unavailableNoEmail"),
51
- };
52
- }