@astryxdesign/lab 0.7.6-canary.ec128c4 → 0.7.6-canary.f73623d
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 +1 -1
- package/dist/Comments/CommentComposer.d.ts.map +1 -1
- package/dist/Comments/CommentComposer.js +10 -3
- package/dist/Comments/CommentParts.d.ts +9 -2
- package/dist/Comments/CommentParts.d.ts.map +1 -1
- package/dist/Comments/CommentParts.js +32 -15
- package/dist/Comments/CommentRow.d.ts.map +1 -1
- package/dist/Comments/CommentRow.js +5 -2
- package/dist/Comments/Comments.d.ts.map +1 -1
- package/dist/Comments/Comments.js +10 -1
- package/dist/Comments/CommentsContext.d.ts +2 -0
- package/dist/Comments/CommentsContext.d.ts.map +1 -1
- package/dist/Comments/CommentsContext.js +7 -3
- package/dist/Comments/useStatusAnnouncement.d.ts +26 -0
- package/dist/Comments/useStatusAnnouncement.d.ts.map +1 -0
- package/dist/Comments/useStatusAnnouncement.js +48 -0
- package/package.json +4 -4
- package/src/Comments/CommentComposer.test.tsx +54 -4
- package/src/Comments/CommentComposer.tsx +10 -2
- package/src/Comments/CommentParts.tsx +50 -14
- package/src/Comments/CommentRow.tsx +5 -6
- package/src/Comments/Comments.doc.mjs +1 -1
- package/src/Comments/Comments.test.tsx +339 -13
- package/src/Comments/Comments.tsx +16 -1
- package/src/Comments/CommentsContext.tsx +13 -1
- package/src/Comments/useStatusAnnouncement.ts +57 -0
|
@@ -13,7 +13,13 @@
|
|
|
13
13
|
* @position Internal building blocks of the Comments family
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
useRef,
|
|
18
|
+
useState,
|
|
19
|
+
type CSSProperties,
|
|
20
|
+
type ReactNode,
|
|
21
|
+
type Ref,
|
|
22
|
+
} from 'react';
|
|
17
23
|
import * as stylex from '@stylexjs/stylex';
|
|
18
24
|
import {Avatar} from '@astryxdesign/core/Avatar';
|
|
19
25
|
import {Badge} from '@astryxdesign/core/Badge';
|
|
@@ -51,6 +57,7 @@ import {
|
|
|
51
57
|
spacingVars,
|
|
52
58
|
} from '@astryxdesign/core/theme/tokens.stylex';
|
|
53
59
|
import {CommentIcon} from './icons';
|
|
60
|
+
import {useStatusAnnouncement} from './useStatusAnnouncement';
|
|
54
61
|
import {eventAnchorId, type AnyComment} from './utils';
|
|
55
62
|
import type {
|
|
56
63
|
CommentAnchor,
|
|
@@ -260,11 +267,18 @@ export type ErrorBannerContent = {
|
|
|
260
267
|
actionLabel?: string;
|
|
261
268
|
onAction?: () => void;
|
|
262
269
|
isActionDisabled?: boolean;
|
|
270
|
+
/** Its own retry is running: say nothing until the outcome (FR6). */
|
|
271
|
+
isRetrying?: boolean;
|
|
272
|
+
/** The failure was already announced elsewhere; this Banner stays silent. */
|
|
273
|
+
isAnnounced?: boolean;
|
|
263
274
|
};
|
|
264
275
|
|
|
265
276
|
/**
|
|
266
|
-
* An inline failure as an error Banner.
|
|
267
|
-
*
|
|
277
|
+
* An inline failure as an error Banner. The Banner carries no live role: it
|
|
278
|
+
* mounts already holding its text, which may not be announced. The failure is
|
|
279
|
+
* announced once, assertively, through the shared channel instead, unless the
|
|
280
|
+
* Banner sits inside a live container such as the chat log, which delivers it
|
|
281
|
+
* (spec:AST-086 FR2, FR4, FR5).
|
|
268
282
|
*/
|
|
269
283
|
export function ErrorBanner({
|
|
270
284
|
actionRef,
|
|
@@ -279,10 +293,21 @@ export function ErrorBanner({
|
|
|
279
293
|
[dataAttribute: `data-${string}`]: string | undefined;
|
|
280
294
|
}) {
|
|
281
295
|
const {actionLabel, description, isActionDisabled, onAction, title} = content;
|
|
296
|
+
const t = useTranslator();
|
|
297
|
+
const bannerRef = useRef<HTMLDivElement>(null);
|
|
298
|
+
useStatusAnnouncement(
|
|
299
|
+
bannerRef,
|
|
300
|
+
content.isRetrying === true || content.isAnnounced === true
|
|
301
|
+
? null
|
|
302
|
+
: description != null
|
|
303
|
+
? t('@astryx.comments.errorAnnouncement', {title, description})
|
|
304
|
+
: title,
|
|
305
|
+
'assertive',
|
|
306
|
+
);
|
|
282
307
|
return (
|
|
283
308
|
<Banner
|
|
309
|
+
ref={bannerRef}
|
|
284
310
|
status="error"
|
|
285
|
-
role="alert"
|
|
286
311
|
container="card"
|
|
287
312
|
title={title}
|
|
288
313
|
description={description}
|
|
@@ -466,6 +491,11 @@ export function CommentAnchorQuote({
|
|
|
466
491
|
|
|
467
492
|
/** A comment its author is still writing: what it is doing, and where to watch. */
|
|
468
493
|
export function CommentProgressStatus({progress}: {progress: CommentProgress}) {
|
|
494
|
+
const labelRef = useRef<HTMLElement>(null);
|
|
495
|
+
// The label carries no live role: it mounts already holding its text. It is
|
|
496
|
+
// announced politely through the shared channel, unless the chat log around
|
|
497
|
+
// it delivers it (spec:AST-086 FR2, FR4).
|
|
498
|
+
useStatusAnnouncement(labelRef, progress.label, 'polite');
|
|
469
499
|
return (
|
|
470
500
|
<HStack
|
|
471
501
|
gap={1}
|
|
@@ -474,9 +504,9 @@ export function CommentProgressStatus({progress}: {progress: CommentProgress}) {
|
|
|
474
504
|
width="100%"
|
|
475
505
|
data-comment-progress="shimmer">
|
|
476
506
|
<Text
|
|
507
|
+
ref={labelRef}
|
|
477
508
|
type="body"
|
|
478
509
|
color="secondary"
|
|
479
|
-
role="status"
|
|
480
510
|
xstyle={partStyles.progressLabel}>
|
|
481
511
|
{progress.label}
|
|
482
512
|
</Text>
|
|
@@ -724,17 +754,23 @@ export function HistoryDialog({
|
|
|
724
754
|
}
|
|
725
755
|
content={
|
|
726
756
|
<LayoutContent>
|
|
757
|
+
{/* The shared channel is not exposed while a native modal is open
|
|
758
|
+
(spec:AST-086), so a failure here is delivered by a persistent
|
|
759
|
+
alert slot inside the dialog. The slot is mounted empty and the
|
|
760
|
+
Banner is added to it (FR3). */}
|
|
761
|
+
<div role="alert">
|
|
762
|
+
{!history.isLoading && history.error != null && (
|
|
763
|
+
<Banner
|
|
764
|
+
status="error"
|
|
765
|
+
title={t('@astryx.comments.historyFailed')}
|
|
766
|
+
description={history.error}
|
|
767
|
+
container="section"
|
|
768
|
+
/>
|
|
769
|
+
)}
|
|
770
|
+
</div>
|
|
727
771
|
{history.isLoading ? (
|
|
728
772
|
<Spinner size="lg" label={t('@astryx.comments.historyLoading')} />
|
|
729
|
-
) : history.error != null ? (
|
|
730
|
-
<Banner
|
|
731
|
-
status="error"
|
|
732
|
-
role="alert"
|
|
733
|
-
title={t('@astryx.comments.historyFailed')}
|
|
734
|
-
description={history.error}
|
|
735
|
-
container="section"
|
|
736
|
-
/>
|
|
737
|
-
) : history.versions.length === 0 ? (
|
|
773
|
+
) : history.error != null ? null : history.versions.length === 0 ? (
|
|
738
774
|
<EmptyState
|
|
739
775
|
title={t('@astryx.comments.historyEmptyTitle')}
|
|
740
776
|
description={t('@astryx.comments.historyEmptyDescription')}
|
|
@@ -502,6 +502,8 @@ export function CommentRow({
|
|
|
502
502
|
actionLabel: can.retry ? t('@astryx.comments.retry') : undefined,
|
|
503
503
|
onAction: can.retry ? () => scope.retry(comment) : undefined,
|
|
504
504
|
isActionDisabled: rowActionsBusy,
|
|
505
|
+
isRetrying: isBusy,
|
|
506
|
+
isAnnounced: actionFailure?.isAnnounced,
|
|
505
507
|
}}
|
|
506
508
|
// The Banner unmounts once the retry starts; keep focus on the comment.
|
|
507
509
|
onBeforeAction={() => articleRef.current?.focus()}
|
|
@@ -536,6 +538,7 @@ export function CommentRow({
|
|
|
536
538
|
? t('@astryx.comments.retry')
|
|
537
539
|
: undefined,
|
|
538
540
|
onAction: actionFailure.retry,
|
|
541
|
+
isAnnounced: actionFailure.isAnnounced,
|
|
539
542
|
}}
|
|
540
543
|
onBeforeAction={() => articleRef.current?.focus()}
|
|
541
544
|
data-comment-action-error="banner"
|
|
@@ -624,9 +627,7 @@ export function CommentRow({
|
|
|
624
627
|
{hasHistory ? (
|
|
625
628
|
<MetadataActionLink
|
|
626
629
|
label={t('@astryx.comments.edited')}
|
|
627
|
-
accessibleLabel={t(
|
|
628
|
-
'@astryx.comments.viewHistory',
|
|
629
|
-
)}
|
|
630
|
+
accessibleLabel={t('@astryx.comments.viewHistory')}
|
|
630
631
|
actionRole="history"
|
|
631
632
|
textType="body"
|
|
632
633
|
onClick={() => scope.openHistory(comment)}
|
|
@@ -705,9 +706,7 @@ export function CommentRow({
|
|
|
705
706
|
triggers={composerTriggers ?? []}
|
|
706
707
|
agentCommands={agentCommands}
|
|
707
708
|
hasEmojiPicker={hasEmojiPicker}
|
|
708
|
-
onActionPendingChange={
|
|
709
|
-
scope.composerActionPendingChange
|
|
710
|
-
}
|
|
709
|
+
onActionPendingChange={scope.composerActionPendingChange}
|
|
711
710
|
onUploadImages={uploaderFor({
|
|
712
711
|
kind: 'edit',
|
|
713
712
|
commentId: comment.id,
|
|
@@ -166,7 +166,7 @@ export const docs = {
|
|
|
166
166
|
category: 'Content',
|
|
167
167
|
criterion: '4.1.3 Status Messages',
|
|
168
168
|
description:
|
|
169
|
-
'Failures show in
|
|
169
|
+
'Failures show in error Banners next to the thing that failed, each with Retry when the action can be repeated. A Banner carries no live role of its own: its failure is announced once, assertively, through the shared announcement channel, unless it sits inside the chat log, which delivers it. The progress label of a comment still being written follows the same rule, politely. The edit-history dialog announces its failure through an alert region inside the dialog. A failed delete is announced once, assertively, as the confirmation dialog changes its text.',
|
|
170
170
|
},
|
|
171
171
|
],
|
|
172
172
|
},
|
|
@@ -24,6 +24,24 @@ import {
|
|
|
24
24
|
// jsdom has no layout, so the measuring OverflowList is replaced by one that
|
|
25
25
|
// collapses exactly the comment actions a test names.
|
|
26
26
|
const overflowControl = vi.hoisted(() => ({collapsed: new Set<string>()}));
|
|
27
|
+
const announce = vi.hoisted(() => vi.fn());
|
|
28
|
+
// Records each announcement and still speaks it through the real channel, which
|
|
29
|
+
// other tests here read back.
|
|
30
|
+
vi.mock('@astryxdesign/core/hooks', async importOriginal => {
|
|
31
|
+
const actual =
|
|
32
|
+
await importOriginal<typeof import('@astryxdesign/core/hooks')>();
|
|
33
|
+
return {
|
|
34
|
+
...actual,
|
|
35
|
+
useAnnounce: () => {
|
|
36
|
+
const speak = actual.useAnnounce();
|
|
37
|
+
return (message: string, politeness?: 'polite' | 'assertive') => {
|
|
38
|
+
announce(message, politeness);
|
|
39
|
+
speak(message, politeness);
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
|
|
27
45
|
vi.mock('@astryxdesign/core/OverflowList', async () => {
|
|
28
46
|
const React = await import('react');
|
|
29
47
|
type Item = {
|
|
@@ -82,12 +100,6 @@ import type {
|
|
|
82
100
|
CommentUser,
|
|
83
101
|
} from './types';
|
|
84
102
|
|
|
85
|
-
// The page's shared live regions are not the component's error Banner.
|
|
86
|
-
const errorBanner = () =>
|
|
87
|
-
screen
|
|
88
|
-
.queryAllByRole('alert')
|
|
89
|
-
.find(element => !element.hasAttribute('data-astryx-live-region'));
|
|
90
|
-
|
|
91
103
|
const VIEWER: CommentUser = {id: 'avery', name: 'Avery Kim'};
|
|
92
104
|
const OTHER: CommentUser = {id: 'maya', name: 'Maya Chen'};
|
|
93
105
|
const AGENT: CommentUser = {
|
|
@@ -133,6 +145,15 @@ const COMMENTS: readonly CommentThreadData[] = [
|
|
|
133
145
|
},
|
|
134
146
|
];
|
|
135
147
|
|
|
148
|
+
/** An inline failure Banner by its data attribute; it carries no live role. */
|
|
149
|
+
function bannerByData(attribute: string): HTMLElement {
|
|
150
|
+
const banner = document.querySelector<HTMLElement>(`[${attribute}]`);
|
|
151
|
+
if (banner == null) {
|
|
152
|
+
throw new Error(`No Banner with ${attribute}`);
|
|
153
|
+
}
|
|
154
|
+
return banner;
|
|
155
|
+
}
|
|
156
|
+
|
|
136
157
|
/** A plain composer standing in for the contenteditable one. */
|
|
137
158
|
function TestComposer(props: CommentComposerRenderProps) {
|
|
138
159
|
return (
|
|
@@ -267,6 +288,7 @@ afterAll(() => {
|
|
|
267
288
|
});
|
|
268
289
|
|
|
269
290
|
beforeEach(() => {
|
|
291
|
+
announce.mockClear();
|
|
270
292
|
overflowControl.collapsed = new Set();
|
|
271
293
|
writeText.mockReset();
|
|
272
294
|
writeText.mockResolvedValue(undefined);
|
|
@@ -392,9 +414,10 @@ describe('Comments rendering', () => {
|
|
|
392
414
|
);
|
|
393
415
|
const article = articleByAuthor('Release Assistant');
|
|
394
416
|
expect(within(article).getByText('Agent')).toBeTruthy();
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
);
|
|
417
|
+
// The label carries no live role; the chat log around it delivers it.
|
|
418
|
+
const progressLabel = within(article).getByText('Checking the rollout…');
|
|
419
|
+
expect(progressLabel).not.toHaveAttribute('role');
|
|
420
|
+
expect(within(article).queryByRole('status')).toBeNull();
|
|
398
421
|
expect(
|
|
399
422
|
within(article).getByRole('link', {name: 'Open session'}),
|
|
400
423
|
).toBeTruthy();
|
|
@@ -906,12 +929,13 @@ describe('Comments threads', () => {
|
|
|
906
929
|
}),
|
|
907
930
|
);
|
|
908
931
|
await flush();
|
|
909
|
-
const banner =
|
|
932
|
+
const banner = bannerByData('data-comment-action-error');
|
|
933
|
+
expect(banner).not.toHaveAttribute('role');
|
|
910
934
|
expect(banner.textContent).toContain("Your reaction couldn't be saved.");
|
|
911
935
|
await click(within(banner).getByRole('button', {name: 'Retry'}));
|
|
912
936
|
await flush();
|
|
913
937
|
expect(onReact).toHaveBeenCalledTimes(2);
|
|
914
|
-
expect(
|
|
938
|
+
expect(document.querySelector('[data-comment-action-error]')).toBeNull();
|
|
915
939
|
});
|
|
916
940
|
|
|
917
941
|
it('copies a link to the comment', async () => {
|
|
@@ -1005,7 +1029,8 @@ describe('Comments threads', () => {
|
|
|
1005
1029
|
/>
|
|
1006
1030
|
</Sized>,
|
|
1007
1031
|
);
|
|
1008
|
-
const banner =
|
|
1032
|
+
const banner = bannerByData('data-comment-delivery-error');
|
|
1033
|
+
expect(banner).not.toHaveAttribute('role');
|
|
1009
1034
|
expect(banner.textContent).toContain("Couldn't post this comment.");
|
|
1010
1035
|
await click(within(banner).getByRole('button', {name: 'Retry'}));
|
|
1011
1036
|
await flush();
|
|
@@ -1028,7 +1053,8 @@ describe('Comments threads', () => {
|
|
|
1028
1053
|
);
|
|
1029
1054
|
await click(screen.getByRole('button', {name: 'Load earlier comments'}));
|
|
1030
1055
|
await flush();
|
|
1031
|
-
const banner =
|
|
1056
|
+
const banner = bannerByData('data-comments-older-error');
|
|
1057
|
+
expect(banner).not.toHaveAttribute('role');
|
|
1032
1058
|
expect(banner.textContent).toContain("Earlier comments couldn't load");
|
|
1033
1059
|
await click(within(banner).getByRole('button', {name: 'Retry'}));
|
|
1034
1060
|
await flush();
|
|
@@ -1250,6 +1276,133 @@ describe('Comments keyboard and focus', () => {
|
|
|
1250
1276
|
).toHaveFocus();
|
|
1251
1277
|
});
|
|
1252
1278
|
|
|
1279
|
+
it('announces a failed delete once when no chat log wraps the row', async () => {
|
|
1280
|
+
const onDelete = vi.fn().mockRejectedValue(new Error('offline'));
|
|
1281
|
+
render(
|
|
1282
|
+
<Sized>
|
|
1283
|
+
<Comments
|
|
1284
|
+
layout="embedded"
|
|
1285
|
+
comments={COMMENTS}
|
|
1286
|
+
currentUser={OTHER}
|
|
1287
|
+
onDelete={onDelete}
|
|
1288
|
+
selectedThreadId="root-1"
|
|
1289
|
+
onSelectedThreadChange={vi.fn()}
|
|
1290
|
+
/>
|
|
1291
|
+
</Sized>,
|
|
1292
|
+
);
|
|
1293
|
+
await click(
|
|
1294
|
+
within(articleByAuthor('Maya Chen')).getByRole('button', {
|
|
1295
|
+
name: "Actions for Maya Chen's comment",
|
|
1296
|
+
}),
|
|
1297
|
+
);
|
|
1298
|
+
await flush();
|
|
1299
|
+
await click(menuItem('Delete'));
|
|
1300
|
+
const dialog = document.querySelector('dialog[open]');
|
|
1301
|
+
if (!(dialog instanceof HTMLDialogElement)) {
|
|
1302
|
+
throw new Error('Delete confirmation not found');
|
|
1303
|
+
}
|
|
1304
|
+
announce.mockClear();
|
|
1305
|
+
await click(within(dialog).getByRole('button', {name: 'Delete'}));
|
|
1306
|
+
await flush();
|
|
1307
|
+
await nextFrame();
|
|
1308
|
+
|
|
1309
|
+
// The dialog owns the announcement; the row's stored failure is silent.
|
|
1310
|
+
const deleteAnnouncements = announce.mock.calls.filter(([message]) =>
|
|
1311
|
+
/couldn't be deleted/.test(message),
|
|
1312
|
+
);
|
|
1313
|
+
expect(deleteAnnouncements).toEqual([
|
|
1314
|
+
["This comment couldn't be deleted. Try again.", 'assertive'],
|
|
1315
|
+
]);
|
|
1316
|
+
});
|
|
1317
|
+
|
|
1318
|
+
it('announces a failed delete once when onDelete throws synchronously', async () => {
|
|
1319
|
+
const onDelete = vi.fn(() => {
|
|
1320
|
+
throw new Error('offline');
|
|
1321
|
+
});
|
|
1322
|
+
render(
|
|
1323
|
+
<Sized>
|
|
1324
|
+
<Comments
|
|
1325
|
+
layout="embedded"
|
|
1326
|
+
comments={COMMENTS}
|
|
1327
|
+
currentUser={OTHER}
|
|
1328
|
+
onDelete={onDelete}
|
|
1329
|
+
selectedThreadId="root-1"
|
|
1330
|
+
onSelectedThreadChange={vi.fn()}
|
|
1331
|
+
/>
|
|
1332
|
+
</Sized>,
|
|
1333
|
+
);
|
|
1334
|
+
await click(
|
|
1335
|
+
within(articleByAuthor('Maya Chen')).getByRole('button', {
|
|
1336
|
+
name: "Actions for Maya Chen's comment",
|
|
1337
|
+
}),
|
|
1338
|
+
);
|
|
1339
|
+
await flush();
|
|
1340
|
+
await click(menuItem('Delete'));
|
|
1341
|
+
const dialog = document.querySelector('dialog[open]');
|
|
1342
|
+
if (!(dialog instanceof HTMLDialogElement)) {
|
|
1343
|
+
throw new Error('Delete confirmation not found');
|
|
1344
|
+
}
|
|
1345
|
+
announce.mockClear();
|
|
1346
|
+
await click(within(dialog).getByRole('button', {name: 'Delete'}));
|
|
1347
|
+
await flush();
|
|
1348
|
+
await nextFrame();
|
|
1349
|
+
|
|
1350
|
+
// The dialog owns the announcement; the row's stored failure is silent.
|
|
1351
|
+
const deleteAnnouncements = announce.mock.calls.filter(([message]) =>
|
|
1352
|
+
/couldn't be deleted/.test(message),
|
|
1353
|
+
);
|
|
1354
|
+
expect(deleteAnnouncements).toEqual([
|
|
1355
|
+
["This comment couldn't be deleted. Try again.", 'assertive'],
|
|
1356
|
+
]);
|
|
1357
|
+
});
|
|
1358
|
+
|
|
1359
|
+
it('announces a failed delete of a failed post once', async () => {
|
|
1360
|
+
const onDelete = vi.fn().mockRejectedValue(new Error('offline'));
|
|
1361
|
+
render(
|
|
1362
|
+
<Sized>
|
|
1363
|
+
<Comments
|
|
1364
|
+
layout="embedded"
|
|
1365
|
+
comments={[
|
|
1366
|
+
{
|
|
1367
|
+
id: 'failed',
|
|
1368
|
+
author: VIEWER,
|
|
1369
|
+
body: 'Kept text',
|
|
1370
|
+
createdAt: '2026-09-30T19:00:00Z',
|
|
1371
|
+
status: 'error',
|
|
1372
|
+
errorMessage: "Couldn't post this comment.",
|
|
1373
|
+
},
|
|
1374
|
+
]}
|
|
1375
|
+
currentUser={VIEWER}
|
|
1376
|
+
onDelete={onDelete}
|
|
1377
|
+
/>
|
|
1378
|
+
</Sized>,
|
|
1379
|
+
);
|
|
1380
|
+
await click(
|
|
1381
|
+
within(articleByAuthor('Avery Kim')).getByRole('button', {
|
|
1382
|
+
name: "Actions for Avery Kim's comment",
|
|
1383
|
+
}),
|
|
1384
|
+
);
|
|
1385
|
+
await flush();
|
|
1386
|
+
await click(menuItem('Delete'));
|
|
1387
|
+
const dialog = document.querySelector('dialog[open]');
|
|
1388
|
+
if (!(dialog instanceof HTMLDialogElement)) {
|
|
1389
|
+
throw new Error('Delete confirmation not found');
|
|
1390
|
+
}
|
|
1391
|
+
announce.mockClear();
|
|
1392
|
+
await click(within(dialog).getByRole('button', {name: 'Delete'}));
|
|
1393
|
+
await flush();
|
|
1394
|
+
await nextFrame();
|
|
1395
|
+
|
|
1396
|
+
// The dialog owns the announcement; the failed post's Banner shows the
|
|
1397
|
+
// failure as its description without saying it a second time.
|
|
1398
|
+
const deleteAnnouncements = announce.mock.calls.filter(([message]) =>
|
|
1399
|
+
/couldn't be deleted/.test(message),
|
|
1400
|
+
);
|
|
1401
|
+
expect(deleteAnnouncements).toEqual([
|
|
1402
|
+
["This comment couldn't be deleted. Try again.", 'assertive'],
|
|
1403
|
+
]);
|
|
1404
|
+
});
|
|
1405
|
+
|
|
1253
1406
|
it('moves focus to the thread after deleting a reply, and announces a failure once', async () => {
|
|
1254
1407
|
const onDelete = vi
|
|
1255
1408
|
.fn()
|
|
@@ -1330,3 +1483,176 @@ describe('Comments keyboard and focus', () => {
|
|
|
1330
1483
|
).toHaveFocus();
|
|
1331
1484
|
});
|
|
1332
1485
|
});
|
|
1486
|
+
|
|
1487
|
+
describe('Comments status announcements (spec:AST-086)', () => {
|
|
1488
|
+
const FAILED_COMMENT = {
|
|
1489
|
+
id: 'failed',
|
|
1490
|
+
author: VIEWER,
|
|
1491
|
+
body: 'Kept text',
|
|
1492
|
+
createdAt: '2026-09-30T19:00:00Z',
|
|
1493
|
+
status: 'error' as const,
|
|
1494
|
+
errorMessage: "Couldn't post this comment.",
|
|
1495
|
+
};
|
|
1496
|
+
|
|
1497
|
+
it('announces a load failure once, assertively, and the Banner has no live role', async () => {
|
|
1498
|
+
const {rerender} = render(
|
|
1499
|
+
<Sized>
|
|
1500
|
+
<Comments comments={[]} loadError="Server unreachable" />
|
|
1501
|
+
</Sized>,
|
|
1502
|
+
);
|
|
1503
|
+
await flush();
|
|
1504
|
+
// Only the shared channel's own region is an alert; the Banner is not.
|
|
1505
|
+
expect(
|
|
1506
|
+
document.querySelectorAll(
|
|
1507
|
+
'[role="alert"]:not([data-astryx-live-region])',
|
|
1508
|
+
),
|
|
1509
|
+
).toHaveLength(0);
|
|
1510
|
+
expect(screen.getByText('Server unreachable')).toBeTruthy();
|
|
1511
|
+
expect(announce.mock.calls).toEqual([
|
|
1512
|
+
["Comments couldn't load Server unreachable", 'assertive'],
|
|
1513
|
+
]);
|
|
1514
|
+
|
|
1515
|
+
rerender(
|
|
1516
|
+
<Sized>
|
|
1517
|
+
<Comments comments={[]} loadError="Server unreachable" />
|
|
1518
|
+
</Sized>,
|
|
1519
|
+
);
|
|
1520
|
+
await flush();
|
|
1521
|
+
expect(announce).toHaveBeenCalledTimes(1);
|
|
1522
|
+
});
|
|
1523
|
+
|
|
1524
|
+
it('leaves an in-timeline failure to the chat log', async () => {
|
|
1525
|
+
render(
|
|
1526
|
+
<Sized>
|
|
1527
|
+
<Comments comments={[FAILED_COMMENT]} currentUser={VIEWER} />
|
|
1528
|
+
</Sized>,
|
|
1529
|
+
);
|
|
1530
|
+
const banner = bannerByData('data-comment-delivery-error');
|
|
1531
|
+
expect(banner.closest('[role="log"]')).not.toBeNull();
|
|
1532
|
+
expect(announce).not.toHaveBeenCalled();
|
|
1533
|
+
});
|
|
1534
|
+
|
|
1535
|
+
it('announces a failure itself when no chat log wraps it', async () => {
|
|
1536
|
+
render(
|
|
1537
|
+
<Sized>
|
|
1538
|
+
<Comments
|
|
1539
|
+
layout="embedded"
|
|
1540
|
+
comments={[FAILED_COMMENT]}
|
|
1541
|
+
currentUser={VIEWER}
|
|
1542
|
+
/>
|
|
1543
|
+
</Sized>,
|
|
1544
|
+
);
|
|
1545
|
+
const banner = bannerByData('data-comment-delivery-error');
|
|
1546
|
+
expect(banner.closest('[role="log"]')).toBeNull();
|
|
1547
|
+
expect(announce.mock.calls).toEqual([
|
|
1548
|
+
[expect.stringContaining("Couldn't post this comment."), 'assertive'],
|
|
1549
|
+
]);
|
|
1550
|
+
});
|
|
1551
|
+
|
|
1552
|
+
it('does not repeat a failure when a retry starts, and announces each failed retry', async () => {
|
|
1553
|
+
const onRetryComment = vi.fn().mockRejectedValue(new Error('offline'));
|
|
1554
|
+
render(
|
|
1555
|
+
<Sized>
|
|
1556
|
+
<Comments
|
|
1557
|
+
layout="embedded"
|
|
1558
|
+
comments={[FAILED_COMMENT]}
|
|
1559
|
+
currentUser={VIEWER}
|
|
1560
|
+
onRetryComment={onRetryComment}
|
|
1561
|
+
/>
|
|
1562
|
+
</Sized>,
|
|
1563
|
+
);
|
|
1564
|
+
await flush();
|
|
1565
|
+
const first = ["Couldn't post this comment.", 'assertive'];
|
|
1566
|
+
const failed = [
|
|
1567
|
+
"Couldn't post this comment. Retrying didn't work.",
|
|
1568
|
+
'assertive',
|
|
1569
|
+
];
|
|
1570
|
+
expect(announce.mock.calls).toEqual([first]);
|
|
1571
|
+
|
|
1572
|
+
const banner = () => bannerByData('data-comment-delivery-error');
|
|
1573
|
+
const retry = () => within(banner()).getByRole('button', {name: 'Retry'});
|
|
1574
|
+
await click(retry());
|
|
1575
|
+
await flush();
|
|
1576
|
+
expect(announce.mock.calls).toEqual([first, failed]);
|
|
1577
|
+
|
|
1578
|
+
// Starting a retry says nothing; its failure, a new occasion, speaks.
|
|
1579
|
+
await click(retry());
|
|
1580
|
+
await flush();
|
|
1581
|
+
expect(announce.mock.calls).toEqual([first, failed, failed]);
|
|
1582
|
+
});
|
|
1583
|
+
|
|
1584
|
+
it('does not repeat a failure when an unrelated post settles', async () => {
|
|
1585
|
+
let finishPost!: () => void;
|
|
1586
|
+
const onSubmit = vi.fn(() => new Promise<void>(r => (finishPost = r)));
|
|
1587
|
+
render(
|
|
1588
|
+
<Sized>
|
|
1589
|
+
<Comments
|
|
1590
|
+
layout="embedded"
|
|
1591
|
+
comments={[FAILED_COMMENT]}
|
|
1592
|
+
currentUser={VIEWER}
|
|
1593
|
+
onSubmit={onSubmit}
|
|
1594
|
+
renderComposer={renderComposer}
|
|
1595
|
+
/>
|
|
1596
|
+
</Sized>,
|
|
1597
|
+
);
|
|
1598
|
+
const composer = screen.getByRole('region', {name: 'New comment'});
|
|
1599
|
+
await click(within(composer).getByText('Set draft'));
|
|
1600
|
+
await click(within(composer).getByText('Submit composer'));
|
|
1601
|
+
await act(async () => finishPost());
|
|
1602
|
+
await flush();
|
|
1603
|
+
expect(announce.mock.calls).toEqual([
|
|
1604
|
+
["Couldn't post this comment.", 'assertive'],
|
|
1605
|
+
]);
|
|
1606
|
+
});
|
|
1607
|
+
|
|
1608
|
+
it('announces a comment still being written, politely, outside a chat log', async () => {
|
|
1609
|
+
render(
|
|
1610
|
+
<Sized>
|
|
1611
|
+
<Comments
|
|
1612
|
+
layout="embedded"
|
|
1613
|
+
comments={[
|
|
1614
|
+
{
|
|
1615
|
+
id: 'agent',
|
|
1616
|
+
author: AGENT,
|
|
1617
|
+
body: '',
|
|
1618
|
+
createdAt: '2026-09-30T19:00:00Z',
|
|
1619
|
+
progress: {label: 'Checking the rollout…'},
|
|
1620
|
+
},
|
|
1621
|
+
]}
|
|
1622
|
+
currentUser={VIEWER}
|
|
1623
|
+
/>
|
|
1624
|
+
</Sized>,
|
|
1625
|
+
);
|
|
1626
|
+
await flush();
|
|
1627
|
+
expect(announce.mock.calls).toEqual([['Checking the rollout…', 'polite']]);
|
|
1628
|
+
});
|
|
1629
|
+
|
|
1630
|
+
it('delivers a history failure through an alert slot that exists before the Banner', async () => {
|
|
1631
|
+
let rejectVersions!: (error: Error) => void;
|
|
1632
|
+
const loadVersions = vi.fn(
|
|
1633
|
+
() => new Promise<never>((_, reject) => (rejectVersions = reject)),
|
|
1634
|
+
);
|
|
1635
|
+
render(
|
|
1636
|
+
<Sized>
|
|
1637
|
+
<Comments comments={COMMENTS} loadVersions={loadVersions} />
|
|
1638
|
+
</Sized>,
|
|
1639
|
+
);
|
|
1640
|
+
await click(screen.getByRole('button', {name: 'View edit history'}));
|
|
1641
|
+
await flush();
|
|
1642
|
+
// While the history loads, the slot is already mounted, and empty.
|
|
1643
|
+
const slot = document.querySelector<HTMLElement>('dialog [role="alert"]');
|
|
1644
|
+
if (slot == null) {
|
|
1645
|
+
throw new Error('History alert slot not found while loading');
|
|
1646
|
+
}
|
|
1647
|
+
expect(slot.textContent).toBe('');
|
|
1648
|
+
|
|
1649
|
+
await act(async () => {
|
|
1650
|
+
rejectVersions(new Error('nope'));
|
|
1651
|
+
});
|
|
1652
|
+
await flush();
|
|
1653
|
+
// The failure lands in that slot; the Banner has no live role of its own.
|
|
1654
|
+
expect(document.querySelector('dialog [role="alert"]')).toBe(slot);
|
|
1655
|
+
expect(slot.textContent).toContain("Edit history couldn't load");
|
|
1656
|
+
expect(slot.querySelector('[role]')).toBeNull();
|
|
1657
|
+
});
|
|
1658
|
+
});
|
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
ErrorBanner,
|
|
45
45
|
} from './CommentParts';
|
|
46
46
|
import {CommentRow, THREAD_DIVIDERS, type ThreadDivider} from './CommentRow';
|
|
47
|
+
import {useStatusAnnouncement} from './useStatusAnnouncement';
|
|
47
48
|
import {
|
|
48
49
|
CommentsContextProvider,
|
|
49
50
|
useCommentsController,
|
|
@@ -249,6 +250,20 @@ export function Comments({
|
|
|
249
250
|
const loadingOlderRef = useRef(false);
|
|
250
251
|
const loadOlderButtonRef = useRef<HTMLButtonElement>(null);
|
|
251
252
|
const olderRetryRef = useRef<HTMLButtonElement>(null);
|
|
253
|
+
// The load-failure Banner carries no live role: it mounts already holding
|
|
254
|
+
// its text. It is announced once, assertively, through the shared channel
|
|
255
|
+
// (spec:AST-086 FR2, FR5).
|
|
256
|
+
const loadErrorRef = useRef<HTMLDivElement>(null);
|
|
257
|
+
useStatusAnnouncement(
|
|
258
|
+
loadErrorRef,
|
|
259
|
+
loadError != null
|
|
260
|
+
? t('@astryx.comments.errorAnnouncement', {
|
|
261
|
+
title: t('@astryx.comments.loadFailed'),
|
|
262
|
+
description: loadError,
|
|
263
|
+
})
|
|
264
|
+
: null,
|
|
265
|
+
'assertive',
|
|
266
|
+
);
|
|
252
267
|
const rootRef = useRef<HTMLElement | null>(null);
|
|
253
268
|
const setRootRef = useCallback(
|
|
254
269
|
(element: HTMLElement | null) => {
|
|
@@ -571,8 +586,8 @@ export function Comments({
|
|
|
571
586
|
)}>
|
|
572
587
|
{loadError != null && (
|
|
573
588
|
<Banner
|
|
589
|
+
ref={loadErrorRef}
|
|
574
590
|
status="error"
|
|
575
|
-
role="alert"
|
|
576
591
|
title={t('@astryx.comments.loadFailed')}
|
|
577
592
|
description={loadError}
|
|
578
593
|
container="section"
|
|
@@ -78,7 +78,12 @@ function editComposerContext(comment: AnyComment): CommentComposerContext {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/** A failed comment action and how to run it again. */
|
|
81
|
-
export type ActionFailure = {
|
|
81
|
+
export type ActionFailure = {
|
|
82
|
+
message: string;
|
|
83
|
+
retry?: () => void;
|
|
84
|
+
/** Already spoken by whoever raised it, so the row's Banner stays silent. */
|
|
85
|
+
isAnnounced?: boolean;
|
|
86
|
+
};
|
|
82
87
|
|
|
83
88
|
type FocusTarget = 'reply' | 'actions' | 'history' | 'article' | 'thread';
|
|
84
89
|
|
|
@@ -348,6 +353,9 @@ export function useCommentsController({
|
|
|
348
353
|
action: () => MaybePromise,
|
|
349
354
|
failureMessage: string,
|
|
350
355
|
retry?: () => void,
|
|
356
|
+
/** True when another owner announces this failure, so the row's banner
|
|
357
|
+
* stays silent from its first render. */
|
|
358
|
+
isAnnounced?: boolean,
|
|
351
359
|
): Promise<boolean> => {
|
|
352
360
|
setPendingActionIds(previous => new Set(previous).add(commentId));
|
|
353
361
|
clearActionError(commentId);
|
|
@@ -362,6 +370,7 @@ export function useCommentsController({
|
|
|
362
370
|
retry:
|
|
363
371
|
retry ??
|
|
364
372
|
(() => void runCommentAction(commentId, action, failureMessage)),
|
|
373
|
+
isAnnounced,
|
|
365
374
|
},
|
|
366
375
|
}));
|
|
367
376
|
return false;
|
|
@@ -480,6 +489,9 @@ export function useCommentsController({
|
|
|
480
489
|
t('@astryx.comments.deleteFailed'),
|
|
481
490
|
// Retrying a delete asks for confirmation again.
|
|
482
491
|
() => setDeleteTarget(target),
|
|
492
|
+
// The dialog announces a failed delete (AST-086 FR1, FR6), so the stored
|
|
493
|
+
// failure the row shows is marked before it first renders.
|
|
494
|
+
true,
|
|
483
495
|
);
|
|
484
496
|
if (succeeded) {
|
|
485
497
|
commitAndFocus(
|