test(e2e): robustness — stable locators, exact assertions, no fixed sleep

- 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>
This commit is contained in:
fabi
2026-07-01 19:24:03 +02:00
parent 104c3dde16
commit 564104ae23
5 changed files with 33 additions and 17 deletions

View File

@@ -72,9 +72,24 @@ test.describe('Browser chaos — network', () => {
await signIn(page, g);
await page.goto('/feed');
await page.waitForTimeout(3_000);
// 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).toBeLessThan(15);
expect(attempts, `retry attempts=${attempts}`).toBeLessThan(15);
});
});