mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
118 lines
3.8 KiB
TypeScript
118 lines
3.8 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 { JournalVolumeListElementComponent } from './journal-volume-list-element.component';
|
|
import { of as observableOf } from 'rxjs';
|
|
import { Item } from '../../../../core/shared/item.model';
|
|
import { TruncatePipe } from '../../../../shared/utils/truncate.pipe';
|
|
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
|
import { TruncatableService } from '../../../../shared/truncatable/truncatable.service';
|
|
|
|
let journalVolumeListElementComponent: JournalVolumeListElementComponent;
|
|
let fixture: ComponentFixture<JournalVolumeListElementComponent>;
|
|
|
|
const mockItemWithMetadata: Item = Object.assign(new Item(), {
|
|
bitstreams: observableOf({}),
|
|
metadata: {
|
|
'dc.title': [
|
|
{
|
|
language: 'en_US',
|
|
value: 'This is just another title'
|
|
}
|
|
],
|
|
'journal.title': [
|
|
{
|
|
language: 'en_US',
|
|
value: 'This is just another journal title'
|
|
}
|
|
],
|
|
'publicationvolume.volumeNumber': [
|
|
{
|
|
language: 'en_US',
|
|
value: '1234'
|
|
}
|
|
]
|
|
}
|
|
});
|
|
const mockItemWithoutMetadata: Item = Object.assign(new Item(), {
|
|
bitstreams: observableOf({}),
|
|
metadata: {
|
|
'dc.title': [
|
|
{
|
|
language: 'en_US',
|
|
value: 'This is just another title'
|
|
}
|
|
]
|
|
}
|
|
});
|
|
|
|
describe('JournalVolumeListElementComponent', () => {
|
|
beforeEach(async(() => {
|
|
TestBed.configureTestingModule({
|
|
declarations: [ JournalVolumeListElementComponent , TruncatePipe],
|
|
providers: [
|
|
{ provide: ITEM, useValue: mockItemWithMetadata},
|
|
{ provide: TruncatableService, useValue: {} }
|
|
],
|
|
|
|
schemas: [ NO_ERRORS_SCHEMA ]
|
|
}).overrideComponent(JournalVolumeListElementComponent, {
|
|
set: { changeDetection: ChangeDetectionStrategy.Default }
|
|
}).compileComponents();
|
|
}));
|
|
|
|
beforeEach(async(() => {
|
|
fixture = TestBed.createComponent(JournalVolumeListElementComponent);
|
|
journalVolumeListElementComponent = fixture.componentInstance;
|
|
|
|
}));
|
|
|
|
describe('When the item has a journal title', () => {
|
|
beforeEach(() => {
|
|
journalVolumeListElementComponent.item = mockItemWithMetadata;
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
it('should show the journal title span', () => {
|
|
const journalTitleField = fixture.debugElement.query(By.css('span.item-list-journal-volumes'));
|
|
expect(journalTitleField).not.toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('When the item has no journal title', () => {
|
|
beforeEach(() => {
|
|
journalVolumeListElementComponent.item = mockItemWithoutMetadata;
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
it('should not show the journal title span', () => {
|
|
const journalTitleField = fixture.debugElement.query(By.css('span.item-list-journal-volumes'));
|
|
expect(journalTitleField).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('When the item has a journal identifier', () => {
|
|
beforeEach(() => {
|
|
journalVolumeListElementComponent.item = mockItemWithMetadata;
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
it('should show the journal identifiers span', () => {
|
|
const journalIdentifierField = fixture.debugElement.query(By.css('span.item-list-journal-volume-identifiers'));
|
|
expect(journalIdentifierField).not.toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('When the item has no journal identifier', () => {
|
|
beforeEach(() => {
|
|
journalVolumeListElementComponent.item = mockItemWithoutMetadata;
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
it('should not show the journal identifiers span', () => {
|
|
const journalIdentifierField = fixture.debugElement.query(By.css('span.item-list-journal-volume-identifiers'));
|
|
expect(journalIdentifierField).toBeNull();
|
|
});
|
|
});
|
|
});
|