forked from hazza/dspace-angular
fixed list element tests
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
<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>
|
||||
|
@@ -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<CollectionSearchResultListElementComponent>;
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,2 +1,2 @@
|
||||
<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>
|
||||
|
@@ -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<CommunitySearchResultListElementComponent>;
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -8,7 +8,7 @@
|
||||
[innerHTML]="getFirstValue('dc.publisher')">, </span><span
|
||||
*ngIf="dso.findMetadata('dc.date.issued')" class="item-list-date"
|
||||
[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">
|
||||
<span *ngFor="let author of getValues(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']); let last=last;">
|
||||
<span [innerHTML]="author"><span [innerHTML]="author"></span></span>
|
||||
|
@@ -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<ItemSearchResultListElementComponent>;
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user