diff --git a/frontend/src/app/shared/services/chustomization.service.spec.ts b/frontend/src/app/shared/services/chustomization.service.spec.ts new file mode 100644 index 0000000000..d209fe0ecd --- /dev/null +++ b/frontend/src/app/shared/services/chustomization.service.spec.ts @@ -0,0 +1,38 @@ +import { TestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { CustomizationService } from "./customization.service"; +import { DOCUMENT } from "@angular/common"; +import { ConfigService } from "../../config.service"; +import { Observable, of } from "rxjs"; + +describe('CustomizationService', () => { + let service: CustomizationService; + + const body = { + title: "title", + favicon: "favicon", + logo: "logo", + customStyles: {cssVar1: "foo"} + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ + { provide: DOCUMENT, useValue: undefined}, + { provide: ConfigService, useValue: { + config$: of(body) + }} + ] + }); + service = TestBed.inject(CustomizationService); + }); + + it('should be created', () => { + const currentConfig = service.getCurrentConfig(); + expect(currentConfig?.title).toBe(body.title) + expect(currentConfig?.logo).toBe(body.logo) + expect(currentConfig?.favicon).toBe(body.favicon) + expect(currentConfig?.customStyles['cssVar1']).toBe(body.customStyles['cssVar1']) + }); +}); diff --git a/frontend/src/app/shared/services/customization.service.ts b/frontend/src/app/shared/services/customization.service.ts index 75e34cdb3d..e96215cc12 100644 --- a/frontend/src/app/shared/services/customization.service.ts +++ b/frontend/src/app/shared/services/customization.service.ts @@ -18,6 +18,10 @@ export class CustomizationService { }); } + public getCurrentConfig() { + return this.currentConfig; + } + private updateCustomizations(config: CustomizationConfig) { this.setTitle(config.title); this.setFavicon(config.favicon); @@ -31,6 +35,10 @@ export class CustomizationService { return; } + if (!this.document) { + return; + } + this.document.getElementById('favicon')?.setAttribute('href', favicon); } @@ -38,6 +46,11 @@ export class CustomizationService { if (!title || this.currentConfig?.title === title) { return; } + + if (!this.document) { + return; + } + this.document.querySelector('title')!.innerHTML = title; } @@ -59,6 +72,10 @@ export class CustomizationService { return; } + if (!this.document) { + return; + } + const styles = this.document.querySelector('html')!.style; if (!styles) { return;