fixed list element tests

This commit is contained in:
Lotte Hofstede
2018-02-13 15:06:07 +01:00
parent 52781d02c4
commit 2895bb61e8
21 changed files with 545 additions and 354 deletions

View File

@@ -24,6 +24,7 @@ export class Community extends DSpaceObject {
* Corresponds to the metadata field dc.description.abstract * Corresponds to the metadata field dc.description.abstract
*/ */
get shortDescription(): string { get shortDescription(): string {
debugger;
return this.findMetadata('dc.description.abstract'); return this.findMetadata('dc.description.abstract');
} }

View File

@@ -1,21 +1,13 @@
import { CollectionGridElementComponent } from './collection-grid-element.component'; import { CollectionGridElementComponent } from './collection-grid-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
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 { By } from '@angular/platform-browser';
import { Collection } from '../../../core/shared/collection.model'; import { Collection } from '../../../core/shared/collection.model';
let collectionGridElementComponent: CollectionGridElementComponent;
let fixture: ComponentFixture<CollectionGridElementComponent>; let fixture: ComponentFixture<CollectionGridElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; const mockCollectionWithAbstract: Collection = Object.assign(new Collection(), {
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
const mockCollection: Collection = Object.assign(new Collection(), {
metadata: [ metadata: [
{ {
key: 'dc.description.abstract', key: 'dc.description.abstract',
@@ -23,37 +15,56 @@ const mockCollection: Collection = Object.assign(new Collection(), {
value: 'Short description' 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', () => { describe('CollectionGridElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ CollectionGridElementComponent ], declarations: [ CollectionGridElementComponent ],
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: (mockCollectionWithAbstract)}
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdGridElementComponent)}
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css }).overrideComponent(CollectionGridElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
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',() => { describe('When the collection has an abstract', () => {
expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined(); 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',() => { describe('When the collection has no abstract', () => {
const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); beforeEach(() => {
collectionGridElementComponent.object = mockCollectionWithoutAbstract;
fixture.detectChanges();
});
if (mockCollection.shortDescription.length > 0) { it('should not show the description paragraph', () => {
expect(descriptionText).toBeDefined(); const collectionAbstractField = fixture.debugElement.query(By.css('p.card-text'));
}else { expect(collectionAbstractField).toBeNull();
expect(descriptionText).not.toBeDefined(); });
}
}); });
}) });

View File

@@ -1,24 +1,13 @@
import { CommunityGridElementComponent } from './community-grid-element.component'; import { CommunityGridElementComponent } from './community-grid-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterStub } from '../../testing/router-stub';
import { Observable } from 'rxjs/Observable';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { Community } from '../../../core/shared/community.model'; import { Community } from '../../../core/shared/community.model';
let communityGridElementComponent: CommunityGridElementComponent; let communityGridElementComponent: CommunityGridElementComponent;
let fixture: ComponentFixture<CommunityGridElementComponent>; let fixture: ComponentFixture<CommunityGridElementComponent>;
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: [ metadata: [
{ {
key: 'dc.description.abstract', 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', () => { describe('CommunityGridElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ CommunityGridElementComponent ], declarations: [ CommunityGridElementComponent ],
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: (mockCommunityWithAbstract)}
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdGridElementComponent)}
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css }).overrideComponent(CommunityGridElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
beforeEach(async(() => { beforeEach(async(() => {
fixture = TestBed.createComponent(CommunityGridElementComponent); fixture = TestBed.createComponent(CommunityGridElementComponent);
communityGridElementComponent = fixture.componentInstance; communityGridElementComponent = fixture.componentInstance;
})); }));
it('should show the community cards in the grid element',() => { describe('When the community has an abstract', () => {
console.log(fixture.debugElement.query(By.css('ds-community-grid-element'))); beforeEach(() => {
expect(fixture.debugElement.query(By.css('ds-community-grid-element'))).toBeDefined(); communityGridElementComponent.object = mockCommunityWithAbstract;
}) fixture.detectChanges();
});
it('should only show the description if "short description" metadata is present',() => { it('should show the description paragraph', () => {
const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); const communityAbstractField = fixture.debugElement.query(By.css('p.card-text'));
expect(communityAbstractField).not.toBeNull();
});
});
if (mockCommunity.shortDescription.length > 0) { describe('When the community has no abstract', () => {
expect(descriptionText).toBeDefined(); beforeEach(() => {
}else { communityGridElementComponent.object = mockCommunityWithoutAbstract;
expect(descriptionText).not.toBeDefined(); fixture.detectChanges();
} });
it('should not show the description paragraph', () => {
const communityAbstractField = fixture.debugElement.query(By.css('p.card-text'));
expect(communityAbstractField).toBeNull();
});
}); });
}); });

View File

