diff --git a/src/app/shared/label.resolver.spec.ts b/src/app/shared/label.resolver.spec.ts index 97b5285..1e15aed 100644 --- a/src/app/shared/label.resolver.spec.ts +++ b/src/app/shared/label.resolver.spec.ts @@ -1,9 +1,10 @@ +import { Observable, of } from 'rxjs' import { LabelResolver } from './label.resolver' let labelResolver: LabelResolver describe('LabelResolver', () => { - const translateServiceSpy = jasmine.createSpyObj('TranslateService', ['instant']) + const translateServiceSpy = jasmine.createSpyObj('TranslateService', ['get']) const activatedRouteSpy = jasmine.createSpyObj('ActivatedRouteSnapshot', [], { routeConfig: { @@ -16,28 +17,31 @@ describe('LabelResolver', () => { beforeEach(async () => { labelResolver = new LabelResolver(translateServiceSpy) - translateServiceSpy.instant.calls.reset() + translateServiceSpy.get.calls.reset() const dataSpy = Object.getOwnPropertyDescriptor(activatedRouteSpy, 'data')?.get as jasmine.Spy<() => {}> dataSpy.and.returnValue({}) }) - it('should translate if breadcrumb is present', () => { + it('should translate if breadcrumb is present', (done: DoneFn) => { const dataSpy = Object.getOwnPropertyDescriptor(activatedRouteSpy, 'data')?.get as jasmine.Spy<() => {}> dataSpy.and.returnValue({ breadcrumb: 'defined' }) - translateServiceSpy.instant.and.returnValue('translation') + translateServiceSpy.get.and.returnValue(of('translation')) - const result = labelResolver.resolve(activatedRouteSpy, routerStateSpy) + const obsResult = labelResolver.resolve(activatedRouteSpy, routerStateSpy) as Observable + obsResult.subscribe((result) => { + expect(result).toBe('translation') + expect(translateServiceSpy.get).toHaveBeenCalledOnceWith('defined') - expect(result).toBe('translation') - expect(translateServiceSpy.instant).toHaveBeenCalledOnceWith('defined') + done() + }) }) it('should use route path if breadcrumb is not present', () => { const result = labelResolver.resolve(activatedRouteSpy, routerStateSpy) expect(result).toBe('path') - expect(translateServiceSpy.instant).toHaveBeenCalledTimes(0) + expect(translateServiceSpy.get).toHaveBeenCalledTimes(0) }) }) diff --git a/src/app/shared/label.resolver.ts b/src/app/shared/label.resolver.ts index 9d2f623..c09047b 100644 --- a/src/app/shared/label.resolver.ts +++ b/src/app/shared/label.resolver.ts @@ -1,19 +1,15 @@ import { Injectable } from '@angular/core' import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router' import { TranslateService } from '@ngx-translate/core' -import { Observable } from 'rxjs' +import { Observable, map } from 'rxjs' //dont use `providedIn root` - wont work when we are in shell @Injectable() export class LabelResolver implements Resolve { constructor(private translate: TranslateService) {} - resolve(route: ActivatedRouteSnapshot, _state: RouterStateSnapshot): string | Observable | Promise { - return route.data['breadcrumb'] ? this.translate.instant(route.data['breadcrumb']) : route.routeConfig?.path - /* TODO: use this if tests are running with it. resolve(route: ActivatedRouteSnapshot, _state: RouterStateSnapshot): string | Observable | Promise { return route.data['breadcrumb'] ? this.translate.get(route.data['breadcrumb']).pipe(map((t) => t.toString())) : route.routeConfig?.path ?? '' - */ } }