mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 21:13:07 +00:00
56434: JournalPageFieldsComponent tests
This commit is contained in:
@@ -6,11 +6,11 @@
|
|||||||
<ds-metadata-field-wrapper>
|
<ds-metadata-field-wrapper>
|
||||||
<ds-thumbnail [thumbnail]="this.item.getThumbnail() | async"></ds-thumbnail>
|
<ds-thumbnail [thumbnail]="this.item.getThumbnail() | async"></ds-thumbnail>
|
||||||
</ds-metadata-field-wrapper>
|
</ds-metadata-field-wrapper>
|
||||||
<ds-generic-item-page-field [item]="item"
|
<ds-generic-item-page-field class="item-page-fields" [item]="item"
|
||||||
[fields]="['journal.identifier.issn']"
|
[fields]="['journal.identifier.issn']"
|
||||||
[label]="'journal.page.issn'">
|
[label]="'journal.page.issn'">
|
||||||
</ds-generic-item-page-field>
|
</ds-generic-item-page-field>
|
||||||
<ds-generic-item-page-field [item]="item"
|
<ds-generic-item-page-field class="item-page-fields" [item]="item"
|
||||||
[fields]="['journal.publisher']"
|
[fields]="['journal.publisher']"
|
||||||
[label]="'journal.page.publisher'">
|
[label]="'journal.page.publisher'">
|
||||||
</ds-generic-item-page-field>
|
</ds-generic-item-page-field>
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
[entities]="volumes$ | async"
|
[entities]="volumes$ | async"
|
||||||
[label]="'relationships.isVolumeOf' | translate">
|
[label]="'relationships.isVolumeOf' | translate">
|
||||||
</ds-related-entities>
|
</ds-related-entities>
|
||||||
<ds-generic-item-page-field [item]="item"
|
<ds-generic-item-page-field class="item-page-fields" [item]="item"
|
||||||
[fields]="['journal.identifier.description']"
|
[fields]="['journal.identifier.description']"
|
||||||
[label]="'journal.page.description'">
|
[label]="'journal.page.description'">
|
||||||
</ds-generic-item-page-field>
|
</ds-generic-item-page-field>
|
||||||
|
@@ -0,0 +1,88 @@
|
|||||||
|
import { ChangeDetectionStrategy, DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { TruncatableService } from '../../../../shared/truncatable/truncatable.service';
|
||||||
|
import { ITEM } from '../../../../shared/entities/switcher/entity-type-switcher.component';
|
||||||
|
import { TruncatePipe } from '../../../../shared/utils/truncate.pipe';
|
||||||
|
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { MockTranslateLoader } from '../../../../shared/mocks/mock-translate-loader';
|
||||||
|
import { GenericItemPageFieldComponent } from '../../field-components/specific-field/generic/generic-item-page-field.component';
|
||||||
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
|
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||||
|
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||||
|
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||||
|
import { JournalPageFieldsComponent } from './journal-page-fields.component';
|
||||||
|
|
||||||
|
let comp: JournalPageFieldsComponent;
|
||||||
|
let fixture: ComponentFixture<JournalPageFieldsComponent>;
|
||||||
|
|
||||||
|
const mockItem: Item = Object.assign(new Item(), {
|
||||||
|
bitstreams: Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
|
||||||
|
metadata: [
|
||||||
|
{
|
||||||
|
key: 'journal.identifier.issn',
|
||||||
|
language: 'en_US',
|
||||||
|
value: '1234'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'journal.publisher',
|
||||||
|
language: 'en_US',
|
||||||
|
value: 'Atmire'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'journal.identifier.description',
|
||||||
|
language: 'en_US',
|
||||||
|
value: 'desc'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('JournalPageFieldsComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot({
|
||||||
|
loader: {
|
||||||
|
provide: TranslateLoader,
|
||||||
|
useClass: MockTranslateLoader
|
||||||
|
}
|
||||||
|
})],
|
||||||
|
declarations: [JournalPageFieldsComponent, GenericItemPageFieldComponent, TruncatePipe],
|
||||||
|
providers: [
|
||||||
|
{provide: ITEM, useValue: mockItem},
|
||||||
|
{provide: ItemDataService, useValue: {}},
|
||||||
|
{provide: TruncatableService, useValue: {}}
|
||||||
|
],
|
||||||
|
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).overrideComponent(JournalPageFieldsComponent, {
|
||||||
|
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
fixture = TestBed.createComponent(JournalPageFieldsComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
for (const metadata of mockItem.metadata) {
|
||||||
|
it(`should be calling a component with metadata field ${metadata.key}`, () => {
|
||||||
|
const fields = fixture.debugElement.queryAll(By.css('.item-page-fields'));
|
||||||
|
expect(containsFieldInput(fields, metadata.key)).toBeTruthy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function containsFieldInput(fields: DebugElement[], metadataKey: string): boolean {
|
||||||
|
for (const field of fields) {
|
||||||
|
const fieldComp = field.componentInstance;
|
||||||
|
if (isNotEmpty(fieldComp.fields)) {
|
||||||
|
if (fieldComp.fields.indexOf(metadataKey) > -1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
@@ -9,6 +9,7 @@ import {
|
|||||||
EntityPageFieldsComponent, filterRelationsByTypeLabel,
|
EntityPageFieldsComponent, filterRelationsByTypeLabel,
|
||||||
relationsToItems
|
relationsToItems
|
||||||
} from '../shared/entity-page-fields.component';
|
} from '../shared/entity-page-fields.component';
|
||||||
|
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||||
|
|
||||||
@rendersEntityType('Journal', ElementViewMode.Full)
|
@rendersEntityType('Journal', ElementViewMode.Full)
|
||||||
@Component({
|
@Component({
|
||||||
@@ -28,9 +29,11 @@ export class JournalPageFieldsComponent extends EntityPageFieldsComponent {
|
|||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
super.ngOnInit();
|
super.ngOnInit();
|
||||||
|
|
||||||
this.volumes$ = this.resolvedRelsAndTypes$.pipe(
|
if (isNotEmpty(this.resolvedRelsAndTypes$)) {
|
||||||
filterRelationsByTypeLabel('isVolumeOfJournal'),
|
this.volumes$ = this.resolvedRelsAndTypes$.pipe(
|
||||||
relationsToItems(this.item.id, this.ids)
|
filterRelationsByTypeLabel('isVolumeOfJournal'),
|
||||||
);
|
relationsToItems(this.item.id, this.ids)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user