Commits

Nicolai Olsen authored d7ef1d7b60d
Fixed broken unit-tests
No tags

src/app/privately-marked/privately-marked.component.spec.ts

Modified
1 1 import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
2 2
3 3 import { PrivatelyMarkedComponent } from './privately-marked.component';
4 4 import {AngularMaterialModule} from '../modules/angular-material.module';
5 5 import {DialogService} from '../modals/dialog/dialog.service';
6 6 import {of} from 'rxjs/internal/observable/of';
7 7 import {Observable} from 'rxjs';
8 8 import {PatientContextService} from '../services/patient-context.service';
9 9 import {TemplateRef} from '@angular/core';
10 10 import {WindowService} from '../services/window.service';
11 +import {appUrls} from '../../utils/URL_STRING_LITERALS';
11 12
12 13 describe('PrivatelyMarkedComponent', () => {
13 14 let component: PrivatelyMarkedComponent;
14 15 let fixture: ComponentFixture<PrivatelyMarkedComponent>;
15 16 let dialogStub: TemplateRef<any>;
16 17 let dialogServiceStub: DialogService;
17 18 let dialogObservableStub: Observable<boolean>;
18 19 let patientContextServiceStub: PatientContextService;
19 20 let windowLocationStub: typeof location;
20 21 let windowServiceStub: WindowService;
25 26 } as any;
26 27
27 28 patientContextServiceStub = {
28 29 setXBreakTheGlassReason: () => {}
29 30 } as any;
30 31
31 32 dialogStub = {
32 33 } as any;
33 34
34 35 windowLocationStub = {
35 - reload: () => {},
36 + assign: () => {},
36 37 } as any;
37 38
38 39 windowServiceStub = {
39 40 nativeWindow: () => ({
40 41 location: windowLocationStub,
41 42 } as Window),
42 43 } as any;
43 44
44 45 await TestBed.configureTestingModule({
45 46 declarations: [ PrivatelyMarkedComponent ],
78 79 dialogObservableStub = of(true);
79 80 });
80 81
81 82 it('should set patientContext.XBreakTheGlassReason', () => {
82 83 spyOn(patientContextServiceStub, 'setXBreakTheGlassReason');
83 84 component.openDialog();
84 85 expect(patientContextServiceStub.setXBreakTheGlassReason).toHaveBeenCalledTimes(1);
85 86 });
86 87
87 88 it('should reload the page', () => {
88 - spyOn(windowLocationStub, 'reload');
89 + spyOn(windowLocationStub, 'assign');
89 90 component.openDialog();
90 - expect(windowLocationStub.reload).toHaveBeenCalledTimes(1);
91 + expect(windowLocationStub.assign).toHaveBeenCalledTimes(1);
92 + expect(windowLocationStub.assign).toHaveBeenCalledWith(appUrls.base);
91 93 });
92 94 });
93 95
94 96 describe('when dialog closes with "no" option', () => {
95 97 beforeEach(() => {
96 98 dialogObservableStub = of(false);
97 99 });
98 100
99 101 it('should not set patientContext.XBreakTheGlassReason', () => {
100 102 spyOn(patientContextServiceStub, 'setXBreakTheGlassReason');

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut