|
1 | 1 | import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest'; |
2 | | -import { forceReload, forceCheckForUpdates, startVersionChecking, stopVersionChecking } from './versionChecker'; |
| 2 | +import { forceCheckForUpdates, startVersionChecking, stopVersionChecking } from './versionChecker'; |
3 | 3 |
|
4 | 4 | // Helper to mock fetch responses sequence |
5 | 5 | function mockFetchSequence(responses: Array<Response | Promise<Response>>) { |
@@ -81,44 +81,6 @@ describe('versionChecker', () => { |
81 | 81 | expect(window.alert).toHaveBeenCalled(); |
82 | 82 | }); |
83 | 83 |
|
84 | | - it('forceReload clears caches (when available), removes localStorage except allowlist, and updates href', async () => { |
85 | | - const cachesDelete = vi.fn(); |
86 | | - const cachesKeys = vi.fn().mockResolvedValue(['a', 'b']); |
87 | | - const cachesMock = { keys: cachesKeys, delete: cachesDelete }; |
88 | | - // @ts-expect-error assign |
89 | | - globalThis.caches = cachesMock; |
90 | | - // @ts-expect-error assign |
91 | | - window.caches = cachesMock; |
92 | | - |
93 | | - localStorage.setItem('debugMode', '1'); |
94 | | - localStorage.setItem('currentConnection', 'X'); |
95 | | - localStorage.setItem('loginSalt', 'Y'); |
96 | | - localStorage.setItem('removeMe', 'Z'); |
97 | | - |
98 | | - const swPost = vi.fn(); |
99 | | - // @ts-expect-error augment |
100 | | - navigator.serviceWorker = { controller: { postMessage: swPost } } as unknown as ServiceWorkerContainer; |
101 | | - |
102 | | - const originalHref = window.location.href; |
103 | | - |
104 | | - forceReload(); |
105 | | - // wait a microtask for caches.keys().then(...) to run |
106 | | - await Promise.resolve(); |
107 | | - |
108 | | - expect(cachesKeys).toHaveBeenCalled(); |
109 | | - expect(cachesDelete).toHaveBeenCalledTimes(2); |
110 | | - expect(swPost).toHaveBeenCalledWith({ type: 'CLEAR_CACHE' }); |
111 | | - |
112 | | - expect(localStorage.getItem('debugMode')).toBe('1'); |
113 | | - expect(localStorage.getItem('loginSalt')).toBe('Y'); |
114 | | - expect(localStorage.getItem('currentConnection')).toBe('X'); |
115 | | - |
116 | | - expect(localStorage.getItem('removeMe')).toBeNull(); |
117 | | - |
118 | | - expect(window.location.href).not.toBe(originalHref); |
119 | | - expect(window.location.href).toContain('_t='); |
120 | | - }); |
121 | | - |
122 | 84 | it('startVersionChecking stops interval when user declines reload', async () => { |
123 | 85 | mockFetchSequence([ |
124 | 86 | jsonResponse({ buildHash: 'v1' }), // init |
|
0 commit comments