Skip to content

Commit 14f4d8f

Browse files
feat(app-shell): Notification Settings offers Follow organization setting for digest and quiet hours (#36804)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBEaJzgBWzjWCNjBjkVoeRto)_ repo:objectstack#3 · os-support-ai · session_01WGufzi4PechTRCTBrfxV8W Fixes #36701 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:成员在自己的「通知设置」页,对已自己设过的每日汇总或免打扰时段,多了一个「跟随组织设置」按钮;点了以后页面显示组织当前的设置,并标为来自组织。 - 为什么做:属于通知平台收口工作;成员自己改过一次后,原来只能找管理员才能回到跟随组织,这次让成员自己能撤回。 - 出错会怎样:只影响点了这个按钮的成员本人的汇总或免打扰;按钮只清空那一项,不删任何记录,成员可以随时再选回自己的值。 - 要你做什么:无。 ## What changes - **The action.** On the member's Notification Settings page, digest and quiet hours each get a "Follow organization setting" button when that field is the member's own answer (the door's `source` is `own`, so the member's own general row sets it). Clicking it sends one update of the member's own general row with that one field empty (`digest: null` or `quiet_hours: null`), the same empty the Setup grid writes. Under ruling 7073270426 on #35123 empty is "not set": the next row decides, in the end the organization's default. The page then reads the door again and draws the value in force with its source label ("Organization default", or "Default" when the organization sets nothing). - **When it is not drawn.** No own general row, or the field already inherited (`default` / `builtin`): there is nothing to clear, so the button is hidden, not disabled. For a caller with no write grant it is drawn disabled with the page's read-only reason, like every other control. - **What it is not.** The member's general row stays, and so does its on/off; per-topic and per-channel rows are untouched. No delete is sent (the member grant has none, ruling 6968686390). - **Code.** `followOrganizationWrite(general, field)` in `myPreferences.ts` (returns `null` when there is nothing to clear); the page draws one button per field from it. The header docblock sentence that said there is no reset to the organization default is rewritten to what ships: the two fields follow the organization by an update to empty; removing a row is still a delete the member grant does not carry. - **Strings.** `notificationSettings.followOrganization` and `notificationSettings.followOrganizationFor` (the button's accessible name, naming the field) in all eleven built-in locales of `@object-ui/i18n`, where the page's other strings live. - **Server-side pin (test only).** A new case in the plugin-security notification-preference suite, on the real SecurityPlugin, the shipped permission sets and the real `PreferenceResolver`: a member saves their own digest and quiet hours, clears both with an update to empty through the own-row policy, the stored row holds empty, `effectiveFor` answers the organization default for both, and a later change of the organization default reaches the member. Read first, by risk: 1. `ui/packages/app-shell/src/console/notification-settings/myPreferences.ts`: `followOrganizationWrite`, the condition that decides when there is something to clear. 2. `ui/packages/app-shell/src/console/notification-settings/NotificationSettingsPage.tsx`: the two buttons and their disabled / read-only wiring. 3. `packages/plugins/plugin-security/src/default-permission-sets.notification-preference.integration.test.ts`: the new round-trip case. Two-minute check: `pnpm --dir ui exec vitest run packages/app-shell/src/console/notification-settings/`, expect 3 files and 52 tests passing. ## Tests - `ui/packages/app-shell/src/console/notification-settings/` (3 files): 52/52 pass. New: three unit cases for `followOrganizationWrite` (own value cleared, explicit off cleared, nothing to clear), three page cases (digest round trip, quiet-hours round trip, hidden when nothing to clear), and the external-member read-only case now also asserts the follow button is disabled with the reason and sends nothing. - plugin-security `default-permission-sets.notification-preference.integration.test.ts`: 38/38 pass (37 before plus the round-trip case). - Ablations, each committed first, mutated through `scripts/ablation-replace.mjs` (anchor 1 to 0 on disk), restored, and the restored file's hash matched the HEAD blob: - `followOrganizationWrite` always `null`: 6 tests red. - the `source !== 'own'` half of its condition removed: 4 tests red (the hidden-when-inherited cases and both round trips). <details><summary>Run readings</summary> - notification-settings directory: `Test Files 3 passed (3)`, `Tests 52 passed (52)`, lock verdict `command-exit 0`. - plugin-security suite: `Test Files 1 passed (1)`, `Tests 38 passed (38)`, lock verdict `command-exit 0`. - grant map, Slack setup page and the whole `@object-ui/i18n` package: `Test Files 109 passed (109)`, `Tests 2071 passed | 13 skipped`. - `type-check` of `@object-ui/app-shell` and `@object-ui/i18n`, `typecheck` of `@objectstack/plugin-security`: lock verdict `command-exit 0`. </details> ## Acceptance notes - **The ruled-out sentence.** The old header line pointed at ruling 6968686390 on #34728: "Reset to the admin default is not built here. It needs a delete ... If it is pulled later it is an own-row delete door on its own card." That ruling scoped a whole-row reset out of that card on the ground that it needs a delete. It does not forbid a per-field follow, and ruling 7073270426 since made empty a legal "not set" state for these two fields, so clearing them is an update inside the existing grant. A whole-row reset (on/off and per-cell rows included) still needs a delete and is still not built. - **Server acceptance of the empty update, measured.** The round-trip case above is the measurement: the own-row policy accepts a member's update writing empty to `digest` and `quiet_hours`, and the resolver then answers the organization default. - **Inherited display.** The door already says where each value comes from (`own` / `default` / `builtin`), so the page labels the inherited value without a server change. - **Left as is.** The member's general row keeps deciding the matrix's on/off for cells they did not set (the existing warning under the General heading says so). Following the organization for on/off would need that row removed, which is the delete above. ## Verification Local derived gate families (`dispatch-gates.mjs --commands`, head `9268c30fe`): 72 derived; 70 ran with exit 0; `--ran` with recorded exit codes answers 72 accounted for, 70 run, 2 NOT-MEASURED, 0 UNRUN. Two families exited 3 (`PREREQUISITE NOT MET`, built output missing: `check:i18n`, `check:dual-build-cjs-loads`) and are NOT MEASURED locally; CI runs both in `Lint & Repo Gates`. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzi4PechTRCTBrfxV8W)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzi4PechTRCTBrfxV8W --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0d6589d commit 14f4d8f

17 files changed

Lines changed: 277 additions & 10 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+
feat(app-shell): Notification Settings offers "Follow organization setting" for digest and quiet hours
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Once a member has saved a digest or quiet hours of their own, the Notification Settings page now offers a "Follow organization setting" action beside each one. It empties that field on the member's own general preference (the same empty the Setup grid writes), so the organization's default decides again, including any later change to it. The page then shows the value in force as the organization default. The action appears only where the field is the member's own choice; where there is nothing to clear, it is not drawn.
12+
13+
The member's own general preference itself stays, and so does its on/off; per-topic and per-channel choices are not reset by this action.
14+
15+
New strings `notificationSettings.followOrganization` and `notificationSettings.followOrganizationFor` in all eleven built-in locales.

‎packages/plugins/plugin-security/src/default-permission-sets.notification-preference.integration.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,52 @@ describe('member_default: who reads and writes sys_notification_preference rows'
353353
]);
354354
});
355355
});
356+
357+
// [ruling 7073270426 on #35123] An empty digest or quiet hours on a member's
358+
// own `(*, *)` row is "not set": the next row decides, in the end the
359+
// organization's default. Clearing a field is therefore an UPDATE of the
360+
// member's own row, inside the grant (no delete), which is what the
361+
// Notification Settings page's "Follow organization setting" sends.
362+
describe('a member clears their own digest and quiet hours and follows the organization again', () => {
363+
const general = async () =>
364+
(await new PreferenceResolver({ getData: () => ql as never, logger: silent }).effectiveFor(ALICE, ORG, [], ['inbox'])).general;
365+
366+
it('save a value of their own, clear it to empty, and the resolver answers the organization default, and a later change of it', async () => {
367+
const orgWindow = { tz: 'UTC', start: '22:00', end: '07:00' };
368+
const ownWindow = { start: '12:00', end: '13:00' };
369+
const orgDefault = String((await insert(SYS, { topic: '*', channel: '*', enabled: true, digest: 'daily', quiet_hours: orgWindow })).id);
370+
const own = String(
371+
(await insert(as.alice, { user_id: ALICE, topic: '*', channel: '*', enabled: true, digest: 'weekly', quiet_hours: ownWindow })).id,
372+
);
373+
try {
374+
expect(await general()).toMatchObject({
375+
ownRowId: own,
376+
digest: { value: 'weekly', source: 'own' },
377+
quietHours: { value: ownWindow, source: 'own' },
378+
});
379+
380+
// The member's own update writing empty to both fields: accepted by the own-row policy.
381+
await update(as.alice, own, { digest: null, quiet_hours: null });
382+
const row = await storedById(own);
383+
expect(row).toMatchObject({ user_id: ALICE, topic: '*', channel: '*' });
384+
expect(row?.digest ?? null).toBeNull();
385+
expect(row?.quiet_hours ?? null).toBeNull();
386+
expect(await general()).toMatchObject({
387+
ownRowId: own,
388+
digest: { value: 'daily', source: 'default' },
389+
quietHours: { value: orgWindow, source: 'default' },
390+
});
391+
392+
// A later change of the organization's default reaches the member.
393+
await update(SYS, orgDefault, { digest: 'weekly', quiet_hours: { tz: 'UTC', start: '20:00', end: '06:00' } });
394+
expect(await general()).toMatchObject({
395+
digest: { value: 'weekly', source: 'default' },
396+
quietHours: { value: { tz: 'UTC', start: '20:00', end: '06:00' }, source: 'default' },
397+
});
398+
} finally {
399+
await ql.delete(OBJ, { where: { id: own }, context: SYS } as never);
400+
await ql.delete(OBJ, { where: { id: orgDefault }, context: SYS } as never);
401+
}
402+
});
403+
});
356404
});

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

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { getAppComponent } from '../../services/componentRegistry';
3838
import '@objectstack/lint';
3939
import '../../services/builtinComponents';
4040

