mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Added new unit tests.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
import { ObjectNotFoundComponent } from './objectnotfound.component';
|
||||
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
describe('ObjectNotFoundComponent', () => {
|
||||
let comp: ObjectNotFoundComponent;
|
||||
let fixture: ComponentFixture<ObjectNotFoundComponent>;
|
||||
const testUUID = '34cfed7c-f597-49ef-9cbe-ea351f0023c2';
|
||||
const uuidType = 'uuid';
|
||||
const handlePrefix = '123456789';
|
||||
const handleId = '22';
|
||||
const activatedRouteStub = Object.assign(new ActivatedRouteStub(), {
|
||||
params: observableOf({id: testUUID, idType: uuidType})
|
||||
});
|
||||
const activatedRouteStubHandle = Object.assign(new ActivatedRouteStub(), {
|
||||
params: observableOf({id: handleId, idType: handlePrefix})
|
||||
});
|
||||
describe('uuid request', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot()
|
||||
], providers: [
|
||||
{provide: ActivatedRoute, useValue: activatedRouteStub}
|
||||
],
|
||||
declarations: [ObjectNotFoundComponent],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ObjectNotFoundComponent);
|
||||
comp = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create instance', () => {
|
||||
expect(comp).toBeDefined()
|
||||
});
|
||||
|
||||
it('should have id and idType', () => {
|
||||
expect(comp.id).toEqual(testUUID);
|
||||
expect(comp.idType).toEqual(uuidType);
|
||||
expect(comp.missingItem).toEqual('uuid: ' + testUUID);
|
||||
});
|
||||
});
|
||||
|
||||
describe( 'legacy handle request', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot()
|
||||
], providers: [
|
||||
{provide: ActivatedRoute, useValue: activatedRouteStubHandle}
|
||||
],
|
||||
declarations: [ObjectNotFoundComponent],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ObjectNotFoundComponent);
|
||||
comp = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should have handle prefix and id', () => {
|
||||
expect(comp.id).toEqual(handleId);
|
||||
expect(comp.idType).toEqual(handlePrefix);
|
||||
expect(comp.missingItem).toEqual('handle: ' + handlePrefix + '/' + handleId);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -1,7 +1,6 @@
|
||||
import { cold, getTestScheduler } from 'jasmine-marbles';
|
||||
import { TestScheduler } from 'rxjs/testing';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { FindByIDRequest } from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
@@ -11,7 +10,6 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { IdentifierType } from '../index/index.reducer';
|
||||
import { DsoDataRedirectService } from './dso-data-redirect.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { CoreState } from '../core.reducers';
|
||||
|
||||
@@ -22,7 +20,7 @@ describe('DsoDataRedirectService', () => {
|
||||
let requestService: RequestService;
|
||||
let rdbService: RemoteDataBuildService;
|
||||
let objectCache: ObjectCacheService;
|
||||
let router: Router;
|
||||
let router;
|
||||
let remoteData;
|
||||
const dsoUUID = '9b4f22f4-164a-49db-8817-3316b6ee5746';
|
||||
const dsoHandle = '1234567789/22';
|
||||
@@ -31,15 +29,12 @@ describe('DsoDataRedirectService', () => {
|
||||
const requestHandleURL = `https://rest.api/rest/api/pid/find?id=${encodedHandle}`;
|
||||
const requestUUIDURL = `https://rest.api/rest/api/pid/find?id=${dsoUUID}`;
|
||||
const requestUUID = '34cfed7c-f597-49ef-9cbe-ea351f0023c2';
|
||||
const testObject = {
|
||||
uuid: dsoUUID
|
||||
} as DSpaceObject;
|
||||
|
||||
beforeEach(() => {
|
||||
scheduler = getTestScheduler();
|
||||
|
||||
halService = jasmine.createSpyObj('halService', {
|
||||
getEndpoint: cold('a', { a: pidLink })
|
||||
getEndpoint: cold('a', {a: pidLink})
|
||||
});
|
||||
requestService = jasmine.createSpyObj('requestService', {
|
||||
generateRequestId: requestUUID,
|
||||
@@ -47,21 +42,20 @@ describe('DsoDataRedirectService', () => {
|
||||
});
|
||||
rdbService = jasmine.createSpyObj('rdbService', {
|
||||
buildSingle: cold('a', {
|
||||
a: {
|
||||
payload: testObject
|
||||
}
|
||||
a: remoteData
|
||||
})
|
||||
});
|
||||
router = jasmine.createSpyObj('router', {
|
||||
navigate: () => true
|
||||
});
|
||||
router = {
|
||||
navigate: jasmine.createSpy('navigate')
|
||||
};
|
||||
remoteData = {
|
||||
isSuccessful: true,
|
||||
error: undefined,
|
||||
hasSucceeded: true,
|
||||
isLoading: false,
|
||||
payload: {
|
||||
type: 'item',
|
||||
id: '123456789'
|
||||
uuid: '123456789'
|
||||
}
|
||||
};
|
||||
objectCache = {} as ObjectCacheService;
|
||||
@@ -86,7 +80,7 @@ describe('DsoDataRedirectService', () => {
|
||||
});
|
||||
|
||||
describe('findById', () => {
|
||||
it('should call HALEndpointService with the path to the dso endpoint', () => {
|
||||
it('should call HALEndpointService with the path to the pid endpoint', () => {
|
||||
scheduler.schedule(() => service.findById(dsoUUID));
|
||||
scheduler.flush();
|
||||
|
||||
@@ -107,6 +101,13 @@ describe('DsoDataRedirectService', () => {
|
||||
expect(requestService.configure).toHaveBeenCalledWith(new FindByIDRequest(requestUUID, requestHandleURL, dsoHandle, IdentifierType.HANDLE), false);
|
||||
});
|
||||
|
||||
// TODO: test for router.navigate
|
||||
});
|
||||
it('should navigate to dso route', () => {
|
||||
const redir = service.findById(dsoHandle, IdentifierType.HANDLE);
|
||||
// The framework would normally subscribe but do it here so we can test navigation.
|
||||
redir.subscribe();
|
||||
scheduler.schedule(() => redir);
|
||||
scheduler.flush();
|
||||
expect(router.navigate).toHaveBeenCalledWith([remoteData.payload.type + 's/' + remoteData.payload.uuid]);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
@@ -9,14 +9,14 @@ import { RequestService } from './request.service';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { CoreState } from '../core.reducers';
|
||||
import { FindAllOptions, FindByIDRequest } from './request.models';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { Observable } from 'rxjs';
|
||||
import { IdentifierType } from '../index/index.reducer';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { hasValue } from '../../shared/empty.util';
|
||||
import { getFinishedRemoteData, getSucceededRemoteData } from '../shared/operators';
|
||||
import { getFinishedRemoteData } from '../shared/operators';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Injectable()
|
||||
|
Reference in New Issue
Block a user