create-ailk 0.36.0 → 0.37.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 (101) hide show
  1. package/README.md +20 -2
  2. package/component-catalog.json +40 -1
  3. package/component-catalog.md +7 -5
  4. package/dist/add-route.d.ts +5 -0
  5. package/dist/add-route.js +10 -2
  6. package/dist/surfaces.js +60 -19
  7. package/dist/sync-routes.d.ts +15 -1
  8. package/dist/sync-routes.js +58 -6
  9. package/dist/template-record.d.ts +11 -0
  10. package/dist/template-record.js +18 -0
  11. package/dist/update.d.ts +33 -1
  12. package/dist/update.js +439 -56
  13. package/package.json +3 -3
  14. package/templates/.env.example +17 -0
  15. package/templates/apps/api/.env.example +38 -0
  16. package/templates/apps/api/CLAUDE.md +3 -0
  17. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  18. package/templates/apps/mcp/CLAUDE.md +1 -1
  19. package/templates/apps/web/CLAUDE.md +28 -1
  20. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  21. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  22. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  23. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +240 -76
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +369 -196
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  27. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  28. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  29. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  30. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  31. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  32. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  33. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  34. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  36. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  38. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +19 -3
  39. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  40. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  41. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  42. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  43. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  44. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  45. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  46. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  47. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  48. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  49. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  50. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  52. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +309 -113
  53. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +192 -65
  54. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  56. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  57. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  58. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +55 -58
  59. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +2 -1
  60. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  61. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  62. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  63. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  64. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  65. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  66. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  68. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +3 -2
  69. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  70. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  71. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  72. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  73. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  74. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  75. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  76. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  77. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  78. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +18 -21
  79. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  80. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  81. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  82. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  83. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  84. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  85. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  86. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  87. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  88. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +263 -0
  89. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  90. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  91. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  92. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  93. package/templates/apps/web/lib/account-config.ts +132 -8
  94. package/templates/apps/web/lib/auth-routes.ts +11 -6
  95. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  96. package/templates/apps/web/messages/en.json +156 -80
  97. package/versions.json +48 -48
  98. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  99. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  100. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  101. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
@@ -1,15 +1,14 @@
1
1
  /**
2
- * Tests for /[locale]/account/privacy — User settings › Privacy (#8438
3
- * D14, AC-4). The deletion-request cases moved here from general.test.tsx,
4
- * expectations unchanged (#8438 D16).
2
+ * Tests for /[locale]/account/privacy — User settings › Privacy (#8438 D14;
3
+ * #11164 AC-1, AC-2, AC-3 — the new lead, the expandable data-use row, the
4
+ * training switch and the "Your data" table in place of the Cookies section,
5
+ * the summary row, the agreements list and the deletion request).
5
6
  */
6
7
  import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
7
8
  import { tmpdir } from "node:os";
8
9
  import { join } from "node:path";
9
10
 
10
11
  import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
11
- import { consentStatementText } from "@working-theory/ui/blocks";
12
- import { ACCOUNT_TERMS_STATEMENT } from "@working-theory/validation";
13
12
 
