refactor(theme): remove obsolete compatibility

This commit is contained in:
nessar committed 2026-08-28 14:56:45 +02:00
1 parent c19b62ff85
commit dfb25b249b
3 files changed
+55 -137

No files matched your search

-42
View File
@@ -1,42 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { provideZonelessChangeDetection } from '@angular/core';
import { ThemeService } from './theme-service';
describe('ThemeService', () => {
let service: ThemeService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [provideZonelessChangeDetection()],
});
service = TestBed.inject(ThemeService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
it('should initialize with system preference', () => {
expect(service.isLightMode()).toBeDefined();
});
it('should toggle theme', () => {
const initialMode = service.isLightMode();
service.toggleTheme();
expect(service.isLightMode()).toBe(!initialMode);
});
it('should force light mode when specified', () => {
service.toggleTheme(true);
expect(service.isLightMode()).toBe(true);
expect(document.body.classList.contains('light-mode')).toBe(true);
expect(document.body.classList.contains('dark-mode')).toBe(false);
});
it('should force dark mode when specified', () => {
service.toggleTheme(false);
expect(service.isLightMode()).toBe(false);
expect(document.body.classList.contains('light-mode')).toBe(false);
expect(document.body.classList.contains('dark-mode')).toBe(true);
});
});
+5 -11
View File
@@ -13,7 +13,6 @@ export class ThemeService {
const preference = this.selectedPreference();
return preference === 'system' ? (this.systemIsLight() ? 'light' : 'dark') : preference;
});
readonly isLightMode = computed(() => this.effectiveTheme() === 'light');
readonly nextThemePreference = computed(() => this.nextPreference(this.selectedPreference()));
constructor() {
@@ -26,18 +25,13 @@ export class ThemeService {
});
}
setThemePreference(preference: ThemePreference): void {
this.selectedPreference.set(preference);
this.applyEffectiveTheme();
toggleTheme(): void {
this.setThemePreference(this.nextThemePreference());
}
toggleTheme(forceLight?: boolean): void {
if (forceLight !== undefined) {
this.setThemePreference(forceLight ? 'light' : 'dark');
return;
}
this.setThemePreference(this.nextThemePreference());
private setThemePreference(preference: ThemePreference): void {
this.selectedPreference.set(preference);
this.applyEffectiveTheme();
}
private nextPreference(preference: ThemePreference): ThemePreference {