mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
50632: Added tests for registry service and updated component tests
This commit is contained in:
@@ -8,8 +8,14 @@ import { CommonModule } from '@angular/common';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { SharedModule } from '../../../shared/shared.module';
|
||||
import { PaginationComponent } from '../../../shared/pagination/pagination.component';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { EnumKeysPipe } from '../../../shared/utils/enum-keys-pipe';
|
||||
import { HostWindowService } from '../../../shared/host-window.service';
|
||||
import { HostWindowServiceStub } from '../../../shared/testing/host-window-service-stub';
|
||||
|
||||
describe('BitstreamFormatsComponent', () => {
|
||||
fdescribe('BitstreamFormatsComponent', () => {
|
||||
let comp: BitstreamFormatsComponent;
|
||||
let fixture: ComponentFixture<BitstreamFormatsComponent>;
|
||||
let registryService: RegistryService;
|
||||
@@ -54,10 +60,11 @@ describe('BitstreamFormatsComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot()],
|
||||
declarations: [BitstreamFormatsComponent],
|
||||
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule.forRoot()],
|
||||
declarations: [BitstreamFormatsComponent, PaginationComponent, EnumKeysPipe],
|
||||
providers: [
|
||||
{ provide: RegistryService, useValue: registryServiceStub }
|
||||
{ provide: RegistryService, useValue: registryServiceStub },
|
||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) }
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
@@ -8,18 +8,26 @@ import { By } from '@angular/platform-browser';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { RegistryService } from '../../../core/registry/registry.service';
|
||||
import { SharedModule } from '../../../shared/shared.module';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { EnumKeysPipe } from '../../../shared/utils/enum-keys-pipe';
|
||||
import { PaginationComponent } from '../../../shared/pagination/pagination.component';
|
||||
import { HostWindowServiceStub } from '../../../shared/testing/host-window-service-stub';
|
||||
import { HostWindowService } from '../../../shared/host-window.service';
|
||||
|
||||
describe('MetadataRegistryComponent', () => {
|
||||
fdescribe('MetadataRegistryComponent', () => {
|
||||
let comp: MetadataRegistryComponent;
|
||||
let fixture: ComponentFixture<MetadataRegistryComponent>;
|
||||
let registryService: RegistryService;
|
||||
const mockSchemasList = [
|
||||
{
|
||||
id: 1,
|
||||
self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/metadataschemas/1',
|
||||
prefix: 'dc',
|
||||
namespace: 'http://dublincore.org/documents/dcmi-terms/'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/metadataschemas/2',
|
||||
prefix: 'mock',
|
||||
namespace: 'http://dspace.org/mockschema'
|
||||
@@ -32,10 +40,11 @@ describe('MetadataRegistryComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot()],
|
||||
declarations: [MetadataRegistryComponent],
|
||||
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule.forRoot()],
|
||||
declarations: [MetadataRegistryComponent, PaginationComponent, EnumKeysPipe],
|
||||
providers: [
|
||||
{ provide: RegistryService, useValue: registryServiceStub }
|
||||
{ provide: RegistryService, useValue: registryServiceStub },
|
||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) }
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
@@ -53,10 +62,10 @@ describe('MetadataRegistryComponent', () => {
|
||||
});
|
||||
|
||||
it('should contain the correct schemas', () => {
|
||||
const dcName: HTMLElement = fixture.debugElement.query(By.css('#metadata-schemas tr:nth-child(1) td:nth-child(2)')).nativeElement;
|
||||
const dcName: HTMLElement = fixture.debugElement.query(By.css('#metadata-schemas tr:nth-child(1) td:nth-child(3)')).nativeElement;
|
||||
expect(dcName.textContent).toBe('dc');
|
||||
|
||||
const mockName: HTMLElement = fixture.debugElement.query(By.css('#metadata-schemas tr:nth-child(2) td:nth-child(2)')).nativeElement;
|
||||
const mockName: HTMLElement = fixture.debugElement.query(By.css('#metadata-schemas tr:nth-child(2) td:nth-child(3)')).nativeElement;
|
||||
expect(mockName.textContent).toBe('mock');
|
||||
});
|
||||
|
||||
|
@@ -6,22 +6,33 @@ import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
import { MetadataSchema } from '../../../core/metadata/metadataschema.model';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { MockTranslateLoader } from '../../../shared/testing/mock-translate-loader';
|
||||
import { RegistryService } from '../../../core/registry/registry.service';
|
||||
import { SharedModule } from '../../../shared/shared.module';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { EnumKeysPipe } from '../../../shared/utils/enum-keys-pipe';
|
||||
import { PaginationComponent } from '../../../shared/pagination/pagination.component';
|
||||
import { HostWindowServiceStub } from '../../../shared/testing/host-window-service-stub';
|
||||
import { HostWindowService } from '../../../shared/host-window.service';
|
||||
import { RouterStub } from '../../../shared/testing/router-stub';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { ActivatedRouteStub } from '../../../shared/testing/active-router-stub';
|
||||
|
||||
describe('MetadataSchemaComponent', () => {
|
||||
fdescribe('MetadataSchemaComponent', () => {
|
||||
let comp: MetadataSchemaComponent;
|
||||
let fixture: ComponentFixture<MetadataSchemaComponent>;
|
||||
let registryService: RegistryService;
|
||||
const mockSchemasList = [
|
||||
{
|
||||
id: 1,
|
||||
self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/metadataschemas/1',
|
||||
prefix: 'dc',
|
||||
namespace: 'http://dublincore.org/documents/dcmi-terms/'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/metadataschemas/2',
|
||||
prefix: 'mock',
|
||||
namespace: 'http://dspace.org/mockschema'
|
||||
@@ -64,19 +75,21 @@ describe('MetadataSchemaComponent', () => {
|
||||
getMetadataSchemaByName: (schemaName: string) => Observable.of(new RemoteData(false, false, true, undefined, mockSchemasList.filter((value) => value.prefix === schemaName)[0]))
|
||||
};
|
||||
const schemaNameParam = 'mock';
|
||||
const activatedRouteStub = {
|
||||
const activatedRouteStub = Object.assign(new ActivatedRouteStub(), {
|
||||
params: Observable.of({
|
||||
schemaName: schemaNameParam
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CommonModule, TranslateModule.forRoot()],
|
||||
declarations: [MetadataSchemaComponent],
|
||||
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule.forRoot()],
|
||||
declarations: [MetadataSchemaComponent, PaginationComponent, EnumKeysPipe],
|
||||
providers: [
|
||||
{ provide: RegistryService, useValue: registryServiceStub },
|
||||
{ provide: ActivatedRoute, useValue: activatedRouteStub }
|
||||
{ provide: ActivatedRoute, useValue: activatedRouteStub },
|
||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
||||
{ provide: Router, useValue: new RouterStub() }
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
200
src/app/core/registry/registry.service.spec.ts
Normal file
200
src/app/core/registry/registry.service.spec.ts
Normal file
@@ -0,0 +1,200 @@
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { RegistryService } from './registry.service';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ResponseCacheService } from '../cache/response-cache.service';
|
||||
import { RequestService } from '../data/request.service';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { ResponseCacheEntry } from '../cache/response-cache.reducer';
|
||||
import { RequestEntry } from '../data/request.reducer';
|
||||
import { RemoteData } from '../data/remote-data';
|
||||
import { PaginatedList } from '../data/paginated-list';
|
||||
import { PageInfo } from '../shared/page-info.model';
|
||||
|
||||
fdescribe('RegistryService', () => {
|
||||
let registryService: RegistryService;
|
||||
const pagination: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
|
||||
id: 'registry-service-spec-pagination',
|
||||
pageSize: 20
|
||||
});
|
||||
|
||||
const mockSchemasList = [
|
||||
{
|
||||
id: 1,
|
||||
self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/metadataschemas/1',
|
||||
prefix: 'dc',
|
||||
namespace: 'http://dublincore.org/documents/dcmi-terms/'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/metadataschemas/2',
|
||||
prefix: 'mock',
|
||||
namespace: 'http://dspace.org/mockschema'
|
||||
}
|
||||
];
|
||||
const mockFieldsList = [
|
||||
{
|
||||
self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/metadatafields/8',
|
||||
element: 'contributor',
|
||||
qualifier: 'advisor',
|
||||
scopenote: null,
|
||||
schema: mockSchemasList[0]
|
||||
},
|
||||
{
|
||||
self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/metadatafields/9',
|
||||
element: 'contributor',
|
||||
qualifier: 'author',
|
||||
scopenote: null,
|
||||
schema: mockSchemasList[0]
|
||||
},
|
||||
{
|
||||
self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/metadatafields/10',
|
||||
element: 'contributor',
|
||||
qualifier: 'editor',
|
||||
scopenote: 'test scope note',
|
||||
schema: mockSchemasList[1]
|
||||
},
|
||||
{
|
||||
self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/metadatafields/11',
|
||||
element: 'contributor',
|
||||
qualifier: 'illustrator',
|
||||
scopenote: null,
|
||||
schema: mockSchemasList[1]
|
||||
}
|
||||
];
|
||||
const mockFormatsList = [
|
||||
{
|
||||
shortDescription: 'Unknown',
|
||||
description: 'Unknown data format',
|
||||
mimetype: 'application/octet-stream',
|
||||
supportLevel: 0,
|
||||
internal: false,
|
||||
extensions: null
|
||||
},
|
||||
{
|
||||
shortDescription: 'License',
|
||||
description: 'Item-specific license agreed upon to submission',
|
||||
mimetype: 'text/plain; charset=utf-8',
|
||||
supportLevel: 1,
|
||||
internal: true,
|
||||
extensions: null
|
||||
},
|
||||
{
|
||||
shortDescription: 'CC License',
|
||||
description: 'Item-specific Creative Commons license agreed upon to submission',
|
||||
mimetype: 'text/html; charset=utf-8',
|
||||
supportLevel: 2,
|
||||
internal: true,
|
||||
extensions: null
|
||||
},
|
||||
{
|
||||
shortDescription: 'Adobe PDF',
|
||||
description: 'Adobe Portable Document Format',
|
||||
mimetype: 'application/pdf',
|
||||
supportLevel: 0,
|
||||
internal: false,
|
||||
extensions: null
|
||||
}
|
||||
];
|
||||
|
||||
const pageInfo = new PageInfo();
|
||||
pageInfo.elementsPerPage = 10;
|
||||
pageInfo.currentPage = 1;
|
||||
|
||||
const halServiceStub = {
|
||||
getEndpoint: () => Observable.of('path')
|
||||
};
|
||||
|
||||
const rdbMetadataschemasStub = {
|
||||
toRemoteDataObservable: () => {
|
||||
const payload = new PaginatedList(pageInfo, mockSchemasList);
|
||||
const remoteData = new RemoteData(false, false, true, undefined, payload);
|
||||
return Observable.of(remoteData);
|
||||
}
|
||||
};
|
||||
const rdbMetadatafieldsStub = {
|
||||
toRemoteDataObservable: () => {
|
||||
const payload = new PaginatedList(pageInfo, mockFieldsList);
|
||||
const remoteData = new RemoteData(false, false, true, undefined, payload);
|
||||
return Observable.of(remoteData);
|
||||
}
|
||||
};
|
||||
const rdbBitstreamformatsStub = {
|
||||
toRemoteDataObservable: () => {
|
||||
const payload = new PaginatedList(pageInfo, mockFormatsList);
|
||||
const remoteData = new RemoteData(false, false, true, undefined, payload);
|
||||
return Observable.of(remoteData);
|
||||
}
|
||||
};
|
||||
|
||||
describe('when requesting metadataschemas', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ CommonModule ],
|
||||
providers: [
|
||||
{ provide: ResponseCacheService, useValue: {} },
|
||||
{ provide: RequestService, useValue: {} },
|
||||
{ provide: RemoteDataBuildService, useValue: rdbMetadataschemasStub },
|
||||
{ provide: HALEndpointService, useValue: halServiceStub },
|
||||
RegistryService
|
||||
]
|
||||
});
|
||||
|
||||
registryService = TestBed.get(RegistryService);
|
||||
});
|
||||
|
||||
it('should recieve the correct data', () => {
|
||||
registryService.getMetadataSchemas(pagination).subscribe((value) => {
|
||||
expect(value.payload.page[0].prefix).toEqual('dc');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when requesting metadatafields', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ CommonModule ],
|
||||
providers: [
|
||||
{ provide: ResponseCacheService, useValue: {} },
|
||||
{ provide: RequestService, useValue: {} },
|
||||
{ provide: RemoteDataBuildService, useValue: rdbMetadatafieldsStub },
|
||||
{ provide: HALEndpointService, useValue: halServiceStub },
|
||||
RegistryService
|
||||
]
|
||||
});
|
||||
|
||||
registryService = TestBed.get(RegistryService);
|
||||
});
|
||||
|
||||
it('should recieve the correct data', () => {
|
||||
registryService.getMetadataFieldsBySchema(mockSchemasList[0], pagination).subscribe((value) => {
|
||||
expect(value.payload.page[0].element).toEqual('contributor');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when requesting bitstreamformats', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ CommonModule ],
|
||||
providers: [
|
||||
{ provide: ResponseCacheService, useValue: {} },
|
||||
{ provide: RequestService, useValue: {} },
|
||||
{ provide: RemoteDataBuildService, useValue: rdbBitstreamformatsStub },
|
||||
{ provide: HALEndpointService, useValue: halServiceStub },
|
||||
RegistryService
|
||||
]
|
||||
});
|
||||
|
||||
registryService = TestBed.get(RegistryService);
|
||||
});
|
||||
|
||||
it('should recieve the correct data', () => {
|
||||
registryService.getBitstreamFormats(pagination).subscribe((value) => {
|
||||
expect(value.payload.page[0].shortDescription).toEqual('Unknown');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,4 +1,4 @@
|
||||
yarn add{
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"sourceMap": true
|
||||
|
Reference in New Issue
Block a user