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,400 +0,0 @@
1
- /**
2
- * Tests for ConversationalIntakeWrapper (#4534, epic #4521's integration
3
- * leg).
4
- *
5
- * AC1 (integration test) — a completed conversation lands a lead through
6
- * the EXISTING lead-capture endpoint. Only the outermost network
7
- * boundary is mocked (`@working-theory/api-client`'s `leads.submit`) —
8
- * the REAL `ConversationalIntake` block (#4543) and its engine (#4532),
9
- * the REAL `captureLeadAction` (the SAME action the shared
10
- * `LeadCaptureForm` on `/contact` uses), and the REAL `contactFormSchema` validation all run, proving
11
- * the whole chain end to end. No file under apps/api is imported, mocked,
12
- * or touched by this test or by the wiring it exercises.
13
- * AC2 — Skip renders the existing form, carrying over answers already
14
- * captured as `initialValues`.
15
- * AC3 — per-turn abandonment analytics: `recordIntakeTurn`
16
- * (`./intake-analytics.ts`, mocked at the `track()` boundary) fires once
17
- * per turn with an increasing `turnIndex`, plus one terminal call tagging
18
- * the outcome.
19
- */
20
- import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
21
-
22
- jest.mock("next-intl", () => ({
23
- useTranslations: () => (key: string) => key,
24
- useLocale: () => "en",
25
- useMessages: () => ({}),
26
- }));
27
-
28
- jest.mock("@working-theory/api-client", () => ({
29
- leads: {
30
- submit: jest.fn(),
31
- },
32
- }));
33
-
34
- jest.mock("@working-theory/analytics/server", () => ({
35
- track: jest.fn().mockResolvedValue(undefined),
36
- }));
37
-
38
- // ConversationalIntakeWrapper's own responsibility under test here is the
39
- // submission/skip/analytics wiring around the block — not the shared
40
- // LeadCaptureForm's own rendering, which its block suite covers
41
- // (packages/ui/src/blocks/__tests__/LeadCaptureForm.test.tsx). The real
42
- // `@working-theory/ui` runs (the ConversationalIntake block included); only
43
- // the form block is stubbed, so the carried-over `initialValues` can be read.
44
- jest.mock("@working-theory/ui", () => ({
45
- ...jest.requireActual("@working-theory/ui"),
46
- LeadCaptureForm: (props: { initialValues?: Record<string, string> }) =>
47
- require("react").createElement("div", {
48
- "data-testid": "contact-form-stub",
49
- "data-initial-values": JSON.stringify(props.initialValues ?? {}),
50
- }),
51
- }));
52
-
53
- import { leads } from "@working-theory/api-client";
54
- import { track } from "@working-theory/analytics/server";
55
-
56
- import { ConversationalIntakeWrapper } from "../ConversationalIntakeWrapper.js";
57
- import * as intakeAnalytics from "../intake-analytics";
58
-
59
- const mockSubmit = leads.submit as jest.Mock;
60
- const mockTrack = track as jest.Mock;
61
-
62
- const TEST_ID = "contact-conversational-intake";
63
-
64
- beforeEach(() => {
65
- jest.useFakeTimers();
66
- });
67
-
68
- afterEach(() => {
69
- act(() => {
70
- jest.runOnlyPendingTimers();
71
- });
72
- jest.useRealTimers();
73
- jest.clearAllMocks();
74
- });
75
-
76
- /** Advances past the thinking pause (600–900ms) and flushes the reveal. */
77
- function advanceThinking(): void {
78
- act(() => {
79
- jest.advanceTimersByTime(1000);
80
- });
81
- }
82
-
83
- /**
84
- * Flushes the microtask queue — needed after a turn transition that
85
- * triggers an async Server Action call (`onComplete`'s `await
86
- * captureLeadAction(...)`), whose own state updates (fallback to the form,
87
- * the submit-error message) land a tick after the timer-driven reveal
88
- * `advanceThinking()` already flushed.
89
- */
90
- async function flushMicrotasks(): Promise<void> {
91
- await act(async () => {
92
- await Promise.resolve();
93
- await Promise.resolve();
94
- });
95
- }
96
-
97
- /** #8730 D2 — the intake's own terms turn: tap the accept pill. */
98
- function acceptTerms(): void {
99
- fireEvent.click(screen.getByTestId(`${TEST_ID}-pill-accept`));
100
- }
101
-
102
- function answer(text: string): void {
103
- const input = screen.getByTestId(`${TEST_ID}-free-text-input`);
104
- fireEvent.change(input, { target: { value: text } });
105
- fireEvent.click(screen.getByTestId(`${TEST_ID}-free-text-submit`));
106
- }
107
-
108
- describe("ConversationalIntakeWrapper — completion (AC1)", () => {
109
- it("submits through the existing lead-capture endpoint's api-client surface", async () => {
110
- mockSubmit.mockResolvedValue({
111
- ok: true,
112
- body: { id: "lead_abc123", persisted: "db" },
113
- });
114
-
115
- render(<ConversationalIntakeWrapper />);
116
- advanceThinking(); // turn 1 (name) revealed
117
-
118
- answer("Jane Smith");
119
- advanceThinking(); // turn 2 (message) revealed
120
-
121
- answer("I'd like a demo.");
122
- advanceThinking(); // turn 3 (email) revealed
123
-
124
- answer("jane@example.com");
125
- advanceThinking(); // turn 4 (terms) revealed
126
- acceptTerms();
127
- advanceThinking(); // completion revealed, onComplete fires
128
- // The action awaits its bot check (#9255) before the write.
129
- await waitFor(() => expect(mockSubmit).toHaveBeenCalledTimes(1));
130
- const body = mockSubmit.mock.calls[0][0] as {
131
- source: string;
132
- email: string;
133
- payload: { name: string; message?: string };
134
- };
135
- // #8747 — no siteId: the API names the workspace itself.
136
- expect(body).not.toHaveProperty("siteId");
137
- expect(body.source).toBe("conversational-intake");
138
- expect(body.email).toBe("jane@example.com");
139
- expect(body.payload.name).toBe("Jane Smith");
140
- expect(body.payload.message).toBe("I'd like a demo.");
141
-
142
- // The block stays mounted on success — its own completion message is
143
- // already the confirmation; no fallback form appears.
144
- expect(screen.queryByTestId("contact-form-stub")).toBeNull();
145
- });
146
-
147
- it("falls back to the existing form, prefilled, when the submit fails", async () => {
148
- mockSubmit.mockResolvedValue({ ok: false, status: 503, body: {} });
149
-
150
- render(<ConversationalIntakeWrapper />);
151
- advanceThinking();
152
- answer("Jane Smith");
153
- advanceThinking();
154
- answer("I'd like a demo.");
155
- advanceThinking();
156
- answer("jane@example.com");
157
- advanceThinking(); // turn 4 (terms) revealed
158
- acceptTerms();
159
- advanceThinking();
160
- await flushMicrotasks();
161
-
162
- const stub = screen.getByTestId("contact-form-stub");
163
- const initialValues = JSON.parse(
164
- stub.getAttribute("data-initial-values") ?? "{}",
165
- );
166
- expect(initialValues).toMatchObject({
167
- name: "Jane Smith",
168
- email: "jane@example.com",
169
- message: "I'd like a demo.",
170
- });
171
- expect(
172
- screen.getByTestId("contact-intake-submit-error"),
173
- ).toBeInTheDocument();
174
- });
175
- });
176
-
177
- describe("ConversationalIntakeWrapper — the intake's own terms turn (#8730 D2)", () => {
178
- /** Answers the three open turns and reveals the terms turn. */
179
- function reachTerms(): void {
180
- render(<ConversationalIntakeWrapper />);
181
- advanceThinking();
182
- answer("Jane Smith");
183
- advanceThinking();
184
- answer("I'd like a demo.");
185
- advanceThinking();
186
- answer("jane@example.com");
187
- advanceThinking(); // turn 4 (terms) revealed
188
- }
189
-
190
- it("asks for the terms before it submits, offering accept and decline", () => {
191
- reachTerms();
192
-
193
- expect(screen.getByText("intake.consentPrompt")).toBeInTheDocument();
194
- expect(screen.getByTestId(`${TEST_ID}-pill-accept`)).toHaveTextContent("intake.consentAccept");
195
- expect(screen.getByTestId(`${TEST_ID}-pill-decline`)).toHaveTextContent("intake.consentDecline");
196
- expect(mockSubmit).not.toHaveBeenCalled();
197
- });
198
-
199
- it("accepting submits the lead carrying consent: true", async () => {
200
- mockSubmit.mockResolvedValue({ ok: true, body: { id: "lead_abc123", persisted: "db" } });
201
-
202
- reachTerms();
203
- acceptTerms();
204
- advanceThinking();
205
- await flushMicrotasks();
206
-
207
- expect(mockSubmit).toHaveBeenCalledTimes(1);
208
- const body = mockSubmit.mock.calls[0][0] as { source: string; consent: unknown };
209
- expect(body.source).toBe("conversational-intake");
210
- expect(body.consent).toBe(true);
211
- });
212
-
213
- it("declining submits nothing and shows the form, prefilled, with its own terms box", async () => {
214
- reachTerms();
215
- fireEvent.click(screen.getByTestId(`${TEST_ID}-pill-decline`));
216
- advanceThinking();
217
- await flushMicrotasks();
218
-
219
- expect(mockSubmit).not.toHaveBeenCalled();
220
- const stub = screen.getByTestId("contact-form-stub");
221
- expect(JSON.parse(stub.getAttribute("data-initial-values") ?? "{}")).toMatchObject({
222
- name: "Jane Smith",
223
- email: "jane@example.com",
224
- message: "I'd like a demo.",
225
- });
226
- });
227
-
228
- it("typing anything but the accept answer is not acceptance", async () => {
229
- reachTerms();
230
- answer("sure, whatever");
231
- advanceThinking();
232
- await flushMicrotasks();
233
-
234
- expect(mockSubmit).not.toHaveBeenCalled();
235
- expect(screen.getByTestId("contact-form-stub")).toBeInTheDocument();
236
- });
237
- });
238
-
239
- describe("ConversationalIntakeWrapper — Skip (AC2)", () => {
240
- it("renders the existing form on Skip, carrying over the answers captured so far", () => {
241
- render(<ConversationalIntakeWrapper />);
242
- advanceThinking(); // turn 1 (name) revealed
243
-
244
- answer("Jane Smith");
245
- advanceThinking(); // turn 2 (message) revealed
246
-
247
- fireEvent.click(screen.getByTestId(`${TEST_ID}-skip`));
248
- advanceThinking(); // skip message revealed, onSkip fires
249
-
250
- const stub = screen.getByTestId("contact-form-stub");
251
- const initialValues = JSON.parse(
252
- stub.getAttribute("data-initial-values") ?? "{}",
253
- );
254
- expect(initialValues).toMatchObject({ name: "Jane Smith" });
255
- expect(mockSubmit).not.toHaveBeenCalled();
256
- });
257
- });
258
-
259
- describe("ConversationalIntakeWrapper — per-turn abandonment analytics (AC3)", () => {
260
- it("fires one in_progress event per turn, then a terminal completed event, with increasing turnIndex", async () => {
261
- mockSubmit.mockResolvedValue({
262
- ok: true,
263
- body: { id: "lead_abc123", persisted: "db" },
264
- });
265
-
266
- render(<ConversationalIntakeWrapper />);
267
- advanceThinking();
268
- answer("Jane Smith");
269
- advanceThinking();
270
- answer("I'd like a demo.");
271
- advanceThinking();
272
- answer("jane@example.com");
273
- advanceThinking(); // turn 4 (terms) revealed
274
- acceptTerms();
275
- advanceThinking();
276
- await flushMicrotasks(); // recordIntakeTurn is dispatched on a later microtask (#6465)
277
-
278
- const calls = mockTrack.mock.calls.map(([name, props]) => ({
279
- name,
280
- ...(props as { turnIndex: number; status: string; locale: string }),
281
- }));
282
-
283
- expect(calls.every((c) => c.name === "intake-turn-abandonment")).toBe(
284
- true,
285
- );
286
- const inProgress = calls.filter((c) => c.status === "in_progress");
287
- expect(inProgress.map((c) => c.turnIndex)).toEqual([1, 2, 3, 4, 5]);
288
-
289
- const terminal = calls[calls.length - 1];
290
- expect(terminal).toMatchObject({ status: "completed", turnIndex: 5 });
291
-
292
- // PII-free: only turnIndex/status/locale ever leave the client.
293
- for (const call of mockTrack.mock.calls) {
294
- const props = call[1] as Record<string, unknown>;
295
- expect(Object.keys(props).sort()).toEqual(
296
- ["turnIndex", "status", "locale"].sort(),
297
- );
298
- }
299
- });
300
-
301
- it("tags an abandoned (skipped) session with the turn it stopped at", async () => {
302
- render(<ConversationalIntakeWrapper />);
303
- advanceThinking();
304
- answer("Jane Smith");
305
- advanceThinking();
306
-
307
- fireEvent.click(screen.getByTestId(`${TEST_ID}-skip`));
308
- advanceThinking();
309
- await flushMicrotasks(); // recordIntakeTurn is dispatched on a later microtask (#6465)
310
-
311
- const calls = mockTrack.mock.calls.map(([, props]) => props) as Array<{
312
- status: string;
313
- turnIndex: number;
314
- }>;
315
- const terminal = calls[calls.length - 1];
316
- expect(terminal).toMatchObject({ status: "skipped" });
317
- expect(terminal?.turnIndex).toBeGreaterThan(0);
318
- });
319
- });
320
-
321
- describe("ConversationalIntakeWrapper — a failing analytics call never strands the intake (#6465)", () => {
322
- let recordSpy: jest.SpyInstance | undefined;
323
-
324
- afterEach(() => {
325
- recordSpy?.mockRestore();
326
- });
327
-
328
- /** The Server Action reference throws synchronously at the call site. */
329
- function spyRecordIntakeTurnThrowing(): void {
330
- recordSpy = jest
331
- .spyOn(intakeAnalytics, "recordIntakeTurn")
332
- .mockImplementation(() => {
333
- throw new Error("boom");
334
- });
335
- }
336
-
337
- it("drives the intake from mount to its first question with Skip enabled", async () => {
338
- spyRecordIntakeTurnThrowing();
339
-
340
- render(<ConversationalIntakeWrapper />);
341
- expect(screen.getByTestId(`${TEST_ID}-skip`)).toBeDisabled();
342
-
343
- advanceThinking(); // turn 1 (name) revealed
344
- await flushMicrotasks();
345
-
346
- expect(screen.queryByTestId(`${TEST_ID}-thinking`)).toBeNull();
347
- expect(screen.getByText("intake.namePrompt")).toBeInTheDocument();
348
- expect(screen.getByTestId(`${TEST_ID}-skip`)).not.toBeDisabled();
349
- });
350
-
351
- it("dispatches the per-turn analytics call off the delay callback's synchronous path", async () => {
352
- recordSpy = jest
353
- .spyOn(intakeAnalytics, "recordIntakeTurn")
354
- .mockResolvedValue(undefined);
355
-
356
- render(<ConversationalIntakeWrapper />);
357
- expect(recordSpy).toHaveBeenCalledTimes(0);
358
-
359
- await flushMicrotasks();
360
- expect(recordSpy).toHaveBeenCalledTimes(1);
361
- expect(recordSpy.mock.calls[0]?.[0]).toMatchObject({
362
- turnIndex: 1,
363
- status: "in_progress",
364
- });
365
- });
366
-
367
- it("still falls back to the form on Skip", async () => {
368
- spyRecordIntakeTurnThrowing();
369
-
370
- render(<ConversationalIntakeWrapper />);
371
- advanceThinking();
372
- fireEvent.click(screen.getByTestId(`${TEST_ID}-skip`));
373
- advanceThinking(); // skip message revealed, onSkip fires
374
- await flushMicrotasks();
375
-
376
- expect(screen.getByTestId("contact-form-stub")).toBeInTheDocument();
377
- });
378
-
379
- it("still submits the lead on completion", async () => {
380
- spyRecordIntakeTurnThrowing();
381
- mockSubmit.mockResolvedValue({
382
- ok: true,
383
- body: { id: "lead_abc123", persisted: "db" },
384
- });
385
-
386
- render(<ConversationalIntakeWrapper />);
387
- advanceThinking();
388
- answer("Jane Smith");
389
- advanceThinking();
390
- answer("I'd like a demo.");
391
- advanceThinking();
392
- answer("jane@example.com");
393
- advanceThinking(); // turn 4 (terms) revealed
394
- acceptTerms();
395
- advanceThinking(); // completion revealed, onComplete fires
396
- await flushMicrotasks();
397
-
398
- expect(mockSubmit).toHaveBeenCalledTimes(1);
399
- });
400
- });
@@ -1,138 +0,0 @@
1
- /**
2
- * contactFormFromConfig (#8661 D6) — a Contact form magnet's config mapped
3
- * onto the shared `LeadCaptureForm` block's fields, statement and label.
4
- *
5
- * AC-3: the seeded config maps to the five-field form in order (the terms box
6
- * is the statement, not a field); a relabelled subject and a sixth option
7
- * render; a config the action cannot submit (no `name`, a non-field first
8
- * step) is `null`; `address` and a second `consent` field are not rendered;
9
- * copy resolves per locale. AC-5's fallback is the same mapping over the
10
- * built-in config, which is never `null`.
11
- */
12
- import {
13
- CONTACT_FORM_SUBJECT_OPTIONS,
14
- CONTACT_FORM_TERMS_STATEMENT,
15
- contactFormFlowConfig,
16
- type FlowConfig,
17
- } from "@working-theory/validation";
18
-
19
- import { contactFormFromConfig } from "../contact-form-magnet";
20
-
21
- type FieldStep = Extract<FlowConfig["steps"][number], { type: "field" }>;
22
-
23
- /** A deep copy of the seeded config, so a case can edit it freely. */
24
- function seeded(): FlowConfig {
25
- return JSON.parse(JSON.stringify(contactFormFlowConfig)) as FlowConfig;
26
- }
27
-
28
- function firstStep(config: FlowConfig): FieldStep {
29
- return config.steps[0] as FieldStep;
30
- }
31
-
32
- describe("contactFormFromConfig — the seeded config (AC-3)", () => {
33
- const view = contactFormFromConfig(contactFormFlowConfig, "en");
34
-
35
- it("is never null", () => {
36
- expect(view).not.toBeNull();
37
- });
38
-
39
- it("maps name, email, subject and message, in order", () => {
40
- expect(view!.fields.map((f) => f.name)).toEqual(["name", "email", "subject", "message"]);
41
- expect(view!.fields.map((f) => f.required)).toEqual([true, true, false, false]);
42
- expect(view!.fields.map((f) => f.type)).toEqual(["text", "email", "select", "textarea"]);
43
- expect(view!.fields.map((f) => f.label)).toEqual(["Name", "Email", "Subject", "Message"]);
44
- });
45
-
46
- it("pairs name and email, and runs every other field full width", () => {
47
- expect(view!.fields.map((f) => f.colSpan)).toEqual([1, 1, 2, 2]);
48
- });
49
-
50
- it("gives the subject its five options as { value, label } pairs and its placeholder", () => {
51
- const subject = view!.fields.find((f) => f.name === "subject")!;
52
- expect(subject.options).toEqual(
53
- CONTACT_FORM_SUBJECT_OPTIONS.map((value) => ({ value, label: value })),
54
- );
55
- expect(subject.placeholder).toBe("Choose a subject");
56
- });
57
-
58
- it("takes the terms statement and the step's cta", () => {
59
- expect(view!.consentStatement).toBe(CONTACT_FORM_TERMS_STATEMENT);
60
- expect(view!.submitLabel).toBe("Send message");
61
- });
62
- });
63
-
64
- describe("contactFormFromConfig — an owner's edit (AC-3)", () => {
65
- it("renders a relabelled subject and a sixth option", () => {
66
- const config = seeded();
67
- const subject = firstStep(config).fields.find((f) => f.name === "subject")!;
68
- subject.copy.label = { en: "Topic" };
69
- subject.options = [...subject.options!, { value: "Podcast", label: { en: "Podcast" } }];
70
-
71
- const view = contactFormFromConfig(config, "en")!;
72
- const rendered = view.fields.find((f) => f.name === "subject")!;
73
- expect(rendered.label).toBe("Topic");
74
- expect(rendered.options).toHaveLength(6);
75
- });
76
-
77
- it("is null when the step has no name field", () => {
78
- const config = seeded();
79
- const step = firstStep(config);
80
- step.fields = step.fields.filter((f) => f.name !== "name");
81
- expect(contactFormFromConfig(config, "en")).toBeNull();
82
- });
83
-
84
- it("is null when the step has no email field", () => {
85
- const config = seeded();
86
- const step = firstStep(config);
87
- step.fields = step.fields.filter((f) => f.name !== "email");
88
- expect(contactFormFromConfig(config, "en")).toBeNull();
89
- });
90
-
91
- it("is null when the first step is not a field step", () => {
92
- const config = seeded();
93
- config.steps = [
94
- {
95
- key: "segment",
96
- type: "segmentation",
97
- copy: { title: { en: "Who are you?" } },
98
- questions: [{ name: "role", options: [{ value: "a", label: { en: "A" } }] }],
99
- },
100
- ...config.steps,
101
- ];
102
- expect(contactFormFromConfig(config, "en")).toBeNull();
103
- });
104
-
105
- it("renders neither an address field nor a second consent field", () => {
106
- const config = seeded();
107
- const step = firstStep(config);
108
- step.fields = [
109
- ...step.fields,
110
- { name: "where", inputType: "address", copy: { label: { en: "Address" } } },
111
- {
112
- name: "marketing",
113
- inputType: "consent",
114
- purposes: ["marketing"],
115
- copy: { label: { en: "Send me news." } },
116
- },
117
- ] as FieldStep["fields"];
118
-
119
- const view = contactFormFromConfig(config, "en")!;
120
- expect(view.fields.map((f) => f.name)).toEqual(["name", "email", "subject", "message"]);
121
- expect(view.consentStatement).toBe(CONTACT_FORM_TERMS_STATEMENT);
122
- });
123
-
124
- it("gives no statement when the step has no consent field", () => {
125
- const config = seeded();
126
- const step = firstStep(config);
127
- step.fields = step.fields.filter((f) => f.inputType !== "consent");
128
- expect(contactFormFromConfig(config, "en")!.consentStatement).toBeUndefined();
129
- });
130
-
131
- it("resolves copy for the active locale", () => {
132
- const config = seeded();
133
- firstStep(config).fields[0]!.copy.label = { en: "Name", fr: "Nom" };
134
-
135
- expect(contactFormFromConfig(config, "fr")!.fields[0]!.label).toBe("Nom");
136
- expect(contactFormFromConfig(config, "en")!.fields[0]!.label).toBe("Name");
137
- });
138
- });
@@ -1,49 +0,0 @@
1
- /**
2
- * contactFormText (#6730 D8) — the `contact` namespace mapped onto the shared
3
- * form block's copy, with `unavailableBody`'s `{email}` placeholder kept for
4
- * the block to fill.
5
- */
6
- import messages from "../../../../messages/en.json";
7
- import { CONTACT_FORM_TERMS_STATEMENT } from "@working-theory/validation";
8
-
9
- import { contactFormText } from "../contact-form-text";
10
-
11
- /** A translator over the English catalog that interpolates `{name}` values, as ICU does. */
12
- function translator(key: string, values?: Record<string, string>): string {
13
- const template = (messages.contact as Record<string, unknown>)[key];
14
- if (typeof template !== "string") throw new Error(`missing contact.${key}`);
15
- return template.replace(/\{(\w+)\}/g, (m, name: string) => values?.[name] ?? m);
16
- }
17
-
18
- describe("contactFormText", () => {
19
- it("maps every block string from the English catalog, keeping {email} for the block", () => {
20
- expect(contactFormText(translator)).toEqual({
21
- nameLabel: "Name",
22
- emailLabel: "Email",
23
- messageLabel: "Message",
24
- submit: "Send message",
25
- sending: "Sending…",
26
- success: messages.contact.successMessage,
27
- genericError: messages.contact.genericError,
28
- consentStatement: messages.contact.consentStatement,
29
- consentRequired: "Please accept the terms to send your message.",
30
- unavailableHeading: messages.contact.unavailableHeading,
31
- unavailableBody: "Email us at {email} and we'll reply.",
32
- unavailableNoEmail: messages.contact.unavailableNoEmail,
33
- });
34
- });
35
- });
36
-
37
- describe("the contact catalog (#8661 D9)", () => {
38
- it("states the three-link terms statement the Contact form magnet seeds", () => {
39
- expect(messages.contact.consentStatement).toBe(CONTACT_FORM_TERMS_STATEMENT);
40
- });
41
-
42
- it("carries a workingAgreement namespace in the terms namespace's shape", () => {
43
- expect(messages.workingAgreement).toEqual({
44
- heading: "Working Agreement",
45
- emptyState: "Working agreement content coming soon.",
46
- });
47
- expect(Object.keys(messages.workingAgreement)).toEqual(Object.keys(messages.terms));
48
- });
49
- });