Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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;
Expand Down
81 changes: 81 additions & 0 deletions client/src/components/ReviewForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<MockedProvider mocks={[{ request, result, maxUsageCount: 2 }]}>
<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 } });
}
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) => {
Expand Down
102 changes: 82 additions & 20 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 All @@ -39,7 +40,7 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) {

async function submit(event: React.FormEvent<HTMLFormElement>) {
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;
Expand All @@ -48,37 +49,80 @@ 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);
}
}

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);
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,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"
Expand All @@ -147,6 +194,21 @@ export default function ReviewForm({ albumId, review, onChanged }: Props) {
{MAX_COMMENT_LENGTH.toLocaleString('en-US')} characters
</p>
{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 @@ -156,7 +218,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 @@ -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
</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 @@ -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
Expand Down