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,546 +0,0 @@
1
- /**
2
- * The careers set over the Job application magnet (#8746 D1, D5; #8849 D7,
3
- * D8; AC-5, AC-6): the posting page carries an Apply button and no form, and
4
- * the Free apply page, careers/[slug]/[action]/page.tsx, draws the form.
5
- *
6
- * Renders the REAL `LeadCaptureForm` bound to the REAL apply action, so the
7
- * form, its fields and a submit are all visible. Mocked boundaries:
8
- * `@working-theory/api-client` (`flows.get`, `leads.captureStatus`,
9
- * `leads.submit`), `next/headers`, `next-intl/server` (over the real English
10
- * catalog), the `_site.mdx` contact-email read, and the page-renderer's
11
- * content loader (injected, and spied on for `lib/posting-title.ts`'s read).
12
- */
13
- import React from "react";
14
- import {
15
- act,
16
- fireEvent,
17
- render,
18
- screen,
19
- waitFor,
20
- } from "@testing-library/react";
21
- import {
22
- jobApplicationFlowConfig,
23
- type FlowConfig,
24
- } from "@working-theory/validation";
25
-
26
- jest.mock("next/navigation", () => ({
27
- __esModule: true,
28
- notFound: jest.fn(() => {
29
- throw new Error("NEXT_NOT_FOUND");
30
- }),
31
- }));
32
-
33
- jest.mock("next-mdx-remote/rsc", () => ({
34
- __esModule: true,
35
- MDXRemote: ({ source }: { source: string }) =>
36
- React.createElement("div", { "data-testid": "mdx-rendered" }, source),
37
- }));
38
-
39
- jest.mock("@working-theory/api-client", () => ({
40
- flows: { get: jest.fn() },
41
- leads: { captureStatus: jest.fn(), submit: jest.fn() },
42
- visitorForwardHeaders: () => undefined,
43
- }));
44
-
45
- jest.mock("next/headers", () => ({
46
- __esModule: true,
47
- headers: jest.fn().mockResolvedValue({ get: () => null }),
48
- cookies: jest.fn().mockResolvedValue({ get: () => undefined }),
49
- }));
50
-
51
- jest.mock("next-intl/server", () => {
52
- const messages = jest.requireActual("../../../../messages/en.json") as Record<
53
- string,
54
- Record<string, unknown>
55
- >;
56
- return {
57
- getTranslations: async (arg: string | { namespace: string }) => {
58
- const ns = messages[typeof arg === "string" ? arg : arg.namespace] ?? {};
59
- return (key: string, values?: Record<string, string>) =>
60
- String(ns[key] ?? key).replace(
61
- /\{(\w+)\}/g,
62
- (m, name: string) => values?.[name] ?? m,
63
- );
64
- },
65
- };
66
- });
67
-
68
- // 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
69
- jest.mock("../../contact/site-contact-email", () => ({
70
- readSiteContactEmail: jest.fn().mockReturnValue("jobs@example.com"),
71
- }));
72
-
73
- import { readFileSync } from "node:fs";
74
- import { join } from "node:path";
75
-
76
- import { flows, leads } from "@working-theory/api-client";
77
- import * as pageRenderer from "@working-theory/page-renderer";
78
-
79
- import messages from "../../../../messages/en.json";
80
-
81
- import CareersPage from "../page";
82
- import JobPage from "../[slug]/page";
83
- import * as jobPageModule from "../[slug]/page";
84
- import ApplyPage, { generateMetadata as applyMetadata } from "../[slug]/[action]/page";
85
-
86
- const mockFlowsGet = flows.get as jest.Mock;
87
- const mockCaptureStatus = leads.captureStatus as jest.Mock;
88
- const mockSubmit = leads.submit as jest.Mock;
89
- let mockPostingSource: jest.SpyInstance;
90
-
91
- type FieldStep = Extract<FlowConfig["steps"][number], { type: "field" }>;
92
-
93
- const JOB = "writer";
94
- const jobSource = {
95
- frontmatter: {
96
- type: "JobPosting" as const,
97
- slug: JOB,
98
- title: "Writer",
99
- description: "Write for us.",
100
- },
101
- body: "mdx-body-content",
102
- };
103
-
104
- async function renderApplyPage(slug = JOB, action = "apply") {
105
- const element = await ApplyPage({
106
- params: Promise.resolve({ locale: "en", slug, action }),
107
- });
108
- return render(element);
109
- }
110
-
111
- /** The form's field names; a composite's parts (`field-phone-country`, …) are left out. */
112
- function fieldNames(): string[] {
113
- return Array.from(
114
- screen
115
- .getByTestId("lead-capture-form")
116
- .querySelectorAll<HTMLElement>("[data-testid^='field-']"),
117
- )
118
- .map((el) => el.dataset.testid!.slice("field-".length))
119
- .filter((name) => !name.includes("-"));
120
- }
121
-
122
- // The apply page shares its two hub reads for a few seconds, per module
123
- // instance (as /contact does, #8731). Each test starts an hour later so none
124
- // sees another's read.
125
- let clock = 1_800_000_000_000;
126
- const nowSpy = jest.spyOn(Date, "now");
127
-
128
- beforeEach(() => {
129
- clock += 60 * 60 * 1000;
130
- nowSpy.mockImplementation(() => clock);
131
- mockCaptureStatus.mockResolvedValue({
132
- ok: true,
133
- status: 200,
134
- body: { ok: true, data: { contact: true, newsletter: true } },
135
- });
136
- mockFlowsGet.mockResolvedValue({
137
- ok: true,
138
- status: 200,
139
- body: jobApplicationFlowConfig,
140
- });
141
- mockSubmit.mockResolvedValue({ ok: true, status: 201, body: { ok: true } });
142
- // `lib/posting-title.ts` reads the posting through the package loader.
143
- mockPostingSource = jest
144
- .spyOn(pageRenderer, "getMdxSource")
145
- .mockImplementation(async (_type, slug) => (slug === JOB ? jobSource : null));
146
- });
147
-
148
- afterEach(() => {
149
- jest.clearAllMocks();
150
- mockPostingSource.mockRestore();
151
- });
152
-
153
- describe("the posting page carries an Apply button and no form (#8849 D8, AC-5)", () => {
154
- it("renders job-apply-cta to the localized apply page, and no form or hub read", async () => {
155
- const element = await JobPage({
156
- params: Promise.resolve({ locale: "fr", slug: JOB }),
157
- getMdxSource: jest.fn().mockResolvedValue(jobSource),
158
- });
159
- render(element);
160
- const cta = screen.getByTestId("job-apply-cta");
161
- expect(cta.getAttribute("href")).toBe("/fr/careers/writer/apply");
162
- expect(cta.textContent).toBe(messages.careers.apply);
163
- expect(screen.queryByTestId("job-apply")).toBeNull();
164
- expect(document.getElementById("apply")).toBeNull();
165
- expect(screen.queryByTestId("lead-capture-form")).toBeNull();
166
- expect(document.querySelector("form")).toBeNull();
167
- expect(mockFlowsGet).not.toHaveBeenCalled();
168
- expect(mockCaptureStatus).not.toHaveBeenCalled();
169
- // The posting itself still renders above it.
170
- expect(screen.getByTestId("mdx-rendered").textContent).toBe(
171
- "mdx-body-content",
172
- );
173
- });
174
-
175
- it("an unknown posting is a 404 and builds no button", async () => {
176
- await expect(
177
- JobPage({
178
- params: Promise.resolve({ locale: "en", slug: "unknown" }),
179
- getMdxSource: jest.fn().mockResolvedValue(null),
180
- }),
181
- ).rejects.toThrow("NEXT_NOT_FOUND");
182
- expect(screen.queryByTestId("job-apply-cta")).toBeNull();
183
- expect(mockFlowsGet).not.toHaveBeenCalled();
184
- });
185
-
186
- it("the page module no longer exports dynamic", () => {
187
- expect("dynamic" in jobPageModule).toBe(false);
188
- });
189
- });
190
-
191
- describe("the Free apply page draws the Job application (#8849 D7, AC-6; #8746 D1, D5)", () => {
192
- it("renders a back link to the posting, the posting's title and the magnet's field step", async () => {
193
- await renderApplyPage();
194
- expect(mockFlowsGet).toHaveBeenCalledWith("job-application");
195
- expect(
196
- screen.getByRole("heading", { level: 1, name: "Writer" }),
197
- ).toBeTruthy();
198
- expect(screen.getByTestId("nav-back-link").getAttribute("href")).toBe(
199
- "/careers/writer",
200
- );
201
- expect(fieldNames()).toEqual([
202
- "first_name",
203
- "last_name",
204
- "email",
205
- "phone",
206
- ]);
207
- expect(screen.getByTestId("contact-submit").textContent).toBe(
208
- "Submit application",
209
- );
210
- });
211
-
212
- it("an owner's edit to the magnet shows on the page", async () => {
213
- const edited = JSON.parse(
214
- JSON.stringify(jobApplicationFlowConfig),
215
- ) as FlowConfig;
216
- (edited.steps[0] as FieldStep).fields[2]!.copy.label = { en: "Work email" };
217
- mockFlowsGet.mockResolvedValue({ ok: true, status: 200, body: edited });
218
- await renderApplyPage();
219
- expect(
220
- screen.getByTestId("field-email").closest("div")!.textContent,
221
- ).toContain("Work email");
222
- });
223
-
224
- it.each([
225
- [
226
- "absent or off (404)",
227
- () =>
228
- mockFlowsGet.mockResolvedValue({ ok: false, status: 404, body: null }),
229
- ],
230
- [
231
- "unreadable (throws)",
232
- () => mockFlowsGet.mockRejectedValue(new Error("down")),
233
- ],
234
- [
235
- "unusable (no first_name)",
236
- () => {
237
- const broken = JSON.parse(
238
- JSON.stringify(jobApplicationFlowConfig),
239
- ) as FlowConfig;
240
- const step = broken.steps[0] as FieldStep;
241
- step.fields = step.fields.filter((f) => f.name !== "first_name");
242
- mockFlowsGet.mockResolvedValue({ ok: true, status: 200, body: broken });
243
- },
244
- ],
245
- ])(
246
- "falls back to the built-in form with the same fields when the magnet is %s",
247
- async (_label, arrange) => {
248
- arrange();
249
- await renderApplyPage();
250
- expect(fieldNames()).toEqual([
251
- "first_name",
252
- "last_name",
253
- "email",
254
- "phone",
255
- ]);
256
- },
257
- );
258
-
259
- it("shows the site's contact email instead of a form when the deployment accepts no lead", async () => {
260
- mockCaptureStatus.mockResolvedValue({
261
- ok: true,
262
- status: 200,
263
- body: { ok: true, data: { contact: false, newsletter: false } },
264
- });
265
- await renderApplyPage();
266
- expect(screen.queryByTestId("lead-capture-form")).toBeNull();
267
- expect(screen.getByTestId("job-apply").textContent).toContain(
268
- "jobs@example.com",
269
- );
270
- });
271
-
272
- it.each([
273
- ["an action other than apply", JOB, "start"],
274
- ["an uppercase slug", "Writer", "apply"],
275
- ["an encoded traversal slug", "a%2F..%2Fb", "apply"],
276
- ])("%s is a 404 before any read", async (_label, slug, action) => {
277
- await expect(renderApplyPage(slug, action)).rejects.toThrow("NEXT_NOT_FOUND");
278
- expect(mockPostingSource).not.toHaveBeenCalled();
279
- expect(mockFlowsGet).not.toHaveBeenCalled();
280
- expect(mockCaptureStatus).not.toHaveBeenCalled();
281
- });
282
-
283
- it("an unknown posting is a 404 with no hub read", async () => {
284
- await expect(renderApplyPage("unknown")).rejects.toThrow("NEXT_NOT_FOUND");
285
- expect(mockPostingSource).toHaveBeenCalledWith("JobPosting", "unknown", "en");
286
- expect(mockFlowsGet).not.toHaveBeenCalled();
287
- expect(mockCaptureStatus).not.toHaveBeenCalled();
288
- });
289
-
290
- it("is noindex, follow, titled with the posting", async () => {
291
- const metadata = await applyMetadata({
292
- params: Promise.resolve({ locale: "en", slug: JOB, action: "apply" }),
293
- });
294
- expect(metadata.robots).toEqual({ index: false, follow: true });
295
- expect(metadata.title).toBe("Writer");
296
- const unknown = await applyMetadata({
297
- params: Promise.resolve({ locale: "en", slug: "unknown", action: "apply" }),
298
- });
299
- expect(unknown.robots).toEqual({ index: false, follow: true });
300
- });
301
-
302
- it("is core: it imports no flows/ or module file, and reads the title from lib/posting-title", () => {
303
- const source = readFileSync(
304
- join(__dirname, "..", "[slug]", "[action]", "page.tsx"),
305
- "utf8",
306
- );
307
- const imports = source
308
- .split("\n")
309
- .filter((line) => /^import |^\} from |^ [\w{}, ]+ from /.test(line) || line.includes(" from \""))
310
- .join("\n");
311
- expect(imports).not.toMatch(/flows\//);
312
- expect(imports).not.toContain("FlowStepper");
313
- expect(imports).not.toContain("@working-theory/ui-signal-collectors");
314
- expect(imports).not.toMatch(/["']\.\/apply|\/apply\//);
315
- expect(imports).toContain('from "../../../../../lib/posting-title"');
316
- });
317
- });
318
-
319
- describe("the Free apply page shares its two hub reads (#8746 security review, as #8731)", () => {
320
- it("a burst of views makes one hub read of each kind, not one per view", async () => {
321
- for (let i = 0; i < 25; i += 1) {
322
- const view = await renderApplyPage();
323
- expect(screen.getByTestId("lead-capture-form")).toBeTruthy();
324
- view.unmount();
325
- }
326
- expect(mockFlowsGet).toHaveBeenCalledTimes(1);
327
- expect(mockCaptureStatus).toHaveBeenCalledTimes(1);
328
- });
329
-
330
- it("a failed read is shared too, so an unreachable hub is not retried per view", async () => {
331
- mockFlowsGet.mockRejectedValue(new Error("hub down"));
332
- mockCaptureStatus.mockRejectedValue(new Error("hub down"));
333
- for (let i = 0; i < 5; i += 1) {
334
- const view = await renderApplyPage();
335
- expect(fieldNames()).toEqual([
336
- "first_name",
337
- "last_name",
338
- "email",
339
- "phone",
340
- ]);
341
- view.unmount();
342
- }
343
- expect(mockFlowsGet).toHaveBeenCalledTimes(1);
344
- expect(mockCaptureStatus).toHaveBeenCalledTimes(1);
345
- });
346
-
347
- it("an Admin edit shows once the shared read expires", async () => {
348
- const first = await renderApplyPage();
349
- expect(
350
- screen.getByTestId("field-email").closest("div")!.textContent,
351
- ).toContain("Email");
352
- first.unmount();
353
-
354
- const edited = JSON.parse(
355
- JSON.stringify(jobApplicationFlowConfig),
356
- ) as FlowConfig;
357
- (edited.steps[0] as FieldStep).fields[2]!.copy.label = { en: "Work email" };
358
- mockFlowsGet.mockResolvedValue({ ok: true, status: 200, body: edited });
359
- clock += 60_000;
360
- await renderApplyPage();
361
- expect(
362
- screen.getByTestId("field-email").closest("div")!.textContent,
363
- ).toContain("Work email");
364
- expect(mockFlowsGet).toHaveBeenCalledTimes(2);
365
- });
366
- });
367
-
368
- describe("a submission from the Free apply page lands as a job application lead (#8746 D4, D5; #8849 AC-6)", () => {
369
- it("posts source flow:job-application, name = first + last and the posting's slug as job", async () => {
370
- await renderApplyPage();
371
- for (const [name, value] of Object.entries({
372
- first_name: "Ada",
373
- last_name: "Lovelace",
374
- email: "ada@example.com",
375
- })) {
376
- fireEvent.change(screen.getByTestId(`field-${name}`), {
377
- target: { value },
378
- });
379
- }
380
- fireEvent.click(screen.getByTestId("contact-consent"));
381
- await act(async () => {
382
- fireEvent.submit(screen.getByTestId("lead-capture-form"));
383
- });
384
- await waitFor(() => expect(mockSubmit).toHaveBeenCalledTimes(1));
385
- const body = mockSubmit.mock.calls[0][0] as {
386
- source: string;
387
- email: string;
388
- payload: Record<string, unknown>;
389
- };
390
- expect(body.source).toBe("flow:job-application");
391
- expect(body.email).toBe("ada@example.com");
392
- expect(body.payload).toMatchObject({
393
- name: "Ada Lovelace",
394
- job: JOB,
395
- page: "careers",
396
- });
397
- // #8746 — the careers catalog's own success line, not /contact's.
398
- const success = await screen.findByTestId("contact-success");
399
- expect(success.textContent).toBe(messages.careers.applicationSuccess);
400
- expect(success.textContent).not.toContain("reaching out");
401
- });
402
- });
403
-
404
- describe("the Free apply page runs the flow its posting names (#10054 D4, D6)", () => {
405
- const NAMED = "writer-application";
406
-
407
- /** The seed, renamed, with a portfolio field on step 1 (`first_name`, `last_name`, `email` kept). */
408
- function writerConfig(): FlowConfig {
409
- const config = JSON.parse(JSON.stringify(jobApplicationFlowConfig)) as FlowConfig;
410
- config.slug = NAMED;
411
- (config.steps[0] as FieldStep).fields.splice(3, 0, {
412
- name: "portfolio_url",
413
- inputType: "url",
414
- required: false,
415
- copy: { label: { en: "Portfolio URL" } },
416
- });
417
- return config;
418
- }
419
-
420
- function namePosting(applicationFlow?: string) {
421
- mockPostingSource.mockImplementation(async (_type, slug) =>
422
- slug === JOB
423
- ? {
424
- ...jobSource,
425
- frontmatter: {
426
- ...jobSource.frontmatter,
427
- ...(applicationFlow !== undefined && { applicationFlow }),
428
- },
429
- }
430
- : null,
431
- );
432
- }
433
-
434
- /** `flows.get` answers `named` for the posting's flow, the seed for job-application. */
435
- function serve(named: () => Promise<unknown>) {
436
- mockFlowsGet.mockImplementation(async (slug: string) =>
437
- slug === NAMED
438
- ? named()
439
- : { ok: true, status: 200, body: jobApplicationFlowConfig },
440
- );
441
- }
442
-
443
- async function submit(): Promise<{ source: string; consent?: unknown; payload: Record<string, unknown> }> {
444
- for (const [name, value] of Object.entries({
445
- first_name: "Ada",
446
- last_name: "Lovelace",
447
- email: "ada@example.com",
448
- })) {
449
- fireEvent.change(screen.getByTestId(`field-${name}`), { target: { value } });
450
- }
451
- fireEvent.click(screen.getByTestId("contact-consent"));
452
- await act(async () => {
453
- fireEvent.submit(screen.getByTestId("lead-capture-form"));
454
- });
455
- await waitFor(() => expect(mockSubmit).toHaveBeenCalledTimes(1));
456
- return mockSubmit.mock.calls[0][0];
457
- }
458
-
459
- let warn: jest.SpyInstance;
460
- beforeEach(() => {
461
- warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
462
- });
463
- afterEach(() => warn.mockRestore());
464
-
465
- it("AC-5 — renders the named flow's step 1 and records the posting and the flow", async () => {
466
- namePosting(NAMED);
467
- serve(async () => ({ ok: true, status: 200, body: writerConfig() }));
468
- await renderApplyPage();
469
- expect(fieldNames()).toContain("portfolio_url");
470
- expect(mockFlowsGet).not.toHaveBeenCalledWith("job-application");
471
- const body = await submit();
472
- expect(body.source).toBe("flow:job-application");
473
- expect(body.consent).toBe(true);
474
- expect(body.payload["job"]).toBe(JOB);
475
- expect(body.payload["applicationFlow"]).toBe(NAMED);
476
- expect(warn).not.toHaveBeenCalled();
477
- });
478
-
479
- it.each([
480
- ["absent", async () => ({ ok: false, status: 404, body: null })],
481
- [
482
- "unmappable",
483
- async () => {
484
- const config = writerConfig();
485
- const step = config.steps[0] as FieldStep;
486
- step.fields = step.fields.filter((f) => f.name !== "last_name");
487
- return { ok: true, status: 200, body: config };
488
- },
489
- ],
490
- ])("AC-6 — an %s flow renders the Job application, posts no applicationFlow and warns once", async (reason, named) => {
491
- namePosting(NAMED);
492
- serve(named);
493
- await renderApplyPage();
494
- expect(fieldNames()).toEqual(["first_name", "last_name", "email", "phone"]);
495
- expect(warn).toHaveBeenCalledTimes(1);
496
- const logged = JSON.stringify(warn.mock.calls[0]);
497
- expect(logged).toContain(JOB);
498
- expect(logged).toContain(NAMED);
499
- expect(logged).toContain(reason);
500
- const body = await submit();
501
- expect(body.payload).not.toHaveProperty("applicationFlow");
502
- expect(body.payload["job"]).toBe(JOB);
503
- });
504
-
505
- it("AC-6 — a named flow whose read throws renders the Job application and warns nothing", async () => {
506
- namePosting(NAMED);
507
- serve(async () => {
508
- throw new Error("down");
509
- });
510
- await renderApplyPage();
511
- expect(fieldNames()).toEqual(["first_name", "last_name", "email", "phone"]);
512
- expect(warn).not.toHaveBeenCalled();
513
- const body = await submit();
514
- expect(body.payload).not.toHaveProperty("applicationFlow");
515
- });
516
-
517
- it("AC-6 — a posting naming no flow posts a payload with no applicationFlow key", async () => {
518
- await renderApplyPage();
519
- const body = await submit();
520
- expect(body.payload).not.toHaveProperty("applicationFlow");
521
- for (const call of mockFlowsGet.mock.calls) expect(call[0]).toBe("job-application");
522
- expect(warn).not.toHaveBeenCalled();
523
- });
524
- });
525
-
526
- describe("the /careers index links to each job and carries no form (#8746 D1, #8849 D10)", () => {
527
- it("renders the list with no apply form and reads no magnet", async () => {
528
- const element = await CareersPage({
529
- params: Promise.resolve({ locale: "en" }),
530
- getMdxSlugs: jest.fn().mockResolvedValue([]),
531
- getMdxSource: jest.fn().mockResolvedValue({
532
- frontmatter: {
533
- type: "CareersList",
534
- slug: "careers",
535
- title: "Careers",
536
- description: "Open roles.",
537
- },
538
- body: "",
539
- }),
540
- });
541
- render(element);
542
- expect(screen.queryByTestId("lead-capture-form")).toBeNull();
543
- expect(document.getElementById("apply")).toBeNull();
544
- expect(mockFlowsGet).not.toHaveBeenCalled();
545
- });
546
- });