Files
dspace-angular/src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.spec.ts
Kristof De Langhe ed3f7dfc7b Merge branch 'master' into w2p-65572_Add-support-for-bundles
Conflicts:
	src/app/core/shared/item.model.ts
	src/app/entity-groups/journal-entities/item-grid-elements/journal-issue/journal-issue-grid-element.component.spec.ts
	src/app/entity-groups/journal-entities/item-grid-elements/journal-volume/journal-volume-grid-element.component.spec.ts
	src/app/entity-groups/journal-entities/item-grid-elements/journal/journal-grid-element.component.spec.ts
	src/app/entity-groups/journal-entities/item-list-elements/journal-issue/journal-issue-list-element.component.spec.ts
	src/app/entity-groups/journal-entities/item-list-elements/journal-volume/journal-volume-list-element.component.spec.ts
	src/app/entity-groups/journal-entities/item-list-elements/journal/journal-list-element.component.spec.ts
	src/app/entity-groups/research-entities/item-grid-elements/person/person-grid-element.component.spec.ts
	src/app/entity-groups/research-entities/item-grid-elements/project/project-grid-element.component.spec.ts
	src/app/entity-groups/research-entities/item-list-elements/orgunit/orgunit-list-element.component.spec.ts
	src/app/entity-groups/research-entities/item-list-elements/person/person-list-element.component.spec.ts
	src/app/entity-groups/research-entities/item-list-elements/project/project-list-element.component.spec.ts
	src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts
	src/app/shared/object-grid/item-grid-element/item-types/publication/publication-grid-element.component.spec.ts
	src/app/shared/object-list/item-list-element/item-types/publication/publication-list-element.component.spec.ts
	src/app/shared/testing/utils.ts
2019-11-21 14:14:39 +01:00

132 lines
3.6 KiB
TypeScript

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { By } from '@angular/platform-browser';
import { of as observableOf } from 'rxjs';
import { TruncatePipe } from '../../../utils/truncate.pipe';
import { Item } from '../../../../core/shared/item.model';
import { ItemListPreviewComponent } from './item-list-preview.component';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
let component: ItemListPreviewComponent;
let fixture: ComponentFixture<ItemListPreviewComponent>;
const mockItemWithAuthorAndDate: Item = Object.assign(new Item(), {
bundles: observableOf({}),
metadata: {
'dc.contributor.author': [
{
language: 'en_US',
value: 'Smith, Donald'
}
],
'dc.date.issued': [
{
language: null,
value: '2015-06-26'
}
]
}
});
const mockItemWithoutAuthorAndDate: Item = Object.assign(new Item(), {
bundles: observableOf({}),
metadata: {
'dc.title': [
{
language: 'en_US',
value: 'This is just another title'
}
],
'dc.type': [
{
language: null,
value: 'Article'
}
]
}
});
describe('ItemListPreviewComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: MockTranslateLoader
}
}),
],
declarations: [ItemListPreviewComponent, TruncatePipe],
providers: [
{ provide: 'objectElementProvider', useValue: { mockItemWithAuthorAndDate } }
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(ItemListPreviewComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
}));
beforeEach(async(() => {
fixture = TestBed.createComponent(ItemListPreviewComponent);
component = fixture.componentInstance;
}));
beforeEach(() => {
component.object = { hitHighlights: {} } as any;
});
describe('When the item has an author', () => {
beforeEach(() => {
component.item = mockItemWithAuthorAndDate;
fixture.detectChanges();
});
it('should show the author paragraph', () => {
const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors'));
expect(itemAuthorField).not.toBeNull();
});
});
describe('When the item has no author', () => {
beforeEach(() => {
component.item = mockItemWithoutAuthorAndDate;
fixture.detectChanges();
});
it('should not show the author paragraph', () => {
const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors'));
expect(itemAuthorField).toBeNull();
});
});
describe('When the item has an issuedate', () => {
beforeEach(() => {
component.item = mockItemWithAuthorAndDate;
fixture.detectChanges();
});
it('should show the issuedate span', () => {
const dateField = fixture.debugElement.query(By.css('span.item-list-date'));
expect(dateField).not.toBeNull();
});
});
describe('When the item has no issuedate', () => {
beforeEach(() => {
component.item = mockItemWithoutAuthorAndDate;
fixture.detectChanges();
});
it('should show the issuedate empty placeholder', () => {
const dateField = fixture.debugElement.query(By.css('span.item-list-date'));
expect(dateField).not.toBeNull();
});
});
});