From 4adb4b60e1f9cbd28e10aa0e90e895a62559dce9 Mon Sep 17 00:00:00 2001 From: Robert Andreas Kyllo Date: Mon, 23 Nov 2026 13:35:34 +0100 Subject: [PATCH 1/2] fix: #122 separate review and refresh errors --- client/src/components/ReviewForm.css | 9 +++ client/src/components/ReviewForm.test.tsx | 76 ++++++++++++++++++ client/src/components/ReviewForm.tsx | 98 ++++++++++++++++++----- docs/AI-USAGE.md | 1 + 4 files changed, 166 insertions(+), 18 deletions(-) diff --git a/client/src/components/ReviewForm.css b/client/src/components/ReviewForm.css index 1367d6e..aefc73e 100644 --- a/client/src/components/ReviewForm.css +++ b/client/src/components/ReviewForm.css @@ -69,6 +69,15 @@ min-width: 0; max-width: 100%; } +.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 57f7165..296dc58 100644 --- a/client/src/components/ReviewForm.test.tsx +++ b/client/src/components/ReviewForm.test.tsx @@ -230,6 +230,82 @@ 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 } }); + } + fireEvent.click( + screen.getByRole('button', { + name: + action === 'publish' + ? 'Publish review' + : action === 'update' + ? 'Save changes' + : 'Delete review', + }), + ); + + 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(); + + 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 902160b..6e342ac 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); @@ -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); @@ -68,17 +84,45 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { 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,11 +184,26 @@ 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} /> {error &&

{error}

} + {refreshError && ( +
+

{refreshError}

+ +
+ )} {status && (

{status} @@ -151,7 +213,7 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) { @@ -160,7 +222,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 5a9659f..b041961 100644 --- a/docs/AI-USAGE.md +++ b/docs/AI-USAGE.md @@ -109,6 +109,7 @@ the part that matters most. | 2026-11-22 | evenkkl | Claude | #96, skip count and facet queries on Load more: Claude made the search aggregates lazy `AlbumConnection` field resolvers, added a `SearchAlbumsPage` query for Load more, kept page one's count and facets in the Apollo merge, and added server and client tests. Verified with lint, typecheck, the test suites and the PostgreSQL tests on PGlite. | | 2026-11-22 | erikhfj | Antigravity | #117, stabilized `ReviewForm.test.tsx`: traced the intermittent CI failure (run `88055`) to `findByRole('status')` resolving via `MutationObserver` before React's passive `useEffect` focused `statusRef`, and wrapped the status focus assertions in `waitFor`. Verified with 10 consecutive test runs plus `pnpm format:check && pnpm lint && pnpm typecheck && pnpm test`. | | 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) | #122: Split review mutation failures from album refresh failures, added a refresh-only retry, and tested publish, update, and delete behavior. | ## Task delegation and verification workflow From d2e7481a2641c80214cc8ff4056d3f076c9c98de Mon Sep 17 00:00:00 2001 From: Erik Hjelm Fjeldheim Date: Mon, 23 Nov 2026 14:19:51 -0600 Subject: [PATCH 2/2] fix: #122 block submit and delete while refresh error is active --- client/src/components/ReviewForm.test.tsx | 27 ++++++++++++++--------- client/src/components/ReviewForm.tsx | 4 ++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/client/src/components/ReviewForm.test.tsx b/client/src/components/ReviewForm.test.tsx index b138795..ee0f923 100644 --- a/client/src/components/ReviewForm.test.tsx +++ b/client/src/components/ReviewForm.test.tsx @@ -283,7 +283,7 @@ it.each(['publish', 'update', 'delete'])( : { id: 'r1', rating: action === 'update' ? 2 : 4, comment: 'Before' }; render( - + , ); @@ -292,16 +292,15 @@ it.each(['publish', 'update', 'delete'])( fireEvent.click(screen.getByRole('radio', { name: '4 stars' })); fireEvent.change(screen.getByRole('textbox'), { target: { value: comment } }); } - fireEvent.click( - screen.getByRole('button', { - name: - action === 'publish' - ? 'Publish review' - : action === 'update' - ? 'Save changes' - : 'Delete review', - }), - ); + 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' @@ -317,6 +316,12 @@ it.each(['publish', 'update', 'delete'])( ); 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( diff --git a/client/src/components/ReviewForm.tsx b/client/src/components/ReviewForm.tsx index f516985..ac1defe 100644 --- a/client/src/components/ReviewForm.tsx +++ b/client/src/components/ReviewForm.tsx @@ -40,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; @@ -80,7 +80,7 @@ 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);