mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 08:13:50 +00:00
After a load the logins other than the one on screen reconnect in the background, and until they are all back the unified counts cover only some of them. With many logins that lasts seconds, and a partial total looks exactly like the whole one. While that restore runs, the "All accounts" header shows how many logins are already in the scope, e.g. "4/10", with a translated label for screen readers. It goes away when the scope is complete or the restore is over - a login that failed to reconnect does not keep it up. `restoringAccounts` in the auth store marks the background restore; the count itself is a pure function with its own tests.
38 lines
2.1 KiB
TypeScript
38 lines
2.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { unifiedLoadProgress } from '@/lib/unified-mailbox';
|
|
|
|
// While a browser restores its logins the unified counts cover only the ones
|
|
// already back. The sidebar says how many, so a partial total is not read as
|
|
// the whole - and stops saying it the moment the restore is over.
|
|
const scope = (...ids: string[]) => ids.map((id) => ({ clientAccountId: id, isShared: false }));
|
|
const accounts = (n: number, failed = 0) =>
|
|
Array.from({ length: n }, (_, i) => ({ hasError: i < failed }));
|
|
|
|
describe('unifiedLoadProgress', () => {
|
|
it('counts the logins already in the scope against those expected', () => {
|
|
expect(unifiedLoadProgress({ crossAccountActive: true, restoring: true, scope: scope('a', 'b', 'c', 'd'), accounts: accounts(10) }))
|
|
.toEqual({ loaded: 4, total: 10 });
|
|
});
|
|
|
|
it('leaves out logins whose restore failed', () => {
|
|
expect(unifiedLoadProgress({ crossAccountActive: true, restoring: true, scope: scope('a', 'b'), accounts: accounts(4, 1) }))
|
|
.toEqual({ loaded: 2, total: 3 });
|
|
});
|
|
|
|
it('counts a login once however many shared owners it brings', () => {
|
|
const withShared = [...scope('a'), { clientAccountId: 'a', isShared: true }, { clientAccountId: 'a', isShared: true }];
|
|
expect(unifiedLoadProgress({ crossAccountActive: true, restoring: true, scope: withShared, accounts: accounts(3) }))
|
|
.toEqual({ loaded: 1, total: 3 });
|
|
});
|
|
|
|
it('says nothing once the scope is complete, the restore is over, or there is one login', () => {
|
|
expect(unifiedLoadProgress({ crossAccountActive: true, restoring: true, scope: scope('a', 'b'), accounts: accounts(2) })).toBeNull();
|
|
expect(unifiedLoadProgress({ crossAccountActive: true, restoring: false, scope: scope('a'), accounts: accounts(5) })).toBeNull();
|
|
expect(unifiedLoadProgress({ crossAccountActive: true, restoring: true, scope: [], accounts: accounts(1) })).toBeNull();
|
|
});
|
|
|
|
it('says nothing when the unified mailbox stays within one login', () => {
|
|
expect(unifiedLoadProgress({ crossAccountActive: false, restoring: true, scope: scope('a'), accounts: accounts(5) })).toBeNull();
|
|
});
|
|
});
|