- 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>
96 lines
3.5 KiB
TypeScript
96 lines
3.5 KiB
TypeScript
/**
|
|
* Phase 2 browser chaos — going offline, coming back, and throttled
|
|
* connections. The app's upload queue is expected to "park" pending
|
|
* items on offline and resume on reconnect.
|
|
*/
|
|
import { test, expect } from '../../fixtures/test';
|
|
|
|
test.describe('Browser chaos — network', () => {
|
|
test('offline → reconnect — page does not crash and bottom nav is responsive', async ({ page, guest, signIn }) => {
|
|
const g = await guest('Offline1');
|
|
await signIn(page, g);
|
|
await page.goto('/feed');
|
|
|
|
const errors: Error[] = [];
|
|
page.on('pageerror', (e) => errors.push(e));
|
|
|
|
await page.context().setOffline(true);
|
|
// Tap the bottom nav — should not raise unhandled errors.
|
|
await page.getByRole('link', { name: 'Konto' }).click().catch(() => {});
|
|
await page.waitForTimeout(500);
|
|
await page.context().setOffline(false);
|
|
|
|
// App still functional after coming back.
|
|
await page.goto('/feed');
|
|
await expect(page.getByRole('link', { name: 'Galerie' })).toBeVisible();
|
|
|
|
expect(errors.filter((e) => !e.message.toLowerCase().includes('fetch'))).toHaveLength(0);
|
|
});
|
|
|
|
test('slow 3G simulation — initial nav completes within reasonable bound', async ({ page, guest, signIn }) => {
|
|
const g = await guest('Slow3g');
|
|
|
|
// 50ms latency on every request, applied to /api/* only so navigation isn't catastrophic.
|
|
await page.route('**/api/v1/**', async (route) => {
|
|
await new Promise((r) => setTimeout(r, 50));
|
|
await route.continue();
|
|
});
|
|
|
|
await signIn(page, g);
|
|
await page.goto('/feed');
|
|
await expect(page.getByRole('link', { name: 'Galerie' })).toBeVisible({ timeout: 15_000 });
|
|
});
|
|
|
|
test('intermittent API failures during navigation — UI surfaces an error state', async ({ page, guest, signIn }) => {
|
|
const g = await guest('FlakyApi');
|
|
|
|
let count = 0;
|
|
await page.route('**/api/v1/me/context', async (route) => {
|
|
count++;
|
|
if (count % 2 === 1) await route.fulfill({ status: 503, body: 'service unavailable' });
|
|
else await route.continue();
|
|
});
|
|
|
|
await signIn(page, g);
|
|
await page.goto('/feed');
|
|
// App should still mount even when /me/context bounces — it's not on the critical render path.
|
|
await expect(page.getByRole('link', { name: 'Galerie' })).toBeVisible({ timeout: 10_000 });
|
|
});
|
|
|
|
test('429 from server is surfaced (no infinite retry storm)', async ({ page, guest, signIn }) => {
|
|
const g = await guest('Throttled');
|
|
|
|
let attempts = 0;
|
|
await page.route('**/api/v1/feed', async (route) => {
|
|
attempts++;
|
|
await route.fulfill({
|
|
status: 429,
|
|
headers: { 'retry-after': '60' },
|
|
body: JSON.stringify({ error: 'rate_limited', message: 'Zu viele Anfragen.' }),
|
|
});
|
|
});
|
|
|
|
await signIn(page, g);
|
|
await page.goto('/feed');
|
|
|
|
// Wait until the retry count stops climbing instead of sleeping a fixed 3s: a
|
|
// well-behaved client surfaces the 429 and stops, so the count settles quickly;
|
|
// a retry storm would keep incrementing and never stabilize (→ this poll times
|
|
// out and the test fails, which is the outcome we want).
|
|
let prev = -1;
|
|
await expect
|
|
.poll(
|
|
() => {
|
|
const stable = attempts === prev;
|
|
prev = attempts;
|
|
return stable;
|
|
},
|
|
{ timeout: 8_000, intervals: [300] }
|
|
)
|
|
.toBe(true);
|
|
|
|
// Sanity: client did not hammer the endpoint > a few times under throttle.
|
|
expect(attempts, `retry attempts=${attempts}`).toBeLessThan(15);
|
|
});
|
|
});
|