diff --git a/src/app/core/shared/community.model.ts b/src/app/core/shared/community.model.ts index c34666b0f0..ea80a02269 100644 --- a/src/app/core/shared/community.model.ts +++ b/src/app/core/shared/community.model.ts @@ -24,6 +24,7 @@ export class Community extends DSpaceObject { * Corresponds to the metadata field dc.description.abstract */ get shortDescription(): string { + debugger; return this.findMetadata('dc.description.abstract'); } 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 eaa6edc4d0..cc72ff3043 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 @@ -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; -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(); + }); }); -}) +}); 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 1fd98bf225..dabb137ea7 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 @@ -1,24 +1,13 @@ import { CommunityGridElementComponent } from './community-grid-element.component'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { NO_ERRORS_SCHEMA } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; -import { RouterStub } from '../../testing/router-stub'; -import { Observable } from 'rxjs/Observable'; +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; import { Community } from '../../../core/shared/community.model'; let communityGridElementComponent: CommunityGridElementComponent; let fixture: ComponentFixture; -const queryParam = 'test query'; -const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; -const activatedRouteStub = { - queryParams: Observable.of({ - query: queryParam, - scope: scopeParam - }) -}; -const mockCommunity: Community = Object.assign(new Community(), { +const mockCommunityWithAbstract: Community = Object.assign(new Community(), { metadata: [ { key: 'dc.description.abstract', @@ -27,40 +16,55 @@ const mockCommunity: Community = Object.assign(new Community(), { }] }); -const createdGridElementComponent:CommunityGridElementComponent= new CommunityGridElementComponent(mockCommunity); +const mockCommunityWithoutAbstract: Community = Object.assign(new Community(), { + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'Test title' + }] +}); describe('CommunityGridElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ CommunityGridElementComponent ], providers: [ - { provide: ActivatedRoute, useValue: activatedRouteStub }, - { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useValue: (createdGridElementComponent)} + { provide: 'objectElementProvider', useValue: (mockCommunityWithAbstract)} ], schemas: [ NO_ERRORS_SCHEMA ] - }).compileComponents(); // compile template and css + }).overrideComponent(CommunityGridElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); })); beforeEach(async(() => { fixture = TestBed.createComponent(CommunityGridElementComponent); communityGridElementComponent = fixture.componentInstance; - })); - it('should show the community cards in the grid element',() => { - console.log(fixture.debugElement.query(By.css('ds-community-grid-element'))); - expect(fixture.debugElement.query(By.css('ds-community-grid-element'))).toBeDefined(); - }) + describe('When the community has an abstract', () => { + beforeEach(() => { + communityGridElementComponent.object = mockCommunityWithAbstract; + fixture.detectChanges(); + }); - it('should only show the description if "short description" metadata is present',() => { - const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + it('should show the description paragraph', () => { + const communityAbstractField = fixture.debugElement.query(By.css('p.card-text')); + expect(communityAbstractField).not.toBeNull(); + }); + }); - if (mockCommunity.shortDescription.length > 0) { - expect(descriptionText).toBeDefined(); - }else { - expect(descriptionText).not.toBeDefined(); - } + describe('When the community has no abstract', () => { + beforeEach(() => { + communityGridElementComponent.object = mockCommunityWithoutAbstract; + fixture.detectChanges(); + }); + + it('should not show the description paragraph', () => { + const communityAbstractField = fixture.debugElement.query(By.css('p.card-text')); + expect(communityAbstractField).toBeNull(); + }); }); }); diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html index 47b5a6b2e6..328bfc3bc9 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html @@ -6,11 +6,11 @@

{{object.findMetadata('dc.title')}}

-

+

{{authorMd.value}} ; - {{object.findMetadata("dc.date.issued")}} + {{object.findMetadata("dc.date.issued")}}

{{object.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

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 8c7f856450..0dd7f0be0a 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 @@ -1,47 +1,55 @@ import { ItemGridElementComponent } from './item-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 { TruncatePipe } from '../../utils/truncate.pipe'; import { Item } from '../../../core/shared/item.model'; +import { Observable } from 'rxjs/Observable'; let itemGridElementComponent: ItemGridElementComponent; let fixture: ComponentFixture; -const queryParam = 'test query'; -const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; -const activatedRouteStub = { - queryParams: Observable.of({ - query: queryParam, - scope: scopeParam - }) -}; -/* tslint:disable:no-shadowed-variable */ -const mockItem: Item = Object.assign(new Item(), { + +const mockItemWithAuthorAndDate: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), metadata: [ { key: 'dc.contributor.author', language: 'en_US', value: 'Smith, Donald' + }, + { + key: 'dc.date.issued', + language: null, + value: '2015-06-26' + }] +}); +const mockItemWithoutAuthorAndDate: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }, + { + key: 'dc.type', + language: null, + value: 'Article' }] }); - -const createdGridElementComponent:ItemGridElementComponent= new ItemGridElementComponent(mockItem); describe('ItemGridElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ ItemGridElementComponent , TruncatePipe], providers: [ - { provide: ActivatedRoute, useValue: activatedRouteStub }, - { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useValue: {createdGridElementComponent}} + { provide: 'objectElementProvider', useValue: {mockItemWithAuthorAndDate}} ], schemas: [ NO_ERRORS_SCHEMA ] - }).compileComponents(); // compile template and css + }).overrideComponent(ItemGridElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); })); beforeEach(async(() => { @@ -50,18 +58,51 @@ describe('ItemGridElementComponent', () => { })); - it('should show the item cards in the grid element',() => { - expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined() + describe('When the item has an author', () => { + beforeEach(() => { + itemGridElementComponent.object = mockItemWithAuthorAndDate; + fixture.detectChanges(); + }); + + it('should show the author paragraph', () => { + const itemAuthorField = fixture.debugElement.query(By.css('p.item-authors')); + expect(itemAuthorField).not.toBeNull(); + }); }); - it('should only show the author span if the author metadata is present',() => { - const itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); + describe('When the item has no author', () => { + beforeEach(() => { + itemGridElementComponent.object = mockItemWithoutAuthorAndDate; + fixture.detectChanges(); + }); - if (mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0) { - expect(itemAuthorField).toBeDefined(); - }else { - expect(itemAuthorField).toBeDefined(); - } + it('should not show the author paragraph', () => { + const itemAuthorField = fixture.debugElement.query(By.css('p.item-authors')); + expect(itemAuthorField).toBeNull(); + }); }); + describe('When the item has an issuedate', () => { + beforeEach(() => { + itemGridElementComponent.object = mockItemWithAuthorAndDate; + fixture.detectChanges(); + }); + + it('should show the issuedate span', () => { + const itemAuthorField = fixture.debugElement.query(By.css('span.item-date')); + expect(itemAuthorField).not.toBeNull(); + }); + }); + + describe('When the item has no issuedate', () => { + beforeEach(() => { + itemGridElementComponent.object = mockItemWithoutAuthorAndDate; + fixture.detectChanges(); + }); + + it('should not show the issuedate span', () => { + const dateField = fixture.debugElement.query(By.css('span.item-date')); + expect(dateField).toBeNull(); + }); + }); }); 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 index 9eb65dbbdd..f3220baaa3 100644 --- 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 @@ -1,69 +1,83 @@ 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 { ChangeDetectionStrategy, 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'; import { TruncatableService } from '../../../truncatable/truncatable.service'; +import { CollectionSearchResult } from '../../../object-collection/shared/collection-search-result.model'; +let collectionSearchResultGridElementComponent: CollectionSearchResultGridElementComponent; let fixture: ComponentFixture; -const queryParam = 'test query'; -const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; -const activatedRouteStub = { - queryParams: Observable.of({ - query: queryParam, - scope: scopeParam - }) -}; + const truncatableServiceStub: any = { isCollapsed: (id: number) => Observable.of(true), }; -const mockCollection: Collection = Object.assign(new Collection(), { +const mockCollectionWithAbstract: CollectionSearchResult = new CollectionSearchResult(); +mockCollectionWithAbstract.hitHighlights = []; +mockCollectionWithAbstract.dspaceObject = Object.assign(new Collection(), { metadata: [ { key: 'dc.description.abstract', language: 'en_US', value: 'Short description' - }] - + } ] +}); + +const mockCollectionWithoutAbstract: CollectionSearchResult = new CollectionSearchResult(); +mockCollectionWithoutAbstract.hitHighlights = []; +mockCollectionWithoutAbstract.dspaceObject = Object.assign(new Collection(), { + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'Test title' + } ] }); -const createdGridElementComponent: CollectionSearchResultGridElementComponent = new CollectionSearchResultGridElementComponent(mockCollection, truncatableServiceStub as TruncatableService); describe('CollectionSearchResultGridElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [CollectionSearchResultGridElementComponent, TruncatePipe], + declarations: [ CollectionSearchResultGridElementComponent, TruncatePipe ], providers: [ { provide: TruncatableService, useValue: truncatableServiceStub }, - { 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 + schemas: [ NO_ERRORS_SCHEMA ] + }).overrideComponent(CollectionSearchResultGridElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); })); beforeEach(async(() => { fixture = TestBed.createComponent(CollectionSearchResultGridElementComponent); + collectionSearchResultGridElementComponent = fixture.componentInstance; })); - it('should show the item result cards in the grid element', () => { - expect(fixture.debugElement.query(By.css('ds-collection-search-result-grid-element'))).toBeDefined(); + describe('When the collection has an abstract', () => { + beforeEach(() => { + collectionSearchResultGridElementComponent.dso = mockCollectionWithAbstract.dspaceObject; + 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(() => { + collectionSearchResultGridElementComponent.dso = mockCollectionWithoutAbstract.dspaceObject; + 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(); + }); }); }); 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 index 6d70d08901..aa62baadc9 100644 --- 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 @@ -1,39 +1,41 @@ 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 { ChangeDetectionStrategy, 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 { TruncatableService } from '../../../truncatable/truncatable.service'; +import { CommunitySearchResult } from '../../../object-collection/shared/community-search-result.model'; - +let communitySearchResultGridElementComponent: CommunitySearchResultGridElementComponent; let fixture: ComponentFixture; -const queryParam = 'test query'; -const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; -const activatedRouteStub = { - queryParams: Observable.of({ - query: queryParam, - scope: scopeParam - }) -}; + const truncatableServiceStub: any = { isCollapsed: (id: number) => Observable.of(true), }; -const mockCommunity: Community = Object.assign(new Community(), { +const mockCommunityWithAbstract: CommunitySearchResult = new CommunitySearchResult(); +mockCommunityWithAbstract.hitHighlights = []; +mockCommunityWithAbstract.dspaceObject = Object.assign(new Community(), { metadata: [ { key: 'dc.description.abstract', language: 'en_US', value: 'Short description' } ] - }); -const createdGridElementComponent: CommunitySearchResultGridElementComponent = new CommunitySearchResultGridElementComponent(mockCommunity, truncatableServiceStub as TruncatableService); +const mockCommunityWithoutAbstract: CommunitySearchResult = new CommunitySearchResult(); +mockCommunityWithoutAbstract.hitHighlights = []; +mockCommunityWithoutAbstract.dspaceObject = Object.assign(new Community(), { + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'Test title' + } ] +}); describe('CommunitySearchResultGridElementComponent', () => { beforeEach(async(() => { @@ -41,30 +43,41 @@ describe('CommunitySearchResultGridElementComponent', () => { declarations: [ CommunitySearchResultGridElementComponent, TruncatePipe ], providers: [ { provide: TruncatableService, useValue: truncatableServiceStub }, - { provide: ActivatedRoute, useValue: activatedRouteStub }, - { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useValue: (createdGridElementComponent) } + { provide: 'objectElementProvider', useValue: (mockCommunityWithAbstract) } ], schemas: [ NO_ERRORS_SCHEMA ] - }).compileComponents(); // compile template and css + }).overrideComponent(CommunitySearchResultGridElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); })); beforeEach(async(() => { fixture = TestBed.createComponent(CommunitySearchResultGridElementComponent); + communitySearchResultGridElementComponent = fixture.componentInstance; })); - it('should show the item result cards in the grid element', () => { - expect(fixture.debugElement.query(By.css('ds-community-search-result-grid-element'))).toBeDefined(); + describe('When the community has an abstract', () => { + beforeEach(() => { + communitySearchResultGridElementComponent.dso = mockCommunityWithAbstract.dspaceObject; + fixture.detectChanges(); + }); + + it('should show the description paragraph', () => { + const communityAbstractField = fixture.debugElement.query(By.css('p.card-text')); + expect(communityAbstractField).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 community has no abstract', () => { + beforeEach(() => { + communitySearchResultGridElementComponent.dso = mockCommunityWithoutAbstract.dspaceObject; + fixture.detectChanges(); + }); - if (mockCommunity.shortDescription.length > 0) { - expect(descriptionText).toBeDefined(); - }else { - expect(descriptionText).not.toBeDefined(); - } + it('should not show the description paragraph', () => { + const communityAbstractField = fixture.debugElement.query(By.css('p.card-text')); + expect(communityAbstractField).toBeNull(); + }); }); }); 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 index fbb267b8e6..cf8a097ddb 100644 --- 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 @@ -1,8 +1,6 @@ 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, ChangeDetectionStrategy } from '@angular/core'; import { By } from '@angular/platform-browser'; import { TruncatePipe } from '../../../utils/truncate.pipe'; @@ -13,14 +11,6 @@ import { ItemSearchResult } from '../../../object-collection/shared/item-search- let itemSearchResultGridElementComponent: ItemSearchResultGridElementComponent; let fixture: ComponentFixture; -const queryParam = 'test query'; -const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; -const activatedRouteStub = { - queryParams: Observable.of({ - query: queryParam, - scope: scopeParam - }) -}; const truncatableServiceStub: any = { isCollapsed: (id: number) => Observable.of(true), @@ -46,7 +36,7 @@ mockItemWithAuthorAndDate.dspaceObject = Object.assign(new Item(), { const mockItemWithoutAuthorAndDate: ItemSearchResult = new ItemSearchResult(); mockItemWithoutAuthorAndDate.hitHighlights = []; mockItemWithoutAuthorAndDate.dspaceObject = Object.assign(new Item(), { - bitstream: Observable.of({}), + bitstreams: Observable.of({}), metadata: [ { key: 'dc.title', @@ -60,8 +50,6 @@ mockItemWithoutAuthorAndDate.dspaceObject = Object.assign(new Item(), { }] }); -const createdGridElementComponent: ItemSearchResultGridElementComponent = new ItemSearchResultGridElementComponent(mockItemWithAuthorAndDate, truncatableServiceStub as TruncatableService); - describe('ItemSearchResultGridElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ @@ -69,9 +57,7 @@ describe('ItemSearchResultGridElementComponent', () => { declarations: [ItemSearchResultGridElementComponent, TruncatePipe], providers: [ { provide: TruncatableService, useValue: truncatableServiceStub }, - { provide: ActivatedRoute, useValue: activatedRouteStub }, - { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useValue: (createdGridElementComponent) } + { provide: 'objectElementProvider', useValue: (mockItemWithoutAuthorAndDate) } ], schemas: [NO_ERRORS_SCHEMA] }).overrideComponent(ItemSearchResultGridElementComponent, { @@ -84,7 +70,7 @@ describe('ItemSearchResultGridElementComponent', () => { itemSearchResultGridElementComponent = fixture.componentInstance; })); - fdescribe('When the item has an author', () => { + describe('When the item has an author', () => { beforeEach(() => { itemSearchResultGridElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject; fixture.detectChanges(); @@ -99,6 +85,7 @@ describe('ItemSearchResultGridElementComponent', () => { describe('When the item has no author', () => { beforeEach(() => { itemSearchResultGridElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject; + fixture.detectChanges(); }); it('should not show the author paragraph', () => { @@ -110,6 +97,7 @@ describe('ItemSearchResultGridElementComponent', () => { describe('When the item has an issuedate', () => { beforeEach(() => { itemSearchResultGridElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject; + fixture.detectChanges(); }); it('should show the issuedate span', () => { @@ -121,6 +109,7 @@ describe('ItemSearchResultGridElementComponent', () => { describe('When the item has no issuedate', () => { beforeEach(() => { itemSearchResultGridElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject; + fixture.detectChanges(); }); it('should not show the issuedate span', () => { diff --git a/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts index c04c1d54f4..e6217eb0bb 100644 --- a/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts @@ -17,10 +17,9 @@ import { Observable } from 'rxjs/Observable'; export class SearchResultGridElementComponent, K extends DSpaceObject> extends AbstractListableElementComponent { dso: K; - public constructor(@Inject('objectElementProvider') public gridable: ListableObject, private truncatableService: TruncatableService) { - super(gridable); + public constructor(@Inject('objectElementProvider') public listableObject: ListableObject, private truncatableService: TruncatableService) { + super(listableObject); this.dso = this.object.dspaceObject; - console.log(JSON.stringify(this.object.hitHighlights)); } getValues(keys: string[]): string[] { @@ -44,7 +43,6 @@ export class SearchResultGridElementComponent, K exten getFirstValue(key: string): string { let result: string; - console.log(JSON.stringify(this.object.hitHighlights)); this.object.hitHighlights.some( (md: Metadatum) => { if (key === md.key) { diff --git a/src/app/shared/object-list/collection-list-element/collection-list-element.component.html b/src/app/shared/object-list/collection-list-element/collection-list-element.component.html index 8fb498d474..dec2794dca 100644 --- a/src/app/shared/object-list/collection-list-element/collection-list-element.component.html +++ b/src/app/shared/object-list/collection-list-element/collection-list-element.component.html @@ -1,6 +1,6 @@ {{object.name}} -
+
{{object.shortDescription}}
diff --git a/src/app/shared/object-list/collection-list-element/collection-list-element.component.spec.ts b/src/app/shared/object-list/collection-list-element/collection-list-element.component.spec.ts index fe54b8195e..a31af1e50c 100644 --- a/src/app/shared/object-list/collection-list-element/collection-list-element.component.spec.ts +++ b/src/app/shared/object-list/collection-list-element/collection-list-element.component.spec.ts @@ -1,21 +1,13 @@ import { CollectionListElementComponent } from './collection-list-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 collectionListElementComponent: CollectionListElementComponent; let fixture: ComponentFixture; -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 createdListElementComponent:CollectionListElementComponent= new CollectionListElementComponent(mockCollection); + +const mockCollectionWithoutAbstract: Collection = Object.assign(new Collection(), { + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'Test title' + }] +}); describe('CollectionListElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ CollectionListElementComponent ], providers: [ - { provide: ActivatedRoute, useValue: activatedRouteStub }, - { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useValue: (createdListElementComponent)} + { provide: 'objectElementProvider', useValue: (mockCollectionWithAbstract)} ], schemas: [ NO_ERRORS_SCHEMA ] - }).compileComponents(); // compile template and css + }).overrideComponent(CollectionListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); })); beforeEach(async(() => { fixture = TestBed.createComponent(CollectionListElementComponent); + collectionListElementComponent = fixture.componentInstance; })); - it('should show the collection cards in the list element',() => { - expect(fixture.debugElement.query(By.css('ds-collection-list-element'))).toBeDefined(); + describe('When the collection has an abstract', () => { + beforeEach(() => { + collectionListElementComponent.object = mockCollectionWithAbstract; + fixture.detectChanges(); + }); + + it('should show the description paragraph', () => { + const collectionAbstractField = fixture.debugElement.query(By.css('div.abstract-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(() => { + collectionListElementComponent.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('div.abstract-text')); + expect(collectionAbstractField).toBeNull(); + }); }); }); diff --git a/src/app/shared/object-list/community-list-element/community-list-element.component.html b/src/app/shared/object-list/community-list-element/community-list-element.component.html index d39995de40..7582680fb2 100644 --- a/src/app/shared/object-list/community-list-element/community-list-element.component.html +++ b/src/app/shared/object-list/community-list-element/community-list-element.component.html @@ -1,6 +1,6 @@ {{object.name}} -
+
{{object.shortDescription}}
diff --git a/src/app/shared/object-list/community-list-element/community-list-element.component.spec.ts b/src/app/shared/object-list/community-list-element/community-list-element.component.spec.ts index ff5a7fa441..08147d8573 100644 --- a/src/app/shared/object-list/community-list-element/community-list-element.component.spec.ts +++ b/src/app/shared/object-list/community-list-element/community-list-element.component.spec.ts @@ -1,24 +1,13 @@ import { CommunityListElementComponent } from './community-list-element.component'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { NO_ERRORS_SCHEMA } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; -import { RouterStub } from '../../testing/router-stub'; -import { Observable } from 'rxjs/Observable'; +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; import { Community } from '../../../core/shared/community.model'; let communityListElementComponent: CommunityListElementComponent; let fixture: ComponentFixture; -const queryParam = 'test query'; -const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; -const activatedRouteStub = { - queryParams: Observable.of({ - query: queryParam, - scope: scopeParam - }) -}; -const mockCommunity: Community = Object.assign(new Community(), { +const mockCommunityWithAbstract: Community = Object.assign(new Community(), { metadata: [ { key: 'dc.description.abstract', @@ -27,39 +16,55 @@ const mockCommunity: Community = Object.assign(new Community(), { }] }); -const createdListElementComponent:CommunityListElementComponent= new CommunityListElementComponent(mockCommunity); +const mockCommunityWithoutAbstract: Community = Object.assign(new Community(), { + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'Test title' + }] +}); describe('CommunityListElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ CommunityListElementComponent ], providers: [ - { provide: ActivatedRoute, useValue: activatedRouteStub }, - { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useValue: (createdListElementComponent)} + { provide: 'objectElementProvider', useValue: (mockCommunityWithAbstract)} ], - schemas: [ NO_ERRORS_SCHEMA ] - }).compileComponents(); // compile template and css + schemas: [ NO_ERRORS_SCHEMA ] + }).overrideComponent(CommunityListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); })); beforeEach(async(() => { fixture = TestBed.createComponent(CommunityListElementComponent); communityListElementComponent = fixture.componentInstance; - })); - it('should show the community cards in the list element',() => { - expect(fixture.debugElement.query(By.css('ds-community-list-element'))).toBeDefined(); - }) + describe('When the community has an abstract', () => { + beforeEach(() => { + communityListElementComponent.object = mockCommunityWithAbstract; + fixture.detectChanges(); + }); - it('should only show the description if "short description" metadata is present',() => { - const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + it('should show the description paragraph', () => { + const communityAbstractField = fixture.debugElement.query(By.css('div.abstract-text')); + expect(communityAbstractField).not.toBeNull(); + }); + }); - if (mockCommunity.shortDescription.length > 0) { - expect(descriptionText).toBeDefined(); - }else { - expect(descriptionText).not.toBeDefined(); - } + describe('When the community has no abstract', () => { + beforeEach(() => { + communityListElementComponent.object = mockCommunityWithoutAbstract; + fixture.detectChanges(); + }); + + it('should not show the description paragraph', () => { + const communityAbstractField = fixture.debugElement.query(By.css('div.abstract-text')); + expect(communityAbstractField).toBeNull(); + }); }); }); diff --git a/src/app/shared/object-list/item-list-element/item-list-element.component.html b/src/app/shared/object-list/item-list-element/item-list-element.component.html index e9bde67295..b4259c25c2 100644 --- a/src/app/shared/object-list/item-list-element/item-list-element.component.html +++ b/src/app/shared/object-list/item-list-element/item-list-element.component.html @@ -3,7 +3,7 @@
- {{authorMd.value}} ; diff --git a/src/app/shared/object-list/item-list-element/item-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/item-list-element.component.spec.ts index 3383ed8454..fc40527693 100644 --- a/src/app/shared/object-list/item-list-element/item-list-element.component.spec.ts +++ b/src/app/shared/object-list/item-list-element/item-list-element.component.spec.ts @@ -1,47 +1,55 @@ import { ItemListElementComponent } from './item-list-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 { TruncatePipe } from '../../utils/truncate.pipe'; import { Item } from '../../../core/shared/item.model'; +import { Observable } from 'rxjs/Observable'; let itemListElementComponent: ItemListElementComponent; let fixture: ComponentFixture; -const queryParam = 'test query'; -const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; -const activatedRouteStub = { - queryParams: Observable.of({ - query: queryParam, - scope: scopeParam - }) -}; -/* tslint:disable:no-shadowed-variable */ -const mockItem: Item = Object.assign(new Item(), { + +const mockItemWithAuthorAndDate: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), metadata: [ { key: 'dc.contributor.author', language: 'en_US', value: 'Smith, Donald' + }, + { + key: 'dc.date.issued', + language: null, + value: '2015-06-26' + }] +}); +const mockItemWithoutAuthorAndDate: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }, + { + key: 'dc.type', + language: null, + value: 'Article' }] }); - -const createdListElementComponent:ItemListElementComponent= new ItemListElementComponent(mockItem); describe('ItemListElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ ItemListElementComponent , TruncatePipe], providers: [ - { provide: ActivatedRoute, useValue: activatedRouteStub }, - { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useValue: {createdListElementComponent}} + { provide: 'objectElementProvider', useValue: {mockItemWithAuthorAndDate}} ], schemas: [ NO_ERRORS_SCHEMA ] - }).compileComponents(); // compile template and css + }).overrideComponent(ItemListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); })); beforeEach(async(() => { @@ -50,18 +58,51 @@ describe('ItemListElementComponent', () => { })); - it('should show the item cards in the list element',() => { - expect(fixture.debugElement.query(By.css('ds-item-list-element'))).toBeDefined() + describe('When the item has an author', () => { + beforeEach(() => { + itemListElementComponent.object = mockItemWithAuthorAndDate; + fixture.detectChanges(); + }); + + it('should show the author paragraph', () => { + const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors')); + expect(itemAuthorField).not.toBeNull(); + }); }); - it('should only show the author span if the author metadata is present',() => { - const itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); + describe('When the item has no author', () => { + beforeEach(() => { + itemListElementComponent.object = mockItemWithoutAuthorAndDate; + fixture.detectChanges(); + }); - if (mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0) { - expect(itemAuthorField).toBeDefined(); - }else { - expect(itemAuthorField).toBeDefined(); - } + it('should not show the author paragraph', () => { + const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors')); + expect(itemAuthorField).toBeNull(); + }); }); -}) + describe('When the item has an issuedate', () => { + beforeEach(() => { + itemListElementComponent.object = mockItemWithAuthorAndDate; + fixture.detectChanges(); + }); + + it('should show the issuedate span', () => { + const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-date')); + expect(itemAuthorField).not.toBeNull(); + }); + }); + + describe('When the item has no issuedate', () => { + beforeEach(() => { + itemListElementComponent.object = mockItemWithoutAuthorAndDate; + fixture.detectChanges(); + }); + + it('should not show the issuedate span', () => { + const dateField = fixture.debugElement.query(By.css('span.item-list-date')); + expect(dateField).toBeNull(); + }); + }); +}); diff --git a/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html index 914fb49487..be549b2b76 100644 --- a/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html +++ b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html @@ -1,2 +1,2 @@ -
+
diff --git a/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.spec.ts b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.spec.ts index 37756b5916..0395904070 100644 --- a/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.spec.ts +++ b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.spec.ts @@ -1,68 +1,83 @@ import { CollectionSearchResultListElementComponent } from './collection-search-result-list-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 { TruncatePipe } from '../../../utils/truncate.pipe'; import { Collection } from '../../../../core/shared/collection.model'; import { TruncatableService } from '../../../truncatable/truncatable.service'; +import { CollectionSearchResult } from '../../../object-collection/shared/collection-search-result.model'; +let collectionSearchResultListElementComponent: CollectionSearchResultListElementComponent; let fixture: ComponentFixture; -const queryParam = 'test query'; -const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; -const activatedRouteStub = { - queryParams: Observable.of({ - query: queryParam, - scope: scopeParam - }) -}; + const truncatableServiceStub: any = { isCollapsed: (id: number) => Observable.of(true), }; -const mockCollection: Collection = Object.assign(new Collection(), { +const mockCollectionWithAbstract: CollectionSearchResult = new CollectionSearchResult(); +mockCollectionWithAbstract.hitHighlights = []; +mockCollectionWithAbstract.dspaceObject = Object.assign(new Collection(), { metadata: [ { key: 'dc.description.abstract', language: 'en_US', value: 'Short description' - }] - + } ] +}); + +const mockCollectionWithoutAbstract: CollectionSearchResult = new CollectionSearchResult(); +mockCollectionWithoutAbstract.hitHighlights = []; +mockCollectionWithoutAbstract.dspaceObject = Object.assign(new Collection(), { + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'Test title' + } ] }); -const createdListElementComponent: CollectionSearchResultListElementComponent = new CollectionSearchResultListElementComponent(mockCollection, truncatableServiceStub as TruncatableService); describe('CollectionSearchResultListElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [CollectionSearchResultListElementComponent, TruncatePipe], + declarations: [ CollectionSearchResultListElementComponent, TruncatePipe ], providers: [ { provide: TruncatableService, useValue: truncatableServiceStub }, - { provide: ActivatedRoute, useValue: activatedRouteStub }, - { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useValue: (createdListElementComponent) } + { provide: 'objectElementProvider', useValue: (mockCollectionWithAbstract) } ], - schemas: [NO_ERRORS_SCHEMA] - }).compileComponents(); // compile template and css + schemas: [ NO_ERRORS_SCHEMA ] + }).overrideComponent(CollectionSearchResultListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); })); beforeEach(async(() => { fixture = TestBed.createComponent(CollectionSearchResultListElementComponent); + collectionSearchResultListElementComponent = fixture.componentInstance; })); - it('should show the item result cards in the list element', () => { - expect(fixture.debugElement.query(By.css('ds-collection-search-result-list-element'))).toBeDefined(); + describe('When the collection has an abstract', () => { + beforeEach(() => { + collectionSearchResultListElementComponent.dso = mockCollectionWithAbstract.dspaceObject; + fixture.detectChanges(); + }); + + it('should show the description paragraph', () => { + const collectionAbstractField = fixture.debugElement.query(By.css('div.abstract-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(() => { + collectionSearchResultListElementComponent.dso = mockCollectionWithoutAbstract.dspaceObject; + 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('div.abstract-text')); + expect(collectionAbstractField).toBeNull(); + }); }); }); diff --git a/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html index d09ef7d668..150ca503cc 100644 --- a/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html +++ b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html @@ -1,2 +1,2 @@ -
+
diff --git a/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.spec.ts b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.spec.ts index 3e82e824ec..54dde5dee6 100644 --- a/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.spec.ts +++ b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.spec.ts @@ -1,38 +1,41 @@ import { CommunitySearchResultListElementComponent } from './community-search-result-list-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 { TruncatePipe } from '../../../utils/truncate.pipe'; import { Community } from '../../../../core/shared/community.model'; import { TruncatableService } from '../../../truncatable/truncatable.service'; +import { CommunitySearchResult } from '../../../object-collection/shared/community-search-result.model'; +let communitySearchResultListElementComponent: CommunitySearchResultListElementComponent; let fixture: ComponentFixture; -const queryParam = 'test query'; -const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; -const activatedRouteStub = { - queryParams: Observable.of({ - query: queryParam, - scope: scopeParam - }) -}; + const truncatableServiceStub: any = { isCollapsed: (id: number) => Observable.of(true), }; -const mockCommunity: Community = Object.assign(new Community(), { +const mockCommunityWithAbstract: CommunitySearchResult = new CommunitySearchResult(); +mockCommunityWithAbstract.hitHighlights = []; +mockCommunityWithAbstract.dspaceObject = Object.assign(new Community(), { metadata: [ { key: 'dc.description.abstract', language: 'en_US', value: 'Short description' } ] - }); -const createdListElementComponent: CommunitySearchResultListElementComponent = new CommunitySearchResultListElementComponent(mockCommunity, truncatableServiceStub as TruncatableService); +const mockCommunityWithoutAbstract: CommunitySearchResult = new CommunitySearchResult(); +mockCommunityWithoutAbstract.hitHighlights = []; +mockCommunityWithoutAbstract.dspaceObject = Object.assign(new Community(), { + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'Test title' + } ] +}); describe('CommunitySearchResultListElementComponent', () => { beforeEach(async(() => { @@ -40,30 +43,41 @@ describe('CommunitySearchResultListElementComponent', () => { declarations: [ CommunitySearchResultListElementComponent, TruncatePipe ], providers: [ { provide: TruncatableService, useValue: truncatableServiceStub }, - { provide: ActivatedRoute, useValue: activatedRouteStub }, - { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useValue: (createdListElementComponent) } + { provide: 'objectElementProvider', useValue: (mockCommunityWithAbstract) } ], schemas: [ NO_ERRORS_SCHEMA ] - }).compileComponents(); // compile template and css + }).overrideComponent(CommunitySearchResultListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); })); beforeEach(async(() => { fixture = TestBed.createComponent(CommunitySearchResultListElementComponent); + communitySearchResultListElementComponent = fixture.componentInstance; })); - it('should show the item result cards in the list element', () => { - expect(fixture.debugElement.query(By.css('ds-community-search-result-list-element'))).toBeDefined(); + describe('When the community has an abstract', () => { + beforeEach(() => { + communitySearchResultListElementComponent.dso = mockCommunityWithAbstract.dspaceObject; + fixture.detectChanges(); + }); + + it('should show the description paragraph', () => { + const communityAbstractField = fixture.debugElement.query(By.css('div.abstract-text')); + expect(communityAbstractField).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 community has no abstract', () => { + beforeEach(() => { + communitySearchResultListElementComponent.dso = mockCommunityWithoutAbstract.dspaceObject; + fixture.detectChanges(); + }); - if (mockCommunity.shortDescription.length > 0) { - expect(descriptionText).toBeDefined(); - }else { - expect(descriptionText).not.toBeDefined(); - } + it('should not show the description paragraph', () => { + const communityAbstractField = fixture.debugElement.query(By.css('div.abstract-text')); + expect(communityAbstractField).toBeNull(); + }); }); }); diff --git a/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html index d7ef1c673c..b8f3197a7c 100644 --- a/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html +++ b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html @@ -8,7 +8,7 @@ [innerHTML]="getFirstValue('dc.publisher')">,
) - diff --git a/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.spec.ts b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.spec.ts index c7bf09ea1e..f492c58483 100644 --- a/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.spec.ts +++ b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.spec.ts @@ -1,30 +1,25 @@ import { ItemSearchResultListElementComponent } from './item-search-result-list-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 { NO_ERRORS_SCHEMA, ChangeDetectionStrategy } from '@angular/core'; import { By } from '@angular/platform-browser'; import { TruncatePipe } from '../../../utils/truncate.pipe'; import { Item } from '../../../../core/shared/item.model'; import { TruncatableService } from '../../../truncatable/truncatable.service'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; let itemSearchResultListElementComponent: ItemSearchResultListElementComponent; let fixture: ComponentFixture; -const queryParam = 'test query'; -const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; -const activatedRouteStub = { - queryParams: Observable.of({ - query: queryParam, - scope: scopeParam - }) -}; const truncatableServiceStub: any = { isCollapsed: (id: number) => Observable.of(true), }; -const mockItem: Item = Object.assign(new Item(), { +const mockItemWithAuthorAndDate: ItemSearchResult = new ItemSearchResult(); +mockItemWithAuthorAndDate.hitHighlights = []; +mockItemWithAuthorAndDate.dspaceObject = Object.assign(new Item(), { + bitstreams: Observable.of({}), metadata: [ { key: 'dc.contributor.author', @@ -34,24 +29,40 @@ const mockItem: Item = Object.assign(new Item(), { { key: 'dc.date.issued', language: null, - value: '1650-06-26' + value: '2015-06-26' + }] +}); + +const mockItemWithoutAuthorAndDate: ItemSearchResult = new ItemSearchResult(); +mockItemWithoutAuthorAndDate.hitHighlights = []; +mockItemWithoutAuthorAndDate.dspaceObject = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }, + { + key: 'dc.type', + language: null, + value: 'Article' }] }); -const createdListElementComponent: ItemSearchResultListElementComponent = new ItemSearchResultListElementComponent(mockItem, truncatableServiceStub as TruncatableService); describe('ItemSearchResultListElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ + imports: [NoopAnimationsModule], declarations: [ItemSearchResultListElementComponent, TruncatePipe], providers: [ { provide: TruncatableService, useValue: truncatableServiceStub }, - { provide: ActivatedRoute, useValue: activatedRouteStub }, - { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useValue: (createdListElementComponent) } + { provide: 'objectElementProvider', useValue: (mockItemWithoutAuthorAndDate) } ], - schemas: [NO_ERRORS_SCHEMA] - }).compileComponents(); // compile template and css + }).overrideComponent(ItemSearchResultListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); })); beforeEach(async(() => { @@ -59,28 +70,51 @@ describe('ItemSearchResultListElementComponent', () => { itemSearchResultListElementComponent = fixture.componentInstance; })); - it('should show the item result cards in the list element', () => { - expect(fixture.debugElement.query(By.css('ds-item-search-result-list-element'))).toBeDefined(); + describe('When the item has an author', () => { + beforeEach(() => { + itemSearchResultListElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject; + fixture.detectChanges(); + }); + + it('should show the author paragraph', () => { + const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors')); + expect(itemAuthorField).not.toBeNull(); + }); }); - it('should only show the author span if the author metadata is present', () => { - const itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); + describe('When the item has no author', () => { + beforeEach(() => { + itemSearchResultListElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject; + fixture.detectChanges(); + }); - if (mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0) { - expect(itemAuthorField).toBeDefined(); - } else { - expect(itemAuthorField).not.toBeDefined(); - } + it('should not show the author paragraph', () => { + const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors')); + expect(itemAuthorField).toBeNull(); + }); }); - it('should only show the date span if the issuedate is present', () => { - const dateField = expect(fixture.debugElement.query(By.css('span.item-list-date'))); + describe('When the item has an issuedate', () => { + beforeEach(() => { + itemSearchResultListElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject; + fixture.detectChanges(); + }); - if (mockItem.findMetadata('dc.date.issued').length > 0) { - expect(dateField).toBeDefined(); - } else { - expect(dateField).not.toBeDefined(); - } + it('should show the issuedate span', () => { + const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-date')); + expect(itemAuthorField).not.toBeNull(); + }); }); + describe('When the item has no issuedate', () => { + beforeEach(() => { + itemSearchResultListElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject; + fixture.detectChanges(); + }); + + it('should not show the issuedate span', () => { + const dateField = fixture.debugElement.query(By.css('span.item-list-date')); + expect(dateField).toBeNull(); + }); + }); });