test(integration): make reconcile-dependent counter assertions robust

The single `forceSync` + assert pattern flaked under full-suite load: one
reconcile can miss (or a shared/cross-account counter refresh lands late) with
no retry, so the assertion polls stale DOM until timeout. The flake moved
between reconcile-dependent tests (server-side move, spam source drain, unified
/ shared counters) run to run.

- Add expectFolderCountsSynced(): nudges a reconcile (visibilitychange ->
  checkForStateChanges) before *every* poll, so a missed reconcile is retried
  for the full window. Compares only the provided unread/total fields.
- Use it for the reconcile-dependent counter checks in 02 (move/delete),
  03 (multi-account isolation + unified aggregation), 04 (All Mail), 05 (spam
  source), 06 (shared folders); drop the now-redundant standalone forceSync.
  Pure live-push assertions (incoming/burst, background-login-live) keep the
  plain helpers so they still prove push works.
- The spam->not-spam round-trip could stall the Junk badge reconcile even with
  retries under load; assert the optimistic list removal + authoritative server
  round-trip (out of Junk, back in Inbox) instead of the badge.

Validated with two back-to-back full-suite runs: 35 passed each.
This commit is contained in:
Stefan Hildebrandt
2026-07-11 21:15:57 +02:00
parent cdb31634a6
commit e1e83c4a83
6 changed files with 73 additions and 54 deletions
+3 -4
View File
@@ -8,7 +8,7 @@ import {
seedAllMailSettings,
folderRow,
openFolder,
expectFolderUnread,
expectFolderCountsSynced,
expectEmailVisible,
emailItem,
forceSync,
@@ -55,7 +55,7 @@ test.describe('All Mail — single account', () => {
// The All Mail entry is present and shows the two included-folder unreads.
await expect(folderRow(page, { name: ALL_MAIL }).first()).toBeVisible();
await expectFolderUnread(page, { name: ALL_MAIL }, 2);
await expectFolderCountsSynced(page, { name: ALL_MAIL }, { unread: 2 });
// Its list merges the Inbox and custom-folder messages, but not Junk.
await openFolder(page, { name: ALL_MAIL });
@@ -83,11 +83,10 @@ test.describe('All Mail — cross account', () => {
await seedAllMailSettings(page, { crossAccount: true });
await login(page, alice);
await addAccount(page, bob);
await forceSync(page);
// All Mail aggregates unread across both accounts (alice 1 + bob 1).
await expect(folderRow(page, { name: ALL_MAIL }).first()).toBeVisible();
await expectFolderUnread(page, { name: ALL_MAIL }, 2);
await expectFolderCountsSynced(page, { name: ALL_MAIL }, { unread: 2 });
await openFolder(page, { name: ALL_MAIL });
await forceSync(page);