14
13
  jest.mock("next-intl/server", () => {
15
14
  const msgs: unknown = require("../../../../../messages/en.json");
@@ -23,26 +22,29 @@ jest.mock("next-intl/server", () => {
23
22
  getTranslations: async (arg: string | { namespace?: string; locale?: string }) => {
24
23
  const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
25
24
  const messages = dig(msgs, ns);
26
- return (key: string, values?: Record<string, unknown>): string => {
25
+ const t = (key: string, values?: Record<string, unknown>): string => {
27
26
  const value = dig(messages, key);
28
27
  if (typeof value !== "string") return `${ns}.${key}`;
29
28
  return value.replace(/\{(\w+)\}/g, (m, name: string) =>
30
29
  values && name in values ? String(values[name]) : m,
31
30
  );
32
31
  };
32
+ // #11164: the lead is a `t.rich` message with a `<policy>` tag, the
33
+ // deletion line an ICU plural.
34
+ const { withRich } = require("./rich-translator") as typeof import("./rich-translator");
35
+ return withRich(t, (key: string) => dig(messages, key), ns);
33
36
  },
34
37
  getLocale: jest.fn().mockResolvedValue("en"),
35
38
  };
36
39
  });
37
40
 
38
41
  const mockHeaders = jest.fn();
39
- const mockCookies: Record<string, string> = {};
40
42
  jest.mock("next/headers", () => ({
41
43
  __esModule: true,
42
44
  headers: (...args: unknown[]) => mockHeaders(...args),
43
45
  cookies: jest.fn().mockResolvedValue({
44
46
  toString: () => "session=abc",
45
- get: (name: string) => (name in mockCookies ? { name, value: mockCookies[name] } : undefined),
47
+ get: () => undefined,
46
48
  }),
47
49
  }));
48
50
 
@@ -54,9 +56,9 @@ jest.mock("../../../../../auth", () => ({
54
56
  }));
55
57
 
56
58
  const mockPieces = jest.fn();
57
- const mockRequestDeletion = jest.fn();
58
59
  const mockConsents = jest.fn();
59
60
  const mockSetConsent = jest.fn();
61
+ const mockDeleteStoredSessions = jest.fn();
60
62
  jest.mock("@working-theory/api-client", () => ({
61
63
  __esModule: true,
62
64
  waitlistSignups: { me: jest.fn() },
@@ -65,9 +67,9 @@ jest.mock("@working-theory/api-client", () => ({
65
67
  leads: { submit: jest.fn() },
66
68
  member: {
67
69
  pieces: (...args: unknown[]) => mockPieces(...args),
68
- requestDeletion: (...args: unknown[]) => mockRequestDeletion(...args),
69
70
  consents: (...args: unknown[]) => mockConsents(...args),
70
71
  setConsent: (...args: unknown[]) => mockSetConsent(...args),
72
+ deleteStoredSessions: (...args: unknown[]) => mockDeleteStoredSessions(...args),
71
73
  },
72
74
  hubSignIn: { me: jest.fn() },
73
75
  visitorForwardHeaders: () => null,
@@ -99,15 +101,23 @@ const refusal = (status: number, code: string) => ({
99
101
  body: { ok: false, error: { code, message: code } },
100
102
  });
101
103
 
102
- function dataPurpose(overrides: Partial<{ id: string; effective: boolean; state: unknown }> = {}) {
104
+ const LEAD =
105
+ "We believe in transparent data practices. Learn how your information is protected when using our products, and view our Privacy Policy for more details.";
106
+ const BULLET_1 =
107
+ "With your permission, we will use your communications, artifacts, and sessions to train and improve our AI models. This helps us to make AI more helpful and accurate for everyone and to develop more robust safeguards against harmful outputs.";
108
+ const BULLET_2 =
109
+ "We may conduct aggregated, anonymized analysis of data to understand how people use products and services.";
110
+
111
+ /** `ai_training` as `GET /v1/member/consents` serves it from the shipped registry. */
112
+ function trainingPurpose(overrides: Partial<{ effective: boolean; state: unknown }> = {}) {
103
113
  return {
104
- id: overrides.id ?? "data_sharing",
114
+ id: "ai_training",
105
115
  kind: "consent" as const,
106
116
  area: "data" as const,
107
117
  required: false,
108
118
  signUp: false,
109
- description: "Product-usage data.",
110
- statement: "Share product-usage data with us.",
119
+ description: "Use of your communications, artifacts and sessions to train and improve AI models.",
120
+ statement: "I allow the use of my communications, artifacts, and sessions to train and improve AI models.",
111
121
  policyHref: "/privacy",
112
122
  policyVersion: 1,
113
123
  state: overrides.state === undefined ? null : overrides.state,
@@ -115,19 +125,14 @@ function dataPurpose(overrides: Partial<{ id: string; effective: boolean; state:
115
125
  };
116
126
  }
117
127
 
118
- function agreementPurpose(overrides: Partial<{ id: string; state: unknown }> = {}) {
128
+ /** A communications purpose, which Privacy never lists. */
129
+ function communicationsPurpose() {
119
130
  return {
120
- id: overrides.id ?? "account_terms",
121
- kind: "agreement" as const,
122
- area: null,
123
- required: true,
124
- signUp: true,
125
- description: "Account terms.",
126
- statement: ACCOUNT_TERMS_STATEMENT,
127
- policyHref: "/working-agreement",
128
- policyVersion: 2,
129
- state: overrides.state === undefined ? null : overrides.state,
130
- effective: false,
131
+ ...trainingPurpose(),
132
+ id: "newsletter",
133
+ area: "communications" as const,
134
+ description: "This site's newsletter by email",
135
+ statement: "Email me the newsletter.",
131
136
  };
132
137
  }
133
138
 
@@ -138,12 +143,11 @@ beforeEach(() => {
138
143
  process.env.AILK_CONTENT_ROOT = contentRoot;
139
144
  writeFileSync(join(contentRoot, "_site.mdx"), '---\nsiteName: "Test"\n---\n');
140
145
  mockHeaders.mockReset().mockResolvedValue(new Headers());
141
- for (const key of Object.keys(mockCookies)) delete mockCookies[key];
142
146
  mockGetSession.mockReset().mockResolvedValue(SESSION);
143
147
  mockPieces.mockReset().mockResolvedValue(ok([]));
144
- mockRequestDeletion.mockReset().mockResolvedValue(ok({ sentTo: "site-operator" }));
145
- mockConsents.mockReset().mockResolvedValue(ok({ purposes: [] }));
148
+ mockConsents.mockReset().mockResolvedValue(ok({ purposes: [trainingPurpose(), communicationsPurpose()] }));
146
149
  mockSetConsent.mockReset();
150
+ mockDeleteStoredSessions.mockReset().mockResolvedValue(ok({ deleted: 2 }));
147
151
  });
148
152
 
149
153
  afterEach(() => {
@@ -154,7 +158,11 @@ async function renderPage(locale = "en"): Promise<void> {
154
158
  render(await Page({ params: Promise.resolve({ locale }) }));
155
159
  }
156
160
 
157
- describe("AC-4 — the frame", () => {
161
+ /** True when `a` comes before `b` in the document. */
162
+ const before = (a: Element, b: Element): boolean =>
163
+ (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0;
164
+
165
+ describe("the frame", () => {
158
166
  it("the Settings rail reads General, Security, Notifications, Privacy, Billing, Privacy current", async () => {
159
167
  await renderPage();
160
168
  const rail = screen.getByRole("navigation", { name: "Settings" });
@@ -169,224 +177,274 @@ describe("AC-4 — the frame", () => {
169
177
  expect(screen.getByTestId("account-settings-rail-privacy")).toHaveAttribute("aria-current", "page");
170
178
  });
171
179
 
172
- it("a non-default locale prefixes the rail", async () => {
180
+ it("a non-default locale prefixes the rail and the policy link", async () => {
173
181
  await renderPage("fr");
174
182
  expect(screen.getByTestId("account-settings-rail-privacy")).toHaveAttribute("href", "/fr/account/privacy");
183
+ expect(screen.getByTestId("account-privacy-policy")).toHaveAttribute("href", "/fr/privacy");
175
184
  });
176
185
  });
177
186
 
178
- describe("AC-4 — DOM order: summary, cookies, consents, agreements, deletion", () => {
179
- it("renders the five sections in order", async () => {
187
+ describe("AC-1 — the order, the copy and the absences", () => {
188
+ it("renders, in order: the title and the new lead, the data-use row collapsed, the training switch row, the Your data table", async () => {
180
189
  mockConsents.mockResolvedValue(
181
- ok({ purposes: [dataPurpose(), agreementPurpose()] }),
190
+ ok({
191
+ purposes: [
192
+ trainingPurpose({
193
+ effective: true,
194
+ state: { granted: true, at: "2026-11-08T12:00:00.000Z", source: "account_settings", policyVersion: 1 },
195
+ }),
196
+ ],
197
+ }),
182
198
  );
183
199
  await renderPage();
184
200
  const pane = screen.getByTestId("account-settings-privacy");
185
- const ids = [
201
+
202
+ const title = within(pane).getByRole("heading", { level: 1 });
203
+ expect(title).toHaveTextContent("Privacy");
204
+ const policy = within(pane).getByTestId("account-privacy-policy");
205
+ expect(policy).toHaveTextContent("Privacy Policy");
206
+ expect(policy).toHaveAttribute("href", "/privacy");
207
+ expect(policy.closest("p")).toHaveTextContent(LEAD);
208
+
209
+ const trigger = within(pane).getByTestId("account-privacy-data-use-trigger");
210
+ expect(trigger.tagName).toBe("BUTTON");
211
+ expect(trigger).toHaveTextContent("How we use your data");
212
+ expect(trigger).toHaveAttribute("aria-expanded", "false");
213
+ expect(within(pane).queryByText(BULLET_1)).not.toBeInTheDocument();
214
+
215
+ const switchRow = within(pane).getByTestId("account-privacy-data-consent-ai_training");
216
+ expect(within(switchRow).getByTestId("account-privacy-data-consent-ai_training-label")).toHaveTextContent(
217
+ "Help improve our AI models",
218
+ );
219
+ expect(switchRow).toHaveTextContent(
220
+ "Allow the use of your communications, artifacts, and sessions to train and improve AI models.",
221
+ );
222
+ expect(within(switchRow).getByTestId("account-privacy-data-consent-ai_training-date")).toHaveTextContent(
223
+ "Given Nov 8, 2026",
224
+ );
225
+ expect(within(switchRow).getByRole("switch")).toBeChecked();
226
+
227
+ const table = within(pane).getByTestId("account-privacy-your-data");
228
+ expect(within(table).getByRole("heading", { level: 2 })).toHaveTextContent("Your data");
229
+ const rows = within(table).getAllByRole("row");
230
+ expect(rows).toHaveLength(2);
231
+ expect(within(table).queryByRole("columnheader")).not.toBeInTheDocument();
232
+ expect(rows[0]).toHaveTextContent("Export data");
233
+ expect(within(rows[0]!).getByTestId("account-privacy-your-data-export-button")).toHaveTextContent(
234
+ "Export data",
235
+ );
236
+ expect(within(rows[0]!).getByTestId("account-privacy-your-data-export-button").closest("td")).toHaveClass(
237
+ "text-end",
238
+ );
239
+ expect(rows[1]).toHaveTextContent("Delete stored sessions");
240
+ expect(rows[1]).toHaveTextContent("Permanently delete server-side copies of your stored sessions.");
241
+ expect(within(rows[1]!).getByTestId("account-privacy-your-data-delete-button")).toHaveTextContent("Delete");
242
+ expect(within(rows[1]!).getByTestId("account-privacy-your-data-delete-button").closest("td")).toHaveClass(
243
+ "text-end",
244
+ );
245
+
246
+ // The order.
247
+ expect(before(title, policy)).toBe(true);
248
+ expect(before(policy, trigger)).toBe(true);
249
+ expect(before(trigger, switchRow)).toBe(true);
250
+ expect(before(switchRow, table)).toBe(true);
251
+ // The data-use row and the switch share one card; the table is its own.
252
+ const cards = within(pane).getAllByTestId("account-settings-privacy-card");
253
+ expect(cards).toHaveLength(2);
254
+ expect(cards[0]).toContainElement(trigger);
255
+ expect(cards[0]).toContainElement(switchRow);
256
+ expect(cards[1]).toContainElement(table);
257
+ });
258
+
259
+ it("renders no Cookies section, no summary row, no agreements list and no account-deletion line or button", async () => {
260
+ await renderPage();
261
+ for (const id of [
186
262
  "account-privacy-summary",
187
263
  "account-privacy-cookies",
264
+ "account-cookie-settings",
188
265
  "account-privacy-consents",
189
266
  "account-privacy-agreements",
190
267
  "account-deletion",
191
- ];
192
- const positions = ids.map((id) => {
193
- const el = within(pane).getByTestId(id);
194
- let index = 0;
195
- let node: Element | null = pane.firstElementChild;
196
- while (node && node !== el) {
197
- node = node.nextElementSibling;
198
- index += 1;
199
- }
200
- return index;
201
- });
202
- expect(positions).toEqual([...positions].sort((a, b) => a - b));
268
+ "account-deletion-request",
269
+ "account-deletion-support",
270
+ ]) {
271
+ expect(screen.queryByTestId(id)).not.toBeInTheDocument();
272
+ }
273
+ for (const text of [
274
+ "Cookies",
275
+ "Cookies and your data.",
276
+ "How we use your data.",
277
+ "Read our privacy policy",
278
+ "Data use",
279
+ "Agreements accepted",
280
+ "Request account deletion",
281
+ "Ask the site owner to delete your account and its data.",
282
+ ]) {
283
+ expect(screen.queryByText(text)).not.toBeInTheDocument();
284
+ }
285
+ // The communications purpose is Notifications', never listed here.
286
+ expect(screen.queryByTestId("account-privacy-data-consent-newsletter")).not.toBeInTheDocument();
287
+ expect(screen.getAllByRole("switch")).toHaveLength(1);
203
288
  });
204
- });
205
289
 
206
- describe("AC-4 — account-privacy-summary", () => {
207
- it("links to the site's privacy policy", async () => {
290
+ it("the chevron expands the row in place to the two bullets, in order, and is a disclosure button", async () => {
208
291
  await renderPage();
209
- expect(screen.getByTestId("account-privacy-policy")).toHaveAttribute("href", "/privacy");
292
+ const trigger = screen.getByTestId("account-privacy-data-use-trigger");
293
+ fireEvent.click(trigger);
294
+ expect(trigger).toHaveAttribute("aria-expanded", "true");
295
+ const content = screen.getByTestId("account-privacy-data-use-content");
296
+ expect(within(content).getAllByRole("listitem").map((li) => li.textContent)).toEqual([BULLET_1, BULLET_2]);
297
+ expect(screen.getByTestId("account-privacy-data-use")).toContainElement(content);
298
+ expect(before(trigger, content)).toBe(true);
299
+ fireEvent.click(trigger);
300
+ expect(trigger).toHaveAttribute("aria-expanded", "false");
210
301
  });
211
- });
212
302
 
213
- describe("AC-4 — account-privacy-cookies (read from the browser cookie, not the ledger)", () => {
214
- it.each([
215
- ["accepted", "Accepted"],
216
- ["declined", "Declined"],
217
- ])("reads %s as %s", async (value, label) => {
218
- mockCookies["ailk-consent"] = value;
303
+ it("with no data purpose declared, the switch list shows its one line under the data-use row", async () => {
304
+ mockConsents.mockResolvedValue(ok({ purposes: [communicationsPurpose()] }));
219
305
  await renderPage();
220
- expect(within(screen.getByTestId("account-privacy-cookies")).getByText(label)).toBeInTheDocument();
306
+ expect(screen.getByTestId("account-privacy-data-consent-empty")).toHaveTextContent(
307
+ "This site asks for no data-use consents.",
308
+ );
309
+ expect(screen.getByTestId("account-privacy-your-data")).toBeInTheDocument();
221
310
  });
222
311
 
223
- it("with no cookie set, reads Not chosen yet", async () => {
312
+ it("a failed consents read keeps the lead, the data-use row and the table, and shows the one line in place of the switch", async () => {
313
+ mockConsents.mockResolvedValue(refusal(503, "tenant_unresolved"));
224
314
  await renderPage();
225
- expect(within(screen.getByTestId("account-privacy-cookies")).getByText("Not chosen yet")).toBeInTheDocument();
315
+ expect(screen.getByTestId("account-privacy-policy")).toBeInTheDocument();
316
+ expect(screen.getByTestId("account-privacy-data-use-trigger")).toBeInTheDocument();
317
+ expect(screen.getByTestId("account-privacy-your-data")).toBeInTheDocument();
318
+ expect(screen.queryByRole("switch")).not.toBeInTheDocument();
319
+ expect(screen.getByTestId("account-privacy-unavailable")).toHaveTextContent(
320
+ "Your consent choices can't be shown right now.",
321
+ );
226
322
  });
323
+ });
227
324
 
228
- it("the Change link points at /privacy#cookie-settings", async () => {
325
+ describe("AC-2 — Help improve our AI models is a registry area: data consent, off until ticked", () => {
326
+ it("renders off with no date line when the person has no row, and off is `effective: false`", async () => {
229
327
  await renderPage();
230
- expect(screen.getByTestId("account-cookie-settings")).toHaveAttribute("href", "/privacy#cookie-settings");
328
+ expect(screen.getByTestId("account-privacy-data-consent-ai_training-switch")).not.toBeChecked();
329
+ expect(screen.queryByTestId("account-privacy-data-consent-ai_training-date")).not.toBeInTheDocument();
231
330
  });
232
- });
233
331
 
234
- describe("AC-4 — account-privacy-consents (data-use switches)", () => {
235
- it("a declared data purpose renders a switch with its date", async () => {
236
- mockConsents.mockResolvedValue(
332
+ it("ticking it writes the ledger through setConsentAction and shows the given date the answer carries", async () => {
333
+ mockSetConsent.mockResolvedValue(
237
334
  ok({
238
- purposes: [
239
- dataPurpose({
240
- effective: true,
241
- state: { granted: true, at: "2026-10-12T12:00:00.000Z", source: "account_settings", policyVersion: 1 },
242
- }),
243
- ],
335
+ purpose: trainingPurpose({
336
+ effective: true,
337
+ state: { granted: true, at: "2026-11-08T12:00:00.000Z", source: "account_settings", policyVersion: 1 },
338
+ }),
244
339
  }),
245
340
  );
246
341
  await renderPage();
247
- expect(screen.getByTestId("account-privacy-data-consent-data_sharing-switch")).toBeChecked();
248
- expect(screen.getByTestId("account-privacy-data-consent-data_sharing-date")).toHaveTextContent(
249
- "Given Oct 12, 2026",
342
+ fireEvent.click(screen.getByTestId("account-privacy-data-consent-ai_training-switch"));
343
+ await waitFor(() => expect(mockSetConsent).toHaveBeenCalledTimes(1));
344
+ expect(mockSetConsent).toHaveBeenCalledWith({ purposeId: "ai_training", granted: true, locale: "en" }, COOKIE_INIT);
345
+ expect(await screen.findByTestId("account-privacy-data-consent-ai_training-date")).toHaveTextContent(
346
+ "Given Nov 8, 2026",
250
347
  );
348
+ expect(screen.getByTestId("account-privacy-data-consent-ai_training-switch")).toBeChecked();
251
349
  });
252
350
 
253
- it("toggling calls setConsentAction, and a failed answer reverts the switch with its message", async () => {
254
- mockConsents.mockResolvedValue(ok({ purposes: [dataPurpose({ effective: true })] }));
351
+ it("a failed answer reverts the switch with its message", async () => {
255
352
  mockSetConsent.mockResolvedValue(refusal(500, "internal"));
256
353
  await renderPage();
257
- fireEvent.click(screen.getByTestId("account-privacy-data-consent-data_sharing-switch"));
354
+ fireEvent.click(screen.getByTestId("account-privacy-data-consent-ai_training-switch"));
258
355
  await waitFor(() =>
259
- expect(screen.getByTestId("account-privacy-data-consent-data_sharing-error")).toBeInTheDocument(),
356
+ expect(screen.getByTestId("account-privacy-data-consent-ai_training-error")).toBeInTheDocument(),
260
357
  );
261
- expect(screen.getByTestId("account-privacy-data-consent-data_sharing-switch")).toBeChecked();
262
- expect(mockSetConsent).toHaveBeenCalledWith({ purposeId: "data_sharing", granted: false, locale: "en" }, COOKIE_INIT);
358
+ expect(screen.getByTestId("account-privacy-data-consent-ai_training-switch")).not.toBeChecked();
263
359
  });
264
360
 
265
- it("with no data purpose declared, shows the one line", async () => {
266
- await renderPage();
267
- expect(screen.getByTestId("account-privacy-data-consent-empty")).toHaveTextContent(
268
- "This site asks for no other data-use consents.",
269
- );
270
- });
271
- });
272
-
273
- describe("AC-4 — account-privacy-agreements (read-only)", () => {
274
- it("an accepted agreement shows its version and date, read-only", async () => {
361
+ it("a data purpose a site adds is labelled by its statement and described by its description", async () => {
275
362
  mockConsents.mockResolvedValue(
276
363
  ok({
277
364
  purposes: [
278
- agreementPurpose({
279
- state: { granted: true, at: "2026-10-01T12:00:00.000Z", source: "sign_up", policyVersion: 2 },
280
- }),
365
+ {
366
+ ...trainingPurpose(),
367
+ id: "data_sharing",
368
+ description: "Product-usage data.",
369
+ statement: "Share product-usage data with us.",
370
+ },
281
371
  ],
282
372
  }),
283
373
  );
284
374
  await renderPage();
285
- const row = screen.getByTestId("account-privacy-agreement-account_terms");
286
- expect(within(row).getByText("Version 2")).toBeInTheDocument();
287
- expect(within(row).getByText("Accepted Oct 1, 2026")).toBeInTheDocument();
288
- expect(within(row).queryByRole("switch")).not.toBeInTheDocument();
289
- expect(within(row).queryByRole("button")).not.toBeInTheDocument();
290
- });
291
-
292
- it("an agreement with no grant shows None yet", async () => {
293
- mockConsents.mockResolvedValue(ok({ purposes: [agreementPurpose()] }));
294
- await renderPage();
295
- expect(screen.getByTestId("account-privacy-agreement-account_terms-accepted")).toHaveTextContent("None yet");
296
- });
297
-
298
- // #8765 D11 / AC-5 (#8761) — the statement renders with its three links.
299
- it.each(["en", "fr"])(
300
- "%s: the statement is the Contact sentence with no markdown, linking Terms, Privacy Policy and Working Agreement",
301
- async (locale) => {
302
- mockConsents.mockResolvedValue(ok({ purposes: [agreementPurpose()] }));
303
- await renderPage(locale);
304
- const statement = screen.getByTestId("account-privacy-agreement-account_terms-statement");
305
- expect(statement.textContent).toBe(consentStatementText(ACCOUNT_TERMS_STATEMENT));
306
- expect(statement.textContent).not.toContain("[");
307
- expect(statement.textContent).not.toContain("](");
308
- const prefix = locale === "en" ? "" : `/${locale}`;
309
- const links = (["terms", "privacy", "working_agreement"] as const).map((key) => {
310
- const link = within(statement).getByTestId(`consent-policy-link-${key}`);
311
- return [link.textContent, link.getAttribute("href")];
312
- });
313
- expect(links).toEqual([
314
- ["Terms", `${prefix}/terms`],
315
- ["Privacy Policy", `${prefix}/privacy`],
316
- ["Working Agreement", `${prefix}/working-agreement`],
317
- ]);
318
- },
319
- );
320
-
321
- it("no retired card policy link renders, and the policy link is the summary's, to /privacy", async () => {
322
- mockConsents.mockResolvedValue(ok({ purposes: [agreementPurpose()] }));
323
- await renderPage();
324
- expect(
325
- document.querySelector('[data-testid^="account-agreements-prompt-"][data-testid$="-policy"]'),
326
- ).toBeNull();
327
- const policyLinks = screen.getAllByText("Read our privacy policy");
328
- expect(policyLinks).toHaveLength(1);
329
- expect(within(screen.getByTestId("account-privacy-summary")).getByTestId("account-privacy-policy")).toHaveAttribute(
330
- "href",
331
- "/privacy",
375
+ const row = screen.getByTestId("account-privacy-data-consent-data_sharing");
376
+ expect(within(row).getByTestId("account-privacy-data-consent-data_sharing-label")).toHaveTextContent(
377
+ "Share product-usage data with us.",
332
378
  );
379
+ expect(row).toHaveTextContent("Product-usage data.");
333
380
  });
334
381
  });
335
382
 
336
- describe("AC-4 — a failed consents read", () => {
337
- it("keeps sections 1, 2 and 5 and shows the one error line in place of 3 and 4", async () => {
338
- mockConsents.mockResolvedValue(refusal(503, "tenant_unresolved"));
339
- await renderPage();
340
- expect(screen.getByTestId("account-privacy-summary")).toBeInTheDocument();
341
- expect(screen.getByTestId("account-privacy-cookies")).toBeInTheDocument();
342
- expect(screen.getByTestId("account-deletion")).toBeInTheDocument();
343
- expect(screen.queryByTestId("account-privacy-consents")).not.toBeInTheDocument();
344
- expect(screen.queryByTestId("account-privacy-agreements")).not.toBeInTheDocument();
345
- expect(screen.getByTestId("account-privacy-unavailable")).toHaveTextContent(
346
- "Your consent choices can't be shown right now.",
347
- );
383
+ describe("AC-3 — Export data", () => {
384
+ it("the Export data button links this site's own download route for the person's records", async () => {
385
+ await renderPage("fr");
386
+ const button = screen.getByTestId("account-privacy-your-data-export-button");
387
+ expect(button).toHaveAttribute("href", "/fr/account/privacy/export");
388
+ expect(button).toHaveAttribute("download");
348
389
  });
349
390
  });
350
391
 
351
- // ── Deletion (moved from general.test.tsx, #8438 D16 — expectations unchanged) ──
352
-
353
- describe("AC-4 — Request account deletion through the member API (moved from General, D16)", () => {
354
- async function requestDeletion(): Promise<void> {
392
+ describe("AC-3 — Delete stored sessions", () => {
393
+ async function confirmDelete(): Promise<void> {
394
+ fireEvent.click(screen.getByTestId("account-privacy-your-data-delete-button"));
395
+ const dialog = await screen.findByRole("alertdialog");
355
396
  await act(async () => {
356
- fireEvent.click(screen.getByTestId("account-deletion-request"));
397
+ fireEvent.click(within(dialog).getByTestId("account-privacy-your-data-delete-confirm-action"));
357
398
  });
358
399
  }
359
400
 
401
+ it("asks for confirmation, names where an account-deletion request lives, and calls nothing until confirmed", async () => {
402
+ await renderPage();
403
+ fireEvent.click(screen.getByTestId("account-privacy-your-data-delete-button"));
404
+ const dialog = await screen.findByRole("alertdialog");
405
+ expect(dialog).toHaveTextContent("Delete stored sessions?");
406
+ expect(dialog).toHaveTextContent("To ask for your account and its data to be deleted, contact support.");
407
+ expect(within(dialog).getByTestId("account-privacy-your-data-account-deletion")).toHaveAttribute(
408
+ "href",
409
+ "/account/support",
410
+ );
411
+ expect(mockDeleteStoredSessions).not.toHaveBeenCalled();
412
+ });
413
+
360
414
  it.each([
361
- ["site-operator", "Sent to the site operator."],
362
- ["hub-operator", "Sent to the hub operator."],
363
- ])("an answer naming %s shows %s — the answer picks the line", async (sentTo, line) => {
364
- mockRequestDeletion.mockResolvedValue(ok({ sentTo }));
415
+ [2, "Deleted 2 stored sessions."],
416
+ [1, "Deleted 1 stored session."],
417
+ [0, "There were no stored sessions to delete."],
418
+ ])("confirming deletes through the member route and reports %i as %s", async (deleted, line) => {
419
+ mockDeleteStoredSessions.mockResolvedValue(ok({ deleted }));
365
420
  await renderPage();
366
- await requestDeletion();
367
- expect(mockRequestDeletion).toHaveBeenCalledWith({}, COOKIE_INIT);
421
+ await confirmDelete();
422
+ expect(mockDeleteStoredSessions).toHaveBeenCalledWith(COOKIE_INIT);
368
423
  await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent(line));
369
- expect(screen.queryByTestId("account-deletion-request")).not.toBeInTheDocument();
370
424
  });
371
425
 
372
- it("a refusal shows its line and keeps the button", async () => {
373
- mockRequestDeletion.mockResolvedValue(refusal(403, "email_unverified"));
426
+ it("a refusal shows the failure line as an alert", async () => {
427
+ mockDeleteStoredSessions.mockResolvedValue(refusal(429, "rate_limited"));
374
428
  await renderPage();
375
- await requestDeletion();
429
+ await confirmDelete();
376
430
  await waitFor(() =>
377
- expect(screen.getByRole("alert")).toHaveTextContent("Confirm your email address first, then ask again."),
431
+ expect(screen.getByRole("alert")).toHaveTextContent("We couldn't delete your stored sessions. Try again in a moment."),
378
432
  );
379
- expect(screen.getByTestId("account-deletion-request")).toBeEnabled();
380
433
  });
381
- });
382
434
 
383
- describe("a single site with no member API (a 404 from the pieces read) — moved from general.test.tsx", () => {
384
- it("points the deletion request at Support, with no Request button (C2, D5)", async () => {
435
+ // A single site whose build answers no member route (a 404 from the pieces
436
+ // read) still files Support into its own operator inbox, so the pointer
437
+ // stays; the hub-mode spoke that must show none (`via: "none"`,
438
+ // SEC-7894-11) is `AccountDataTable`'s `supportHref: null` case.
439
+ it("a single site with no member API still points an account-deletion request at Support", async () => {
385
440
  mockPieces.mockResolvedValue(refusal(404, "not_found"));
386
441
  await renderPage();
387
- expect(screen.queryByTestId("account-deletion-request")).not.toBeInTheDocument();
388
- expect(screen.getByTestId("account-deletion-support")).toHaveAttribute("href", "/account/support");
389
- expect(screen.getByText("To ask for your account to be deleted, contact support.")).toBeInTheDocument();
442
+ fireEvent.click(screen.getByTestId("account-privacy-your-data-delete-button"));
443
+ const dialog = await screen.findByRole("alertdialog");
444
+ expect(within(dialog).getByTestId("account-privacy-your-data-account-deletion")).toHaveAttribute(
445
+ "href",
446
+ "/account/support",
447
+ );
390
448
  });
391
449
  });
392
450
 
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `t.rich` the way next-intl renders it, for the inline `next-intl/server`
3
+ * mocks of this area's suites (#11175): a `<tag>chunks</tag>` in the message
4
+ * renders the node the tag's function returns for those chunks; `{name}` its
5
+ * value; an ICU `{name, plural, …}` block its matching case with `#` the
6
+ * count (#11164's deletion line). `t.markup` renders the same message as a
7
+ * string, each tag's function given the chunks. `require`d inside a
8
+ * `jest.mock` factory, so it holds no test-file state.
9
+ */
10
+ import { createElement, Fragment, type ReactNode } from "react";
11
+
12
+ type Translate = (key: string, values?: Record<string, unknown>) => string;
13
+ type Rich = (key: string, values?: Record<string, unknown>) => ReactNode;
14
+ type Markup = (key: string, values?: Record<string, unknown>) => string;
15
+
16
+ /** Resolve every `{name, plural, =0 {…} one {…} other {…}}` block in `value`. */
17
+ function plural(value: string, values?: Record<string, unknown>): string {
18
+ return value.replace(
19
+ /\{(\w+), plural,((?:\s*(?:=\d+|zero|one|two|few|many|other)\s*\{[^{}]*\})+)\s*\}/g,
20
+ (_match, name: string, options: string) => {
21
+ const count = Number(values?.[name]);
22
+ const cases = new Map<string, string>();
23
+ for (const [, selector, text] of options.matchAll(/(=\d+|\w+)\s*\{([^{}]*)\}/g)) {
24
+ cases.set(selector!, text!);
25
+ }
26
+ const text =
27
+ cases.get(`=${count}`) ?? (count === 1 ? cases.get("one") : undefined) ?? cases.get("other") ?? "";
28
+ return text.replace(/#/g, String(count));
29
+ },
30
+ );
31
+ }
32
+
33
+ export function withRich(
34
+ t: Translate,
35
+ lookup: (key: string) => unknown,
36
+ ns: string,
37
+ ): Translate & { rich: Rich; markup: Markup } {
38
+ const translate: Translate = (key, values) => plural(t(key, values), values);
39
+ const rich: Rich = (key, values) => {
40
+ const value = lookup(key);
41
+ if (typeof value !== "string") return `${ns}.${key}`;
42
+ return plural(value, values)
43
+ .split(/(<\w+>[^<]*<\/\w+>|\{\w+\})/)
44
+ .map((part, i) => {
45
+ const tag = /^<(\w+)>([^<]*)<\/\1>$/.exec(part);
46
+ const fn = tag ? values?.[tag[1]!] : undefined;
47
+ if (typeof fn === "function") {
48
+ return createElement(Fragment, { key: i }, fn(tag![2] === "" ? [] : [tag![2]]));
49
+ }
50
+ const name = /^\{(\w+)\}$/.exec(part)?.[1];
51
+ return name && values && name in values ? String(values[name]) : part;
52
+ });
53
+ };
54
+ const markup: Markup = (key, values) => {
55
+ const value = lookup(key);
56
+ if (typeof value !== "string") return `${ns}.${key}`;
57
+ return plural(value, values).replace(/<(\w+)>([^<]*)<\/\1>/g, (_match, tag: string, inner: string) => {
58
+ const fn = values?.[tag];
59
+ return typeof fn === "function" ? String(fn(inner)) : inner;
60
+ });
61
+ };
62
+ return Object.assign(translate, { rich, markup });
63
+ }