mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 19:43:04 +00:00
fixed list element tests
This commit is contained in:
@@ -1,21 +1,13 @@
|
||||
import { CollectionGridElementComponent } from './collection-grid-element.component';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { RouterStub } from '../../testing/router-stub';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { Collection } from '../../../core/shared/collection.model';
|
||||
|
||||
let collectionGridElementComponent: CollectionGridElementComponent;
|
||||
let fixture: ComponentFixture<CollectionGridElementComponent>;
|
||||
const queryParam = 'test query';
|
||||
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
|
||||
const activatedRouteStub = {
|
||||
queryParams: Observable.of({
|
||||
query: queryParam,
|
||||
scope: scopeParam
|
||||
})
|
||||
};
|
||||
const mockCollection: Collection = Object.assign(new Collection(), {
|
||||
|
||||
const mockCollectionWithAbstract: Collection = Object.assign(new Collection(), {
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.description.abstract',
|
||||
@@ -23,37 +15,56 @@ const mockCollection: Collection = Object.assign(new Collection(), {
|
||||
value: 'Short description'
|
||||
}]
|
||||
});
|
||||
const createdGridElementComponent:CollectionGridElementComponent= new CollectionGridElementComponent(mockCollection);
|
||||
|
||||
const mockCollectionWithoutAbstract: Collection = Object.assign(new Collection(), {
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.title',
|
||||
language: 'en_US',
|
||||
value: 'Test title'
|
||||
}]
|
||||
});
|
||||
|
||||
describe('CollectionGridElementComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CollectionGridElementComponent ],
|
||||
providers: [
|
||||
{ provide: ActivatedRoute, useValue: activatedRouteStub },
|
||||
{ provide: Router, useClass: RouterStub },
|
||||
{ provide: 'objectElementProvider', useValue: (createdGridElementComponent)}
|
||||
{ provide: 'objectElementProvider', useValue: (mockCollectionWithAbstract)}
|
||||
],
|
||||
|
||||
schemas: [ NO_ERRORS_SCHEMA ]
|
||||
}).compileComponents(); // compile template and css
|
||||
}).overrideComponent(CollectionGridElementComponent, {
|
||||
set: { changeDetection: ChangeDetectionStrategy.Default }
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(CollectionGridElementComponent);
|
||||
collectionGridElementComponent = fixture.componentInstance;
|
||||
}));
|
||||
|
||||
it('should show the collection cards in the grid element',() => {
|
||||
expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined();
|
||||
describe('When the collection has an abstract', () => {
|
||||
beforeEach(() => {
|
||||
collectionGridElementComponent.object = mockCollectionWithAbstract;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should show the description paragraph', () => {
|
||||
const collectionAbstractField = fixture.debugElement.query(By.css('p.card-text'));
|
||||
expect(collectionAbstractField).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it('should only show the description if "short description" metadata is present',() => {
|
||||
const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text')));
|
||||
describe('When the collection has no abstract', () => {
|
||||
beforeEach(() => {
|
||||
collectionGridElementComponent.object = mockCollectionWithoutAbstract;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
if (mockCollection.shortDescription.length > 0) {
|
||||
expect(descriptionText).toBeDefined();
|
||||
}else {
|
||||
expect(descriptionText).not.toBeDefined();
|
||||
}
|
||||
it('should not show the description paragraph', () => {
|
||||
const collectionAbstractField = fixture.debugElement.query(By.css('p.card-text'));
|
||||
expect(collectionAbstractField).toBeNull();
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
|
Reference in New Issue
Block a user