Files
windmill/frontend/src/lib/logout.test.ts
Ruben FiszelandClaude Opus 5.5 0ac2b61034 perf: paint a snapshot of the last home in place of the boot splash (#12158)
* perf: paint home from a per-user persisted cache while it refreshes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep a cached first page from offering load more after a failed refresh

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: drop expired cache entries from disk when hydrating

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf: render home as the last confirmed user while whoami is in flight

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf: hydrate the home cache at boot; file answers only under their session

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf: paint home's cached data in its first frame from a synchronous snapshot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: show nothing rather than 'Loading user...' while rendering as the remembered user

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: bind the cache identity to the session that confirmed the tab's user

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: record the session confirmation before setting the user, so the cache hydrates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: cache immutable chunks on the cloudflare pages previews

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf: keep the cache snapshot's small entries when a large one exceeds its cap

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf: paint a snapshot of the last home in place of the boot splash

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: clean the home snapshot when painted and cache favorites for its hand-over

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: make home's first live frame match its boot snapshot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: save the home snapshot with its boot stylesheets and through keyboard reloads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 03:53:05 +01:00

53 lines
1.6 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('./onboardingProfile', () => ({ noteSessionEmail: vi.fn() }))
vi.mock('./components/sidebar/accountSetup.svelte', () => ({
accountSetup: { reset: vi.fn() }
}))
vi.mock('./storeUtils', () => ({ clearStores: vi.fn() }))
vi.mock('$lib/gen', () => ({ UserService: { logout: vi.fn(async () => {}) } }))
import { clearUser } from './logout'
describe('clearUser', () => {
beforeEach(() => {
sessionStorage.clear()
localStorage.clear()
vi.clearAllMocks()
})
it('drops credential-bearing localStorage entries and keeps preferences', async () => {
const credentialKeys = ['oauth-callback', 'mcp-oauth-callback', 'test_dev_token']
for (const key of credentialKeys) {
localStorage.setItem(key, 'a-token')
}
localStorage.setItem('dark-mode', 'true')
await clearUser()
for (const key of credentialKeys) {
expect(localStorage.getItem(key)).toBeNull()
}
expect(localStorage.getItem('dark-mode')).toBe('true')
})
it("drops the Home snapshot app.html would paint", async () => {
localStorage.setItem('wm-home-snapshot', '{}')
await clearUser()
expect(localStorage.getItem('wm-home-snapshot')).toBeNull()
})
// Logging out while impersonating must not leave the impersonator's own token behind.
it('drops the impersonation token backup', async () => {
sessionStorage.setItem('pre_impersonation_token', 'a-token')
sessionStorage.setItem('pre_impersonation_email', 'admin@windmill.dev')
await clearUser()
expect(sessionStorage.getItem('pre_impersonation_token')).toBeNull()
expect(sessionStorage.getItem('pre_impersonation_email')).toBeNull()
})
})