diff --git a/client/src/components/ReviewForm.css b/client/src/components/ReviewForm.css index 714f28d..91985af 100644 --- a/client/src/components/ReviewForm.css +++ b/client/src/components/ReviewForm.css @@ -75,6 +75,15 @@ margin: 0.4rem 0 0; text-align: right; } +.review-form__refresh-error { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.5rem 0.75rem; +} +.review-form__refresh-error p { + margin: 0; +} .review-form__actions { display: flex; flex-wrap: wrap; diff --git a/client/src/components/ReviewForm.test.tsx b/client/src/components/ReviewForm.test.tsx index 040dc4b..ee0f923 100644 --- a/client/src/components/ReviewForm.test.tsx +++ b/client/src/components/ReviewForm.test.tsx @@ -251,6 +251,87 @@ it('deletes an existing review and clears the form', async () => { expect(screen.queryByRole('radio', { checked: true })).not.toBeInTheDocument(); }); +it.each(['publish', 'update', 'delete'])( + 'reports a successful %s when album refresh fails and retries only the refresh', + async (action) => { + const comment = 'Saved comment'; + const request = + action === 'delete' + ? { query: DELETE_REVIEW, variables: { id: 'r1' } } + : { + query: UPSERT_REVIEW, + variables: { input: { albumId: '1', rating: 4, comment } }, + }; + const result = vi.fn(() => ({ + data: + action === 'delete' + ? { deleteReview: { deletedReviewId: 'r1', album: { id: '1' } } } + : { + upsertReview: { + review: { id: 'r1', rating: 4, comment }, + album: { id: '1' }, + }, + }, + })); + const onChanged = vi + .fn() + .mockRejectedValueOnce(new Error('Refresh failed')) + .mockResolvedValueOnce({}); + const review = + action === 'publish' + ? null + : { id: 'r1', rating: action === 'update' ? 2 : 4, comment: 'Before' }; + + render( + + + , + ); + + if (action !== 'delete') { + fireEvent.click(screen.getByRole('radio', { name: '4 stars' })); + fireEvent.change(screen.getByRole('textbox'), { target: { value: comment } }); + } + const actionButton = screen.getByRole('button', { + name: + action === 'publish' + ? 'Publish review' + : action === 'update' + ? 'Save changes' + : 'Delete review', + }); + fireEvent.click(actionButton); + + expect(await screen.findByRole('status')).toHaveTextContent( + action === 'publish' + ? 'Your review was published.' + : action === 'update' + ? 'Your review was updated.' + : 'Your review was deleted.', + ); + expect(await screen.findByRole('alert')).toHaveTextContent( + action === 'delete' + ? 'Your review was deleted, but album details could not be refreshed.' + : `${action === 'publish' ? 'Your review was published.' : 'Your review was updated.'} Album details could not be refreshed.`, + ); + expect(screen.getByRole('button', { name: 'Retry album refresh' })).toBeVisible(); + + // Activating the aria-disabled submit/delete control must not re-fire the mutation. + expect(actionButton).toHaveAttribute('aria-disabled', 'true'); + fireEvent.click(actionButton); + if (action !== 'delete') fireEvent.submit(actionButton.closest('form')!); + expect(result).toHaveBeenCalledOnce(); + + fireEvent.click(screen.getByRole('button', { name: 'Retry album refresh' })); + await waitFor(() => expect(onChanged).toHaveBeenCalledTimes(2)); + expect(await screen.findByRole('status')).toHaveTextContent( + 'Album details were refreshed.', + ); + expect(result).toHaveBeenCalledOnce(); + expect(screen.queryByRole('alert')).not.toBeInTheDocument(); + }, +); + it.each(['publish', 'update', 'delete'])( 'keeps keyboard focus after a %s error and allows retry', async (action) => { diff --git a/client/src/components/ReviewForm.tsx b/client/src/components/ReviewForm.tsx index af8f9da..ac1defe 100644 --- a/client/src/components/ReviewForm.tsx +++ b/client/src/components/ReviewForm.tsx @@ -18,6 +18,7 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { const [rating, setRating] = useState(review?.rating ?? 0); const [comment, setComment] = useState(review?.comment ?? ''); const [error, setError] = useState(null); + const [refreshError, setRefreshError] = useState(null); const [status, setStatus] = useState(null); const [busy, setBusy] = useState(false); const statusRef = useRef(null); @@ -39,7 +40,7 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { async function submit(event: React.FormEvent) { event.preventDefault(); - if (mutationInFlight.current || unchanged) return; + if (mutationInFlight.current || unchanged || refreshError) return; if (rating < 1 || rating > 5) { setError('Choose a rating from 1 to 5 stars.'); return; @@ -48,15 +49,30 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { mutationInFlight.current = true; setBusy(true); setError(null); + setRefreshError(null); setStatus(null); try { - await saveReview({ variables: { input: { albumId, rating, comment } } }); - await onChanged(); - announce(review ? 'Your review was updated.' : 'Your review was published.'); - } catch (caught) { - setError( - caught instanceof Error ? caught.message : 'Your review could not be saved.', - ); + try { + await saveReview({ variables: { input: { albumId, rating, comment } } }); + } catch (caught) { + setError( + caught instanceof Error ? caught.message : 'Your review could not be saved.', + ); + return; + } + + const successMessage = review + ? 'Your review was updated.' + : 'Your review was published.'; + try { + await onChanged(); + announce(successMessage); + } catch { + setRefreshError( + `${successMessage} Album details could not be refreshed. Try again to update them.`, + ); + announce(successMessage); + } } finally { mutationInFlight.current = false; setBusy(false); @@ -64,21 +80,49 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { } async function remove() { - if (!review || mutationInFlight.current) return; + if (!review || mutationInFlight.current || refreshError) return; mutationInFlight.current = true; setBusy(true); setError(null); + setRefreshError(null); setStatus(null); try { - await deleteReview({ variables: { id: review.id } }); - await onChanged(); + try { + await deleteReview({ variables: { id: review.id } }); + } catch (caught) { + setError( + caught instanceof Error ? caught.message : 'Your review could not be deleted.', + ); + return; + } + setRating(0); setComment(''); - announce('Your review was deleted.'); - } catch (caught) { - setError( - caught instanceof Error ? caught.message : 'Your review could not be deleted.', - ); + try { + await onChanged(); + announce('Your review was deleted.'); + } catch { + setRefreshError( + 'Your review was deleted, but album details could not be refreshed. Try again to update them.', + ); + announce('Your review was deleted.'); + } + } finally { + mutationInFlight.current = false; + setBusy(false); + } + } + + async function retryRefresh() { + if (!refreshError || mutationInFlight.current) return; + mutationInFlight.current = true; + setBusy(true); + try { + await onChanged(); + setRefreshError(null); + announce('Album details were refreshed.'); + } catch { + // Keep the existing message and retry button available. } finally { mutationInFlight.current = false; setBusy(false); @@ -92,7 +136,10 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { onSubmit={(event) => void submit(event)} >

{review ? 'Update your review' : 'Write a review'}

-
+
Rating
{[1, 2, 3, 4, 5].map((value) => ( @@ -137,7 +184,7 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { id="review-comment" value={comment} onChange={(event) => setComment(event.target.value)} - disabled={busy} + disabled={busy || Boolean(refreshError)} maxLength={MAX_COMMENT_LENGTH} rows={4} aria-describedby="review-comment-counter" @@ -147,6 +194,21 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { {MAX_COMMENT_LENGTH.toLocaleString('en-US')} characters

{error &&

{error}

} + {refreshError && ( +
+

{refreshError}

+ +
+ )} {status && (

{status} @@ -156,7 +218,7 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { @@ -165,7 +227,7 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { type="button" className="secondary-button" onClick={() => void remove()} - aria-disabled={busy} + aria-disabled={busy || Boolean(refreshError)} > Delete review diff --git a/docs/AI-USAGE.md b/docs/AI-USAGE.md index 93db65c..2aa9180 100644 --- a/docs/AI-USAGE.md +++ b/docs/AI-USAGE.md @@ -113,6 +113,7 @@ the part that matters most. | 2026-11-22 | erikhfj | Antigravity | #107, documented the team's AI task delegation, verification, and review workflow in `docs/AI-USAGE.md`, reflecting actual practices across all four contributors and complementing #97's prompt-context section. Verified with `pnpm format:check && pnpm lint && pnpm typecheck && pnpm test`. | | 2026-11-23 | robertky | Codex (ChatGPT) | #94: Added an accessible character count for review comments, linked it to the textarea without live announcements on every keystroke, and added component tests. Verified with `pnpm format:check`, `pnpm lint`, `pnpm typecheck`, `pnpm test`, and `pnpm build`. | | 2026-11-23 | robertky | Codex (ChatGPT) | #121: Preserved the visible search page count and scroll position when opening an album, then restored the saved result pages on return. Added state and pagination regression tests. | +| 2026-11-23 | robertky | Codex (ChatGPT) | #122: Split review mutation failures from album refresh failures, added a refresh-only retry, and tested publish, update, and delete behavior. | | 2026-11-23 | robertky | Codex (ChatGPT) | #104 review follow-up: combined the side drawer with the merged country preview, added backdrop dismissal and a keyboard focus loop, corrected the results-status test matcher and component documentation, and expanded the Playwright filter journey. Verified with `pnpm format:check`, `pnpm lint`, `pnpm typecheck`, `pnpm test`, `pnpm build`, and `pnpm test:e2e` against an isolated seeded PostgreSQL database. | ## Task delegation and verification workflow