Skip to content

Commit b537a60

Browse files
[DSC-1917] fix of failing tests
1 parent 6ecb330 commit b537a60

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/app/core/services/route.service.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { RouteService } from './route.service';
99
import { RouterMock } from '../../shared/mocks/router.mock';
1010
import { TestScheduler } from 'rxjs/testing';
1111
import { AddUrlToHistoryAction } from '../history/history.actions';
12-
import {NativeWindowRef, NativeWindowService} from './window.service';
12+
import { NativeWindowRefMock} from '../../shared/mocks/mock-native-window-ref';
1313

1414
describe('RouteService', () => {
1515
let scheduler: TestScheduler;
@@ -49,18 +49,19 @@ describe('RouteService', () => {
4949
},
5050
{ provide: Router, useValue: router },
5151
{ provide: Store, useValue: store },
52-
{ provide: NativeWindowService, useClass: new NativeWindowRef() },
52+
{ provide: NativeWindowRefMock, useClass: NativeWindowRefMock }
5353
]
5454
});
5555
}));
5656

5757
beforeEach(() => {
58-
service = new RouteService(TestBed.inject(ActivatedRoute), TestBed.inject(Router), TestBed.inject(Store), TestBed.inject(NativeWindowRef));
58+
service = new RouteService(TestBed.inject(ActivatedRoute), TestBed.inject(Router), TestBed.inject(Store), TestBed.inject(NativeWindowRefMock));
5959
serviceAsAny = service;
6060
});
6161

6262
describe('hasQueryParam', () => {
6363
it('should return true when the parameter name exists', () => {
64+
spyOnProperty(serviceAsAny._window.nativeWindow.location, 'href').and.returnValue('http://localhost?name=Test%20Name');
6465
service.hasQueryParam(paramName1).subscribe((status) => {
6566
expect(status).toBeTruthy();
6667
});
@@ -74,6 +75,7 @@ describe('RouteService', () => {
7475

7576
describe('hasQueryParamWithValue', () => {
7677
it('should return true when the parameter name exists and contains the specified value', () => {
78+
spyOnProperty(serviceAsAny._window.nativeWindow.location, 'href').and.returnValue('http://localhost?name=Test%20Name');
7779
service.hasQueryParamWithValue(paramName2, paramValue2a).subscribe((status) => {
7880
expect(status).toBeTruthy();
7981
});
@@ -92,6 +94,7 @@ describe('RouteService', () => {
9294

9395
describe('getQueryParameterValues', () => {
9496
it('should return a list of values when the parameter exists', () => {
97+
spyOnProperty(serviceAsAny._window.nativeWindow.location, 'href').and.returnValue('http://localhost?id=Test%20id&another=another%20id');
9598
service.getQueryParameterValues(paramName2).subscribe((params) => {
9699
expect(params).toEqual([paramValue2a, paramValue2b]);
97100
});
@@ -106,12 +109,14 @@ describe('RouteService', () => {
106109

107110
describe('getQueryParameterValue', () => {
108111
it('should return a single value when the parameter exists', () => {
112+
spyOnProperty(serviceAsAny._window.nativeWindow.location, 'href').and.returnValue('http://localhost?name=Test%20Name');
109113
service.getQueryParameterValue(paramName1).subscribe((params) => {
110114
expect(params).toEqual(paramValue1);
111115
});
112116
});
113117

114118
it('should return only the first value when the parameter exists', () => {
119+
spyOnProperty(serviceAsAny._window.nativeWindow.location, 'href').and.returnValue('http://localhost?id=Test%id');
115120
service.getQueryParameterValue(paramName2).subscribe((params) => {
116121
expect(params).toEqual(paramValue2a);
117122
});

src/app/submission/submission.service.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { SubmissionJsonPatchOperationsServiceStub } from '../shared/testing/subm
4545
import { ScrollToService } from '@nicky-lenaers/ngx-scroll-to';
4646
import { NotificationOptions } from '../shared/notifications/models/notification-options.model';
4747
import { SubmissionVisibilityValue } from '../core/config/models/config-submission-section.model';
48+
import {NativeWindowRef, NativeWindowService} from '../core/services/window.service';
4849

4950
describe('SubmissionService test suite', () => {
5051
const collectionId = '43fe1f8c-09a6-4fcf-9c78-5d4fed8f2c8f';
@@ -402,6 +403,7 @@ describe('SubmissionService test suite', () => {
402403
{ provide: SearchService, useValue: searchService },
403404
{ provide: RequestService, useValue: requestServce },
404405
{ provide: SubmissionJsonPatchOperationsService, useValue: submissionJsonPatchOperationsService },
406+
{ provide: NativeWindowService, useValue: new NativeWindowRef() },
405407
ScrollToService,
406408
NotificationsService,
407409
RouteService,

0 commit comments

Comments
 (0)