From 766cc1b43e251db2f166073d2a173ebd2d2cbd5f Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Thu, 26 Feb 2026 21:48:55 +0700 Subject: [PATCH] refactor(ui): remove unused last-route restore helpers --- ui/src/lib/last-route.ts | 28 -------------------- ui/tests/unit/ui/lib/last-route.test.ts | 34 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 ui/tests/unit/ui/lib/last-route.test.ts diff --git a/ui/src/lib/last-route.ts b/ui/src/lib/last-route.ts index 26589822..a071f7b7 100644 --- a/ui/src/lib/last-route.ts +++ b/ui/src/lib/last-route.ts @@ -1,5 +1,4 @@ const LAST_ROUTE_STORAGE_KEY = 'ccs-dashboard:last-route'; -const NON_RESTORABLE_PATHS = new Set(['/login']); export function storeLastRoute(pathname: string, search = '', hash = ''): void { try { @@ -8,30 +7,3 @@ export function storeLastRoute(pathname: string, search = '', hash = ''): void { // Ignore storage failures (private mode, quota, etc.) } } - -export function getStoredLastRoute(): string | null { - try { - const route = localStorage.getItem(LAST_ROUTE_STORAGE_KEY); - if (!route || !route.startsWith('/')) { - return null; - } - - const pathOnly = route.split(/[?#]/, 1)[0]; - if (NON_RESTORABLE_PATHS.has(pathOnly)) { - return null; - } - - return route; - } catch { - return null; - } -} - -export function shouldRestoreRoute(route: string | null): route is string { - if (!route) { - return false; - } - - const pathOnly = route.split(/[?#]/, 1)[0]; - return pathOnly !== '/' && !NON_RESTORABLE_PATHS.has(pathOnly); -} diff --git a/ui/tests/unit/ui/lib/last-route.test.ts b/ui/tests/unit/ui/lib/last-route.test.ts new file mode 100644 index 00000000..19548c6b --- /dev/null +++ b/ui/tests/unit/ui/lib/last-route.test.ts @@ -0,0 +1,34 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { storeLastRoute } from '@/lib/last-route'; + +const LAST_ROUTE_STORAGE_KEY = 'ccs-dashboard:last-route'; + +describe('storeLastRoute', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('writes pathname with search and hash', () => { + storeLastRoute('/accounts', '?tab=auth', '#matrix'); + + expect(localStorage.setItem).toHaveBeenCalledWith( + LAST_ROUTE_STORAGE_KEY, + '/accounts?tab=auth#matrix' + ); + }); + + it('writes pathname when search and hash are omitted', () => { + storeLastRoute('/health'); + + expect(localStorage.setItem).toHaveBeenCalledWith(LAST_ROUTE_STORAGE_KEY, '/health'); + }); + + it('does not throw when localStorage write fails', () => { + const setItemSpy = vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => { + throw new Error('quota exceeded'); + }); + + expect(() => storeLastRoute('/providers')).not.toThrow(); + setItemSpy.mockRestore(); + }); +});