#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 { RouterStub } from '../../testing/router-stub';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { NO_ERRORS_SCHEMA } from '@angular/core';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { Collection } from '../../../core/shared/collection.model';
let collectionGridElementComponent: CollectionGridElementComponent; let collectionGridElementComponent: CollectionGridElementComponent;
let fixture: ComponentFixture<CollectionGridElementComponent>; let fixture: ComponentFixture<CollectionGridElementComponent>;
@@ -16,6 +17,15 @@ const activatedRouteStub = {
scope: scopeParam 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', () => { describe('CollectionGridElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
@@ -24,7 +34,7 @@ describe('CollectionGridElementComponent', () => {
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useClass: RouterStub }, { provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useFactory: (collectionGridElementComponent)} { provide: 'objectElementProvider', useValue: (createdGridElementComponent)}
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
@@ -33,11 +43,19 @@ describe('CollectionGridElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
fixture = TestBed.createComponent(CollectionGridElementComponent); fixture = TestBed.createComponent(CollectionGridElementComponent);
collectionGridElementComponent = fixture.componentInstance;
})); }));
it('should show the collection cards in the grid element',()=>{ it('should show the collection cards in the grid element',()=>{
expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined(); 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();
}
});
}) })

View File

@@ -18,6 +18,18 @@ const activatedRouteStub = {
scope: scopeParam scope: scopeParam
}) })
}; };
let mockCommunity: Community = Object.assign(new Community(), {
metadata: [
{
key: 'dc.description.abstract',
language: 'en_US',
value: 'Short description'
}]
});
let createdGridElementComponent:CommunityGridElementComponent= new CommunityGridElementComponent(mockCommunity);
describe('CommunityGridElementComponent', () => { describe('CommunityGridElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -25,7 +37,7 @@ describe('CommunityGridElementComponent', () => {
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useClass: RouterStub }, { provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useFactory: (communityGridElementComponent)} { provide: 'objectElementProvider', useValue: (createdGridElementComponent)}
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
@@ -41,4 +53,14 @@ describe('CommunityGridElementComponent', () => {
it('should show the community cards in the grid element',()=>{ it('should show the community cards in the grid element',()=>{
expect(fixture.debugElement.query(By.css('ds-community-grid-element'))).toBeDefined(); expect(fixture.debugElement.query(By.css('ds-community-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(mockCommunity.shortDescription.length>0){
expect(descriptionText).toBeDefined();
}else{
expect(descriptionText).not.toBeDefined();
}
});
}); });

View File

@@ -6,6 +6,7 @@ import { RouterStub } from '../../testing/router-stub';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { NO_ERRORS_SCHEMA } from '@angular/core';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { TruncatePipe } from '../../utils/truncate.pipe'; import { TruncatePipe } from '../../utils/truncate.pipe';
import { Item } from '../../../core/shared/item.model';
let itemGridElementComponent: ItemGridElementComponent; let itemGridElementComponent: ItemGridElementComponent;
let fixture: ComponentFixture<ItemGridElementComponent>; let fixture: ComponentFixture<ItemGridElementComponent>;
@@ -17,6 +18,17 @@ const activatedRouteStub = {
scope: scopeParam scope: scopeParam
}) })
}; };
/* tslint:disable:no-shadowed-variable */
let mockItem: Item = Object.assign(new Item(), {
metadata: [
{
key: 'dc.contributor.author',
language: 'en_US',
value: 'Smith, Donald'
}]
});
let createdGridElementComponent:ItemGridElementComponent= new ItemGridElementComponent(mockItem);
describe('ItemGridElementComponent', () => { describe('ItemGridElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
@@ -25,7 +37,7 @@ describe('ItemGridElementComponent', () => {
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useClass: RouterStub }, { provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useFactory: (itemGridElementComponent)} { provide: 'objectElementProvider', useValue: {createdGridElementComponent}}
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
@@ -39,6 +51,18 @@ describe('ItemGridElementComponent', () => {
})); }));
it('should show the item cards in the grid element',()=>{ it('should show the item cards in the grid element',()=>{
expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined(); expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined()
}) });
it('should only show the author span if the author metadata is present',()=>{
let itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors')));
if(mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length>0){
expect(itemAuthorField).toBeDefined();
}else{
expect(itemAuthorField).toBeDefined();
}
});
}) })

