mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 06:53:03 +00:00
57557: Added missing spec files
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { MockTranslateLoader } from '../../../../shared/mocks/mock-translate-loader';
|
||||
import { GenericItemPageFieldComponent } from '../../field-components/specific-field/generic/generic-item-page-field.component';
|
||||
import { TruncatePipe } from '../../../../shared/utils/truncate.pipe';
|
||||
import { ITEM } from '../../../../shared/entities/switcher/entity-type-switcher.component';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { SearchFixedFilterService } from '../../../../+search-page/search-filters/search-filter/search-fixed-filter.service';
|
||||
import { TruncatableService } from '../../../../shared/truncatable/truncatable.service';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { PublicationPageFieldsComponent } from './publication-page-fields.component';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||
import { createRelationshipsObservable } from '../shared/entity-page-fields.component.spec';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
bitstreams: Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
|
||||
metadata: [],
|
||||
relationships: createRelationshipsObservable()
|
||||
});
|
||||
|
||||
describe('PublicationPageFieldsComponent', () => {
|
||||
let comp: PublicationPageFieldsComponent;
|
||||
let fixture: ComponentFixture<PublicationPageFieldsComponent>;
|
||||
|
||||
const searchFixedFilterServiceStub = {
|
||||
/* tslint:disable:no-empty */
|
||||
getQueryByRelations: () => {}
|
||||
/* tslint:enable:no-empty */
|
||||
};
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useClass: MockTranslateLoader
|
||||
}
|
||||
})],
|
||||
declarations: [PublicationPageFieldsComponent, GenericItemPageFieldComponent, TruncatePipe],
|
||||
providers: [
|
||||
{provide: ITEM, useValue: mockItem},
|
||||
{provide: ItemDataService, useValue: {}},
|
||||
{provide: SearchFixedFilterService, useValue: searchFixedFilterServiceStub},
|
||||
{provide: TruncatableService, useValue: {}}
|
||||
],
|
||||
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(PublicationPageFieldsComponent, {
|
||||
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(PublicationPageFieldsComponent);
|
||||
comp = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should contain a component to display the date', () => {
|
||||
const fields = fixture.debugElement.queryAll(By.css('ds-item-page-date-field'));
|
||||
expect(fields.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it('should contain a component to display the author', () => {
|
||||
const fields = fixture.debugElement.queryAll(By.css('ds-item-page-author-field'));
|
||||
expect(fields.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it('should contain a component to display the abstract', () => {
|
||||
const fields = fixture.debugElement.queryAll(By.css('ds-item-page-abstract-field'));
|
||||
expect(fields.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it('should contain a component to display the uri', () => {
|
||||
const fields = fixture.debugElement.queryAll(By.css('ds-item-page-uri-field'));
|
||||
expect(fields.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it('should contain a component to display the collections', () => {
|
||||
const fields = fixture.debugElement.queryAll(By.css('ds-item-page-collections'));
|
||||
expect(fields.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
});
|
91
src/app/+item-page/simple/item-page.component.spec.ts
Normal file
91
src/app/+item-page/simple/item-page.component.spec.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { MockTranslateLoader } from '../../shared/mocks/mock-translate-loader';
|
||||
import { TruncatePipe } from '../../shared/utils/truncate.pipe';
|
||||
import { ItemDataService } from '../../core/data/item-data.service';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ItemPageComponent } from './item-page.component';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
|
||||
import { MetadataService } from '../../core/metadata/metadata.service';
|
||||
import { VarDirective } from '../../shared/utils/var.directive';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
import { PaginatedList } from '../../core/data/paginated-list';
|
||||
import { PageInfo } from '../../core/shared/page-info.model';
|
||||
import { createRelationshipsObservable } from './entity-types/shared/entity-page-fields.component.spec';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
bitstreams: Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
|
||||
metadata: [],
|
||||
relationships: createRelationshipsObservable()
|
||||
});
|
||||
|
||||
describe('ItemPageComponent', () => {
|
||||
let comp: ItemPageComponent;
|
||||
let fixture: ComponentFixture<ItemPageComponent>;
|
||||
|
||||
const mockMetadataService = {
|
||||
/* tslint:disable:no-empty */
|
||||
processRemoteData: () => {}
|
||||
/* tslint:enable:no-empty */
|
||||
};
|
||||
const mockRoute = Object.assign(new ActivatedRouteStub(), {
|
||||
data: Observable.of({ item: new RemoteData(false, false, true, null, mockItem) })
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useClass: MockTranslateLoader
|
||||
}
|
||||
}), BrowserAnimationsModule],
|
||||
declarations: [ItemPageComponent, VarDirective],
|
||||
providers: [
|
||||
{provide: ActivatedRoute, useValue: mockRoute},
|
||||
{provide: ItemDataService, useValue: {}},
|
||||
{provide: MetadataService, useValue: mockMetadataService}
|
||||
],
|
||||
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(ItemPageComponent, {
|
||||
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(ItemPageComponent);
|
||||
comp = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
describe('when the item is loading', () => {
|
||||
beforeEach(() => {
|
||||
comp.itemRD$ = Observable.of(new RemoteData(true, true, true, null, undefined));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should display a loading component', () => {
|
||||
const loading = fixture.debugElement.query(By.css('ds-loading'));
|
||||
expect(loading.nativeElement).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the item failed loading', () => {
|
||||
beforeEach(() => {
|
||||
comp.itemRD$ = Observable.of(new RemoteData(false, false, false, null, undefined));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should display an error component', () => {
|
||||
const error = fixture.debugElement.query(By.css('ds-error'));
|
||||
expect(error.nativeElement).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,51 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { RelatedEntitiesComponent } from './related-entities-component';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||
import { createRelationshipsObservable } from '../entity-types/shared/entity-page-fields.component.spec';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
const mockItem1: Item = Object.assign(new Item(), {
|
||||
bitstreams: Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
|
||||
metadata: [],
|
||||
relationships: createRelationshipsObservable()
|
||||
});
|
||||
const mockItem2: Item = Object.assign(new Item(), {
|
||||
bitstreams: Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
|
||||
metadata: [],
|
||||
relationships: createRelationshipsObservable()
|
||||
});
|
||||
const mockEntities = [mockItem1, mockItem2];
|
||||
|
||||
describe('RelatedEntitiesComponent', () => {
|
||||
let comp: RelatedEntitiesComponent;
|
||||
let fixture: ComponentFixture<RelatedEntitiesComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [],
|
||||
declarations: [RelatedEntitiesComponent],
|
||||
providers: [],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(RelatedEntitiesComponent, {
|
||||
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(RelatedEntitiesComponent);
|
||||
comp = fixture.componentInstance;
|
||||
comp.entities = mockEntities;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it(`should load ${mockEntities.length} entity-type-switcher components`, () => {
|
||||
const fields = fixture.debugElement.queryAll(By.css('ds-entity-type-switcher'));
|
||||
expect(fields.length).toBe(mockEntities.length);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,35 @@
|
||||
import { FilteredDiscoveryPageResponseParsingService } from './filtered-discovery-page-response-parsing.service';
|
||||
import { getMockObjectCacheService } from '../../shared/mocks/mock-object-cache.service';
|
||||
import { GenericConstructor } from '../shared/generic-constructor';
|
||||
import { ResponseParsingService } from './parsing.service';
|
||||
import { GetRequest } from './request.models';
|
||||
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model';
|
||||
import { FilteredDiscoveryQueryResponse } from '../cache/response-cache.models';
|
||||
|
||||
describe('FilteredDiscoveryPageResponseParsingService', () => {
|
||||
let service: FilteredDiscoveryPageResponseParsingService;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new FilteredDiscoveryPageResponseParsingService(undefined, getMockObjectCacheService());
|
||||
});
|
||||
|
||||
describe('parse', () => {
|
||||
const request = Object.assign(new GetRequest('client/f5b4ccb8-fbb0-4548-b558-f234d9fdfad6', 'https://rest.api/path'), {
|
||||
getResponseParser(): GenericConstructor<ResponseParsingService> {
|
||||
return FilteredDiscoveryPageResponseParsingService;
|
||||
}
|
||||
});
|
||||
|
||||
const mockResponse = {
|
||||
payload: {
|
||||
'discovery-query': 'query'
|
||||
},
|
||||
statusCode: '200'
|
||||
} as DSpaceRESTV2Response;
|
||||
|
||||
it('should return a FilteredDiscoveryQueryResponse containing the correct query', () => {
|
||||
const response = service.parse(request, mockResponse);
|
||||
expect((response as FilteredDiscoveryQueryResponse).filterQuery).toBe(mockResponse.payload['discovery-query']);
|
||||
})
|
||||
});
|
||||
});
|
@@ -0,0 +1,46 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { EntityListElementComponent } from './entity-list-element.component';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||
import { createRelationshipsObservable } from '../../../+item-page/simple/entity-types/shared/entity-page-fields.component.spec';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
bitstreams: Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
|
||||
metadata: [],
|
||||
relationships: createRelationshipsObservable()
|
||||
});
|
||||
|
||||
describe('EntityListElementComponent', () => {
|
||||
let comp: EntityListElementComponent;
|
||||
let fixture: ComponentFixture<EntityListElementComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [],
|
||||
declarations: [EntityListElementComponent],
|
||||
providers: [
|
||||
{ provide: 'objectElementProvider', useValue: mockItem }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(EntityListElementComponent, {
|
||||
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(EntityListElementComponent);
|
||||
comp = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should call an entity-type-switcher component and pass the item', () => {
|
||||
const entityTypeSwitcher = fixture.debugElement.query(By.css('ds-entity-type-switcher')).componentInstance;
|
||||
expect(entityTypeSwitcher.object).toBe(mockItem);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,82 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TruncatePipe } from '../../../utils/truncate.pipe';
|
||||
import { TruncatableService } from '../../../truncatable/truncatable.service';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { EntitySearchResultComponent } from './entity-search-result-component';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||
import { createRelationshipsObservable } from '../../../../+item-page/simple/entity-types/shared/entity-page-fields.component.spec';
|
||||
import { ITEM } from '../../../entities/switcher/entity-type-switcher.component';
|
||||
import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model';
|
||||
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
bitstreams: Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
|
||||
metadata: [],
|
||||
relationships: createRelationshipsObservable()
|
||||
});
|
||||
const mockSearchResult = {
|
||||
dspaceObject: mockItem as Item,
|
||||
hitHighlights: []
|
||||
} as ItemSearchResult;
|
||||
|
||||
describe('EntitySearchResultComponent', () => {
|
||||
let comp: EntitySearchResultComponent;
|
||||
let fixture: ComponentFixture<EntitySearchResultComponent>;
|
||||
|
||||
describe('when injecting an Item', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [EntitySearchResultComponent, TruncatePipe],
|
||||
providers: [
|
||||
{provide: TruncatableService, useValue: {}},
|
||||
{provide: ITEM, useValue: mockItem}
|
||||
],
|
||||
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(EntitySearchResultComponent, {
|
||||
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(EntitySearchResultComponent);
|
||||
comp = fixture.componentInstance;
|
||||
}));
|
||||
|
||||
it('should initiate item, object and dso correctly', () => {
|
||||
expect(comp.item).toBe(mockItem);
|
||||
expect(comp.dso).toBe(mockItem);
|
||||
expect(comp.object.dspaceObject).toBe(mockItem);
|
||||
})
|
||||
});
|
||||
|
||||
describe('when injecting an ItemSearchResult', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [EntitySearchResultComponent, TruncatePipe],
|
||||
providers: [
|
||||
{provide: TruncatableService, useValue: {}},
|
||||
{provide: ITEM, useValue: mockSearchResult}
|
||||
],
|
||||
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(EntitySearchResultComponent, {
|
||||
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(EntitySearchResultComponent);
|
||||
comp = fixture.componentInstance;
|
||||
}));
|
||||
|
||||
it('should initiate item, object and dso correctly', () => {
|
||||
expect(comp.item).toBe(mockItem);
|
||||
expect(comp.dso).toBe(mockItem);
|
||||
expect(comp.object.dspaceObject).toBe(mockItem);
|
||||
})
|
||||
});
|
||||
});
|
@@ -0,0 +1,49 @@
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||
import { createRelationshipsObservable } from '../../../../+item-page/simple/entity-types/shared/entity-page-fields.component.spec';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { ItemSearchResultListElementComponent } from './item-search-result-list-element.component';
|
||||
import { TruncatableService } from '../../../truncatable/truncatable.service';
|
||||
import { TruncatePipe } from '../../../utils/truncate.pipe';
|
||||
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
bitstreams: Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
|
||||
metadata: [],
|
||||
relationships: createRelationshipsObservable()
|
||||
});
|
||||
|
||||
describe('ItemSearchResultListElementComponent', () => {
|
||||
let comp: ItemSearchResultListElementComponent;
|
||||
let fixture: ComponentFixture<ItemSearchResultListElementComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [],
|
||||
declarations: [ItemSearchResultListElementComponent, TruncatePipe],
|
||||
providers: [
|
||||
{ provide: TruncatableService, useValue: {} },
|
||||
{ provide: 'objectElementProvider', useValue: mockItem }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(ItemSearchResultListElementComponent, {
|
||||
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(ItemSearchResultListElementComponent);
|
||||
comp = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should call an entity-type-switcher component and pass the item', () => {
|
||||
const entityTypeSwitcher = fixture.debugElement.query(By.css('ds-entity-type-switcher')).componentInstance;
|
||||
expect(entityTypeSwitcher.object).toBe(mockItem);
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user