#150 Grid element testing

This commit is contained in:
Jonas Van Goolen
2017-11-06 13:40:00 +01:00
parent 04218060dd
commit 68dd411ae7
6 changed files with 290 additions and 8 deletions

View File

@@ -5,6 +5,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { RouterStub } from '../../testing/router-stub';
import { 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>;
@@ -16,6 +17,15 @@ const activatedRouteStub = {
scope: scopeParam
})
};
let mockCollection: Collection = Object.assign(new Collection(), {
metadata: [
{
key: 'dc.description.abstract',
language: 'en_US',
value: 'Short description'
}]
});
let createdGridElementComponent:CollectionGridElementComponent= new CollectionGridElementComponent(mockCollection);
describe('CollectionGridElementComponent', () => {
beforeEach(async(() => {
@@ -24,7 +34,7 @@ describe('CollectionGridElementComponent', () => {
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useFactory: (collectionGridElementComponent)}
{ provide: 'objectElementProvider', useValue: (createdGridElementComponent)}
],
schemas: [ NO_ERRORS_SCHEMA ]
@@ -33,11 +43,19 @@ describe('CollectionGridElementComponent', () => {
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();
})
});
it('should only show the description if "short description" metadata is present',()=>{
let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text')));
if(mockCollection.shortDescription.length>0){
expect(descriptionText).toBeDefined();
}else{
expect(descriptionText).not.toBeDefined();
}
});
})