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.
94 lines
3.5 KiB
TypeScript
94 lines
3.5 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { ACCOUNTS } from './helpers/config';
|
|
import { sendMail } from './helpers/smtp';
|
|
import { JmapClient } from './helpers/jmap';
|
|
import {
|
|
login,
|
|
addAccount,
|
|
switchAccount,
|
|
accountSwitcher,
|
|
seedUnifiedSettings,
|
|
folderRow,
|
|
expectFolderUnread,
|
|
expectFolderCountsSynced,
|
|
} from './helpers/app';
|
|
|
|
/**
|
|
* Multi-account synchronisation — the account-scoped Unified Mailbox.
|
|
*
|
|
* Covers the two failure modes that dog multi-account webmail: counters
|
|
* bleeding between accounts, and the cross-account unified view mis-aggregating
|
|
* (or not updating when a background account receives mail).
|
|
*/
|
|
const { alice, bob } = ACCOUNTS;
|
|
|
|
let seq = 0;
|
|
const subj = (l: string) => `IT ${l} ${Date.now()}-${seq++}`;
|
|
|
|
async function send(to: typeof alice, subject: string) {
|
|
await sendMail({ from: to.email, authPass: to.password, to: to.email, subject, body: 'x' });
|
|
}
|
|
|
|
test.describe('Multi-account sync', () => {
|
|
test.beforeEach(async () => {
|
|
for (const a of [alice, bob]) {
|
|
const j = await JmapClient.connect(a.email, a.password);
|
|
await j.reset();
|
|
}
|
|
});
|
|
|
|
test('both accounts connect and their Inbox counters stay isolated', async ({ page }) => {
|
|
// Pre-seed: two unread for alice, one for bob.
|
|
await send(alice, subj('iso-a1'));
|
|
await send(alice, subj('iso-a2'));
|
|
await send(bob, subj('iso-b1'));
|
|
|
|
await login(page, alice);
|
|
// Active = alice: her own Inbox shows 2 unread.
|
|
await expectFolderUnread(page, { role: 'inbox', name: 'Inbox' }, 2);
|
|
|
|
await addAccount(page, bob);
|
|
// Both accounts are now registered in the switcher.
|
|
await accountSwitcher(page).click();
|
|
await expect(page.locator('[data-testid="account-option"]')).toHaveCount(2);
|
|
await page.keyboard.press('Escape');
|
|
|
|
// Active = bob: his own Inbox shows 1 unread — alice's 2 don't leak in.
|
|
await expectFolderCountsSynced(page, { role: 'inbox', name: 'Inbox' }, { unread: 1 });
|
|
|
|
// Switch back to alice: her count is intact.
|
|
await switchAccount(page, alice.email);
|
|
await expectFolderCountsSynced(page, { role: 'inbox', name: 'Inbox' }, { unread: 2 });
|
|
});
|
|
|
|
test('the cross-account Unified Inbox aggregates unread across accounts', async ({ page }) => {
|
|
await send(alice, subj('agg-a'));
|
|
await send(bob, subj('agg-b'));
|
|
|
|
await seedUnifiedSettings(page);
|
|
await login(page, alice);
|
|
await addAccount(page, bob);
|
|
|
|
// Unified Inbox = alice(1) + bob(1) = 2. The active account's own Inbox
|
|
// (bob) still reports just its own 1.
|
|
await expect(folderRow(page, { name: 'unified-inbox' }).first()).toBeVisible();
|
|
await expectFolderCountsSynced(page, { name: 'unified-inbox' }, { unread: 2, total: 2 });
|
|
await expectFolderCountsSynced(page, { role: 'inbox', name: 'Inbox' }, { unread: 1 });
|
|
});
|
|
|
|
test('a delivery to a background account bumps the Unified Inbox counter', async ({ page }) => {
|
|
await seedUnifiedSettings(page);
|
|
await login(page, alice);
|
|
await addAccount(page, bob); // bob is now the active account
|
|
await expectFolderCountsSynced(page, { name: 'unified-inbox' }, { unread: 0 });
|
|
|
|
// Mail lands in alice's inbox while bob is the active account.
|
|
await send(alice, subj('bg'));
|
|
|
|
// The unified counter reflects the background account's new mail.
|
|
await expectFolderCountsSynced(page, { name: 'unified-inbox' }, { unread: 1 });
|
|
// bob (active) own Inbox is unaffected.
|
|
await expectFolderCountsSynced(page, { role: 'inbox', name: 'Inbox' }, { unread: 0 });
|
|
});
|
|
});
|