- ContextSheet: add data-testid="context-sheet". longpress tests targeted the open sheet via the `.translate-y-0` animation class (breaks on any animation refactor) — now target `[data-testid="context-sheet"][aria-modal="true"]`, which is stable and unambiguous vs. the centered LightboxModal (also aria-modal). - toast-on-failure: the like button was `button.filter(hasText:/\d+/).first()`, which could match any digit-bearing button (e.g. the comment count) → use the stable aria-label "Gefällt mir". - config stats: assert the exact user_count (4 = 3 seeded guests + admin) instead of `>= 3` — deterministic after the per-test truncate, catches under/overcount. - offline-network 429 test: replace the fixed 3s waitForTimeout with a poll-until-the-retry-count-stabilizes (faster, and a real storm never stabilizes → the poll fails, which is the intended outcome). Note: reviewed the "config restore not in try/finally" finding — it's a non-issue. The truncate auto-fixture wipes+reseeds the whole config table (and clears the rate limiter) before every test, so config state cannot leak between tests. All affected specs verified green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
55 lines
2.3 KiB
TypeScript
55 lines
2.3 KiB
TypeScript
/**
|
|
* The toast store + <Toaster> primitive surfaces ApiError messages on
|
|
* user-initiated actions that previously failed silently (catch { ignore }).
|
|
* This spec intercepts the like POST and forces a 429 to assert the German
|
|
* error message reaches the user via the global toast region.
|
|
*/
|
|
import { test, expect } from '../../fixtures/test';
|
|
import { uploadRaw } from '../../helpers/upload-client';
|
|
import { readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
const SAMPLE_JPG = join(process.cwd(), 'fixtures', 'media', 'sample.jpg');
|
|
|
|
async function seedUpload(token: string): Promise<{ id: string }> {
|
|
const res = await uploadRaw(token, readFileSync(SAMPLE_JPG), {
|
|
filename: 'tf.jpg',
|
|
contentType: 'image/jpeg',
|
|
caption: 'Toast fixture',
|
|
});
|
|
if (res.status !== 201) throw new Error(`Upload seed failed (${res.status})`);
|
|
return (await res.json()) as { id: string };
|
|
}
|
|
|
|
test.describe('Feed — error toast on user action failures', () => {
|
|
test('like POST 429 surfaces a German error toast', async ({ page, guest, signIn }) => {
|
|
const author = await guest('ToastAuthor');
|
|
const liker = await guest('ToastLiker');
|
|
await seedUpload(author.jwt);
|
|
await signIn(page, liker);
|
|
|
|
// Intercept the like endpoint with a forced rate-limit response.
|
|
await page.route('**/api/v1/upload/*/like', (route) =>
|
|
route.fulfill({
|
|
status: 429,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ error: 'rate_limited', message: 'Zu viele Anfragen — bitte kurz warten.' }),
|
|
})
|
|
);
|
|
|
|
await page.goto('/feed');
|
|
const card = page.locator('article').filter({ hasText: author.displayName }).first();
|
|
await expect(card).toBeVisible({ timeout: 10_000 });
|
|
|
|
// Click the like button by its stable aria-label (the liker hasn't liked yet).
|
|
// Avoids matching a different digit-bearing button (e.g. the comment count).
|
|
await card.getByRole('button', { name: 'Gefällt mir' }).click();
|
|
|
|
// The toast is rendered inside the global Toaster region with aria-live="polite".
|
|
const toast = page.getByTestId('toast').first();
|
|
await expect(toast).toBeVisible({ timeout: 3_000 });
|
|
await expect(toast).toContainText(/Zu viele Anfragen/i);
|
|
await expect(toast).toHaveAttribute('data-toast-tone', 'error');
|
|
});
|
|
});
|