View File

@@ -0,0 +1,67 @@
import {CollectionSearchResultGridElementComponent } from './collection-search-result-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 { By } from '@angular/platform-browser';
import { TruncatePipe } from '../../../utils/truncate.pipe';
import { Community } from '../../../../core/shared/community.model';
import { Collection } from '../../../../core/shared/collection.model';
let fixture: ComponentFixture<CollectionSearchResultGridElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
let mockCollection: Collection = Object.assign(new Collection(), {
metadata: [
{
key: 'dc.description.abstract',
language: 'en_US',
value: 'Short description'
} ]
});
let createdGridElementComponent: CollectionSearchResultGridElementComponent = new CollectionSearchResultGridElementComponent(mockCollection);
describe('CollectionSearchResultGridElementComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CollectionSearchResultGridElementComponent, TruncatePipe ],
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdGridElementComponent) }
],
schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css
}));
beforeEach(async(() => {
fixture = TestBed.createComponent(CollectionSearchResultGridElementComponent);
}));
it('should show the item result cards in the grid element', () => {
expect(fixture.debugElement.query(By.css('ds-collection-search-result-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();
}
});
});

View File

@@ -0,0 +1,67 @@
import { CommunitySearchResultGridElementComponent } from './community-search-result-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 { By } from '@angular/platform-browser';
import { TruncatePipe } from '../../../utils/truncate.pipe';
import { Community } from '../../../../core/shared/community.model';
let communitySearchResultGridElementComponent: CommunitySearchResultGridElementComponent;
let fixture: ComponentFixture<CommunitySearchResultGridElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
let mockCommunity: Community = Object.assign(new Community(), {
metadata: [
{
key: 'dc.description.abstract',
language: 'en_US',
value: 'Short description'
} ]
});
let createdGridElementComponent: CommunitySearchResultGridElementComponent = new CommunitySearchResultGridElementComponent(mockCommunity);
describe('CommunitySearchResultGridElementComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CommunitySearchResultGridElementComponent, TruncatePipe ],
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdGridElementComponent) }
],
schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css
}));
beforeEach(async(() => {
fixture = TestBed.createComponent(CommunitySearchResultGridElementComponent);
}));
it('should show the item result cards in the grid element', () => {
expect(fixture.debugElement.query(By.css('ds-community-search-result-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(mockCommunity.shortDescription.length>0){
expect(descriptionText).toBeDefined();
}else{
expect(descriptionText).not.toBeDefined();
}
});
});

View File

@@ -0,0 +1,84 @@
import { ItemSearchResultGridElementComponent } from './item-search-result-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 { By } from '@angular/platform-browser';
import { TruncatePipe } from '../../../utils/truncate.pipe';
import { Item } from '../../../../core/shared/item.model';
let itemSearchResultGridElementComponent: ItemSearchResultGridElementComponent;
let fixture: ComponentFixture<ItemSearchResultGridElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
let mockItem: Item = Object.assign(new Item(), {
metadata: [
{
key: 'dc.contributor.author',
language: 'en_US',
value: 'Smith, Donald'
},
{
key: 'dc.date.issued',
language: null,
value: '1650-06-26'
}]
});
let createdGridElementComponent:ItemSearchResultGridElementComponent= new ItemSearchResultGridElementComponent(mockItem);
describe('ItemSearchResultGridElementComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ItemSearchResultGridElementComponent, TruncatePipe ],
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdGridElementComponent) }
],
schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css
}));
beforeEach(async(() => {
fixture = TestBed.createComponent(ItemSearchResultGridElementComponent);
itemSearchResultGridElementComponent = fixture.componentInstance;
}));
it('should show the item result cards in the grid element',()=>{
expect(fixture.debugElement.query(By.css('ds-item-search-result-grid-element'))).toBeDefined();
});
it('should only show the author span if the author metadata is present',()=>{
let itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors')));
if(mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length>0){
expect(itemAuthorField).toBeDefined();
}else{
expect(itemAuthorField).not.toBeDefined();
}
});
it('should only show the date span if the issuedate is present',()=>{
let dateField = expect(fixture.debugElement.query(By.css('span.item-list-date')));
if(mockItem.findMetadata('dc.date.issued').length>0){
expect(dateField).toBeDefined();
}else{
expect(dateField).not.toBeDefined();
}
});
});