41-
type General = { digest: { value: string; source: string }; quietHours: { value: unknown; source: string } };
41+
type General = { ownRowId?: string; digest: { value: string; source: string }; quietHours: { value: unknown; source: string } };
4242

4343
const BUILTIN_GENERAL: General = { digest: { value: 'none', source: 'builtin' }, quietHours: { value: null, source: 'builtin' } };
4444

@@ -275,6 +275,85 @@ describe('NotificationSettingsPage', () => {
275275
expect(screen.queryByTestId('notification-settings-matrix')).toBeNull();
276276
});
277277

278+
// [objectstack ruling 7073270426 on #35123] Empty is "not set": the person's
279+
// own (*, *) row with the field emptied hands it back to the organization.
280+
describe('"Follow organization setting" returns digest and quiet hours to the organization', () => {
281+
const OWN_WINDOW = { start: '12:00', end: '13:00' };
282+
const ORG_WINDOW = { start: '22:00', end: '07:00' };
283+
const ownBoth: General = {
284+
ownRowId: 'row-g',
285+
digest: { value: 'weekly', source: 'own' },
286+
quietHours: { value: OWN_WINDOW, source: 'own' },
287+
};
288+
289+
it('the digest round trip: their own weekly, cleared to empty, then the organization daily drawn as inherited', async () => {
290+
const cleared: General = { ...ownBoth, digest: { value: 'daily', source: 'default' } };
291+
const apiFetch = vi
292+
.fn()
293+
.mockResolvedValueOnce(json(answer(false, undefined, ownBoth)))
294+
.mockResolvedValueOnce(json(answer(false, undefined, cleared)));
295+
const adapter = { create: vi.fn(), update: vi.fn(async () => ({})) };
296+
render(<NotificationSettingsPage />, { wrapper: host(apiFetch, adapter) });
297+
298+
expect(await screen.findByTestId('notification-settings-digest-source')).toHaveTextContent('«notificationSettings.sourceOwn»');
299+
const follow = screen.getByTestId('notification-settings-digest-follow');
300+
expect(follow).toHaveTextContent('«notificationSettings.followOrganization»');
301+
expect(follow).toHaveAttribute('aria-label', '«notificationSettings.followOrganizationFor»');
302+
fireEvent.click(follow);
303+
304+
await waitFor(() =>
305+
expect(screen.getByTestId('notification-settings-digest-source')).toHaveTextContent('«notificationSettings.sourceDefault»'),
306+
);
307+
expect(adapter.update).toHaveBeenCalledTimes(1);
308+
expect(adapter.update).toHaveBeenCalledWith('sys_notification_preference', 'row-g', { digest: null });
309+
expect(adapter.create).not.toHaveBeenCalled();
310+
expect(apiFetch).toHaveBeenCalledTimes(2);
311+
expect((screen.getByTestId('notification-settings-digest') as HTMLSelectElement).value).toBe('daily');
312+
// Nothing left to clear on the digest; quiet hours are still their own.
313+
expect(screen.queryByTestId('notification-settings-digest-follow')).toBeNull();
314+
expect(screen.getByTestId('notification-settings-quiet-hours-follow')).toBeInTheDocument();
315+
});
316+
317+
it('the quiet-hours round trip: their own window, cleared to empty, then the organization window drawn as inherited', async () => {
318+
const cleared: General = { ...ownBoth, quietHours: { value: ORG_WINDOW, source: 'default' } };
319+
const apiFetch = vi
320+
.fn()
321+
.mockResolvedValueOnce(json(answer(false, undefined, ownBoth)))
322+
.mockResolvedValueOnce(json(answer(false, undefined, cleared)));
323+
const adapter = { create: vi.fn(), update: vi.fn(async () => ({})) };
324+
render(<NotificationSettingsPage />, { wrapper: host(apiFetch, adapter) });
325+
326+
expect(((await screen.findByTestId('quiet-hours-start')) as HTMLInputElement).value).toBe('12:00');
327+
fireEvent.click(screen.getByTestId('notification-settings-quiet-hours-follow'));
328+
329+
await waitFor(() =>
330+
expect(screen.getByTestId('notification-settings-quiet-hours-source')).toHaveTextContent('«notificationSettings.sourceDefault»'),
331+
);
332+
expect(adapter.update).toHaveBeenCalledTimes(1);
333+
expect(adapter.update).toHaveBeenCalledWith('sys_notification_preference', 'row-g', { quiet_hours: null });
334+
expect(((await screen.findByTestId('quiet-hours-start')) as HTMLInputElement).value).toBe('22:00');
335+
expect(screen.queryByTestId('notification-settings-quiet-hours-follow')).toBeNull();
336+
});
337+
338+
it('nothing to clear, no action: no own (*, *) row, or a field that is not their own answer', async () => {
339+
const orgOnly: General = { digest: { value: 'daily', source: 'default' }, quietHours: { value: ORG_WINDOW, source: 'default' } };
340+
const apiFetch = vi.fn().mockResolvedValue(json(answer(false, undefined, orgOnly)));
341+
render(<NotificationSettingsPage />, { wrapper: host(apiFetch, { create: vi.fn(), update: vi.fn() }) });
342+
await screen.findByTestId('notification-settings-digest');
343+
expect(screen.queryByTestId('notification-settings-digest-follow')).toBeNull();
344+
expect(screen.queryByTestId('notification-settings-quiet-hours-follow')).toBeNull();
345+
cleanup();
346+
347+
// An own (*, *) row that sets only the digest: quiet hours still follow the organization.
348+
const digestOnly: General = { ownRowId: 'row-g', digest: { value: 'none', source: 'own' }, quietHours: { value: ORG_WINDOW, source: 'default' } };
349+
render(<NotificationSettingsPage />, {
350+
wrapper: host(vi.fn().mockResolvedValue(json(answer(false, undefined, digestOnly))), { create: vi.fn(), update: vi.fn() }),
351+
});
352+
expect(await screen.findByTestId('notification-settings-digest-follow')).toBeInTheDocument();
353+
expect(screen.queryByTestId('notification-settings-quiet-hours-follow')).toBeNull();
354+
});
355+
});
356+
278357
it('every built-in locale carries the same keys and placeholders', () => {
279358
type Pack = { notificationSettings?: Record<string, string> };
280359
const en = (builtInLocales as Record<string, Pack>).en.notificationSettings!;
@@ -355,7 +434,12 @@ describe('the caller\'s grant on sys_notification_preference decides whether the
355434
}
356435

357436
it('an external member sees every control disabled with the reason, and no write is sent', async () => {
358-
const orgQuiet: General = { ...BUILTIN_GENERAL, quietHours: { value: { start: '22:00', end: '07:00' }, source: 'default' } };
437+
// A row an administrator wrote in their name: the digest is their own answer, so its action is drawn, disabled.
438+
const orgQuiet: General = {
439+
ownRowId: 'row-g',
440+
digest: { value: 'weekly', source: 'own' },
441+
quietHours: { value: { start: '22:00', end: '07:00' }, source: 'default' },
442+
};
359443
const apiFetch = vi.fn(async () => json(answer(false, undefined, orgQuiet)));
360444
const adapter = { create: vi.fn(), update: vi.fn() };
361445
render(<NotificationSettingsPage />, { wrapper: hostAs(EXTERNAL, apiFetch, adapter) });
@@ -367,7 +451,8 @@ describe('the caller\'s grant on sys_notification_preference decides whether the
367451
const cell = screen.getByTestId('notification-settings-cell-task.assigned-email');
368452
const digest = screen.getByTestId('notification-settings-digest');
369453
const save = screen.getByTestId('notification-settings-quiet-hours-save');
370-
for (const control of [cell, digest, save]) {
454+
const follow = screen.getByTestId('notification-settings-digest-follow');
455+
for (const control of [cell, digest, save, follow]) {
371456
expect(control).toBeDisabled();
372457
expect(control).toHaveAttribute('aria-describedby', reasonId);
373458
}
@@ -379,6 +464,7 @@ describe('the caller\'s grant on sys_notification_preference decides whether the
379464
fireEvent.click(cell);
380465
fireEvent.change(digest, { target: { value: 'weekly' } });
381466
fireEvent.click(save);
467+
fireEvent.click(follow);
382468
expect(adapter.create).not.toHaveBeenCalled();
383469
expect(adapter.update).not.toHaveBeenCalled();
384470
expect(apiFetch).toHaveBeenCalledTimes(1);

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
* organization's default sets (objectstack ruling 7073270426). The field they
2121
* do not change keeps following the organization.
2222
*
23+
* Once digest or quiet hours is the person's own answer (the door says
24+
* `own`), a "Follow organization setting" action beside it empties that field
25+
* on their own `(*, *)` row (`followOrganizationWrite`), the same empty the
26+
* Setup grid writes; the page then reads the door again and draws the value in
27+
* force with its source. Where the field is not their own answer there is
28+
* nothing to clear, and the action is not drawn.
29+
*
2330
* Channels are columns as the door lists them, so a channel the deployment
2431
* adds later (Slack, …) appears without a change here; a channel the
2532
* deployment cannot send on yet says so in its header. Where the door lists
@@ -64,6 +71,7 @@ import { PageHeader } from '../../layout/PageHeader.js';
6471
import {
6572
cellWrite,
6673
digestChoices,
74+
followOrganizationWrite,
6775
quietHoursSaveable,
6876
quietHoursStored,
6977
generalWrite,
@@ -193,6 +201,9 @@ export function NotificationSettingsPage() {
193201
// Every disabled control names the one visible reason as its description.
194202
const readOnlyDescribedBy = writeGranted ? undefined : readOnlyReasonId;
195203
const quietValue = quietDraft === undefined ? prefs.general.quietHours.value : quietDraft;
204+
const followDigest = followOrganizationWrite(prefs.general, 'digest');
205+
const followQuietHours = followOrganizationWrite(prefs.general, 'quiet_hours');
206+
const followLabel = (setting: string) => t('notificationSettings.followOrganizationFor', { setting });
196207

197208
const topicLabel = (topic: PreferenceTopic) =>
198209
topic.topic === PREFERENCE_WILDCARD ? t('notificationSettings.allTopics') : topic.topic;
@@ -241,9 +252,24 @@ export function NotificationSettingsPage() {
241252
</option>
242253
))}
243254
</select>
244-
<p className="text-xs text-muted-foreground" data-testid="notification-settings-digest-source">
245-
{t(SOURCE_KEY[prefs.general.digest.source])}
246-
</p>
255+
<div className="flex items-center gap-3">
256+
<p className="text-xs text-muted-foreground" data-testid="notification-settings-digest-source">
257+
{t(SOURCE_KEY[prefs.general.digest.source])}
258+
</p>
259+
{followDigest && (
260+
<Button
261+
size="sm"
262+
variant="outline"
263+
data-testid="notification-settings-digest-follow"
264+
aria-label={followLabel(t('notificationSettings.digest'))}
265+
disabled={!canWrite}
266+
aria-describedby={readOnlyDescribedBy}
267+
onClick={() => void apply(followDigest)}
268+
>
269+
{t('notificationSettings.followOrganization')}
270+
</Button>
271+
)}
272+
</div>
247273
</div>
248274
<div className="space-y-1" data-testid="notification-settings-quiet-hours">
249275
<Label>{t('notificationSettings.quietHours')}</Label>
@@ -273,6 +299,19 @@ export function NotificationSettingsPage() {
273299
<span className="text-xs text-muted-foreground" data-testid="notification-settings-quiet-hours-source">
274300
{t(SOURCE_KEY[prefs.general.quietHours.source])}
275301
</span>
302+
{followQuietHours && (
303+
<Button
304+
size="sm"
305+
variant="outline"
306+
data-testid="notification-settings-quiet-hours-follow"
307+
aria-label={followLabel(t('notificationSettings.quietHours'))}
308+
disabled={!canWrite}
309+
aria-describedby={readOnlyDescribedBy}
310+
onClick={() => void apply(followQuietHours)}
311+
>
312+
{t('notificationSettings.followOrganization')}
313+
</Button>
314+
)}
276315
</div>
277316
</div>
278317
</CardContent>

‎ui/packages/app-shell/src/console/notification-settings/myPreferences.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { describe, expect, it, vi } from 'vitest';
1111
import {
1212
cellWrite,
1313
digestChoices,
14+
followOrganizationWrite,
1415
quietHoursSaveable,
1516
quietHoursStored,
1617
QUIET_HOURS_OFF,
@@ -162,3 +163,38 @@ describe('every choice takes effect, the explicit off included', () => {
162163
});
163164
});
164165
});
166+
167+
// [objectstack ruling 7073270426 on #35123] Empty is the third state, "not
168+
// set": the next row decides, in the end the organization's default. Going back
169+
// to following the organization is an update of the person's own (*, *) row
170+
// that empties one field, never a delete (the member grant carries none).
171+
describe('"Follow organization setting" empties one field of the person\'s own (*, *) row', () => {
172+
const own: GeneralPreferences = {
173+
ownRowId: 'row-g',
174+
enabled: { value: true, source: 'own' },
175+
digest: { value: 'weekly', source: 'own' },
176+
quietHours: { value: { start: '12:00', end: '13:00' }, source: 'own' },
177+
};
178+
179+
it('an own digest or quiet hours is cleared by an update writing that field empty, and nothing else', () => {
180+
expect(followOrganizationWrite(own, 'digest')).toEqual({ kind: 'update', id: 'row-g', data: { digest: null } });
181+
expect(followOrganizationWrite(own, 'quiet_hours')).toEqual({ kind: 'update', id: 'row-g', data: { quiet_hours: null } });
182+
});
183+
184+
it('the explicit off is the person\'s own answer too, and is cleared the same way', () => {
185+
const off: GeneralPreferences = { ...own, digest: { value: 'none', source: 'own' }, quietHours: { value: null, source: 'own' } };
186+
expect(followOrganizationWrite(off, 'digest')).toEqual({ kind: 'update', id: 'row-g', data: { digest: null } });
187+
expect(followOrganizationWrite(off, 'quiet_hours')).toEqual({ kind: 'update', id: 'row-g', data: { quiet_hours: null } });
188+
});
189+
190+
it('nothing to clear: no own (*, *) row, or a field the door says is not the person\'s own', () => {
191+
const noRow: GeneralPreferences = { enabled: own.enabled, digest: own.digest, quietHours: own.quietHours };
192+
expect(followOrganizationWrite(noRow, 'digest')).toBeNull();
193+
expect(followOrganizationWrite(noRow, 'quiet_hours')).toBeNull();
194+
for (const source of ['default', 'builtin'] as const) {
195+
const inherited: GeneralPreferences = { ...own, digest: { value: 'daily', source }, quietHours: { value: null, source } };
196+
expect(followOrganizationWrite(inherited, 'digest')).toBeNull();
197+
expect(followOrganizationWrite(inherited, 'quiet_hours')).toBeNull();
198+
}
199+
});
200+
});

0 commit comments

Comments
 (0)