diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts index a1af8b5a3cbe9e53b74cfa650cfe6e3dd935c6c0..fd935af992db13bbbe80302546cc51ee90a1ea95 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts @@ -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(); + } + }); }) diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts index f6ab7bc6cdf425f78692f3a34c75cb601c6ee623..dc837e3c0c1e156d0434c42694d7d8571cc19b3a 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts @@ -18,6 +18,18 @@ const activatedRouteStub = { 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', () => { beforeEach(async(() => { TestBed.configureTestingModule({ @@ -25,7 +37,7 @@ describe('CommunityGridElementComponent', () => { providers: [ { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useFactory: (communityGridElementComponent)} + { provide: 'objectElementProvider', useValue: (createdGridElementComponent)} ], schemas: [ NO_ERRORS_SCHEMA ] @@ -41,4 +53,14 @@ describe('CommunityGridElementComponent', () => { it('should show the community cards in the grid element',()=>{ 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(); + } + }); }); diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts index b4fb9c8029048a2d3e9ec6c25007a799a728fed5..8913dca3ee0a2bc91c237a718d7ebdff18b1a5b0 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts @@ -6,6 +6,7 @@ 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 itemGridElementComponent: ItemGridElementComponent; let fixture: ComponentFixture<ItemGridElementComponent>; @@ -17,6 +18,17 @@ const activatedRouteStub = { 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', () => { beforeEach(async(() => { @@ -25,7 +37,7 @@ describe('ItemGridElementComponent', () => { providers: [ { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useFactory: (itemGridElementComponent)} + { provide: 'objectElementProvider', useValue: {createdGridElementComponent}} ], schemas: [ NO_ERRORS_SCHEMA ] @@ -39,6 +51,18 @@ describe('ItemGridElementComponent', () => { })); 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(); + } + }); + + }) diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..8d6fe6fb3837a4bd4eff1fd47769dc82b84bf874 --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts @@ -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(); + } + }); +}); diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..0924700da79db1c4e4592553a8389517733a4d1b --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts @@ -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(); + } + }); +}); diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..318910304fc586d472ff87d76b3fc023803b99b1 --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts @@ -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(); + } + }); + + + + +});