fix bug 16 and 17
Build & Push / Pipeline Tests (push) Successful in 1m53s
Test / Type Check (all packages) (push) Successful in 56s
Build & Push / Build & Push Docker Image (push) Failing after 4m53s
Test / API Unit Tests (push) Successful in 1m15s
Test / Homepage Unit Tests (push) Successful in 46s
Test / Carplace Unit Tests (push) Successful in 41s
Test / Admin Unit Tests (push) Successful in 40s
Test / Dashboard Unit Tests (push) Successful in 42s
Test / API Integration Tests (push) Successful in 1m6s
Build & Push / Pipeline Tests (push) Successful in 1m53s
Test / Type Check (all packages) (push) Successful in 56s
Build & Push / Build & Push Docker Image (push) Failing after 4m53s
Test / API Unit Tests (push) Successful in 1m15s
Test / Homepage Unit Tests (push) Successful in 46s
Test / Carplace Unit Tests (push) Successful in 41s
Test / Admin Unit Tests (push) Successful in 40s
Test / Dashboard Unit Tests (push) Successful in 42s
Test / API Integration Tests (push) Successful in 1m6s
This commit is contained in:
@@ -1,6 +1,28 @@
|
||||
import { currentThemePreference } from '@/lib/theme/client';
|
||||
import { currentThemePreference, persistTheme } from '@/lib/theme/client';
|
||||
import { isThemePreference, resolveTheme, serverResolvedTheme } from '@/lib/theme/config';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
let storage: Map<string, string>;
|
||||
|
||||
beforeEach(() => {
|
||||
storage = new Map<string, string>();
|
||||
Object.defineProperty(window, 'localStorage', {
|
||||
configurable: true,
|
||||
value: {
|
||||
clear: () => storage.clear(),
|
||||
getItem: (key: string) => storage.get(key) ?? null,
|
||||
removeItem: (key: string) => storage.delete(key),
|
||||
setItem: (key: string, value: string) => storage.set(key, value),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
storage.clear();
|
||||
document.cookie = 'hpc-theme=; Path=/; Max-Age=0';
|
||||
document.cookie = 'rentaldrivego-theme=; Path=/; Max-Age=0';
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('theme foundations', () => {
|
||||
it('accepts only approved preferences', () => {
|
||||
@@ -21,4 +43,26 @@ describe('theme foundations', () => {
|
||||
delete document.documentElement.dataset.themePreference;
|
||||
expect(currentThemePreference()).toBe('dark');
|
||||
});
|
||||
|
||||
it('persists the shared dashboard theme when homepage theme changes', () => {
|
||||
vi.spyOn(window, 'matchMedia').mockReturnValue({ matches: false } as MediaQueryList);
|
||||
|
||||
persistTheme('dark');
|
||||
|
||||
expect(window.localStorage.getItem('hpc.theme.preference')).toBe('dark');
|
||||
expect(window.localStorage.getItem('rentaldrivego-theme')).toBe('dark');
|
||||
expect(document.cookie).toContain('hpc-theme=dark');
|
||||
expect(document.cookie).toContain('rentaldrivego-theme=dark');
|
||||
});
|
||||
|
||||
it('stores the resolved shared theme for system preference', () => {
|
||||
vi.spyOn(window, 'matchMedia').mockReturnValue({ matches: false } as MediaQueryList);
|
||||
|
||||
persistTheme('system');
|
||||
|
||||
expect(window.localStorage.getItem('hpc.theme.preference')).toBe('system');
|
||||
expect(window.localStorage.getItem('rentaldrivego-theme')).toBe('light');
|
||||
expect(document.cookie).toContain('hpc-theme=system');
|
||||
expect(document.cookie).toContain('rentaldrivego-theme=light');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user