This commit is contained in:
2026-08-06 20:51:46 +02:00
parent f86db1556c
commit d1b70ea7d2
30 changed files with 1601 additions and 260 deletions

View File

@@ -0,0 +1,60 @@
import { TestBed } from '@angular/core/testing';
import { PiThemeService } from './theme.service';
describe('PiThemeService', () => {
afterEach(() => {
localStorage.clear();
document.body.className = '';
document.documentElement.classList.remove('dark-mode');
});
it('applies `pi-shell pi-shell__default` to <body> by default', () => {
TestBed.inject(PiThemeService);
TestBed.flushEffects();
expect(document.body.className).toBe('pi-shell pi-shell__default');
});
it('updates <body> when the theme changes', () => {
const service = TestBed.inject(PiThemeService);
service.setTheme('alternative');
TestBed.flushEffects();
expect(document.body.className).toBe('pi-shell pi-shell__alternative');
});
it('toggles `dark-mode` on <html>', () => {
const service = TestBed.inject(PiThemeService);
service.setDarkMode(true);
TestBed.flushEffects();
expect(document.documentElement.classList.contains('dark-mode')).toBe(true);
service.toggleDarkMode();
TestBed.flushEffects();
expect(document.documentElement.classList.contains('dark-mode')).toBe(false);
});
it('persists the theme and dark mode across a fresh instance (reload)', () => {
const service = TestBed.inject(PiThemeService);
service.setTheme('minimal');
service.setDarkMode(true);
TestBed.flushEffects();
TestBed.resetTestingModule();
const reloaded = TestBed.inject(PiThemeService);
expect(reloaded.theme()).toBe('minimal');
expect(reloaded.darkMode()).toBe(true);
});
it('falls back to the default theme when nothing valid is stored', () => {
localStorage.setItem('pi-theme', JSON.stringify('not-a-real-theme'));
const service = TestBed.inject(PiThemeService);
expect(service.theme()).toBe('default');
});
});