Skip to content

Commit 8896822

Browse files
feat(app-shell): connect your Slack account on the notification settings page, and an admin Slack page in Setup (Part of #34730) (#35968)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D62xGLMbyWJaMEVnAMEjTK1)_ Part of #34730 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在接入了 Slack 连接器的部署上,成员在通知设置页可以关联或解除自己的 Slack 账号(先看到提议、再确认);组织管理员多了一个 Slack 管理页,可以接入或更换本组织的 Slack 令牌、移除接入、查看和移除成员的关联。没有接入 Slack 的部署界面不变。 - 为什么做:这是「Slack 私信通知」专题的第三步(界面部分),让成员和管理员不用调接口就能完成上一步服务端已提供的关联与接入。 - 出错会怎样:最坏是某人关联不上或管理页显示的提示不准,站内信和邮件不受影响;整个改动只在界面层,可以直接撤回。 - 要你做什么:无。管理页在设置菜单里还没有入口(入口由服务端提供),需要一张服务端小卡补上,已在下方注明供席位立卡。 ## What changes Step 3 of #34730 (ADR-0013 addendum of 2026-11-19): the console side of the Slack link doors that step 2 (#35789) put on `main`. UI and docs only; no server, spec or skills change. This PR was written in session `session_016WV4czKnDE6hsyXQzB9wB2`. - **The doors, one client module** (`console/notification-settings/slackDoors.ts`). All nine Slack link routes are called through the host's authenticated fetch (`SchemaRendererContext.apiFetch`), the way the notification settings page already reads its own door; `@objectstack/client` has no method for these routes (measured: no `slack-link`, `slack/account` or `slack/links` in `packages/client` on the base). Each answer is read as served and refused when it is not the door's shape. A refusal is the server's own sentence: `error.userMessage` when the door sends one (only `slackLinkProposalOutdated` today, already in the caller's language), else `error.message`. - **Notification Settings: the person's Slack section** (`SlackLinkSection.tsx`). Drawn only while the preference door lists the `slack` channel, which it does only where connector-slack is composed. States, each as the `GET /me/slack-link` door answers it: - no install (`account: null`): says so, offers nothing; - install `revoked`: says Slack refused the organization's token, offers no connect; - no link: **Connect Slack** calls `POST …/proposal`; - a proposal (`{ state: 'proposed' }`): says a Slack user with the person's verified email was found, never whom, with **Confirm** (`POST …/confirm`) and **Cancel** (`DELETE /me/slack-link`, which removes the proposal row); - a confirmed link: the Slack user it names, when, and **Disconnect**. - `link: null` from a proposal: the door answers this alike for no verified email, no Slack user with that email, and that Slack user already linked to someone else (step 2's own doc says so), so the page names all three conditions in one sentence and never picks one. - After every action, refused or not, the section reads the door again, so a 409 for a missing install, a 502 that marked the token revoked, or a 404 for a replaced proposal is followed by the state as stored. After a refused confirm, **Ask for a new proposal** is offered. - **Setup's Slack page** (`views/setup/SlackSetupPage.tsx`, component ref `messaging:slack`, so `/apps/setup/component/messaging/slack`). Gated by `setup.write` through `usePermissions().hasCapabilities`, the capability every administrator door asks (`SLACK_ADMIN_CAPABILITY`); without it the page says what is needed and reads no door. It installs or sets again the token (`PUT /slack/account` with `{ token }`) through a password input that starts empty, is emptied as soon as the value is sent, and is never filled from anything (no door answers the token). **Remove Slack** asks first, saying every linked person is told by in-app message and email, then `DELETE /slack/account`. The link list shows each link as served: the person's id, the Slack user only once confirmed (a proposal reads "Proposed, not confirmed yet"), and when it was confirmed; **Remove** per link asks first, then `DELETE /slack/links/:id`. The list is read once, unpaged; when it holds the 10,000 links the store reads at most (`limit: 10000` in `SlackLinkStore.links`), the page says the list may be incomplete. Paging is #35861 (server); this page does not page on its own. - **i18n**: two new sections, `slackLink` and `slackSetup`, in all eleven built-in packs; `zh-Hant.ts` is regenerated by `pnpm --filter @object-ui/i18n gen:zh-hant` from `zh-Hans`, not hand-written. - **Docs**: `content/docs/permissions/administrator-guide.mdx` gains "Deliver notifications by Slack direct message" (no existing page taught Slack DM setup). - Phone width: both surfaces stack their controls (`flex-col` under `sm`), and the link table scrolls inside its card. ## Evals Final head `ddbc916340` (the branch merged with `origin/main` at `73e4b966f6`; the incoming commits touch none of this PR's files). <details><summary>Tests on ddbc916: notification settings, Setup views and the i18n package, 121 files / 2143 tests passed; ui scripts 172 files / 5111 passed</summary> - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/app-shell/src/console/notification-settings/ packages/app-shell/src/views/setup/ packages/i18n/` under the verify lock: `Test Files 121 passed (121)`, `Tests 2143 passed | 13 skipped (2156)`, `VERDICT command-exit 0`. - `pnpm --dir ui exec vitest run scripts/` (derived): `Test Files 172 passed | 2 skipped (174)`, `Tests 5111 passed | 2 skipped (5113)`, `VERDICT command-exit 0`. - New pins: `SlackLinkSection.test.tsx` (connect, proposal, confirm, linked; cancel; disconnect; no install; revoked; `link: null`; stale proposal via `userMessage`; replaced proposal 404; token refused 502 then revoked; no install at click 409; failed read), `SlackSetupPage.test.tsx` (hidden without `setup.write` and no door read; install; update never pre-fills and shows a refusal; remove install with confirm; list and remove a link with confirm; the cap text at the cap and not below; the ref resolves; key and placeholder parity of both sections in every pack), and in `NotificationSettingsPage.test.tsx` the gate (section and door read with `slack` listed; neither without). - Red first: the gate pin ran red before the section existed, at `3494958712`: `Tests 1 failed | 16 passed (17)`. - An earlier run of the same set on the pre-merge head failed three i18n package pins on my locale additions (the `Loading…` group grew by one; `Slack` served verbatim as a title in non-Latin packs; `zh-Hant.ts` hand-written instead of generated). Fixed at `ddbc916340` by a distinct setup loading line, translated titles, and the generator. </details> <details><summary>Ablation of the `slack`-listed gate: red as intended, restored to HEAD</summary> `node scripts/ablation-replace.mjs` on `NotificationSettingsPage.tsx`, anchor `apiFetch && prefs.channels.some((c) => c.channel === SLACK_CHANNEL) && ` replaced by `apiFetch && /* ABLATION-slack-gate-removed */ `: anchor 1 to 0, blob `3cd1154f0563` to `a7bdd0eba035`; the page test ran `Tests 1 failed | 16 passed (17)`, the failure being "without slack listed, no section and no Slack door is called"; restored, blob equals HEAD and `git diff HEAD` empty. A first attempt used a replacement that was a substring of the anchor; the tool refused it as a mutation that did not land (replacement count 1 to 1) and restored, so it measured nothing. </details> <details><summary>Type-check, lint and gates</summary> - `pnpm --filter @object-ui/app-shell --filter @object-ui/i18n run type-check` on `ddbc916340`: `VERDICT command-exit 0` (both `tsconfig.json` and `tsconfig.test.json`; the test files are in the program, since an earlier run reported errors in them, now fixed). - `eslint` on the changed app-shell files: exit 0, no warning in the new files. - ui: `check:i18n-keys`, `check:i18n-drift`, `check:i18n-dead-keys`, `check:new-line-citations`: exit 0 each. - `node scripts/pm/dispatch-gates.mjs --commands` derived 74 commands, re-derived identical on `ddbc916340`; the gate results are in the report. `check:skill-examples` (after building `@objectstack/client-react`) and `check:type-check-debt` (under the lock) exit 0. - `node scripts/pm/overlap-check.mjs --branch=claude/area-a4W-34730-s3`: `VERDICT clean exit 0` (five open PRs share the locale packs; each merges cleanly). - Not run locally, CI's: the whole app-shell suite (2,463 test files; a local two-worker run was stopped after 21 minutes, so it is NOT MEASURED here and Test UI's 16 shards carry it), Lint UI, Type Check UI, Build & E2E UI. </details> ## Verification Two minutes, on a dev stack with connector-slack composed: open **Notification Settings** as a member; under the matrix a "Slack direct messages" card shows. With no install it says an administrator installs Slack first. As an organization administrator open `/apps/setup/component/messaging/slack`, paste a bot token and choose **Install**: the workspace and "Active" show and the field is empty again. Back as the member, **Connect Slack** shows the proposal without a name; **Confirm** shows the Slack user. Files to read first, by risk: `SlackSetupPage.tsx` (the token input and the two confirm dialogs), `slackDoors.ts` (what is read from each answer and which sentence a refusal shows), `SlackLinkSection.tsx` (the state after each action is re-read, never inferred). ## Acceptance notes - **No Setup navigation entry yet.** Setup's entries are contributed by the server package that owns the door (the pattern `CONNECTOR_CREDENTIALS_UI_BUNDLE` in service-automation follows; the shell declares none), so the entry that opens this page belongs in service-messaging: Setup, group `group_integrations`, `componentRef: 'messaging:slack'`, `requiredPermissions: ['setup.write']`, contributed only where the `slack` channel registers. That is a server change, outside this PR's surface; it is named for the seat to file. Until it lands the page is reached by its address, which the docs section names. - **Link list paging** is #35861; this page reads the list as served and says so at the cap. - **Person column** shows the user id the door serves; no name is resolved, as ordered. - The step-2 changeset sentence owed on `messaging.slack_link_removed` (listed as a topic on every deployment) belongs in `@objectstack/service-messaging`'s changeset, outside this PR's surface; it is not carried here. - `ui/AGENTS.md` #2 asks for a package README update for features; `@object-ui/app-shell`'s README documents no individual page, so none was added. - Soft size: 1,718 net added lines (561 of them the eleven locale packs), about 1.9 times the order's 900, under the 2,700 hard stop. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 01e6af6 commit 8896822

21 files changed

Lines changed: 1721 additions & 3 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
Clause-②: no
7+
Metadata-protocol: none
8+
9+
feat(app-shell): connect your Slack account on the notification settings page, and an admin Slack page in Setup
10+
11+
The console side of Slack direct-message delivery (step 3 of the Slack DM work; the server doors shipped with `@objectstack/service-messaging`'s Slack link routes).
12+
13+
- **Notification Settings: your Slack link.** Where the preference door lists the `slack` channel (only on a deployment that composes connector-slack), the page shows a Slack section. Without an install, or with an install whose token Slack refused, it says so and offers nothing. Otherwise **Connect Slack** asks `POST /api/v1/messaging/me/slack-link/proposal`; the page shows what the door answers: that a Slack user with your verified email was found (never whom), with **Confirm** (`…/confirm`) and **Cancel** (`DELETE /api/v1/messaging/me/slack-link`); or, when nothing was proposed, a sentence naming every reason the door does not tell apart (no verified email, no Slack user with it, or that Slack user linked to someone else). A confirmed link shows the Slack user and **Disconnect**. A refusal is shown in the server's own words (its `userMessage` when it carries one), and the section then reads the door again.
14+
- **Setup's Slack page** (component `messaging:slack`, `/apps/setup/component/messaging/slack`): for an organization administrator holding `setup.write`, the capability the doors ask; anyone else sees what is needed and no door is read. It installs or sets again the organization's bot token (`PUT /api/v1/messaging/slack/account`) through a password input that always starts empty, removes the install after a confirm that says every linked person is told, and lists every link as served (person, Slack user once confirmed, when) with a confirmed **Remove** per link. When the list reaches the 10,000 links the server answers, the page says it may be incomplete.
15+
- Every new sentence is in all eleven built-in locales (`slackLink`, `slackSetup`).

‎content/docs/permissions/administrator-guide.mdx‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,32 @@ rules. A flow that should message the whole organization uses the `notify`
250250
step's `org:members` recipient instead
251251
([Flows](/docs/automation/flows)).
252252

253+
## Deliver notifications by Slack direct message
254+
255+
On a deployment that composes the Slack connector (`ConnectorSlackPlugin`),
256+
notifications can also reach people as Slack direct messages, from your
257+
organization's own Slack app. Without the connector none of this appears:
258+
the notification settings page lists no Slack channel.
259+
260+
1. **Install Slack (an administrator).** Open Setup's Slack page,
261+
`/apps/setup/component/messaging/slack`; it needs `setup.write` in your
262+
current organization, as the server does. Paste your Slack app's bot
263+
token (it starts with `xoxb-`) and choose **Install**. Slack checks the
264+
token before anything is saved; it is stored encrypted and never shown
265+
again, so the field is always empty. **Save token** sets it again, for
266+
instance after Slack refused it (the page then says **Token refused**).
267+
2. **Connect (each person).** On **Notification Settings**, the Slack
268+
section's **Connect Slack** asks for a proposal: a Slack user of your
269+
workspace with the person's verified email, not linked to anyone else.
270+
The proposal names no one until the person chooses **Confirm**; **Cancel**
271+
drops it. Nothing reaches them on Slack before they confirm.
272+
**Disconnect** removes the link.
273+
3. **Manage links (an administrator).** The same Slack page lists every
274+
link (the person, the Slack user once confirmed, and when) and removes
275+
one; the person is told by in-app message and email and can connect again.
276+
**Remove Slack** removes the install and every link, and tells each linked
277+
person the same way.
278+
253279
## Quick paths
254280

255281
| I need to… | Do this |

‎ui/packages/app-shell/src/console/notification-settings/NotificationSettingsPage.test.tsx‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { MePermissionsProvider, type MePermissionsAuthenticatedResponse } from '
3030
import { builtInLocales } from '@object-ui/i18n/locales';
3131
import { NotificationSettingsPage } from './NotificationSettingsPage';
3232
import { MY_PREFERENCES_URL } from './myPreferences';
33+
import { SLACK_LINK_URL } from './slackDoors';
3334
import { getAppComponent } from '../../services/componentRegistry';
3435
// The registry check below loads every built-in page, which reaches the
3536
// metadata admin's dynamic `@objectstack/lint` import: pay that load at
@@ -66,10 +67,22 @@ function answer(taskEnabled: boolean, taskRow?: string, general: General = BUILT
6667
};
6768
}
6869

69-
function host(apiFetch: ReturnType<typeof vi.fn>, adapter: { create: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> }) {
70+
const NO_SLACK_INSTALL = { data: { account: null, link: null } };
71+
72+
/**
73+
* The Slack link door (`/me/slack-link`) answers through `slackFetch`, so
74+
* `apiFetch` counts only the preference reads these tests are about.
75+
*/
76+
function host(
77+
apiFetch: ReturnType<typeof vi.fn>,
78+
adapter: { create: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> },
79+
slackFetch: (url: string, init?: RequestInit) => Promise<Response> = async () => json(NO_SLACK_INSTALL),
80+
) {
81+
const prefsFetch = apiFetch as unknown as (url: string, init?: RequestInit) => Promise<Response>;
82+
const routed = (url: string, init?: RequestInit) => (url.startsWith(SLACK_LINK_URL) ? slackFetch(url, init) : prefsFetch(url, init));
7083
return ({ children }: { children: ReactNode }) => (
7184
<AdapterCtx.Provider value={adapter as never}>
72-
<SchemaRendererProvider dataSource={adapter as never} apiFetch={apiFetch as never}>
85+
<SchemaRendererProvider dataSource={adapter as never} apiFetch={routed as never}>
7386
{children}
7487
</SchemaRendererProvider>
7588
</AdapterCtx.Provider>
@@ -366,3 +379,29 @@ describe('the caller\'s grant on sys_notification_preference decides whether the
366379
);
367380
});
368381
});
382+
383+
describe('the Slack section is drawn only where the preference door lists slack', () => {
384+
const withoutSlack = () => {
385+
const body = answer(false);
386+
body.data.channels = body.data.channels.filter((c) => c.channel !== 'slack');
387+
body.data.topics = body.data.topics.map((t) => ({ ...t, channels: t.channels.filter((c) => c.channel !== 'slack') }));
388+
return body;
389+
};
390+
391+
it('with slack listed, the section reads the person’s link', async () => {
392+
const slackFetch = vi.fn(async () => json(NO_SLACK_INSTALL));
393+
render(<NotificationSettingsPage />, { wrapper: host(vi.fn(async () => json(answer(false))), { create: vi.fn(), update: vi.fn() }, slackFetch) });
394+
395+
expect(await screen.findByTestId('slack-link-section')).toBeInTheDocument();
396+
await waitFor(() => expect(slackFetch).toHaveBeenCalledWith(SLACK_LINK_URL, expect.objectContaining({ method: 'GET' })));
397+
});
398+
399+
it('without slack listed, no section and no Slack door is called', async () => {
400+
const slackFetch = vi.fn(async () => json(NO_SLACK_INSTALL));
401+
render(<NotificationSettingsPage />, { wrapper: host(vi.fn(async () => json(withoutSlack())), { create: vi.fn(), update: vi.fn() }, slackFetch) });
402+
403+
await screen.findByTestId('notification-settings-matrix');
404+
expect(screen.queryByTestId('slack-link-section')).toBeNull();
405+
expect(slackFetch).not.toHaveBeenCalled();
406+
});
407+
});

