mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 21:13:07 +00:00
56434: metadata-values component tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<ds-metadata-field-wrapper [label]="label | translate">
|
<ds-metadata-field-wrapper [label]="label | translate">
|
||||||
<a *ngFor="let metadatum of values; let last=last;" [href]="metadatum.value">
|
<a *ngFor="let metadatum of values; let last=last;" [href]="metadatum.value" class="metadata-value-links">
|
||||||
{{ linktext || metadatum.value }}<span *ngIf="!last" [innerHTML]="separator"></span>
|
{{ linktext || metadatum.value }}<span *ngIf="!last" class="metadata-value-separator" [innerHTML]="separator"></span>
|
||||||
</a>
|
</a>
|
||||||
</ds-metadata-field-wrapper>
|
</ds-metadata-field-wrapper>
|
||||||
|
@@ -0,0 +1,97 @@
|
|||||||
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { ChangeDetectionStrategy, DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { MockTranslateLoader } from '../../../shared/mocks/mock-translate-loader';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { MetadataUriValuesComponent } from './metadata-uri-values.component';
|
||||||
|
import { isNotEmpty } from '../../../shared/empty.util';
|
||||||
|
|
||||||
|
let comp: MetadataUriValuesComponent;
|
||||||
|
let fixture: ComponentFixture<MetadataUriValuesComponent>;
|
||||||
|
|
||||||
|
const mockMetadata = [
|
||||||
|
{
|
||||||
|
key: 'dc.identifier.uri',
|
||||||
|
language: 'en_US',
|
||||||
|
value: 'http://fakelink.org'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'dc.identifier.uri',
|
||||||
|
language: 'en_US',
|
||||||
|
value: 'http://another.fakelink.org'
|
||||||
|
}];
|
||||||
|
const mockSeperator = '<br/>';
|
||||||
|
const mockLabel = 'fake.message';
|
||||||
|
const mockLinkText = 'fake link text';
|
||||||
|
|
||||||
|
describe('MetadataUriValuesComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot({
|
||||||
|
loader: {
|
||||||
|
provide: TranslateLoader,
|
||||||
|
useClass: MockTranslateLoader
|
||||||
|
}
|
||||||
|
})],
|
||||||
|
declarations: [MetadataUriValuesComponent],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).overrideComponent(MetadataUriValuesComponent, {
|
||||||
|
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
fixture = TestBed.createComponent(MetadataUriValuesComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
comp.values = mockMetadata;
|
||||||
|
comp.separator = mockSeperator;
|
||||||
|
comp.label = mockLabel;
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should display all metadata values', () => {
|
||||||
|
const innerHTML = fixture.nativeElement.innerHTML;
|
||||||
|
for (const metadatum of mockMetadata) {
|
||||||
|
expect(innerHTML).toContain(metadatum.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should contain the correct hrefs', () => {
|
||||||
|
const links = fixture.debugElement.queryAll(By.css('.metadata-value-links'));
|
||||||
|
for (const metadatum of mockMetadata) {
|
||||||
|
expect(containsHref(links, metadatum.value)).toBeTruthy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should contain separators equal to the amount of metadata values minus one', () => {
|
||||||
|
const separators = fixture.debugElement.queryAll(By.css('.metadata-value-separator'));
|
||||||
|
expect(separators.length).toBe(mockMetadata.length - 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when linktext is defined', () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
comp.linktext = mockLinkText;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should replace the metadata value with the linktext', () => {
|
||||||
|
const link = fixture.debugElement.query(By.css('.metadata-value-links'));
|
||||||
|
expect(link.nativeElement.textContent).toContain(mockLinkText);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function containsHref(links: DebugElement[], href: string): boolean {
|
||||||
|
for (const link of links) {
|
||||||
|
const hrefAtt = link.properties.href;
|
||||||
|
if (isNotEmpty(hrefAtt)) {
|
||||||
|
if (hrefAtt === href) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
<ds-metadata-field-wrapper [label]="label | translate">
|
<ds-metadata-field-wrapper [label]="label | translate">
|
||||||
<span *ngFor="let metadatum of values; let last=last;">
|
<span *ngFor="let metadatum of values; let last=last;">
|
||||||
{{metadatum.value}}<span *ngIf="!last" [innerHTML]="separator"></span>
|
{{metadatum.value}}<span *ngIf="!last" class="metadata-value-separator" [innerHTML]="separator"></span>
|
||||||
</span>
|
</span>
|
||||||
</ds-metadata-field-wrapper>
|
</ds-metadata-field-wrapper>
|
||||||
|
@@ -0,0 +1,67 @@
|
|||||||
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { MockTranslateLoader } from '../../../shared/mocks/mock-translate-loader';
|
||||||
|
import { MetadataValuesComponent } from './metadata-values.component';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
let comp: MetadataValuesComponent;
|
||||||
|
let fixture: ComponentFixture<MetadataValuesComponent>;
|
||||||
|
|
||||||
|
const mockMetadata = [
|
||||||
|
{
|
||||||
|
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'
|
||||||
|
}];
|
||||||
|
const mockSeperator = '<br/>';
|
||||||
|
const mockLabel = 'fake.message';
|
||||||
|
|
||||||
|
describe('MetadataValuesComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot({
|
||||||
|
loader: {
|
||||||
|
provide: TranslateLoader,
|
||||||
|
useClass: MockTranslateLoader
|
||||||
|
}
|
||||||
|
})],
|
||||||
|
declarations: [MetadataValuesComponent],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).overrideComponent(MetadataValuesComponent, {
|
||||||
|
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
fixture = TestBed.createComponent(MetadataValuesComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
comp.values = mockMetadata;
|
||||||
|
comp.separator = mockSeperator;
|
||||||
|
comp.label = mockLabel;
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should display all metadata values', () => {
|
||||||
|
const innerHTML = fixture.nativeElement.innerHTML;
|
||||||
|
for (const metadatum of mockMetadata) {
|
||||||
|
expect(innerHTML).toContain(metadatum.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should contain separators equal to the amount of metadata values minus one', () => {
|
||||||
|
const separators = fixture.debugElement.queryAll(By.css('.metadata-value-separator'));
|
||||||
|
expect(separators.length).toBe(mockMetadata.length - 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Reference in New Issue
Block a user