ProcessDataService.notifyOnCompletion tests (WIP)

This commit is contained in:
Koen Pauwels
2023-08-24 10:00:21 +02:00
parent 78d0bdd336
commit c4d57770c7
2 changed files with 31 additions and 28 deletions

View File

@@ -18,7 +18,6 @@ import { Process } from '../../../process-page/processes/process.model';
import { ProcessStatus } from '../../../process-page/processes/process-status.model'; import { ProcessStatus } from '../../../process-page/processes/process-status.model';
import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../../cache/object-cache.service'; import { ObjectCacheService } from '../../cache/object-cache.service';
import { CoreModule } from '../../core.module';
import { ReducerManager } from '@ngrx/store'; import { ReducerManager } from '@ngrx/store';
import { HALEndpointService } from '../../shared/hal-endpoint.service'; import { HALEndpointService } from '../../shared/hal-endpoint.service';
import { DSOChangeAnalyzer } from '../dso-change-analyzer.service'; import { DSOChangeAnalyzer } from '../dso-change-analyzer.service';
@@ -27,7 +26,7 @@ import { NotificationsService } from '../../../shared/notifications/notification
describe('ProcessDataService', () => { describe('ProcessDataService', () => {
describe('composition', () => { describe('composition', () => {
const initService = () => new ProcessDataService(null, null, null, null, null, null); const initService = () => new ProcessDataService(null, null, null, null, null, null, null);
testFindAllDataImplementation(initService); testFindAllDataImplementation(initService);
testDeleteDataImplementation(initService); testDeleteDataImplementation(initService);
}); });
@@ -38,13 +37,11 @@ describe('ProcessDataService', () => {
describe('notifyOnCompletion', () => { describe('notifyOnCompletion', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
requestService = jasmine.createSpyObj('requestService', ['setStaleByHrefSubstring']);
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [], imports: [],
providers: [ providers: [
ProcessDataService, ProcessDataService,
{ provide: RequestService, useValue: requestService }, { provide: RequestService, useValue: null },
{ provide: RemoteDataBuildService, useValue: null }, { provide: RemoteDataBuildService, useValue: null },
{ provide: ObjectCacheService, useValue: null }, { provide: ObjectCacheService, useValue: null },
{ provide: ReducerManager, useValue: null }, { provide: ReducerManager, useValue: null },
@@ -56,6 +53,7 @@ describe('ProcessDataService', () => {
}); });
processDataService = TestBed.inject(ProcessDataService); processDataService = TestBed.inject(ProcessDataService);
spyOn(processDataService, 'invalidateByHref');
})); }));
it('TODO', () => { it('TODO', () => {
@@ -71,33 +69,35 @@ describe('ProcessDataService', () => {
let process$ = processDataService.notifyOnCompletion('instantly'); let process$ = processDataService.notifyOnCompletion('instantly');
process$.subscribe((rd) => { process$.subscribe((rd) => {
expect(processDataService.findById).toHaveBeenCalledTimes(1); expect(processDataService.findById).toHaveBeenCalledTimes(1);
expect(requestService.setStaleByHrefSubstring).not.toHaveBeenCalled(); expect(processDataService.invalidateByHref).not.toHaveBeenCalled();
}); });
expect(process$).toBeObservable(cold('(c|)', { expect(process$).toBeObservable(cold('(c|)', {
'c': new RemoteData(0, 0, 0, RequestEntryState.Success, null, completedProcess) 'c': new RemoteData(0, 0, 0, RequestEntryState.Success, null, completedProcess)
})); }));
}); });
// it('TODO2', () => { it('TODO2', () => {
// let completedProcess = new Process(); let runningProcess = new Process();
// completedProcess.processStatus = ProcessStatus.COMPLETED; runningProcess.processStatus = ProcessStatus.RUNNING;
let completedProcess = new Process();
completedProcess.processStatus = ProcessStatus.COMPLETED;
// spyOn(processDataService, 'findById').and.returnValue( spyOn(processDataService, 'findById').and.returnValue(
// cold('p 150ms (c|)', { cold('p 150ms (c|)', {
// 'p': new RemoteData(0, 0, 0, RequestEntryState., null, completedProcess), 'p': new RemoteData(0, 0, 0, RequestEntryState.Success, null, runningProcess),
// 'c': new RemoteData(0, 0, 0, RequestEntryState.Success, null, completedProcess) 'c': new RemoteData(0, 0, 0, RequestEntryState.Success, null, completedProcess)
// }) })
// ); );
// let process$ = processDataService.notifyOnCompletion('foo', 100); let process$ = processDataService.notifyOnCompletion('foo', 100);
// expect(process$).toBeObservable(cold('---(c|)', { // expect(process$).toBeObservable(cold('- 800ms (c|)', {
// 'c': new RemoteData(0, 0, 0, RequestEntryState.Success, null, completedProcess) // 'c': new RemoteData(0, 0, 0, RequestEntryState.Success, null, completedProcess)
// })); // }));
// process$.subscribe((rd) => { process$.subscribe((rd) => {
// expect(processDataService.findById).toHaveBeenCalledTimes(1); expect(processDataService.findById).toHaveBeenCalledTimes(1);
// expect(requestService.setStaleByHrefSubstring).not.toHaveBeenCalled(); expect(processDataService.invalidateByHref).toHaveBeenCalledTimes(1);
// }); });
// }); });
}); });
}); });

View File

@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core'; import { Injectable, NgZone } from '@angular/core';
import { RequestService } from '../request.service'; import { RequestService } from '../request.service';
import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../../cache/object-cache.service'; import { ObjectCacheService } from '../../cache/object-cache.service';
@@ -36,6 +36,7 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
protected halService: HALEndpointService, protected halService: HALEndpointService,
protected bitstreamDataService: BitstreamDataService, protected bitstreamDataService: BitstreamDataService,
protected notificationsService: NotificationsService, protected notificationsService: NotificationsService,
protected zone: NgZone,
) { ) {
super('processes', requestService, rdbService, objectCache, halService); super('processes', requestService, rdbService, objectCache, halService);
@@ -129,9 +130,11 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
this.activelyBeingPolled.delete(processId); this.activelyBeingPolled.delete(processId);
sub.unsubscribe(); sub.unsubscribe();
} else { } else {
this.zone.runOutsideAngular(() =>
setTimeout(() => { setTimeout(() => {
this.requestService.setStaleByHrefSubstring(process._links.self.href); this.invalidateByHref(process._links.self.href);
}, pollingIntervalInMs); }, pollingIntervalInMs)
);
} }
}); });
} }