When the mailbox view gets into a stale or wrong state, the only escape was the browser's "clear site data" — which also wipes the saved account list, forcing a re-login of every account. Add a non-destructive "Refresh cached data" button under Settings → Data. It clears the server-derived caches (contacts, calendars, identities, per-account snapshots) and reloads so they re-fetch fresh, while preserving accounts, sessions, settings, themes and user content (templates, S/MIME). Two-click confirm to avoid an accidental reload. English strings added across all locales (translation follow-up); unit tests cover the cache-clear (keeps account-registry/auth/prefs) and the reload.
51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
|
import { clearCachedData } from '../clear-cached-data';
|
|
|
|
describe('clearCachedData', () => {
|
|
let reload: ReturnType<typeof vi.fn>;
|
|
let originalLocation: Location;
|
|
|
|
beforeEach(() => {
|
|
localStorage.clear();
|
|
reload = vi.fn();
|
|
originalLocation = window.location;
|
|
Object.defineProperty(window, 'location', {
|
|
configurable: true,
|
|
value: { ...originalLocation, reload },
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
Object.defineProperty(window, 'location', { configurable: true, value: originalLocation });
|
|
});
|
|
|
|
it('clears re-fetchable caches but keeps accounts, sessions and prefs', () => {
|
|
localStorage.setItem('contact-storage', '1');
|
|
localStorage.setItem('calendar-storage', '1');
|
|
localStorage.setItem('identity-storage', '1');
|
|
localStorage.setItem('calendar-notification-storage', '1');
|
|
// Must survive — losing these is exactly the pain we're avoiding.
|
|
localStorage.setItem('account-registry', 'accounts');
|
|
localStorage.setItem('auth-storage', 'session');
|
|
localStorage.setItem('settings-storage', 'prefs');
|
|
localStorage.setItem('template-storage', 'my templates');
|
|
|
|
clearCachedData();
|
|
|
|
expect(localStorage.getItem('contact-storage')).toBeNull();
|
|
expect(localStorage.getItem('calendar-storage')).toBeNull();
|
|
expect(localStorage.getItem('identity-storage')).toBeNull();
|
|
expect(localStorage.getItem('calendar-notification-storage')).toBeNull();
|
|
|
|
expect(localStorage.getItem('account-registry')).toBe('accounts');
|
|
expect(localStorage.getItem('auth-storage')).toBe('session');
|
|
expect(localStorage.getItem('settings-storage')).toBe('prefs');
|
|
expect(localStorage.getItem('template-storage')).toBe('my templates');
|
|
});
|
|
|
|
it('reloads so data is re-fetched fresh', () => {
|
|
clearCachedData();
|
|
expect(reload).toHaveBeenCalledOnce();
|
|
});
|
|
});
|