create-ailk 0.37.1 → 0.38.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.
- package/README.md +129 -0
- package/component-catalog.json +44 -6
- package/component-catalog.md +6 -5
- package/dist/add-module.js +16 -1
- package/dist/add-route.d.ts +2 -2
- package/dist/add-route.js +18 -11
- package/dist/cli.js +52 -0
- package/dist/declined-routes.d.ts +13 -0
- package/dist/declined-routes.js +74 -0
- package/dist/derive-architecture.d.ts +0 -6
- package/dist/derive-architecture.js +9 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/language-import.d.ts +93 -0
- package/dist/language-import.js +270 -43
- package/dist/lib/import-mdx.js +1 -1
- package/dist/lib/scaffold-render-sweep.d.ts +6 -3
- package/dist/lib/scaffold-render-sweep.js +8 -4
- package/dist/migrate-content.d.ts +6 -2
- package/dist/migrate-content.js +62 -5
- package/dist/module-architecture.js +139 -103
- package/dist/paid-sections.d.ts +13 -0
- package/dist/paid-sections.js +35 -5
- package/dist/programmatic.js +6 -16
- package/dist/remove-module.js +67 -0
- package/dist/routes.d.ts +103 -0
- package/dist/routes.js +708 -0
- package/dist/site-manifest.js +1 -1
- package/dist/site-roster.d.ts +2 -1
- package/dist/site-roster.js +30 -8
- package/dist/spoke-checkout.d.ts +28 -27
- package/dist/spoke-checkout.js +71 -102
- package/dist/surfaces.d.ts +18 -0
- package/dist/surfaces.js +47 -282
- package/dist/sync-routes.d.ts +14 -1
- package/dist/sync-routes.js +86 -5
- package/dist/topology.d.ts +15 -1
- package/dist/topology.js +20 -4
- package/dist/update.d.ts +17 -2
- package/dist/update.js +480 -77
- package/package.json +3 -3
- package/templates/README.md +1 -1
- package/templates/apps/mcp/CLAUDE.md +5 -3
- package/templates/apps/web/CLAUDE.md +62 -20
- package/templates/apps/web/account.config.tsx +101 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +3 -161
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +3 -139
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +3 -406
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +2 -190
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +3 -182
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +8 -420
- package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +8 -214
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +8 -115
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +2 -80
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +8 -121
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +3 -154
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +7 -149
- package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +3 -143
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +3 -126
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +8 -302
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +2 -102
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +3 -240
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -131
- package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +2 -24
- package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +3 -60
- package/templates/apps/web/app/[locale]/layout.tsx +45 -28
- package/templates/apps/web/app/apple-icon.tsx +72 -0
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
- package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
- package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
- package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
- package/templates/apps/web/app/og/route.tsx +155 -72
- package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
- package/templates/apps/web/i18n/request.ts +44 -1
- package/templates/apps/web/jest.config.cjs +13 -1
- package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
- package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +70 -0
- package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
- package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
- package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
- package/templates/apps/web/lib/listings.tsx +2 -2
- package/templates/apps/web/lib/nav-label-keys.ts +16 -2
- package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
- package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
- package/templates/apps/web/lib/profile-back-link.ts +105 -32
- package/templates/apps/web/lib/served-pages.ts +95 -0
- package/templates/apps/web/lib/site-brand.tsx +3 -5
- package/templates/apps/web/messages/en.json +8 -684
- package/templates/apps/web/middleware.ts +3 -1
- package/templates/apps/web/next.config.mjs +27 -0
- package/templates/apps/web/package.json +1 -0
- package/templates/customizations.yaml +9 -0
- package/templates/package.json +3 -1
- package/templates/tools/lint-architecture.ts +164 -11
- package/versions.json +48 -47
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
- package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
- package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
- package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
- package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
- package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
- package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
- package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
- package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
- package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
- package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
- package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
- package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
- package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
- package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
- package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
- package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
- package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
- package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
- package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
- package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
- package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
- package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
- package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
- package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
- package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
- package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
- package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
- package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
- package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
- package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
- package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
- package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
- package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
- package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
- package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
- package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
- package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
- package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
- package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
- package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
- package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
- package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
- package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
- package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
- package/templates/apps/web/lib/account-config.ts +0 -678
- package/templates/apps/web/lib/checkout-config.ts +0 -16
- package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
- package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for /[locale]/account/support — Contact support (#7430, spec 7423
|
|
3
|
-
* U4 · D11; AC-9).
|
|
4
|
-
*
|
|
5
|
-
* Covers:
|
|
6
|
-
* 1. The form posts `{ kind: "support", subject, message }` to
|
|
7
|
-
* `/v1/leads/submit` (`leads.submit`) with `source: "web"`, the
|
|
8
|
-
* session's email and no `siteId`, and shows a confirmation on 201.
|
|
9
|
-
* 2. A missing subject or message is refused without a call.
|
|
10
|
-
* 3. A failed submit says so and keeps what was typed; the API's
|
|
11
|
-
* `lead_capture_not_configured` 503 says requests can't be sent.
|
|
12
|
-
*/
|
|
13
|
-
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
14
|
-
|
|
15
|
-
jest.mock("next-intl/server", () => {
|
|
16
|
-
const msgs: unknown = require("../../../../../messages/en.json");
|
|
17
|
-
const dig = (obj: unknown, path: string): unknown =>
|
|
18
|
-
path.split(".").reduce<unknown>(
|
|
19
|
-
(acc, k) => (acc !== null && typeof acc === "object" ? (acc as Record<string, unknown>)[k] : undefined),
|
|
20
|
-
obj,
|
|
21
|
-
);
|
|
22
|
-
return {
|
|
23
|
-
__esModule: true,
|
|
24
|
-
getTranslations: async (arg: string | { namespace?: string; locale?: string }) => {
|
|
25
|
-
const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
|
|
26
|
-
const messages = dig(msgs, ns);
|
|
27
|
-
return (key: string, values?: Record<string, unknown>): string => {
|
|
28
|
-
const value = dig(messages, key);
|
|
29
|
-
if (typeof value !== "string") return `${ns}.${key}`;
|
|
30
|
-
return value.replace(/\{(\w+)\}/g, (m, name: string) =>
|
|
31
|
-
values && name in values ? String(values[name]) : m,
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
jest.mock("next/headers", () => ({
|
|
39
|
-
__esModule: true,
|
|
40
|
-
headers: jest.fn().mockResolvedValue(new Headers()),
|
|
41
|
-
cookies: jest.fn().mockResolvedValue({ toString: () => "session=abc" }),
|
|
42
|
-
}));
|
|
43
|
-
|
|
44
|
-
const mockGetSession = jest.fn();
|
|
45
|
-
// eslint-disable-next-line no-restricted-syntax -- #507: mock-internal rewrite pending; auth.ts's lazy Better-Auth singleton has no HTTP/DB boundary a unit test of the session fields can mock without standing up Prisma.
|
|
46
|
-
jest.mock("../../../../../auth", () => ({
|
|
47
|
-
__esModule: true,
|
|
48
|
-
auth: { api: { getSession: (...args: unknown[]) => mockGetSession(...args) } },
|
|
49
|
-
}));
|
|
50
|
-
|
|
51
|
-
const mockLeadsSubmit = jest.fn();
|
|
52
|
-
jest.mock("@working-theory/api-client", () => ({
|
|
53
|
-
__esModule: true,
|
|
54
|
-
subscription: { me: jest.fn(), portalSession: jest.fn() },
|
|
55
|
-
leads: { submit: (...args: unknown[]) => mockLeadsSubmit(...args) },
|
|
56
|
-
visitorForwardHeaders: () => undefined,
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
jest.mock("next/navigation", () => ({
|
|
60
|
-
__esModule: true,
|
|
61
|
-
useRouter: () => ({ push: jest.fn(), refresh: jest.fn() }),
|
|
62
|
-
usePathname: () => "/account/support",
|
|
63
|
-
redirect: jest.fn(),
|
|
64
|
-
}));
|
|
65
|
-
|
|
66
|
-
import { submitSupportRequest } from "../support-actions";
|
|
67
|
-
import Page from "../support/page";
|
|
68
|
-
|
|
69
|
-
const SESSION = {
|
|
70
|
-
user: { id: "user_1", name: "Ada", email: "ada@example.com", emailVerified: true },
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
beforeEach(() => {
|
|
74
|
-
mockGetSession.mockReset().mockResolvedValue(SESSION);
|
|
75
|
-
mockLeadsSubmit
|
|
76
|
-
.mockReset()
|
|
77
|
-
.mockResolvedValue({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
async function renderPage(): Promise<void> {
|
|
81
|
-
const element = await Page({ params: Promise.resolve({ locale: "en" }) });
|
|
82
|
-
render(element);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async function submit(subject: string, message: string): Promise<void> {
|
|
86
|
-
fireEvent.change(screen.getByLabelText("Subject"), { target: { value: subject } });
|
|
87
|
-
fireEvent.change(screen.getByLabelText("Message"), { target: { value: message } });
|
|
88
|
-
await act(async () => {
|
|
89
|
-
fireEvent.click(screen.getByTestId("account-support-submit"));
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
describe("Contact support (AC-9, D11)", () => {
|
|
94
|
-
it("the primary is 44px on a phone only — the 36px default from md up (DESIGN.md §4)", async () => {
|
|
95
|
-
await renderPage();
|
|
96
|
-
const submit = screen.getByTestId("account-support-submit");
|
|
97
|
-
expect(submit).toHaveClass("max-md:min-h-11");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("renders the page heading and says where the reply goes", async () => {
|
|
101
|
-
await renderPage();
|
|
102
|
-
expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Contact support");
|
|
103
|
-
expect(screen.getByTestId("account-support")).toHaveTextContent("ada@example.com");
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('posts { kind: "support", subject, message } with source "web", and confirms on 201', async () => {
|
|
107
|
-
await renderPage();
|
|
108
|
-
await submit("Billing question", "Where is my receipt?");
|
|
109
|
-
await waitFor(() => expect(mockLeadsSubmit).toHaveBeenCalledTimes(1));
|
|
110
|
-
expect(mockLeadsSubmit.mock.calls[0]).toEqual([
|
|
111
|
-
{
|
|
112
|
-
source: "web",
|
|
113
|
-
email: "ada@example.com",
|
|
114
|
-
payload: {
|
|
115
|
-
kind: "support",
|
|
116
|
-
subject: "Billing question",
|
|
117
|
-
message: "Where is my receipt?",
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
]);
|
|
121
|
-
await waitFor(() =>
|
|
122
|
-
expect(screen.getByRole("status")).toHaveTextContent("your request is on its way"),
|
|
123
|
-
);
|
|
124
|
-
expect(screen.queryByTestId("account-support-submit")).not.toBeInTheDocument();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("a missing message is refused without a call", async () => {
|
|
128
|
-
await renderPage();
|
|
129
|
-
await submit("Billing question", " ");
|
|
130
|
-
expect(mockLeadsSubmit).not.toHaveBeenCalled();
|
|
131
|
-
expect(screen.getByRole("alert")).toHaveTextContent(
|
|
132
|
-
"Fill in both the subject and the message.",
|
|
133
|
-
);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("a failed submit says so and keeps what was typed", async () => {
|
|
137
|
-
mockLeadsSubmit.mockResolvedValue({ ok: false, status: 500, body: {} });
|
|
138
|
-
await renderPage();
|
|
139
|
-
await submit("Billing question", "Where is my receipt?");
|
|
140
|
-
await waitFor(() =>
|
|
141
|
-
expect(screen.getByRole("alert")).toHaveTextContent("We couldn't send your request."),
|
|
142
|
-
);
|
|
143
|
-
expect(screen.getByLabelText("Subject")).toHaveValue("Billing question");
|
|
144
|
-
expect(screen.getByLabelText("Message")).toHaveValue("Where is my receipt?");
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("a deployment that accepts no contact message says requests can't be sent", async () => {
|
|
148
|
-
mockLeadsSubmit.mockResolvedValue({
|
|
149
|
-
ok: false,
|
|
150
|
-
status: 503,
|
|
151
|
-
body: { error: "lead_capture_not_configured" },
|
|
152
|
-
});
|
|
153
|
-
await renderPage();
|
|
154
|
-
await submit("Billing question", "Where is my receipt?");
|
|
155
|
-
await waitFor(() =>
|
|
156
|
-
expect(screen.getByRole("alert")).toHaveTextContent("Requests can't be sent from this site yet."),
|
|
157
|
-
);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe("submitSupportRequest — the Server Action's own guards", () => {
|
|
162
|
-
function form(fields: Record<string, string>): FormData {
|
|
163
|
-
const data = new FormData();
|
|
164
|
-
for (const [key, value] of Object.entries(fields)) data.set(key, value);
|
|
165
|
-
return data;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
it("with no session, files nothing", async () => {
|
|
169
|
-
mockGetSession.mockResolvedValue(null);
|
|
170
|
-
const state = await submitSupportRequest(
|
|
171
|
-
{ kind: "idle" },
|
|
172
|
-
form({ kind: "support", subject: "Hi", message: "Help" }),
|
|
173
|
-
);
|
|
174
|
-
expect(state).toEqual({ kind: "error", reason: "failed" });
|
|
175
|
-
expect(mockLeadsSubmit).not.toHaveBeenCalled();
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("refuses an over-length subject or message", async () => {
|
|
179
|
-
const long = await submitSupportRequest(
|
|
180
|
-
{ kind: "idle" },
|
|
181
|
-
form({ kind: "support", subject: "x".repeat(201), message: "Help" }),
|
|
182
|
-
);
|
|
183
|
-
expect(long).toEqual({ kind: "error", reason: "required" });
|
|
184
|
-
const longer = await submitSupportRequest(
|
|
185
|
-
{ kind: "idle" },
|
|
186
|
-
form({ kind: "support", subject: "Hi", message: "x".repeat(5001) }),
|
|
187
|
-
);
|
|
188
|
-
expect(longer).toEqual({ kind: "error", reason: "required" });
|
|
189
|
-
expect(mockLeadsSubmit).not.toHaveBeenCalled();
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// #8232 D12 — a deletion request goes through `member.requestDeletion`
|
|
193
|
-
// (`profile-actions.ts`), so Support files support only.
|
|
194
|
-
it.each(["refund", "deletion"])(
|
|
195
|
-
"every request files as support, a posted kind=%s included; the email is always the session's",
|
|
196
|
-
async (kind) => {
|
|
197
|
-
await submitSupportRequest(
|
|
198
|
-
{ kind: "idle" },
|
|
199
|
-
form({ kind, subject: "Hi", message: "Help", email: "someone@else.com" }),
|
|
200
|
-
);
|
|
201
|
-
expect(mockLeadsSubmit).toHaveBeenCalledWith({
|
|
202
|
-
source: "web",
|
|
203
|
-
email: "ada@example.com",
|
|
204
|
-
payload: { kind: "support", subject: "Hi", message: "Help" },
|
|
205
|
-
});
|
|
206
|
-
},
|
|
207
|
-
);
|
|
208
|
-
});
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for /[locale]/account/inbox/thread — the member's one conversation
|
|
3
|
-
* with the workspace (#11152).
|
|
4
|
-
*
|
|
5
|
-
* Covers:
|
|
6
|
-
* 1. The page lists every message between the signed-in person and the
|
|
7
|
-
* workspace — the provider's messages (`member.messages`, start side)
|
|
8
|
-
* and the person's own sent requests and messages (`member.requests`,
|
|
9
|
-
* end side) — oldest first, under a RecordHeader titled Messages whose
|
|
10
|
-
* back link returns to the Inbox's Messages tab, with the composer at
|
|
11
|
-
* the foot of the conversation.
|
|
12
|
-
* 2. An empty thread reads the empty line; a failed read shows the error
|
|
13
|
-
* row with Retry above what did load (D12's posture); signed out is a
|
|
14
|
-
* not-found.
|
|
15
|
-
* 3. A message's own actions (a file's Download) render under its bubble.
|
|
16
|
-
* 4. Posting from the composer runs the existing member message write
|
|
17
|
-
* (`sendMessage` → `member.sendMessage`) with the body as typed and a
|
|
18
|
-
* subject cut from its first line; a success clears the field and
|
|
19
|
-
* refreshes the route, whose next render lists the sent message — no
|
|
20
|
-
* reload; a refusal shows its plain message and keeps the body.
|
|
21
|
-
* 5. `threadSubject` — the first non-blank line, whitespace collapsed,
|
|
22
|
-
* clipped to the subject's cap.
|
|
23
|
-
*/
|
|
24
|
-
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
|
25
|
-
|
|
26
|
-
jest.mock("next-intl/server", () => {
|
|
27
|
-
const msgs: unknown = require("../../../../../messages/en.json");
|
|
28
|
-
const dig = (obj: unknown, path: string): unknown =>
|
|
29
|
-
path.split(".").reduce<unknown>(
|
|
30
|
-
(acc, k) => (acc !== null && typeof acc === "object" ? (acc as Record<string, unknown>)[k] : undefined),
|
|
31
|
-
obj,
|
|
32
|
-
);
|
|
33
|
-
return {
|
|
34
|
-
__esModule: true,
|
|
35
|
-
getTranslations: async (arg: string | { namespace?: string; locale?: string }) => {
|
|
36
|
-
const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
|
|
37
|
-
const messages = dig(msgs, ns);
|
|
38
|
-
return (key: string, values?: Record<string, unknown>): string => {
|
|
39
|
-
const value = dig(messages, key);
|
|
40
|
-
if (typeof value !== "string") return `${ns}.${key}`;
|
|
41
|
-
return value.replace(/\{(\w+)\}/g, (m, name: string) =>
|
|
42
|
-
values && name in values ? String(values[name]) : m,
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
jest.mock("next/headers", () => ({
|
|
50
|
-
__esModule: true,
|
|
51
|
-
headers: jest.fn().mockResolvedValue(new Headers()),
|
|
52
|
-
cookies: jest.fn().mockResolvedValue({ toString: () => "session=abc" }),
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
const mockGetSession = jest.fn();
|
|
56
|
-
// eslint-disable-next-line no-restricted-syntax -- #507: mock-internal rewrite pending; auth.ts's lazy Better-Auth singleton has no HTTP/DB boundary a unit test of the session fields can mock without standing up Prisma.
|
|
57
|
-
jest.mock("../../../../../auth", () => ({
|
|
58
|
-
__esModule: true,
|
|
59
|
-
auth: { api: { getSession: (...args: unknown[]) => mockGetSession(...args) } },
|
|
60
|
-
}));
|
|
61
|
-
|
|
62
|
-
const mockMemberMessages = jest.fn();
|
|
63
|
-
const mockMemberRequests = jest.fn();
|
|
64
|
-
const mockMemberSendMessage = jest.fn();
|
|
65
|
-
jest.mock("@working-theory/api-client", () => ({
|
|
66
|
-
__esModule: true,
|
|
67
|
-
waitlistSignups: { me: jest.fn() },
|
|
68
|
-
subscription: { me: jest.fn() },
|
|
69
|
-
member: {
|
|
70
|
-
messages: (...args: unknown[]) => mockMemberMessages(...args),
|
|
71
|
-
requests: (...args: unknown[]) => mockMemberRequests(...args),
|
|
72
|
-
sendMessage: (...args: unknown[]) => mockMemberSendMessage(...args),
|
|
73
|
-
},
|
|
74
|
-
}));
|
|
75
|
-
|
|
76
|
-
const mockNotFound = jest.fn(() => {
|
|
77
|
-
throw new Error("NEXT_NOT_FOUND");
|
|
78
|
-
});
|
|
79
|
-
const mockRefresh = jest.fn();
|
|
80
|
-
jest.mock("next/navigation", () => ({
|
|
81
|
-
__esModule: true,
|
|
82
|
-
notFound: () => mockNotFound(),
|
|
83
|
-
useRouter: () => ({ push: jest.fn(), refresh: mockRefresh }),
|
|
84
|
-
usePathname: () => "/account/inbox/thread",
|
|
85
|
-
}));
|
|
86
|
-
|
|
87
|
-
import { MESSAGE_SUBJECT_MAX } from "@working-theory/validation";
|
|
88
|
-
|
|
89
|
-
import Page from "../inbox/thread/page";
|
|
90
|
-
import { threadSubject } from "../inbox/thread/thread-data";
|
|
91
|
-
|
|
92
|
-
const SESSION = {
|
|
93
|
-
user: { id: "user_1", name: "Ada", email: "ada@example.com", emailVerified: true },
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/** The cookie a single site forwards (`forwardedCookieInit()`). */
|
|
97
|
-
const INIT = { headers: { cookie: "session=abc" } };
|
|
98
|
-
|
|
99
|
-
const ok = <T,>(body: T) => ({ ok: true, body });
|
|
100
|
-
const refusal = (status: number, code: string) => ({
|
|
101
|
-
ok: false,
|
|
102
|
-
status,
|
|
103
|
-
body: { ok: false, error: { code, message: "x" } },
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
/** The provider's messages to the member, newest first as the read serves them. */
|
|
107
|
-
const MESSAGES = [
|
|
108
|
-
{
|
|
109
|
-
id: "int_file",
|
|
110
|
-
subject: "Your plan",
|
|
111
|
-
body: "The plan is attached.",
|
|
112
|
-
file: { filename: "plan.pdf", contentType: "application/pdf" },
|
|
113
|
-
action: null,
|
|
114
|
-
createdAt: "2026-10-12T09:00:00.000Z",
|
|
115
|
-
readAt: null,
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
id: "int_1",
|
|
119
|
-
subject: "Welcome",
|
|
120
|
-
body: "Thanks for reaching out.",
|
|
121
|
-
file: null,
|
|
122
|
-
action: null,
|
|
123
|
-
createdAt: "2026-10-10T09:00:00.000Z",
|
|
124
|
-
readAt: null,
|
|
125
|
-
},
|
|
126
|
-
];
|
|
127
|
-
|
|
128
|
-
/** The member's own sent rows, newest first as the read serves them. */
|
|
129
|
-
const REQUESTS = [
|
|
130
|
-
{
|
|
131
|
-
id: "intx_a",
|
|
132
|
-
kind: "message" as const,
|
|
133
|
-
subject: "Hello",
|
|
134
|
-
body: "Hi there",
|
|
135
|
-
createdAt: "2026-10-11T10:00:00.000Z",
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
id: "intx_q",
|
|
139
|
-
kind: "quote" as const,
|
|
140
|
-
subject: "Request quote",
|
|
141
|
-
body: "",
|
|
142
|
-
createdAt: "2026-10-09T10:00:00.000Z",
|
|
143
|
-
},
|
|
144
|
-
];
|
|
145
|
-
|
|
146
|
-
const RECEIPT = ok({ id: "intx_new", createdAt: "2026-10-13T10:00:00.000Z" });
|
|
147
|
-
|
|
148
|
-
beforeEach(() => {
|
|
149
|
-
mockGetSession.mockReset().mockResolvedValue(SESSION);
|
|
150
|
-
mockMemberMessages.mockReset().mockResolvedValue(ok({ items: MESSAGES }));
|
|
151
|
-
mockMemberRequests.mockReset().mockResolvedValue(ok({ items: REQUESTS }));
|
|
152
|
-
mockMemberSendMessage.mockReset().mockResolvedValue(RECEIPT);
|
|
153
|
-
mockNotFound.mockClear();
|
|
154
|
-
mockRefresh.mockReset();
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
async function renderThread(locale = "en"): Promise<ReturnType<typeof render>> {
|
|
158
|
-
const element = await Page({ params: Promise.resolve({ locale }) });
|
|
159
|
-
return render(element);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function entries(): HTMLElement[] {
|
|
163
|
-
return screen.getAllByTestId("account-thread-entry");
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
describe("the member thread page lists the whole conversation (AC-2)", () => {
|
|
167
|
-
it("renders both sides oldest first under a Messages header, the composer at the foot", async () => {
|
|
168
|
-
await renderThread();
|
|
169
|
-
const frame = screen.getByTestId("account-thread");
|
|
170
|
-
const header = within(frame).getByTestId("account-thread-header");
|
|
171
|
-
expect(within(header).getByRole("heading", { level: 1 })).toHaveTextContent("Messages");
|
|
172
|
-
const back = within(header).getByTestId("account-thread-back");
|
|
173
|
-
expect(back).toHaveAttribute("href", "/account?tab=messages");
|
|
174
|
-
expect(back).toHaveAccessibleName("Inbox");
|
|
175
|
-
|
|
176
|
-
expect(mockMemberMessages).toHaveBeenCalledWith(INIT);
|
|
177
|
-
expect(mockMemberRequests).toHaveBeenCalledWith(INIT);
|
|
178
|
-
|
|
179
|
-
// Oldest first: the quote request, Welcome, Hello, Your plan.
|
|
180
|
-
const rows = entries();
|
|
181
|
-
expect(rows.map((row) => row.getAttribute("data-kind"))).toEqual([
|
|
182
|
-
"request",
|
|
183
|
-
"message",
|
|
184
|
-
"request",
|
|
185
|
-
"message",
|
|
186
|
-
]);
|
|
187
|
-
expect(rows[0]).toHaveTextContent("Your quote request was sent.");
|
|
188
|
-
expect(rows[1]).toHaveTextContent("Thanks for reaching out.");
|
|
189
|
-
expect(rows[2]).toHaveTextContent("Hi there");
|
|
190
|
-
expect(rows[3]).toHaveTextContent("The plan is attached.");
|
|
191
|
-
// The provider's messages sit on the start side, the member's own on the end.
|
|
192
|
-
expect(within(rows[1]!).getByTestId("account-item-message")).toHaveAttribute("data-side", "start");
|
|
193
|
-
expect(within(rows[2]!).getByTestId("account-item-request")).toHaveAttribute("data-side", "end");
|
|
194
|
-
|
|
195
|
-
// The composer is pinned after the conversation.
|
|
196
|
-
const conversation = within(frame).getByTestId("account-thread-conversation");
|
|
197
|
-
const composer = within(frame).getByTestId("account-thread-composer");
|
|
198
|
-
expect(
|
|
199
|
-
conversation.compareDocumentPosition(composer) & Node.DOCUMENT_POSITION_FOLLOWING,
|
|
200
|
-
).toBeTruthy();
|
|
201
|
-
expect(within(composer).getByRole("form", { name: "Send a message" })).toBeInTheDocument();
|
|
202
|
-
expect(screen.queryByTestId("account-thread-empty")).not.toBeInTheDocument();
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("a message's own actions render under its bubble — the file's Download", async () => {
|
|
206
|
-
await renderThread();
|
|
207
|
-
const row = entries()[3]!;
|
|
208
|
-
const download = within(row).getByRole("link", { name: "Download plan.pdf" });
|
|
209
|
-
expect(download).toHaveAttribute("href", "/account/inbox/message/int_file/file");
|
|
210
|
-
// The provider's plain message carries none.
|
|
211
|
-
expect(within(entries()[1]!).queryByRole("link")).not.toBeInTheDocument();
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("a non-default locale's back link returns to that locale's Inbox", async () => {
|
|
215
|
-
await renderThread("fr");
|
|
216
|
-
expect(screen.getByTestId("account-thread-back")).toHaveAttribute("href", "/fr/account?tab=messages");
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("an empty thread reads the empty line and still offers the composer", async () => {
|
|
220
|
-
mockMemberMessages.mockResolvedValue(ok({ items: [] }));
|
|
221
|
-
mockMemberRequests.mockResolvedValue(ok({ items: [] }));
|
|
222
|
-
await renderThread();
|
|
223
|
-
expect(screen.getByTestId("account-thread-empty")).toHaveTextContent("No messages yet.");
|
|
224
|
-
expect(screen.queryAllByTestId("account-thread-entry")).toEqual([]);
|
|
225
|
-
expect(screen.getByTestId("thread-composer")).toBeInTheDocument();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("a 404 from a read is nothing for this caller, not an error", async () => {
|
|
229
|
-
mockMemberRequests.mockResolvedValue({ ok: false, status: 404, body: {} });
|
|
230
|
-
await renderThread();
|
|
231
|
-
expect(screen.queryByTestId("inbox-error")).not.toBeInTheDocument();
|
|
232
|
-
expect(entries().map((row) => row.getAttribute("data-kind"))).toEqual(["message", "message"]);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("a failed read shows the error row with Retry above what did load (D12)", async () => {
|
|
236
|
-
mockMemberMessages.mockResolvedValue({ ok: false, status: 500, body: {} });
|
|
237
|
-
await renderThread();
|
|
238
|
-
expect(mockNotFound).not.toHaveBeenCalled();
|
|
239
|
-
const error = screen.getByTestId("inbox-error");
|
|
240
|
-
expect(error).toHaveTextContent("We couldn't load this conversation.");
|
|
241
|
-
expect(entries().map((row) => row.getAttribute("data-kind"))).toEqual(["request", "request"]);
|
|
242
|
-
expect(screen.queryByTestId("account-thread-empty")).not.toBeInTheDocument();
|
|
243
|
-
fireEvent.click(screen.getByTestId("inbox-retry"));
|
|
244
|
-
expect(mockRefresh).toHaveBeenCalledTimes(1);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it("signed out is a not-found and reads nothing", async () => {
|
|
248
|
-
mockGetSession.mockResolvedValue(null);
|
|
249
|
-
await expect(renderThread()).rejects.toThrow("NEXT_NOT_FOUND");
|
|
250
|
-
expect(mockMemberMessages).not.toHaveBeenCalled();
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
describe("posting from the composer uses the existing member message write (AC-3)", () => {
|
|
255
|
-
function type(value: string): HTMLTextAreaElement {
|
|
256
|
-
const field = screen.getByLabelText("Message") as HTMLTextAreaElement;
|
|
257
|
-
fireEvent.change(field, { target: { value } });
|
|
258
|
-
return field;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
it("posts the body as typed with its first line as the subject, clears the field and refreshes the route", async () => {
|
|
262
|
-
await renderThread();
|
|
263
|
-
const field = type("Can we move the call?\nThursday works.");
|
|
264
|
-
fireEvent.click(screen.getByTestId("thread-composer-send"));
|
|
265
|
-
await waitFor(() => expect(mockMemberSendMessage).toHaveBeenCalledTimes(1));
|
|
266
|
-
expect(mockMemberSendMessage).toHaveBeenCalledWith(
|
|
267
|
-
{ subject: "Can we move the call?", body: "Can we move the call?\nThursday works." },
|
|
268
|
-
INIT,
|
|
269
|
-
);
|
|
270
|
-
await waitFor(() => expect(field).toHaveValue(""));
|
|
271
|
-
expect(screen.getByTestId("thread-composer-notice")).toHaveTextContent("Sent.");
|
|
272
|
-
expect(mockRefresh).toHaveBeenCalledTimes(1);
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("the refreshed render lists the sent message as the member's own newest bubble — no reload", async () => {
|
|
276
|
-
const { unmount } = await renderThread();
|
|
277
|
-
type("Can we move the call?");
|
|
278
|
-
fireEvent.click(screen.getByTestId("thread-composer-send"));
|
|
279
|
-
await waitFor(() => expect(mockRefresh).toHaveBeenCalledTimes(1));
|
|
280
|
-
unmount();
|
|
281
|
-
// `router.refresh()` re-renders the route's Server Components: the
|
|
282
|
-
// requests read now serves the row the write created.
|
|
283
|
-
mockMemberRequests.mockResolvedValue(
|
|
284
|
-
ok({
|
|
285
|
-
items: [
|
|
286
|
-
{
|
|
287
|
-
id: "intx_new",
|
|
288
|
-
kind: "message" as const,
|
|
289
|
-
subject: "Can we move the call?",
|
|
290
|
-
body: "Can we move the call?",
|
|
291
|
-
createdAt: "2026-10-13T10:00:00.000Z",
|
|
292
|
-
},
|
|
293
|
-
...REQUESTS,
|
|
294
|
-
],
|
|
295
|
-
}),
|
|
296
|
-
);
|
|
297
|
-
await renderThread();
|
|
298
|
-
const rows = entries();
|
|
299
|
-
const last = rows[rows.length - 1]!;
|
|
300
|
-
expect(last).toHaveAttribute("data-kind", "request");
|
|
301
|
-
expect(last).toHaveTextContent("Can we move the call?");
|
|
302
|
-
expect(within(last).getByTestId("account-item-request")).toHaveAttribute("data-side", "end");
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it("a refusal shows its plain message, keeps the body and refreshes nothing", async () => {
|
|
306
|
-
mockMemberSendMessage.mockResolvedValue(refusal(429, "too_many_requests"));
|
|
307
|
-
await renderThread();
|
|
308
|
-
const field = type("Hello again");
|
|
309
|
-
fireEvent.click(screen.getByTestId("thread-composer-send"));
|
|
310
|
-
const notice = await screen.findByTestId("thread-composer-notice");
|
|
311
|
-
expect(notice).toHaveTextContent("Too many requests. Try again later.");
|
|
312
|
-
expect(field).toHaveValue("Hello again");
|
|
313
|
-
expect(mockRefresh).not.toHaveBeenCalled();
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
it("an unlisted refusal code reads the generic line", async () => {
|
|
317
|
-
mockMemberSendMessage.mockResolvedValue(refusal(503, "tenant_unresolved"));
|
|
318
|
-
await renderThread();
|
|
319
|
-
type("Hello again");
|
|
320
|
-
fireEvent.click(screen.getByTestId("thread-composer-send"));
|
|
321
|
-
expect(await screen.findByText("This could not be sent. Try again.")).toBeInTheDocument();
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
describe("threadSubject — the subject cut from the body", () => {
|
|
326
|
-
it("is the first non-blank line, its whitespace collapsed", () => {
|
|
327
|
-
expect(threadSubject(" \n Can we move the call? \nThursday works.")).toBe(
|
|
328
|
-
"Can we move the call?",
|
|
329
|
-
);
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it("is clipped to the subject's cap", () => {
|
|
333
|
-
const long = "x".repeat(MESSAGE_SUBJECT_MAX + 20);
|
|
334
|
-
expect(threadSubject(long)).toHaveLength(MESSAGE_SUBJECT_MAX);
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it("is empty for a blank body — the server's own rule refuses it", () => {
|
|
338
|
-
expect(threadSubject(" \n ")).toBe("");
|
|
339
|
-
});
|
|
340
|
-
});
|