Skip to content

Commit

Permalink
Add customization.service.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Käser committed Mar 21, 2024
1 parent 11c8bfb commit aa4d904
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
38 changes: 38 additions & 0 deletions frontend/src/app/shared/services/chustomization.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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'])
});
});
17 changes: 17 additions & 0 deletions frontend/src/app/shared/services/customization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class CustomizationService {
});
}

public getCurrentConfig() {
return this.currentConfig;
}

private updateCustomizations(config: CustomizationConfig) {
this.setTitle(config.title);
this.setFavicon(config.favicon);
Expand All @@ -31,13 +35,22 @@ export class CustomizationService {
return;
}

if (!this.document) {
return;
}

this.document.getElementById('favicon')?.setAttribute('href', favicon);
}

private setTitle(title: string) {
if (!title || this.currentConfig?.title === title) {
return;
}

if (!this.document) {
return;
}

this.document.querySelector('title')!.innerHTML = title;
}

Expand All @@ -59,6 +72,10 @@ export class CustomizationService {
return;
}

if (!this.document) {
return;
}

const styles = this.document.querySelector('html')!.style;
if (!styles) {
return;
Expand Down

0 comments on commit aa4d904

Please sign in to comment.