‎ui/packages/app-shell/src/console/notification-settings/NotificationSettingsPage.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
*
2222
* Channels are columns as the door lists them, so a channel the deployment
2323
* adds later (Slack, …) appears without a change here; a channel the
24-
* deployment cannot send on yet says so in its header.
24+
* deployment cannot send on yet says so in its header. Where the door lists
25+
* `slack` (connector-slack is composed), the page also draws the person's own
26+
* Slack link (`SlackLinkSection`): Slack delivers only to a confirmed link.
2527
*
2628
* A caller who holds neither a create nor an edit grant on
2729
* `sys_notification_preference` (an external member: `external_default`
@@ -75,6 +77,7 @@ import {
7577
type PreferenceWrite,
7678
type QuietHoursWindow,
7779
} from './myPreferences.js';
80+
import { SlackLinkSection } from './SlackLinkSection.js';
7881

7982
type Load = { readonly state: 'loading' } | { readonly state: 'failed' } | { readonly state: 'read'; readonly prefs: MyPreferences };
8083

@@ -94,6 +97,9 @@ const SOURCE_KEY: Record<PreferenceSource, string> = {
9497
mandatory: 'notificationSettings.sourceMandatory',
9598
};
9699

100+
/** The channel the Slack section belongs to, as the preference door lists it. */
101+
const SLACK_CHANNEL = 'slack';
102+
97103
function errorText(err: unknown): string {
98104
return err instanceof Error && err.message ? err.message : String(err);
99105
}
@@ -336,6 +342,8 @@ export function NotificationSettingsPage() {
336342
</div>
337343
</CardContent>
338344
</Card>
345+
346+
{apiFetch && prefs.channels.some((c) => c.channel === SLACK_CHANNEL) && <SlackLinkSection apiFetch={apiFetch} />}
339347
</div>
340348
</div>
341349
);
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The person's Slack section (#34730 step 3): connect → proposal → confirm →
5+
* linked, cancel, disconnect, and each answer of the Slack link doors drawn as
6+
* the door gave it. The doors are faked by URL and method with the envelopes
7+
* `slack-link-routes.ts` writes; `t` echoes the KEY.
8+
*/
9+
10+
import '@testing-library/jest-dom/vitest';
11+
import { afterEach, describe, expect, it, vi } from 'vitest';
12+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
13+
14+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
15+
...(await importOriginal<Record<string, unknown>>()),
16+
useObjectTranslation: () => ({ t: (key: string) => `«${key}»`, language: 'en' }),
17+
}));
18+
19+
import { SlackLinkSection } from './SlackLinkSection';
20+
import { SLACK_LINK_URL } from './slackDoors';
21+
22+
const ACME = { id: 'acc1', workspace: 'Acme', workspaceId: 'T1', status: 'active' };
23+
const LINKED = { id: 'l1', userId: 'alice', slackUserId: 'UADA', slackUserName: 'Ada', state: 'confirmed', confirmedAt: '2026-11-20T10:00:00.000Z' };
24+
const ok = (data: unknown) => new Response(JSON.stringify({ success: true, data }), { status: 200 });
25+
const refused = (status: number, code: string, message: string, userMessage?: string) =>
26+
new Response(JSON.stringify({ success: false, error: { code, message, ...(userMessage ? { userMessage } : {}) } }), { status });
27+
28+
type Route = (state: { account: unknown; link: unknown }) => Response;
29+
30+
/** A fake of the four person doors over one stored state; `routes` overrides a door by `METHOD path`. */
31+
function doors(initial: { account: unknown; link: unknown }, routes: Record<string, Route> = {}) {
32+
const state = { ...initial };
33+
const fetch = vi.fn(async (url: string, init?: RequestInit) => {
34+
const key = `${init?.method ?? 'GET'} ${url}`;
35+
if (routes[key]) return routes[key](state);
36+
switch (key) {
37+
case `GET ${SLACK_LINK_URL}`:
38+
return ok(state);
39+
case `POST ${SLACK_LINK_URL}/proposal`:
40+
state.link = { state: 'proposed' };
41+
return ok({ link: state.link });
42+
case `POST ${SLACK_LINK_URL}/confirm`:
43+
state.link = LINKED;
44+
return ok({ link: LINKED });
45+
case `DELETE ${SLACK_LINK_URL}`: {
46+
const removed = state.link !== null;
47+
state.link = null;
48+
return ok({ removed });
49+
}
50+
}
51+
return refused(404, 'NOT_FOUND', key);
52+
});
53+
return { fetch, state };
54+
}
55+
56+
const calls = (f: ReturnType<typeof vi.fn>) => f.mock.calls.map(([url, init]) => `${(init as RequestInit | undefined)?.method ?? 'GET'} ${url}`);
57+
58+
afterEach(() => {
59+
cleanup();
60+
vi.restoreAllMocks();
61+
});
62+
63+
describe('SlackLinkSection', () => {
64+
it('connect → the proposal names no one → confirm → linked', async () => {
65+
const { fetch } = doors({ account: ACME, link: null });
66+
render(<SlackLinkSection apiFetch={fetch} />);
67+
68+
fireEvent.click(await screen.findByTestId('slack-link-connect'));
69+
const proposal = await screen.findByTestId('slack-link-proposal');
70+
expect(proposal).toHaveTextContent('«slackLink.proposed»');
71+
expect(proposal).not.toHaveTextContent('Ada');
72+
73+
fireEvent.click(screen.getByTestId('slack-link-confirm'));
74+
expect(await screen.findByTestId('slack-link-linked')).toHaveTextContent('«slackLink.linked»');
75+
expect(calls(fetch)).toEqual([
76+
`GET ${SLACK_LINK_URL}`,
77+
`POST ${SLACK_LINK_URL}/proposal`,
78+
`GET ${SLACK_LINK_URL}`,
79+
`POST ${SLACK_LINK_URL}/confirm`,
80+
`GET ${SLACK_LINK_URL}`,
81+
]);
82+
});
83+
84+
it('cancel removes the proposal', async () => {
85+
const { fetch, state } = doors({ account: ACME, link: { state: 'proposed' } });
86+
render(<SlackLinkSection apiFetch={fetch} />);
87+
88+
fireEvent.click(await screen.findByTestId('slack-link-cancel'));
89+
expect(await screen.findByTestId('slack-link-connect')).toBeInTheDocument();
90+
expect(state.link).toBeNull();
91+
expect(calls(fetch)).toContain(`DELETE ${SLACK_LINK_URL}`);
92+
});
93+
94+
it('disconnect removes the link', async () => {
95+
const { fetch, state } = doors({ account: ACME, link: LINKED });
96+
render(<SlackLinkSection apiFetch={fetch} />);
97+
98+
fireEvent.click(await screen.findByTestId('slack-link-disconnect'));
99+
expect(await screen.findByTestId('slack-link-connect')).toBeInTheDocument();
100+
expect(state.link).toBeNull();
101+
});
102+
103+
it('no install: says so and offers nothing', async () => {
104+
const { fetch } = doors({ account: null, link: null });
105+
render(<SlackLinkSection apiFetch={fetch} />);
106+
107+
expect(await screen.findByTestId('slack-link-not-installed')).toHaveTextContent('«slackLink.notInstalled»');
108+
expect(screen.queryByTestId('slack-link-connect')).toBeNull();
109+
});
110+
111+
it('a revoked token: says so and offers no connect', async () => {
112+
const { fetch } = doors({ account: { ...ACME, status: 'revoked' }, link: null });
113+
render(<SlackLinkSection apiFetch={fetch} />);
114+
115+
expect(await screen.findByTestId('slack-link-revoked')).toHaveTextContent('«slackLink.revoked»');
116+
expect(screen.queryByTestId('slack-link-connect')).toBeNull();
117+
});
118+
119+
it('a proposal answering link: null (no verified email, or no Slack user for it) names every cause, never one', async () => {
120+
const { fetch } = doors({ account: ACME, link: null }, { [`POST ${SLACK_LINK_URL}/proposal`]: () => ok({ link: null }) });
121+
render(<SlackLinkSection apiFetch={fetch} />);
122+
123+
fireEvent.click(await screen.findByTestId('slack-link-connect'));
124+
expect(await screen.findByTestId('slack-link-no-match')).toHaveTextContent('«slackLink.noMatch»');
125+
expect(screen.getByTestId('slack-link-connect')).toBeInTheDocument();
126+
});
127+
128+
it('a stale proposal: the server’s own sentence (its userMessage), and a new proposal can be asked for', async () => {
129+
const stale = 'Your email is no longer verified, or is not the email this Slack link was proposed for: ask for a new proposal. Nothing was changed.';
130+
const { fetch } = doors({ account: ACME, link: { state: 'proposed' } }, {
131+
[`POST ${SLACK_LINK_URL}/confirm`]: () => refused(409, 'RESOURCE_CONFLICT', 'english', stale),
132+
});
133+
render(<SlackLinkSection apiFetch={fetch} />);
134+
135+
fireEvent.click(await screen.findByTestId('slack-link-confirm'));
136+
expect(await screen.findByTestId('slack-link-refused')).toHaveTextContent(stale);
137+
fireEvent.click(await screen.findByTestId('slack-link-propose-again'));
138+
await waitFor(() => expect(calls(fetch)).toContain(`POST ${SLACK_LINK_URL}/proposal`));
139+
});
140+
141+
it('a replaced or removed proposal: the server’s 404 sentence, and the section reads the door again', async () => {
142+
const gone = 'You have no proposed Slack link in this organization to confirm: ask for a proposal first. Nothing was changed.';
143+
const { fetch } = doors({ account: ACME, link: { state: 'proposed' } }, {
144+
[`POST ${SLACK_LINK_URL}/confirm`]: (s) => {
145+
s.link = null;
146+
return refused(404, 'RESOURCE_NOT_FOUND', gone);
147+
},
148+
});
149+
render(<SlackLinkSection apiFetch={fetch} />);
150+
151+
fireEvent.click(await screen.findByTestId('slack-link-confirm'));
152+
expect(await screen.findByTestId('slack-link-refused')).toHaveTextContent(gone);
153+
expect(await screen.findByTestId('slack-link-connect')).toBeInTheDocument();
154+
});
155+
156+
it('Slack refusing the token mid-proposal: the server’s 502 sentence, then the revoked install as re-read', async () => {
157+
const { fetch } = doors({ account: ACME, link: null }, {
158+
[`POST ${SLACK_LINK_URL}/proposal`]: (s) => {
159+
s.account = { ...ACME, status: 'revoked' };
160+
return refused(502, 'EXTERNAL_SERVICE_ERROR', 'Slack answered token_revoked. Nothing was changed.');
161+
},
162+
});
163+
render(<SlackLinkSection apiFetch={fetch} />);
164+
165+
fireEvent.click(await screen.findByTestId('slack-link-connect'));
166+
expect(await screen.findByTestId('slack-link-refused')).toHaveTextContent('Slack answered token_revoked. Nothing was changed.');
167+
expect(await screen.findByTestId('slack-link-revoked')).toBeInTheDocument();
168+
});
169+
170+
it('no install when the person clicks: the server’s 409 sentence', async () => {
171+
const message = 'Slack is not installed for this organization: an administrator installs it first. Nothing was changed.';
172+
const { fetch } = doors({ account: ACME, link: null }, {
173+
[`POST ${SLACK_LINK_URL}/proposal`]: (s) => {
174+
s.account = null;
175+
return refused(409, 'RESOURCE_CONFLICT', message);
176+
},
177+
});
178+
render(<SlackLinkSection apiFetch={fetch} />);
179+
180+
fireEvent.click(await screen.findByTestId('slack-link-connect'));
181+
expect(await screen.findByTestId('slack-link-refused')).toHaveTextContent(message);
182+
expect(await screen.findByTestId('slack-link-not-installed')).toBeInTheDocument();
183+
});
184+
185+
it('a failed read says so', async () => {
186+
const { fetch } = doors({ account: null, link: null }, { [`GET ${SLACK_LINK_URL}`]: () => refused(503, 'SERVICE_UNAVAILABLE', 'no data engine') });
187+
render(<SlackLinkSection apiFetch={fetch} />);
188+
189+
expect(await screen.findByTestId('slack-link-load-failed')).toHaveTextContent('«slackLink.loadFailed»');
190+
});
191+
});

0 commit comments

Comments
 (0)