Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions client/src/components/ReviewForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
76 changes: 76 additions & 0 deletions client/src/components/ReviewForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<MockedProvider mocks={[{ request, result }]}>
<ReviewForm albumId="1" review={review} onChanged={onChanged} />
</MockedProvider>,
);

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) => {
Expand Down
98 changes: 80 additions & 18 deletions client/src/components/ReviewForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | null>(null);
const [refreshError, setRefreshError] = useState<string | null>(null);
const [status, setStatus] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
const statusRef = useRef<HTMLParagraphElement>(null);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -92,7 +136,10 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) {
onSubmit={(event) => void submit(event)}
>
<h3>{review ? 'Update your review' : 'Write a review'}</h3>
<fieldset disabled={busy} aria-describedby="review-rating-hint">
<fieldset
disabled={busy || Boolean(refreshError)}
aria-describedby="review-rating-hint"
>
<legend>Rating</legend>
<div className="review-form__ratings">
{[1, 2, 3, 4, 5].map((value) => (
Expand Down Expand Up @@ -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 && <p role="alert">{error}</p>}
{refreshError && (
<div className="review-form__refresh-error">
<p role="alert">{refreshError}</p>
<button
type="button"
className="secondary-button"
aria-disabled={busy}
onClick={() => {
if (!busy) void retryRefresh();
}}
>
Retry album refresh
</button>
</div>
)}
{status && (
<p ref={statusRef} role="status" aria-live="polite" tabIndex={-1}>
{status}
Expand All @@ -151,7 +213,7 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) {
<button
className="primary-button"
type="submit"
aria-disabled={busy || unchanged}
aria-disabled={busy || Boolean(refreshError) || unchanged}
>
{busy ? 'Saving…' : review ? 'Save changes' : 'Publish review'}
</button>
Expand All @@ -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
</button>
Expand Down
1 change: 1 addition & 0 deletions docs/AI-USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down