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,494 +0,0 @@
1
- /**
2
- * contact/page.tsx over the Contact form magnet (#8661 D6) — AC-3 and AC-5.
3
- *
4
- * Unlike `page-renderer-migration.test.tsx`, this suite renders the REAL
5
- * `LeadCaptureForm` and binds the REAL `captureLeadAction`, so the hidden
6
- * `source` input, the fields and a submit are all visible. Mocked
7
- * boundaries: `@working-theory/api-client` (`flows.get`, `leads.captureStatus`,
8
- * `leads.submit`), `next/headers`, `next-intl/server` (over the real English
9
- * catalog), the `_site.mdx` contact-email read, and the page-renderer's
10
- * content loaders (injected).
11
- */
12
- import React from "react";
13
- import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
14
- import {
15
- CONTACT_FORM_TERMS_STATEMENT,
16
- contactFormFlowConfig,
17
- type FlowConfig,
18
- } from "@working-theory/validation";
19
-
20
- jest.mock("next/navigation", () => ({
21
- __esModule: true,
22
- notFound: jest.fn(() => {
23
- throw new Error("NEXT_NOT_FOUND");
24
- }),
25
- }));
26
-
27
- jest.mock("next-mdx-remote/rsc", () => ({
28
- __esModule: true,
29
- MDXRemote: ({ source }: { source: string }) =>
30
- React.createElement("div", { "data-testid": "mdx-rendered" }, source),
31
- }));
32
-
33
- jest.mock("@working-theory/api-client", () => ({
34
- flows: { get: jest.fn() },
35
- leads: { captureStatus: jest.fn(), submit: jest.fn() },
36
- visitorForwardHeaders: () => undefined,
37
- }));
38
-
39
- jest.mock("next/headers", () => ({
40
- __esModule: true,
41
- headers: jest.fn().mockResolvedValue({ get: () => null }),
42
- cookies: jest.fn().mockResolvedValue({ get: () => undefined }),
43
- }));
44
-
45
- // The real English catalog, so the page's own strings render as they ship.
46
- jest.mock("next-intl/server", () => {
47
- const messages = jest.requireActual("../../../../messages/en.json") as Record<
48
- string,
49
- Record<string, unknown>
50
- >;
51
- return {
52
- getTranslations: async (arg: string | { namespace: string }) => {
53
- const ns = messages[typeof arg === "string" ? arg : arg.namespace] ?? {};
54
- return (key: string, values?: Record<string, string>) =>
55
- String(ns[key] ?? key).replace(/\{(\w+)\}/g, (m, name: string) => values?.[name] ?? m);
56
- },
57
- };
58
- });
59
-
60
- // 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
61
- jest.mock("../site-contact-email", () => ({
62
- readSiteContactEmail: jest.fn().mockReturnValue(undefined),
63
- }));
64
-
65
- import { flows, leads } from "@working-theory/api-client";
66
- import { localeHref } from "@working-theory/ui";
67
-
68
- import { contactFormFromConfig } from "../contact-form-magnet";
69
- import * as pageModule from "../page";
70
- import ContactPage from "../page";
71
-
72
- const mockFlowsGet = flows.get as jest.Mock;
73
- const mockCaptureStatus = leads.captureStatus as jest.Mock;
74
- const mockSubmit = leads.submit as jest.Mock;
75
-
76
- type FieldStep = Extract<FlowConfig["steps"][number], { type: "field" }>;
77
-
78
- const source = {
79
- frontmatter: {
80
- type: "ContactPage" as const,
81
- slug: "contact",
82
- title: "Contact Us",
83
- description: "Get in touch.",
84
- },
85
- body: "",
86
- };
87
-
88
- /** The seeded config with its subject relabelled. */
89
- function configWithSubjectLabel(label: string): FlowConfig {
90
- const config = JSON.parse(JSON.stringify(contactFormFlowConfig)) as FlowConfig;
91
- const subject = (config.steps[0] as FieldStep).fields.find((f) => f.name === "subject")!;
92
- subject.copy.label = { en: label };
93
- return config;
94
- }
95
-
96
- const served = (config: FlowConfig) => ({ ok: true, status: 200, body: config });
97
-
98
- async function renderPage(sections: unknown[] = []) {
99
- const element = await ContactPage({
100
- params: Promise.resolve({ locale: "en" }),
101
- getMdxSource: jest.fn().mockResolvedValue(source),
102
- getPageSections: jest.fn().mockResolvedValue(sections),
103
- });
104
- return render(element);
105
- }
106
-
107
- function sourceInput(): HTMLInputElement | null {
108
- return document.querySelector<HTMLInputElement>("input[name='source']");
109
- }
110
-
111
- function fieldNames(): string[] {
112
- return Array.from(
113
- screen.getByTestId("lead-capture-form").querySelectorAll<HTMLElement>("[data-testid^='field-']"),
114
- ).map((el) => el.dataset.testid!.slice("field-".length));
115
- }
116
-
117
- async function tickAndSubmit(values: Record<string, string>) {
118
- for (const [name, value] of Object.entries(values)) {
119
- fireEvent.change(screen.getByTestId(`field-${name}`), { target: { value } });
120
- }
121
- fireEvent.click(screen.getByTestId("contact-consent"));
122
- await act(async () => {
123
- fireEvent.submit(screen.getByTestId("lead-capture-form"));
124
- });
125
- }
126
-
127
- // #8731 — the page shares its two hub reads for a few seconds, per module
128
- // instance. Each test starts an hour later so none sees another's read.
129
- let clock = 1_800_000_000_000;
130
- const nowSpy = jest.spyOn(Date, "now");
131
-
132
- beforeEach(() => {
133
- jest.clearAllMocks();
134
- clock += 60 * 60 * 1000;
135
- nowSpy.mockImplementation(() => clock);
136
- mockCaptureStatus.mockResolvedValue({
137
- ok: true,
138
- status: 200,
139
- body: { ok: true, data: { contact: true, newsletter: false } },
140
- });
141
- mockSubmit.mockResolvedValue({ ok: true, body: { id: "lead_1", persisted: "db" } });
142
- });
143
-
144
- describe("contact/page — rendering (AC-3)", () => {
145
- it("is rendered on every request, never ISR", () => {
146
- expect(pageModule.dynamic).toBe("force-dynamic");
147
- expect("revalidate" in pageModule).toBe(false);
148
- });
149
-
150
- it("renders the served magnet's fields, and stamps the post flow:contact", async () => {
151
- mockFlowsGet.mockResolvedValue(served(configWithSubjectLabel("Topic")));
152
-
153
- await renderPage();
154
-
155
- expect(mockFlowsGet).toHaveBeenCalledWith("contact");
156
- expect(fieldNames()).toEqual(["name", "email", "subject", "message"]);
157
- expect(screen.getByTestId("lead-capture-form")).toHaveTextContent("Topic");
158
- expect(sourceInput()).toHaveAttribute("type", "hidden");
159
- expect(sourceInput()!.value).toBe("flow:contact");
160
- });
161
-
162
- it("the magnet wins over a content section's declared fields", async () => {
163
- mockFlowsGet.mockResolvedValue(served(configWithSubjectLabel("Topic")));
164
-
165
- await renderPage([
166
- {
167
- id: "contact-form",
168
- type: "contact-form",
169
- data: { fields: [{ name: "company", label: "Company", type: "text" }] },
170
- },
171
- ]);
172
-
173
- expect(fieldNames()).toEqual(["name", "email", "subject", "message"]);
174
- expect(screen.queryByTestId("field-company")).toBeNull();
175
- });
176
-
177
- it("a burst of views makes one hub read of each kind, not one per view (#8731)", async () => {
178
- mockFlowsGet.mockResolvedValue(served(configWithSubjectLabel("Topic")));
179
- for (let i = 0; i < 25; i += 1) {
180
- const view = await renderPage();
181
- expect(screen.getByTestId("lead-capture-form")).toHaveTextContent("Topic");
182
- view.unmount();
183
- }
184
- expect(mockFlowsGet).toHaveBeenCalledTimes(1);
185
- expect(mockCaptureStatus).toHaveBeenCalledTimes(1);
186
- });
187
-
188
- it("concurrent views share one in-flight read of each (#8731)", async () => {
189
- mockFlowsGet.mockResolvedValue(served(contactFormFlowConfig));
190
- await Promise.all([renderPage(), renderPage(), renderPage()]);
191
- expect(mockFlowsGet).toHaveBeenCalledTimes(1);
192
- expect(mockCaptureStatus).toHaveBeenCalledTimes(1);
193
- });
194
-
195
- it("an Admin edit shows once the shared read expires (#8731)", async () => {
196
- mockFlowsGet.mockResolvedValueOnce(served(configWithSubjectLabel("Topic")));
197
- const first = await renderPage();
198
- expect(screen.getByTestId("lead-capture-form")).toHaveTextContent("Topic");
199
- first.unmount();
200
-
201
- mockFlowsGet.mockResolvedValueOnce(served(configWithSubjectLabel("Reason")));
202
- clock += 60_000;
203
- await renderPage();
204
- const form = screen.getByTestId("lead-capture-form");
205
- expect(form).toHaveTextContent("Reason");
206
- expect(form).not.toHaveTextContent("Topic");
207
- expect(mockFlowsGet).toHaveBeenCalledTimes(2);
208
- });
209
-
210
- it("a failed read is shared too, so an unreachable hub is not retried per view (#8731)", async () => {
211
- mockFlowsGet.mockRejectedValue(new Error("hub down"));
212
- mockCaptureStatus.mockRejectedValue(new Error("hub down"));
213
- for (let i = 0; i < 5; i += 1) {
214
- const view = await renderPage();
215
- expect(screen.getByTestId("lead-capture-form")).toBeInTheDocument();
216
- view.unmount();
217
- }
218
- expect(mockFlowsGet).toHaveBeenCalledTimes(1);
219
- expect(mockCaptureStatus).toHaveBeenCalledTimes(1);
220
- });
221
-
222
- it("links Terms and Privacy Policy in the two-link statement (#8847 D2)", async () => {
223
- mockFlowsGet.mockResolvedValue(served(contactFormFlowConfig));
224
-
225
- await renderPage();
226
-
227
- expect(screen.getByTestId("consent-policy-link-terms")).toHaveAttribute(
228
- "href",
229
- localeHref("en", "/terms"),
230
- );
231
- expect(screen.getByTestId("consent-policy-link-privacy")).toHaveAttribute(
232
- "href",
233
- localeHref("en", "/privacy"),
234
- );
235
- expect(screen.queryByTestId("consent-policy-link-working_agreement")).toBeNull();
236
- });
237
-
238
- it("a magnet-driven post reaches leads.submit as flow:contact with its subject", async () => {
239
- mockFlowsGet.mockResolvedValue(served(contactFormFlowConfig));
240
-
241
- await renderPage();
242
- await tickAndSubmit({ name: "Ada", email: "ada@example.com" });
243
-
244
- await waitFor(() => expect(mockSubmit).toHaveBeenCalledTimes(1));
245
- expect(mockSubmit.mock.calls[0][0]).toMatchObject({ source: "flow:contact" });
246
- });
247
- });
248
-
249
- describe("contact/page — fallback (AC-5)", () => {
250
- const builtIn = contactFormFromConfig(contactFormFlowConfig, "en")!;
251
-
252
- it.each([
253
- ["answers 404", () => mockFlowsGet.mockResolvedValue({ ok: false, status: 404, body: {} })],
254
- ["rejects", () => mockFlowsGet.mockRejectedValue(new Error("ECONNREFUSED"))],
255
- [
256
- "serves a config the form cannot use",
257
- () => {
258
- const config = JSON.parse(JSON.stringify(contactFormFlowConfig)) as FlowConfig;
259
- const step = config.steps[0] as FieldStep;
260
- step.fields = step.fields.filter((f) => f.name !== "name");
261
- mockFlowsGet.mockResolvedValue(served(config));
262
- },
263
- ],
264
- ])("flows.get %s → the built-in form, posted as web", async (_label, arrange) => {
265
- arrange();
266
-
267
- await renderPage();
268
-
269
- const form = screen.getByTestId("lead-capture-form");
270
- expect(fieldNames()).toEqual(builtIn.fields.map((f) => f.name));
271
- for (const field of builtIn.fields) expect(form).toHaveTextContent(field.label);
272
- const subject = builtIn.fields.find((f) => f.name === "subject")!;
273
- const native = form.querySelector("select");
274
- if (native) {
275
- const values = Array.from(native.querySelectorAll("option"))
276
- .map((o) => o.value)
277
- .filter(Boolean);
278
- expect(values).toEqual(
279
- subject.options!.map((o) => (typeof o === "string" ? o : o.value)),
280
- );
281
- }
282
- expect(
283
- document.getElementById("lead-capture-consent-statement")!.textContent,
284
- ).toBe(CONTACT_FORM_TERMS_STATEMENT.replace(/\[([^\]]+)\]\([a-z_]+\)/g, "$1"));
285
- expect(sourceInput()).toBeNull();
286
-
287
- await tickAndSubmit({ name: "Ada", email: "ada@example.com" });
288
-
289
- await waitFor(() => expect(mockSubmit).toHaveBeenCalledTimes(1));
290
- expect(mockSubmit.mock.calls[0][0]).toMatchObject({ source: "contact-form" });
291
- });
292
-
293
- it("with no magnet, a section's declared fields still apply", async () => {
294
- mockFlowsGet.mockResolvedValue({ ok: false, status: 404, body: {} });
295
-
296
- await renderPage([
297
- {
298
- id: "contact-form",
299
- type: "contact-form",
300
- data: {
301
- fields: [
302
- { name: "name", label: "Name", type: "text" },
303
- { name: "email", label: "Email", type: "email" },
304
- { name: "company", label: "Company", type: "text" },
305
- ],
306
- submitLabel: "Request a demo",
307
- },
308
- },
309
- ]);
310
-
311
- expect(fieldNames()).toEqual(["name", "email", "company"]);
312
- expect(screen.getByTestId("contact-submit")).toHaveTextContent("Request a demo");
313
- });
314
-
315
- it("the built-in form takes its labels from the contact catalog and ends on the built-in ending (#8847 D7)", async () => {
316
- mockFlowsGet.mockResolvedValue({ ok: false, status: 404, body: {} });
317
- const messages = jest.requireActual("../../../../messages/en.json") as {
318
- contact: Record<string, string>;
319
- };
320
-
321
- await renderPage([
322
- {
323
- id: "contact-form",
324
- type: "contact-form",
325
- data: { fields: [], submitLabel: "Say hello", successMessage: "Got it, thanks." },
326
- },
327
- ]);
328
-
329
- const form = screen.getByTestId("lead-capture-form");
330
- expect(form).toHaveTextContent(messages.contact.nameLabel!);
331
- expect(form).toHaveTextContent(messages.contact.messageLabel!);
332
- expect(screen.getByTestId("contact-submit")).toHaveTextContent(messages.contact.sendMessage!);
333
-
334
- await tickAndSubmit({ name: "Ada", email: "ada@example.com" });
335
- await waitFor(() =>
336
- expect(screen.getByTestId("contact-success-headline")).toHaveTextContent("Message sent."),
337
- );
338
- expect(document.body).not.toHaveTextContent("Got it, thanks.");
339
- });
340
-
341
- it("a magnet's submit label and ending win over the section's copy (#8847 D7)", async () => {
342
- mockFlowsGet.mockResolvedValue(served(contactFormFlowConfig));
343
-
344
- await renderPage([
345
- {
346
- id: "contact-form",
347
- type: "contact-form",
348
- data: { fields: [], submitLabel: "Say hello", successMessage: "Got it, thanks." },
349
- },
350
- ]);
351
-
352
- expect(screen.getByTestId("contact-submit")).toHaveTextContent(
353
- contactFormFromConfig(contactFormFlowConfig, "en")!.submitLabel!,
354
- );
355
-
356
- await tickAndSubmit({ name: "Ada", email: "ada@example.com" });
357
- await waitFor(() =>
358
- expect(screen.getByTestId("contact-success-headline")).toHaveTextContent("Message sent."),
359
- );
360
- expect(document.body).not.toHaveTextContent("Got it, thanks.");
361
- });
362
- });
363
-
364
- // ── #8847 AC-2 — /contact is the magnet ─────────────────────────────────────
365
-
366
- /** A served Contact form whose every visible fact differs from the default. */
367
- function sayHelloConfig(): FlowConfig {
368
- const config = JSON.parse(JSON.stringify(contactFormFlowConfig)) as FlowConfig;
369
- const step = config.steps[0] as FieldStep;
370
- step.copy = { title: { en: "Say hello" }, body: { en: "Two days, tops." }, cta: { en: "Send" } };
371
- step.fields.find((f) => f.name === "terms")!.copy.label = { en: "I agree to the [Terms](terms)." };
372
- config.ending = { default: { kind: "screen", headline: { en: "Got it, {name}." } } };
373
- return config;
374
- }
375
-
376
- const COLUMN_SECTION = {
377
- id: "contact-form",
378
- type: "contact-form",
379
- data: { variant: "column", headline: "Old heading", description: "Old line", fields: [] },
380
- };
381
-
382
- async function renderColumnPage() {
383
- const element = await ContactPage({
384
- params: Promise.resolve({ locale: "en" }),
385
- getMdxSource: jest.fn().mockResolvedValue({
386
- ...source,
387
- frontmatter: { ...source.frontmatter, title: "Old title" },
388
- }),
389
- getPageSections: jest.fn().mockResolvedValue([COLUMN_SECTION]),
390
- });
391
- return render(element);
392
- }
393
-
394
- describe("contact/page — every visible fact comes from the magnet (#8847 AC-2)", () => {
395
- it("the H1, the line, the consent and the ending are the served magnet's", async () => {
396
- mockFlowsGet.mockResolvedValue(served(sayHelloConfig()));
397
-
398
- await renderColumnPage();
399
-
400
- const headings = screen.getAllByRole("heading", { level: 1 });
401
- expect(headings).toHaveLength(1);
402
- expect(headings[0]).toHaveTextContent("Say hello");
403
- expect(screen.getByTestId("contact-form-column")).toHaveTextContent("Two days, tops.");
404
- expect(
405
- document.getElementById("lead-capture-consent-statement")!.textContent,
406
- ).toBe("I agree to the Terms.");
407
- expect(screen.getByTestId("consent-policy-link-terms")).toBeInTheDocument();
408
- for (const old of ["Old heading", "Old line", "Old title"]) {
409
- expect(document.body).not.toHaveTextContent(old);
410
- }
411
-
412
- await tickAndSubmit({ name: "Ada", email: "ada@example.com" });
413
- await waitFor(() =>
414
- expect(screen.getByTestId("contact-success-headline")).toHaveTextContent("Got it, Ada."),
415
- );
416
- const messages = jest.requireActual("../../../../messages/en.json") as {
417
- contact: Record<string, string>;
418
- };
419
- expect(document.body).not.toHaveTextContent(messages.contact.successMessage!);
420
- });
421
-
422
- it("generateMetadata's title is the magnet's step title", async () => {
423
- mockFlowsGet.mockResolvedValue(served(sayHelloConfig()));
424
-
425
- const metadata = await pageModule.generateMetadata({
426
- params: Promise.resolve({ locale: "en" }),
427
- getMdxSource: jest.fn().mockResolvedValue({
428
- ...source,
429
- frontmatter: { ...source.frontmatter, title: "Old title" },
430
- }),
431
- getPageSections: jest.fn().mockResolvedValue([COLUMN_SECTION]),
432
- });
433
-
434
- expect(String((metadata.title as { absolute?: string })?.absolute ?? metadata.title)).toContain(
435
- "Say hello",
436
- );
437
- });
438
-
439
- it("with the hub unreadable, the built-in config's title and two-link statement render", async () => {
440
- mockFlowsGet.mockRejectedValue(new Error("hub down"));
441
-
442
- await renderColumnPage();
443
-
444
- expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Get in touch");
445
- expect(
446
- document.getElementById("lead-capture-consent-statement")!.textContent,
447
- ).toBe("I accept the Terms and Privacy Policy.");
448
- });
449
-
450
- it("under the form, 'Prefer email?' links the _site.mdx contact email; absent with none", async () => {
451
- const { readSiteContactEmail } = jest.requireMock("../site-contact-email") as {
452
- readSiteContactEmail: jest.Mock;
453
- };
454
- mockFlowsGet.mockResolvedValue(served(contactFormFlowConfig));
455
- readSiteContactEmail.mockReturnValue("hi@x.co");
456
-
457
- const view = await renderColumnPage();
458
-
459
- const line = screen.getByTestId("contact-prefer-email");
460
- expect(line).toHaveTextContent("Prefer email? hi@x.co");
461
- expect(line.querySelector("a")).toHaveAttribute("href", "mailto:hi@x.co");
462
- view.unmount();
463
-
464
- readSiteContactEmail.mockReturnValue(undefined);
465
- await renderColumnPage();
466
- expect(screen.queryByTestId("contact-prefer-email")).toBeNull();
467
- });
468
- });
469
-
470
- describe("contact/page — the column look (#8661 D12)", () => {
471
- it("a column section gets the stacked look and an enabled Send", async () => {
472
- mockFlowsGet.mockResolvedValue(served(contactFormFlowConfig));
473
-
474
- await renderPage([
475
- {
476
- id: "contact",
477
- type: "contact-form",
478
- data: { variant: "column", headline: "Contact Us", description: "Say hello.", fields: [] },
479
- },
480
- ]);
481
-
482
- expect(screen.getByTestId("lead-capture-form")).toHaveAttribute("data-look", "column");
483
- expect(screen.getByTestId("contact-submit")).toBeEnabled();
484
- });
485
-
486
- it("a standard page keeps Send disabled until ticked", async () => {
487
- mockFlowsGet.mockResolvedValue(served(contactFormFlowConfig));
488
-
489
- await renderPage();
490
-
491
- expect(screen.getByTestId("lead-capture-form")).not.toHaveAttribute("data-look");
492
- expect(screen.getByTestId("contact-submit")).toBeDisabled();
493
- });
494
- });