@@ -6,11 +6,11 @@
</a> </a>
<div class="card-body"> <div class="card-body">
<h4 class="card-title">{{object.findMetadata('dc.title')}}</h4> <h4 class="card-title">{{object.findMetadata('dc.title')}}</h4>
<p *ngIf="object.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']);" class="item-authors card-text text-muted"> <p *ngIf="object.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0" class="item-authors card-text text-muted">
<span *ngFor="let authorMd of object.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']); let last=last;">{{authorMd.value}} <span *ngFor="let authorMd of object.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']); let last=last;">{{authorMd.value}}
<span *ngIf="!last">; </span> <span *ngIf="!last">; </span>
</span> </span>
<span *ngIf="object.findMetadata('dc.date.issued')">{{object.findMetadata("dc.date.issued")}}</span> <span *ngIf="object.findMetadata('dc.date.issued')" class="item-date">{{object.findMetadata("dc.date.issued")}}</span>
</p> </p>
<p *ngIf="object.findMetadata('dc.description.abstract')" class="item-abstract card-text">{{object.findMetadata("dc.description.abstract") | dsTruncate:[200] }}</p> <p *ngIf="object.findMetadata('dc.description.abstract')" class="item-abstract card-text">{{object.findMetadata("dc.description.abstract") | dsTruncate:[200] }}</p>

View File

@@ -1,47 +1,55 @@
import { ItemGridElementComponent } from './item-grid-element.component'; import { ItemGridElementComponent } from './item-grid-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
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 { By } from '@angular/platform-browser';
import { TruncatePipe } from '../../utils/truncate.pipe'; import { TruncatePipe } from '../../utils/truncate.pipe';
import { Item } from '../../../core/shared/item.model'; import { Item } from '../../../core/shared/item.model';
import { Observable } from 'rxjs/Observable';
let itemGridElementComponent: ItemGridElementComponent; let itemGridElementComponent: ItemGridElementComponent;
let fixture: ComponentFixture<ItemGridElementComponent>; let fixture: ComponentFixture<ItemGridElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; const mockItemWithAuthorAndDate: Item = Object.assign(new Item(), {
const activatedRouteStub = { bitstreams: Observable.of({}),
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
/* tslint:disable:no-shadowed-variable */
const mockItem: Item = Object.assign(new Item(), {
metadata: [ metadata: [
{ {
key: 'dc.contributor.author', key: 'dc.contributor.author',
language: 'en_US', language: 'en_US',
value: 'Smith, Donald' 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', () => { describe('ItemGridElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ ItemGridElementComponent , TruncatePipe], declarations: [ ItemGridElementComponent , TruncatePipe],
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: {mockItemWithAuthorAndDate}}
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: {createdGridElementComponent}}
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css }).overrideComponent(ItemGridElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
beforeEach(async(() => { beforeEach(async(() => {
@@ -50,18 +58,51 @@ describe('ItemGridElementComponent', () => {
})); }));
it('should show the item cards in the grid element',() => { describe('When the item has an author', () => {
expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined() 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',() => { describe('When the item has no author', () => {
const itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); beforeEach(() => {
itemGridElementComponent.object = mockItemWithoutAuthorAndDate;
fixture.detectChanges();
});
if (mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0) { it('should not show the author paragraph', () => {
expect(itemAuthorField).toBeDefined(); const itemAuthorField = fixture.debugElement.query(By.css('p.item-authors'));
}else { expect(itemAuthorField).toBeNull();
expect(itemAuthorField).toBeDefined(); });
}
}); });
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();
});
});
}); });

View File

