Skip to content

Commit

Permalink
104938 Fix ProcessDetailComponent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Pauwels committed Sep 1, 2023
1 parent a59776d commit 53b0af1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { ScriptDataService } from '../../../../core/data/processes/script-data.s
import { ContentSource } from '../../../../core/shared/content-source.model';
import { ProcessDataService } from '../../../../core/data/processes/process-data.service';
import {
getAllCompletedRemoteData,
getAllSucceededRemoteDataPayload,
getFirstCompletedRemoteData,
getFirstSucceededRemoteDataPayload
} from '../../../../core/shared/operators';
import { filter, map, switchMap, tap } from 'rxjs/operators';
import { hasValue, hasValueOperator } from '../../../../shared/empty.util';
import { hasValue } from '../../../../shared/empty.util';
import { ProcessStatus } from '../../../../process-page/processes/process-status.model';
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
import { RequestService } from '../../../../core/data/request.service';
Expand Down
6 changes: 2 additions & 4 deletions src/app/core/data/processes/process-data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { testFindAllDataImplementation } from '../base/find-all-data.spec';
import { ProcessDataService, TIMER_FACTORY } from './process-data.service';
import { testDeleteDataImplementation } from '../base/delete-data.spec';
import { waitForAsync, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { waitForAsync, TestBed } from '@angular/core/testing';
import { RequestService } from '../request.service';
import { RemoteData } from '../remote-data';
import { RequestEntryState } from '../request-entry-state.model';
Expand All @@ -22,9 +22,7 @@ import { HALEndpointService } from '../../shared/hal-endpoint.service';
import { DSOChangeAnalyzer } from '../dso-change-analyzer.service';
import { BitstreamFormatDataService } from '../bitstream-format-data.service';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { TestScheduler, RunHelpers } from 'rxjs/testing';
import { cold } from 'jasmine-marbles';
import { of } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';

describe('ProcessDataService', () => {
let testScheduler;
Expand Down
38 changes: 19 additions & 19 deletions src/app/core/data/processes/process-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ export const TIMER_FACTORY = new InjectionToken<(callback: (...args: any[]) => v
@Injectable()
@dataService(PROCESS)
export class ProcessDataService extends IdentifiableDataService<Process> implements FindAllData<Process>, DeleteData<Process> {
/**
* Return true if the given process has the given status
* @protected
*/
protected static statusIs(process: Process, status: ProcessStatus): boolean {
return hasValue(process) && process.processStatus === status;
}

/**
* Return true if the given process has the status COMPLETED or FAILED
*/
public static hasCompletedOrFailed(process: Process): boolean {
return ProcessDataService.statusIs(process, ProcessStatus.COMPLETED) ||
ProcessDataService.statusIs(process, ProcessStatus.FAILED);
}

private findAllData: FindAllData<Process>;

Check failure on line 54 in src/app/core/data/processes/process-data.service.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Member findAllData should be declared before all static method definitions

Check failure on line 54 in src/app/core/data/processes/process-data.service.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Member findAllData should be declared before all static method definitions
private deleteData: DeleteData<Process>;

Check failure on line 55 in src/app/core/data/processes/process-data.service.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Member deleteData should be declared before all static method definitions

Check failure on line 55 in src/app/core/data/processes/process-data.service.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Member deleteData should be declared before all static method definitions
protected activelyBeingPolled: Map<string, NodeJS.Timeout> = new Map();

Check failure on line 56 in src/app/core/data/processes/process-data.service.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Member activelyBeingPolled should be declared before all static method definitions

Check failure on line 56 in src/app/core/data/processes/process-data.service.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Member activelyBeingPolled should be declared before all static method definitions
Expand Down Expand Up @@ -117,22 +133,6 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
return this.deleteData.deleteByHref(href, copyVirtualMetadata);
}

/**
* Return true if the given process has the given status
* @protected
*/
protected statusIs(process: Process, status: ProcessStatus): boolean {
return hasValue(process) && process.processStatus === status;
}

/**
* Return true if the given process has the status COMPLETED or FAILED
*/
public hasCompletedOrFailed(process: Process): boolean {
return this.statusIs(process, ProcessStatus.COMPLETED) ||
this.statusIs(process, ProcessStatus.FAILED);
}

/**
* Clear the timeout for the given process, if that timeout exists
* @protected
Expand All @@ -142,7 +142,7 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
if (hasValue(timeout)) {
clearTimeout(timeout);
}
};
}

/**
* Poll the process with the given ID, using the given interval, until that process either
Expand All @@ -166,7 +166,7 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
// the polling interval time has been exceeded.
const sub = process$.pipe(
filter((processRD: RemoteData<Process>) =>
!this.hasCompletedOrFailed(processRD.payload) &&
!ProcessDataService.hasCompletedOrFailed(processRD.payload) &&
!this.activelyBeingPolled.has(processId)
)
).subscribe((processRD: RemoteData<Process>) => {
Expand All @@ -183,7 +183,7 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
// observable) that unsubscribes the previous one, removes the processId from the list of
// processes being polled and clears any running timeouts
process$.pipe(
find((processRD: RemoteData<Process>) => this.hasCompletedOrFailed(processRD.payload))
find((processRD: RemoteData<Process>) => ProcessDataService.hasCompletedOrFailed(processRD.payload))
).subscribe(() => {
this.clearCurrentTimeout(processId);
this.activelyBeingPolled.delete(processId);
Expand Down
18 changes: 10 additions & 8 deletions src/app/process-page/detail/process-detail.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { NotificationsServiceStub } from '../../shared/testing/notifications-ser
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { getProcessListRoute } from '../process-page-routing.paths';
import {ProcessStatus} from '../processes/process-status.model';

describe('ProcessDetailComponent', () => {
let component: ProcessDetailComponent;
Expand Down Expand Up @@ -106,12 +105,11 @@ describe('ProcessDetailComponent', () => {
content: { href: 'log-selflink' }
}
});
const processRD$ = createSuccessfulRemoteDataObject$(process);
processService = jasmine.createSpyObj('processService', {
getFiles: createSuccessfulRemoteDataObject$(createPaginatedList(files)),
delete: createSuccessfulRemoteDataObject$(null),
findById: processRD$,
autoRefreshUntilCompletion: processRD$
findById: createSuccessfulRemoteDataObject$(process),
autoRefreshUntilCompletion: createSuccessfulRemoteDataObject$(process)
});
bitstreamDataService = jasmine.createSpyObj('bitstreamDataService', {
findByHref: createSuccessfulRemoteDataObject$(logBitstream)
Expand All @@ -134,7 +132,7 @@ describe('ProcessDetailComponent', () => {
});

route = jasmine.createSpyObj('route', {
data: observableOf({ process: processRD$ }),
data: observableOf({ process: createSuccessfulRemoteDataObject$(process) }),
snapshot: {
params: { id: process.processId }
}
Expand All @@ -149,7 +147,12 @@ describe('ProcessDetailComponent', () => {
providers: [
{
provide: ActivatedRoute,
useValue: { data: observableOf({ process: createSuccessfulRemoteDataObject(process) }) }
useValue: {
data: observableOf({ process: createSuccessfulRemoteDataObject(process) }),
snapshot: {
params: { id: process.processId }
}
}
},
{ provide: ProcessDataService, useValue: processService },
{ provide: BitstreamDataService, useValue: bitstreamDataService },
Expand All @@ -160,8 +163,7 @@ describe('ProcessDetailComponent', () => {
{ provide: NotificationsService, useValue: notificationsService },
{ provide: Router, useValue: router },
],
// schemas: [CUSTOM_ELEMENTS_SCHEMA]
schemas: []
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
}));

Expand Down
12 changes: 4 additions & 8 deletions src/app/process-page/detail/process-detail.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HttpClient } from '@angular/common/http';
import { Component, Inject, NgZone, OnInit, PLATFORM_ID } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, Observable, Subscription, interval } from 'rxjs';
import { finalize, map, switchMap, take, tap, filter, find, startWith } from 'rxjs/operators';
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
import { finalize, map, switchMap, take, tap, find, startWith } from 'rxjs/operators';
import { AuthService } from '../../core/auth/auth.service';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { BitstreamDataService } from '../../core/data/bitstream-data.service';
Expand Down Expand Up @@ -109,20 +109,16 @@ export class ProcessDetailComponent implements OnInit {
this.processRD$ = this.route.data.pipe(
switchMap((data) => {
if (isPlatformBrowser(this.platformId)) {
const x = this.processService.autoRefreshUntilCompletion(this.route.snapshot.params.id, 5000);
//[data.process as RemoteData<Process>];
console.log("ASDF", x);
return x;
return this.processService.autoRefreshUntilCompletion(this.route.snapshot.params.id, 5000);
} else {
return [data.process as RemoteData<Process>];
}
}),
redirectOn4xx(this.router, this.authService),
);

this.processRD$.subscribe(x => console.log("QWER", x));
this.isRefreshing$ = this.processRD$.pipe(
find((processRD: RemoteData<Process>) => this.processService.hasCompletedOrFailed(processRD.payload)),
find((processRD: RemoteData<Process>) => ProcessDataService.hasCompletedOrFailed(processRD.payload)),
map(() => false),
startWith(true)
);
Expand Down

0 comments on commit 53b0af1

Please sign in to comment.