Skip to content

Commit 960bfbb

Browse files
committed
111638: Fix autoRefreshingSearchBy test
1 parent fa2f3e6 commit 960bfbb

1 file changed

Lines changed: 31 additions & 30 deletions

File tree

src/app/core/data/processes/process-data.service.spec.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { testFindAllDataImplementation } from '../base/find-all-data.spec';
1010
import { ProcessDataService, TIMER_FACTORY } from './process-data.service';
1111
import { testDeleteDataImplementation } from '../base/delete-data.spec';
12-
import { waitForAsync, TestBed, fakeAsync, tick, flush } from '@angular/core/testing';
12+
import { waitForAsync, TestBed, fakeAsync, tick } from '@angular/core/testing';
1313
import { RequestService } from '../request.service';
1414
import { RemoteData } from '../remote-data';
1515
import { RequestEntryState } from '../request-entry-state.model';
@@ -27,6 +27,7 @@ import { testSearchDataImplementation } from '../base/search-data.spec';
2727
import { PaginatedList } from '../paginated-list.model';
2828
import { FindListOptions } from '../find-list-options.model';
2929
import { of } from 'rxjs';
30+
import { getMockRequestService } from '../../../shared/mocks/request.service.mock';
3031

3132
describe('ProcessDataService', () => {
3233
let testScheduler;
@@ -43,7 +44,7 @@ describe('ProcessDataService', () => {
4344
testSearchDataImplementation(initService);
4445
});
4546

46-
let requestService;
47+
let requestService = getMockRequestService();
4748
let processDataService;
4849
let remoteDataBuildService;
4950

@@ -136,7 +137,7 @@ describe('ProcessDataService', () => {
136137
imports: [],
137138
providers: [
138139
ProcessDataService,
139-
{ provide: RequestService, useValue: null },
140+
{ provide: RequestService, useValue: requestService },
140141
{ provide: RemoteDataBuildService, useValue: null },
141142
{ provide: ObjectCacheService, useValue: null },
142143
{ provide: ReducerManager, useValue: null },
@@ -152,41 +153,41 @@ describe('ProcessDataService', () => {
152153
}));
153154

154155
it('should refresh after the specified interval', fakeAsync(() => {
155-
const runningProcess = Object.assign(new Process(), {
156-
_links: {
157-
self: {
158-
href: 'https://rest.api/processes/123'
159-
}
156+
const runningProcess = Object.assign(new Process(), {
157+
_links: {
158+
self: {
159+
href: 'https://rest.api/processes/123'
160160
}
161-
});
162-
runningProcess.processStatus = ProcessStatus.RUNNING;
161+
}
162+
});
163+
runningProcess.processStatus = ProcessStatus.RUNNING;
163164

164-
const runningProcessPagination: PaginatedList<Process> = Object.assign(new PaginatedList(), {
165-
page: [runningProcess],
166-
_links: {
167-
self: {
168-
href: 'https://rest.api/processesList/456'
169-
}
165+
const runningProcessPagination: PaginatedList<Process> = Object.assign(new PaginatedList(), {
166+
page: [runningProcess],
167+
_links: {
168+
self: {
169+
href: 'https://rest.api/processesList/456'
170170
}
171-
});
171+
}
172+
});
172173

173-
const runningProcessRD = new RemoteData(0, 0, 0, RequestEntryState.Success, null, runningProcessPagination);
174+
const runningProcessRD = new RemoteData(0, 0, 0, RequestEntryState.Success, null, runningProcessPagination);
174175

175-
spyOn(processDataService, 'invalidateByHref');
176-
spyOn(processDataService, 'searchBy').and.returnValue(
177-
of(runningProcessRD)
178-
);
176+
spyOn(processDataService, 'searchBy').and.returnValue(
177+
of(runningProcessRD)
178+
);
179+
180+
expect(processDataService.searchBy).toHaveBeenCalledTimes(0);
181+
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledTimes(0);
182+
183+
let sub = processDataService.autoRefreshingSearchBy('id', 'byProperty', new FindListOptions(), 200).subscribe();
184+
expect(processDataService.searchBy).toHaveBeenCalledTimes(1);
179185

180-
let sub = processDataService.autoRefreshingSearchBy('byProperty', new FindListOptions(), 200).subscribe();
181-
tick(0);
182-
expect(processDataService.searchBy).toHaveBeenCalledTimes(1);
183-
tick(450);
184-
expect(processDataService.searchBy).toHaveBeenCalledTimes(3);
185-
sub.unsubscribe();
186+
tick(250);
186187

187-
flush();
188+
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledTimes(1);
188189

189-
expect(processDataService.invalidateByHref).toHaveBeenCalledTimes(3);
190+
sub.unsubscribe();
190191
}));
191192
});
192193
});

0 commit comments

Comments
 (0)