@@ -1,69 +1,83 @@
import { CollectionSearchResultGridElementComponent } from './collection-search-result-grid-element.component'; import { CollectionSearchResultGridElementComponent } from './collection-search-result-grid-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { ActivatedRoute, Router } from '@angular/router'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { RouterStub } from '../../../testing/router-stub';
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 { Community } from '../../../../core/shared/community.model';
import { Collection } from '../../../../core/shared/collection.model'; import { Collection } from '../../../../core/shared/collection.model';
import { TruncatableService } from '../../../truncatable/truncatable.service'; import { TruncatableService } from '../../../truncatable/truncatable.service';
import { CollectionSearchResult } from '../../../object-collection/shared/collection-search-result.model';
let collectionSearchResultGridElementComponent: CollectionSearchResultGridElementComponent;
let fixture: ComponentFixture<CollectionSearchResultGridElementComponent>; let fixture: ComponentFixture<CollectionSearchResultGridElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
const truncatableServiceStub: any = { const truncatableServiceStub: any = {
isCollapsed: (id: number) => Observable.of(true), 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: [ metadata: [
{ {
key: 'dc.description.abstract', key: 'dc.description.abstract',
language: 'en_US', language: 'en_US',
value: 'Short description' 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', () => { describe('CollectionSearchResultGridElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [CollectionSearchResultGridElementComponent, TruncatePipe], declarations: [ CollectionSearchResultGridElementComponent, TruncatePipe ],
providers: [ providers: [
{ provide: TruncatableService, useValue: truncatableServiceStub }, { provide: TruncatableService, useValue: truncatableServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: (mockCollectionWithAbstract) }
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdGridElementComponent) }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css }).overrideComponent(CollectionSearchResultGridElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
beforeEach(async(() => { beforeEach(async(() => {
fixture = TestBed.createComponent(CollectionSearchResultGridElementComponent); fixture = TestBed.createComponent(CollectionSearchResultGridElementComponent);
collectionSearchResultGridElementComponent = fixture.componentInstance;
})); }));
it('should show the item result cards in the grid element', () => { describe('When the collection has an abstract', () => {
expect(fixture.debugElement.query(By.css('ds-collection-search-result-grid-element'))).toBeDefined(); 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', () => { describe('When the collection has no abstract', () => {
const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); beforeEach(() => {
collectionSearchResultGridElementComponent.dso = mockCollectionWithoutAbstract.dspaceObject;
fixture.detectChanges();
});
if (mockCollection.shortDescription.length > 0) { it('should not show the description paragraph', () => {
expect(descriptionText).toBeDefined(); const collectionAbstractField = fixture.debugElement.query(By.css('p.card-text'));
} else { expect(collectionAbstractField).toBeNull();
expect(descriptionText).not.toBeDefined(); });
}
}); });
}); });

View File

