mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-11 20:13:07 +00:00
fixed list element tests
This commit is contained in:
@@ -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<CollectionSearchResultGridElementComponent>;
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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<CommunitySearchResultGridElementComponent>;
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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<ItemSearchResultGridElementComponent>;
|
||||
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', () => {
|
||||
|
@@ -17,10 +17,9 @@ import { Observable } from 'rxjs/Observable';
|
||||
export class SearchResultGridElementComponent<T extends SearchResult<K>, K extends DSpaceObject> extends AbstractListableElementComponent<T> {
|
||||
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<T extends SearchResult<K>, 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) {
|
||||
|
Reference in New Issue
Block a user