@@ -1,39 +1,41 @@
import { CommunitySearchResultGridElementComponent } from './community-search-result-grid-element.component'; import { CommunitySearchResultGridElementComponent } from './community-search-result-grid-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { ActivatedRoute, Router } from '@angular/router'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { RouterStub } from '../../../testing/router-stub';
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 { Community } from '../../../../core/shared/community.model'; import { Community } from '../../../../core/shared/community.model';
import { TruncatableService } from '../../../truncatable/truncatable.service'; import { TruncatableService } from '../../../truncatable/truncatable.service';
import { CommunitySearchResult } from '../../../object-collection/shared/community-search-result.model';
let communitySearchResultGridElementComponent: CommunitySearchResultGridElementComponent;
let fixture: ComponentFixture<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
})
};
const truncatableServiceStub: any = { const truncatableServiceStub: any = {
isCollapsed: (id: number) => Observable.of(true), 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: [ metadata: [
{ {
key: 'dc.description.abstract', key: 'dc.description.abstract',
language: 'en_US', language: 'en_US',
value: 'Short description' 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', () => { describe('CommunitySearchResultGridElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
@@ -41,30 +43,41 @@ describe('CommunitySearchResultGridElementComponent', () => {
declarations: [ CommunitySearchResultGridElementComponent, TruncatePipe ], declarations: [ CommunitySearchResultGridElementComponent, TruncatePipe ],
providers: [ providers: [
{ provide: TruncatableService, useValue: truncatableServiceStub }, { provide: TruncatableService, useValue: truncatableServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: (mockCommunityWithAbstract) }
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdGridElementComponent) }
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css }).overrideComponent(CommunitySearchResultGridElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
beforeEach(async(() => { beforeEach(async(() => {
fixture = TestBed.createComponent(CommunitySearchResultGridElementComponent); fixture = TestBed.createComponent(CommunitySearchResultGridElementComponent);
communitySearchResultGridElementComponent = fixture.componentInstance;
})); }));
it('should show the item result cards in the grid element', () => { describe('When the community has an abstract', () => {
expect(fixture.debugElement.query(By.css('ds-community-search-result-grid-element'))).toBeDefined(); 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',() => { describe('When the community has no abstract', () => {
const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); beforeEach(() => {
communitySearchResultGridElementComponent.dso = mockCommunityWithoutAbstract.dspaceObject;
fixture.detectChanges();
});
if (mockCommunity.shortDescription.length > 0) { it('should not show the description paragraph', () => {
expect(descriptionText).toBeDefined(); const communityAbstractField = fixture.debugElement.query(By.css('p.card-text'));
}else { expect(communityAbstractField).toBeNull();
expect(descriptionText).not.toBeDefined(); });
}
}); });
}); });

View File

@@ -1,8 +1,6 @@
import { ItemSearchResultGridElementComponent } from './item-search-result-grid-element.component'; import { ItemSearchResultGridElementComponent } from './item-search-result-grid-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable'; 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 { NO_ERRORS_SCHEMA, ChangeDetectionStrategy } 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';
@@ -13,14 +11,6 @@ import { ItemSearchResult } from '../../../object-collection/shared/item-search-
let itemSearchResultGridElementComponent: ItemSearchResultGridElementComponent; let itemSearchResultGridElementComponent: ItemSearchResultGridElementComponent;
let fixture: ComponentFixture<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
})
};
const truncatableServiceStub: any = { const truncatableServiceStub: any = {
isCollapsed: (id: number) => Observable.of(true), isCollapsed: (id: number) => Observable.of(true),
@@ -46,7 +36,7 @@ mockItemWithAuthorAndDate.dspaceObject = Object.assign(new Item(), {
const mockItemWithoutAuthorAndDate: ItemSearchResult = new ItemSearchResult(); const mockItemWithoutAuthorAndDate: ItemSearchResult = new ItemSearchResult();
mockItemWithoutAuthorAndDate.hitHighlights = []; mockItemWithoutAuthorAndDate.hitHighlights = [];
mockItemWithoutAuthorAndDate.dspaceObject = Object.assign(new Item(), { mockItemWithoutAuthorAndDate.dspaceObject = Object.assign(new Item(), {
bitstream: Observable.of({}), bitstreams: Observable.of({}),
metadata: [ metadata: [
{ {
key: 'dc.title', key: 'dc.title',
@@ -60,8 +50,6 @@ mockItemWithoutAuthorAndDate.dspaceObject = Object.assign(new Item(), {
}] }]
}); });
const createdGridElementComponent: ItemSearchResultGridElementComponent = new ItemSearchResultGridElementComponent(mockItemWithAuthorAndDate, truncatableServiceStub as TruncatableService);
describe('ItemSearchResultGridElementComponent', () => { describe('ItemSearchResultGridElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -69,9 +57,7 @@ describe('ItemSearchResultGridElementComponent', () => {
declarations: [ItemSearchResultGridElementComponent, TruncatePipe], declarations: [ItemSearchResultGridElementComponent, TruncatePipe],
providers: [ providers: [
{ provide: TruncatableService, useValue: truncatableServiceStub }, { provide: TruncatableService, useValue: truncatableServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: (mockItemWithoutAuthorAndDate) }
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdGridElementComponent) }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(ItemSearchResultGridElementComponent, { }).overrideComponent(ItemSearchResultGridElementComponent, {
@@ -84,7 +70,7 @@ describe('ItemSearchResultGridElementComponent', () => {
itemSearchResultGridElementComponent = fixture.componentInstance; itemSearchResultGridElementComponent = fixture.componentInstance;
})); }));
fdescribe('When the item has an author', () => { describe('When the item has an author', () => {
beforeEach(() => { beforeEach(() => {
itemSearchResultGridElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject; itemSearchResultGridElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject;
fixture.detectChanges(); fixture.detectChanges();
@@ -99,6 +85,7 @@ describe('ItemSearchResultGridElementComponent', () => {
describe('When the item has no author', () => { describe('When the item has no author', () => {
beforeEach(() => { beforeEach(() => {
itemSearchResultGridElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject; itemSearchResultGridElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject;
fixture.detectChanges();
}); });
it('should not show the author paragraph', () => { it('should not show the author paragraph', () => {
@@ -110,6 +97,7 @@ describe('ItemSearchResultGridElementComponent', () => {
describe('When the item has an issuedate', () => { describe('When the item has an issuedate', () => {
beforeEach(() => { beforeEach(() => {
itemSearchResultGridElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject; itemSearchResultGridElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject;
fixture.detectChanges();
}); });
it('should show the issuedate span', () => { it('should show the issuedate span', () => {
@@ -121,6 +109,7 @@ describe('ItemSearchResultGridElementComponent', () => {
describe('When the item has no issuedate', () => { describe('When the item has no issuedate', () => {
beforeEach(() => { beforeEach(() => {
itemSearchResultGridElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject; itemSearchResultGridElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject;
fixture.detectChanges();
}); });
it('should not show the issuedate span', () => { it('should not show the issuedate span', () => {

View File

@@ -17,10 +17,9 @@ import { Observable } from 'rxjs/Observable';
export class SearchResultGridElementComponent<T extends SearchResult<K>, K extends DSpaceObject> extends AbstractListableElementComponent<T> { export class SearchResultGridElementComponent<T extends SearchResult<K>, K extends DSpaceObject> extends AbstractListableElementComponent<T> {
dso: K; dso: K;
public constructor(@Inject('objectElementProvider') public gridable: ListableObject, private truncatableService: TruncatableService) { public constructor(@Inject('objectElementProvider') public listableObject: ListableObject, private truncatableService: TruncatableService) {
super(gridable); super(listableObject);
this.dso = this.object.dspaceObject; this.dso = this.object.dspaceObject;
console.log(JSON.stringify(this.object.hitHighlights));
} }
getValues(keys: string[]): string[] { getValues(keys: string[]): string[] {
@@ -44,7 +43,6 @@ export class SearchResultGridElementComponent<T extends SearchResult<K>, K exten
getFirstValue(key: string): string { getFirstValue(key: string): string {
let result: string; let result: string;
console.log(JSON.stringify(this.object.hitHighlights));
this.object.hitHighlights.some( this.object.hitHighlights.some(
(md: Metadatum) => { (md: Metadatum) => {
if (key === md.key) { if (key === md.key) {

View File

@@ -1,6 +1,6 @@
<a [routerLink]="['/collections/' + object.id]" class="lead"> <a [routerLink]="['/collections/' + object.id]" class="lead">
{{object.name}} {{object.name}}
</a> </a>
<div *ngIf="object.shortDescription" class="text-muted"> <div *ngIf="object.shortDescription" class="text-muted abstract-text">
{{object.shortDescription}} {{object.shortDescription}}
</div> </div>

View File

@@ -1,21 +1,13 @@
import { CollectionListElementComponent } from './collection-list-element.component'; import { CollectionListElementComponent } from './collection-list-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
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 { By } from '@angular/platform-browser';
import { Collection } from '../../../core/shared/collection.model'; import { Collection } from '../../../core/shared/collection.model';
let collectionListElementComponent: CollectionListElementComponent;
let fixture: ComponentFixture<CollectionListElementComponent>; let fixture: ComponentFixture<CollectionListElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; const mockCollectionWithAbstract: Collection = Object.assign(new Collection(), {
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
const mockCollection: Collection = Object.assign(new Collection(), {
metadata: [ metadata: [
{ {
key: 'dc.description.abstract', key: 'dc.description.abstract',
@@ -23,37 +15,56 @@ const mockCollection: Collection = Object.assign(new Collection(), {
value: 'Short description' 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', () => { describe('CollectionListElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ CollectionListElementComponent ], declarations: [ CollectionListElementComponent ],
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: (mockCollectionWithAbstract)}
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdListElementComponent)}
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css }).overrideComponent(CollectionListElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
beforeEach(async(() => { beforeEach(async(() => {
fixture = TestBed.createComponent(CollectionListElementComponent); fixture = TestBed.createComponent(CollectionListElementComponent);
collectionListElementComponent = fixture.componentInstance;
})); }));
it('should show the collection cards in the list element',() => { describe('When the collection has an abstract', () => {
expect(fixture.debugElement.query(By.css('ds-collection-list-element'))).toBeDefined(); 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',() => { describe('When the collection has no abstract', () => {
const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); beforeEach(() => {
collectionListElementComponent.object = mockCollectionWithoutAbstract;
fixture.detectChanges();
});
if (mockCollection.shortDescription.length > 0) { it('should not show the description paragraph', () => {
expect(descriptionText).toBeDefined(); const collectionAbstractField = fixture.debugElement.query(By.css('div.abstract-text'));
}else { expect(collectionAbstractField).toBeNull();
expect(descriptionText).not.toBeDefined(); });
}
}); });
}); });

View File

@@ -1,6 +1,6 @@
<a [routerLink]="['/communities/' + object.id]" class="lead"> <a [routerLink]="['/communities/' + object.id]" class="lead">
{{object.name}} {{object.name}}
</a> </a>
<div *ngIf="object.shortDescription" class="text-muted"> <div *ngIf="object.shortDescription" class="text-muted abstract-text">
{{object.shortDescription}} {{object.shortDescription}}
</div> </div>

View File

@@ -1,24 +1,13 @@
import { CommunityListElementComponent } from './community-list-element.component'; import { CommunityListElementComponent } from './community-list-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterStub } from '../../testing/router-stub';
import { Observable } from 'rxjs/Observable';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { Community } from '../../../core/shared/community.model'; import { Community } from '../../../core/shared/community.model';
let communityListElementComponent: CommunityListElementComponent; let communityListElementComponent: CommunityListElementComponent;
let fixture: ComponentFixture<CommunityListElementComponent>; let fixture: ComponentFixture<CommunityListElementComponent>;
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: [ metadata: [
{ {
key: 'dc.description.abstract', 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', () => { describe('CommunityListElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ CommunityListElementComponent ], declarations: [ CommunityListElementComponent ],
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: (mockCommunityWithAbstract)}
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdListElementComponent)}
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css }).overrideComponent(CommunityListElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
beforeEach(async(() => { beforeEach(async(() => {
fixture = TestBed.createComponent(CommunityListElementComponent); fixture = TestBed.createComponent(CommunityListElementComponent);
communityListElementComponent = fixture.componentInstance; communityListElementComponent = fixture.componentInstance;
})); }));
it('should show the community cards in the list element',() => { describe('When the community has an abstract', () => {
expect(fixture.debugElement.query(By.css('ds-community-list-element'))).toBeDefined(); beforeEach(() => {
}) communityListElementComponent.object = mockCommunityWithAbstract;
fixture.detectChanges();
});
it('should only show the description if "short description" metadata is present',() => { it('should show the description paragraph', () => {
const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); const communityAbstractField = fixture.debugElement.query(By.css('div.abstract-text'));
expect(communityAbstractField).not.toBeNull();
});
});
if (mockCommunity.shortDescription.length > 0) { describe('When the community has no abstract', () => {
expect(descriptionText).toBeDefined(); beforeEach(() => {
}else { communityListElementComponent.object = mockCommunityWithoutAbstract;
expect(descriptionText).not.toBeDefined(); fixture.detectChanges();
} });
it('should not show the description paragraph', () => {
const communityAbstractField = fixture.debugElement.query(By.css('div.abstract-text'));
expect(communityAbstractField).toBeNull();
});
}); });
}); });

View File

@@ -3,7 +3,7 @@
</a> </a>
<div> <div>
<span class="text-muted"> <span class="text-muted">
<span *ngIf="object.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']);" <span *ngIf="object.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0"
class="item-list-authors"> class="item-list-authors">
<span *ngFor="let authorMd of object.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']); let last=last;">{{authorMd.value}} <span *ngFor="let authorMd of object.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']); let last=last;">{{authorMd.value}}
<span *ngIf="!last">; </span> <span *ngIf="!last">; </span>

View File

@@ -1,47 +1,55 @@
import { ItemListElementComponent } from './item-list-element.component'; import { ItemListElementComponent } from './item-list-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
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 { By } from '@angular/platform-browser';
import { TruncatePipe } from '../../utils/truncate.pipe'; import { TruncatePipe } from '../../utils/truncate.pipe';
import { Item } from '../../../core/shared/item.model'; import { Item } from '../../../core/shared/item.model';
import { Observable } from 'rxjs/Observable';
let itemListElementComponent: ItemListElementComponent; let itemListElementComponent: ItemListElementComponent;
let fixture: ComponentFixture<ItemListElementComponent>; let fixture: ComponentFixture<ItemListElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; const mockItemWithAuthorAndDate: Item = Object.assign(new Item(), {
const activatedRouteStub = { bitstreams: Observable.of({}),
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
/* tslint:disable:no-shadowed-variable */
const mockItem: Item = Object.assign(new Item(), {
metadata: [ metadata: [
{ {
key: 'dc.contributor.author', key: 'dc.contributor.author',
language: 'en_US', language: 'en_US',
value: 'Smith, Donald' 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', () => { describe('ItemListElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ ItemListElementComponent , TruncatePipe], declarations: [ ItemListElementComponent , TruncatePipe],
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: {mockItemWithAuthorAndDate}}
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: {createdListElementComponent}}
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css }).overrideComponent(ItemListElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
beforeEach(async(() => { beforeEach(async(() => {
@@ -50,18 +58,51 @@ describe('ItemListElementComponent', () => {
})); }));
it('should show the item cards in the list element',() => { describe('When the item has an author', () => {
expect(fixture.debugElement.query(By.css('ds-item-list-element'))).toBeDefined() 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',() => { describe('When the item has no author', () => {
const itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); beforeEach(() => {
itemListElementComponent.object = mockItemWithoutAuthorAndDate;
fixture.detectChanges();
});
if (mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0) { it('should not show the author paragraph', () => {
expect(itemAuthorField).toBeDefined(); const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors'));
}else { expect(itemAuthorField).toBeNull();
expect(itemAuthorField).toBeDefined(); });
}
}); });
}) 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();
});
});
});

View File

@@ -1,2 +1,2 @@
<a [routerLink]="['/collections/' + dso.id]" class="lead" [innerHTML]="getFirstValue('dc.title')"></a> <a [routerLink]="['/collections/' + dso.id]" class="lead" [innerHTML]="getFirstValue('dc.title')"></a>
<div *ngIf="dso.shortDescription" class="text-muted" [innerHTML]="getFirstValue('dc.description.abstract')"></div> <div *ngIf="dso.shortDescription" class="text-muted abstract-text" [innerHTML]="getFirstValue('dc.description.abstract')"></div>

View File

@@ -1,68 +1,83 @@
import { CollectionSearchResultListElementComponent } from './collection-search-result-list-element.component'; import { CollectionSearchResultListElementComponent } from './collection-search-result-list-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { ActivatedRoute, Router } from '@angular/router'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { RouterStub } from '../../../testing/router-stub';
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 { Collection } from '../../../../core/shared/collection.model'; import { Collection } from '../../../../core/shared/collection.model';
import { TruncatableService } from '../../../truncatable/truncatable.service'; import { TruncatableService } from '../../../truncatable/truncatable.service';
import { CollectionSearchResult } from '../../../object-collection/shared/collection-search-result.model';
let collectionSearchResultListElementComponent: CollectionSearchResultListElementComponent;
let fixture: ComponentFixture<CollectionSearchResultListElementComponent>; let fixture: ComponentFixture<CollectionSearchResultListElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
const truncatableServiceStub: any = { const truncatableServiceStub: any = {
isCollapsed: (id: number) => Observable.of(true), 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: [ metadata: [
{ {
key: 'dc.description.abstract', key: 'dc.description.abstract',
language: 'en_US', language: 'en_US',
value: 'Short description' 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', () => { describe('CollectionSearchResultListElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [CollectionSearchResultListElementComponent, TruncatePipe], declarations: [ CollectionSearchResultListElementComponent, TruncatePipe ],
providers: [ providers: [
{ provide: TruncatableService, useValue: truncatableServiceStub }, { provide: TruncatableService, useValue: truncatableServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: (mockCollectionWithAbstract) }
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdListElementComponent) }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css }).overrideComponent(CollectionSearchResultListElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
beforeEach(async(() => { beforeEach(async(() => {
fixture = TestBed.createComponent(CollectionSearchResultListElementComponent); fixture = TestBed.createComponent(CollectionSearchResultListElementComponent);
collectionSearchResultListElementComponent = fixture.componentInstance;
})); }));
it('should show the item result cards in the list element', () => { describe('When the collection has an abstract', () => {
expect(fixture.debugElement.query(By.css('ds-collection-search-result-list-element'))).toBeDefined(); 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', () => { describe('When the collection has no abstract', () => {
const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); beforeEach(() => {
collectionSearchResultListElementComponent.dso = mockCollectionWithoutAbstract.dspaceObject;
fixture.detectChanges();
});
if (mockCollection.shortDescription.length > 0) { it('should not show the description paragraph', () => {
expect(descriptionText).toBeDefined(); const collectionAbstractField = fixture.debugElement.query(By.css('div.abstract-text'));
} else { expect(collectionAbstractField).toBeNull();
expect(descriptionText).not.toBeDefined(); });
}
}); });
}); });

View File

@@ -1,2 +1,2 @@
<a [routerLink]="['/communities/' + dso.id]" class="lead" [innerHTML]="getFirstValue('dc.title')"></a> <a [routerLink]="['/communities/' + dso.id]" class="lead" [innerHTML]="getFirstValue('dc.title')"></a>
<div *ngIf="dso.shortDescription" class="text-muted" [innerHTML]="getFirstValue('dc.description.abstract')"></div> <div *ngIf="dso.shortDescription" class="text-muted abstract-text" [innerHTML]="getFirstValue('dc.description.abstract')"></div>

View File

@@ -1,38 +1,41 @@
import { CommunitySearchResultListElementComponent } from './community-search-result-list-element.component'; import { CommunitySearchResultListElementComponent } from './community-search-result-list-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { ActivatedRoute, Router } from '@angular/router'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { RouterStub } from '../../../testing/router-stub';
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 { Community } from '../../../../core/shared/community.model'; import { Community } from '../../../../core/shared/community.model';
import { TruncatableService } from '../../../truncatable/truncatable.service'; import { TruncatableService } from '../../../truncatable/truncatable.service';
import { CommunitySearchResult } from '../../../object-collection/shared/community-search-result.model';
let communitySearchResultListElementComponent: CommunitySearchResultListElementComponent;
let fixture: ComponentFixture<CommunitySearchResultListElementComponent>; let fixture: ComponentFixture<CommunitySearchResultListElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
const truncatableServiceStub: any = { const truncatableServiceStub: any = {
isCollapsed: (id: number) => Observable.of(true), 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: [ metadata: [
{ {
key: 'dc.description.abstract', key: 'dc.description.abstract',
language: 'en_US', language: 'en_US',
value: 'Short description' 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', () => { describe('CommunitySearchResultListElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
@@ -40,30 +43,41 @@ describe('CommunitySearchResultListElementComponent', () => {
declarations: [ CommunitySearchResultListElementComponent, TruncatePipe ], declarations: [ CommunitySearchResultListElementComponent, TruncatePipe ],
providers: [ providers: [
{ provide: TruncatableService, useValue: truncatableServiceStub }, { provide: TruncatableService, useValue: truncatableServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: (mockCommunityWithAbstract) }
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdListElementComponent) }
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents(); // compile template and css }).overrideComponent(CommunitySearchResultListElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
beforeEach(async(() => { beforeEach(async(() => {
fixture = TestBed.createComponent(CommunitySearchResultListElementComponent); fixture = TestBed.createComponent(CommunitySearchResultListElementComponent);
communitySearchResultListElementComponent = fixture.componentInstance;
})); }));
it('should show the item result cards in the list element', () => { describe('When the community has an abstract', () => {
expect(fixture.debugElement.query(By.css('ds-community-search-result-list-element'))).toBeDefined(); 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',() => { describe('When the community has no abstract', () => {
const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); beforeEach(() => {
communitySearchResultListElementComponent.dso = mockCommunityWithoutAbstract.dspaceObject;
fixture.detectChanges();
});
if (mockCommunity.shortDescription.length > 0) { it('should not show the description paragraph', () => {
expect(descriptionText).toBeDefined(); const communityAbstractField = fixture.debugElement.query(By.css('div.abstract-text'));
}else { expect(communityAbstractField).toBeNull();
expect(descriptionText).not.toBeDefined(); });
}
}); });
}); });

View File

@@ -8,7 +8,7 @@
[innerHTML]="getFirstValue('dc.publisher')">, </span><span [innerHTML]="getFirstValue('dc.publisher')">, </span><span
*ngIf="dso.findMetadata('dc.date.issued')" class="item-list-date" *ngIf="dso.findMetadata('dc.date.issued')" class="item-list-date"
[innerHTML]="getFirstValue('dc.date.issued')"></span>) [innerHTML]="getFirstValue('dc.date.issued')"></span>)
<span *ngIf="dso.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']);" <span *ngIf="dso.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0"
class="item-list-authors"> class="item-list-authors">
<span *ngFor="let author of getValues(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']); let last=last;"> <span *ngFor="let author of getValues(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']); let last=last;">
<span [innerHTML]="author"><span [innerHTML]="author"></span></span> <span [innerHTML]="author"><span [innerHTML]="author"></span></span>

View File

@@ -1,30 +1,25 @@
import { ItemSearchResultListElementComponent } from './item-search-result-list-element.component'; import { ItemSearchResultListElementComponent } from './item-search-result-list-element.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { ActivatedRoute, Router } from '@angular/router'; import { NO_ERRORS_SCHEMA, ChangeDetectionStrategy } from '@angular/core';
import { RouterStub } from '../../../testing/router-stub';
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'; import { Item } from '../../../../core/shared/item.model';
import { TruncatableService } from '../../../truncatable/truncatable.service'; 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 itemSearchResultListElementComponent: ItemSearchResultListElementComponent;
let fixture: ComponentFixture<ItemSearchResultListElementComponent>; let fixture: ComponentFixture<ItemSearchResultListElementComponent>;
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
const truncatableServiceStub: any = { const truncatableServiceStub: any = {
isCollapsed: (id: number) => Observable.of(true), 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: [ metadata: [
{ {
key: 'dc.contributor.author', key: 'dc.contributor.author',
@@ -34,24 +29,40 @@ const mockItem: Item = Object.assign(new Item(), {
{ {
key: 'dc.date.issued', key: 'dc.date.issued',
language: null, 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', () => { describe('ItemSearchResultListElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [NoopAnimationsModule],
declarations: [ItemSearchResultListElementComponent, TruncatePipe], declarations: [ItemSearchResultListElementComponent, TruncatePipe],
providers: [ providers: [
{ provide: TruncatableService, useValue: truncatableServiceStub }, { provide: TruncatableService, useValue: truncatableServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: 'objectElementProvider', useValue: (mockItemWithoutAuthorAndDate) }
{ provide: Router, useClass: RouterStub },
{ provide: 'objectElementProvider', useValue: (createdListElementComponent) }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents(); // compile template and css }).overrideComponent(ItemSearchResultListElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
})); }));
beforeEach(async(() => { beforeEach(async(() => {
@@ -59,28 +70,51 @@ describe('ItemSearchResultListElementComponent', () => {
itemSearchResultListElementComponent = fixture.componentInstance; itemSearchResultListElementComponent = fixture.componentInstance;
})); }));
it('should show the item result cards in the list element', () => { describe('When the item has an author', () => {
expect(fixture.debugElement.query(By.css('ds-item-search-result-list-element'))).toBeDefined(); 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', () => { describe('When the item has no author', () => {
const itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); beforeEach(() => {
itemSearchResultListElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject;
fixture.detectChanges();
});
if (mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0) { it('should not show the author paragraph', () => {
expect(itemAuthorField).toBeDefined(); const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors'));
} else { expect(itemAuthorField).toBeNull();
expect(itemAuthorField).not.toBeDefined(); });
}
}); });
it('should only show the date span if the issuedate is present', () => { describe('When the item has an issuedate', () => {
const dateField = expect(fixture.debugElement.query(By.css('span.item-list-date'))); beforeEach(() => {
itemSearchResultListElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject;
fixture.detectChanges();
});
if (mockItem.findMetadata('dc.date.issued').length > 0) { it('should show the issuedate span', () => {
expect(dateField).toBeDefined(); const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-date'));
} else { expect(itemAuthorField).not.toBeNull();
expect(dateField).not.toBeDefined(); });
}
}); });
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();
});
});
}); });