61133: Post-merge test fixing and refactoring

This commit is contained in:
Kristof De Langhe
2019-03-15 13:57:19 +01:00
parent 4da66b5f35
commit 5d091e6925
15 changed files with 233 additions and 181 deletions

View File

@@ -5,21 +5,21 @@ import { MockTranslateLoader } from '../../../shared/mocks/mock-translate-loader
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { MetadataUriValuesComponent } from './metadata-uri-values.component'; import { MetadataUriValuesComponent } from './metadata-uri-values.component';
import { isNotEmpty } from '../../../shared/empty.util'; import { isNotEmpty } from '../../../shared/empty.util';
import { MetadataValue } from '../../../core/shared/metadata.models';
let comp: MetadataUriValuesComponent; let comp: MetadataUriValuesComponent;
let fixture: ComponentFixture<MetadataUriValuesComponent>; let fixture: ComponentFixture<MetadataUriValuesComponent>;
const mockMetadata = [ const mockMetadata = [
{ {
key: 'dc.identifier.uri',
language: 'en_US', language: 'en_US',
value: 'http://fakelink.org' value: 'http://fakelink.org'
}, },
{ {
key: 'dc.identifier.uri',
language: 'en_US', language: 'en_US',
value: 'http://another.fakelink.org' value: 'http://another.fakelink.org'
}]; }
] as MetadataValue[];
const mockSeperator = '<br/>'; const mockSeperator = '<br/>';
const mockLabel = 'fake.message'; const mockLabel = 'fake.message';
const mockLinkText = 'fake link text'; const mockLinkText = 'fake link text';
@@ -43,7 +43,7 @@ describe('MetadataUriValuesComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
fixture = TestBed.createComponent(MetadataUriValuesComponent); fixture = TestBed.createComponent(MetadataUriValuesComponent);
comp = fixture.componentInstance; comp = fixture.componentInstance;
comp.values = mockMetadata; comp.mdValues = mockMetadata;
comp.separator = mockSeperator; comp.separator = mockSeperator;
comp.label = mockLabel; comp.label = mockLabel;
fixture.detectChanges(); fixture.detectChanges();

View File

@@ -20,12 +20,14 @@ import { By } from '@angular/platform-browser';
const mockItem: Item = Object.assign(new Item(), { const mockItem: Item = Object.assign(new Item(), {
bitstreams: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))), bitstreams: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'test item' value: 'test item'
}] }
]
}
}); });
const routeStub = Object.assign(new ActivatedRouteStub(), { const routeStub = Object.assign(new ActivatedRouteStub(), {
data: observableOf({ item: new RemoteData(false, false, true, null, mockItem) }) data: observableOf({ item: new RemoteData(false, false, true, null, mockItem) })
@@ -69,7 +71,7 @@ describe('FullItemPageComponent', () => {
it('should display the item\'s metadata', () => { it('should display the item\'s metadata', () => {
const table = fixture.debugElement.query(By.css('table')); const table = fixture.debugElement.query(By.css('table'));
for (const metadatum of mockItem.metadata) { for (const metadatum of mockItem.allMetadata([])) {
expect(table.nativeElement.innerHTML).toContain(metadatum.value); expect(table.nativeElement.innerHTML).toContain(metadatum.value);
} }
}) })

View File

@@ -10,6 +10,7 @@ import { RemoteData } from '../../../../core/data/remote-data';
import { ItemPageFieldComponent } from './item-page-field.component'; import { ItemPageFieldComponent } from './item-page-field.component';
import { MetadataValuesComponent } from '../../../field-components/metadata-values/metadata-values.component'; import { MetadataValuesComponent } from '../../../field-components/metadata-values/metadata-values.component';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
import { MetadataMap } from '../../../../core/shared/metadata.models';
let comp: ItemPageFieldComponent; let comp: ItemPageFieldComponent;
let fixture: ComponentFixture<ItemPageFieldComponent>; let fixture: ComponentFixture<ItemPageFieldComponent>;
@@ -50,13 +51,13 @@ describe('ItemPageFieldComponent', () => {
}); });
export function mockItemWithMetadataFieldAndValue(field: string, value: string): Item { export function mockItemWithMetadataFieldAndValue(field: string, value: string): Item {
return Object.assign(new Item(), { const item = Object.assign(new Item(), {
bitstreams: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))), bitstreams: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
metadata: [ metadata: new MetadataMap()
{
key: field,
language: 'en_US',
value: value
}]
}); });
item.metadata[field] = [{
language: 'en_US',
value: value
}];
return item;
} }

View File

@@ -3,6 +3,8 @@ import { RouteService } from '../../../shared/services/route.service';
import { RequestService } from '../../../core/data/request.service'; import { RequestService } from '../../../core/data/request.service';
import { HALEndpointService } from '../../../core/shared/hal-endpoint.service'; import { HALEndpointService } from '../../../core/shared/hal-endpoint.service';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
import { RequestEntry } from '../../../core/data/request.reducer';
import { FilteredDiscoveryQueryResponse, RestResponse } from '../../../core/cache/response.models';
describe('SearchFixedFilterService', () => { describe('SearchFixedFilterService', () => {
let service: SearchFixedFilterService; let service: SearchFixedFilterService;
@@ -14,7 +16,10 @@ describe('SearchFixedFilterService', () => {
/* tslint:disable:no-empty */ /* tslint:disable:no-empty */
configure: () => {}, configure: () => {},
/* tslint:enable:no-empty */ /* tslint:enable:no-empty */
generateRequestId: () => 'fake-id' generateRequestId: () => 'fake-id',
getByUUID: () => observableOf(Object.assign(new RequestEntry(), {
response: new FilteredDiscoveryQueryResponse(filterQuery, '200')
}))
}) as RequestService; }) as RequestService;
const halServiceStub = Object.assign(new HALEndpointService(requestServiceStub, undefined), { const halServiceStub = Object.assign(new HALEndpointService(requestServiceStub, undefined), {
getEndpoint: () => observableOf('fake-url') getEndpoint: () => observableOf('fake-url')

View File

@@ -8,7 +8,7 @@ import { ResponseParsingService } from '../../../core/data/parsing.service';
import { GenericConstructor } from '../../../core/shared/generic-constructor'; import { GenericConstructor } from '../../../core/shared/generic-constructor';
import { FilteredDiscoveryPageResponseParsingService } from '../../../core/data/filtered-discovery-page-response-parsing.service'; import { FilteredDiscoveryPageResponseParsingService } from '../../../core/data/filtered-discovery-page-response-parsing.service';
import { hasValue } from '../../../shared/empty.util'; import { hasValue } from '../../../shared/empty.util';
import { configureRequest } from '../../../core/shared/operators'; import { configureRequest, getResponseFromEntry } from '../../../core/shared/operators';
import { RouteService } from '../../../shared/services/route.service'; import { RouteService } from '../../../shared/services/route.service';
import { FilteredDiscoveryQueryResponse } from '../../../core/cache/response.models'; import { FilteredDiscoveryQueryResponse } from '../../../core/cache/response.models';
@@ -33,7 +33,7 @@ export class SearchFixedFilterService {
getQueryByFilterName(filterName: string): Observable<string> { getQueryByFilterName(filterName: string): Observable<string> {
if (hasValue(filterName)) { if (hasValue(filterName)) {
const requestUuid = this.requestService.generateRequestId(); const requestUuid = this.requestService.generateRequestId();
const requestObs = this.halService.getEndpoint(this.queryByFilterPath).pipe( this.halService.getEndpoint(this.queryByFilterPath).pipe(
map((url: string) => { map((url: string) => {
url += ('/' + filterName); url += ('/' + filterName);
const request = new GetRequest(requestUuid, url); const request = new GetRequest(requestUuid, url);
@@ -44,10 +44,11 @@ export class SearchFixedFilterService {
}); });
}), }),
configureRequest(this.requestService) configureRequest(this.requestService)
); ).subscribe();
// get search results from response cache // get search results from response cache
const filterQuery: Observable<string> = this.requestService.getByUUID(requestUuid).pipe( const filterQuery: Observable<string> = this.requestService.getByUUID(requestUuid).pipe(
getResponseFromEntry(),
map((response: FilteredDiscoveryQueryResponse) => map((response: FilteredDiscoveryQueryResponse) =>
response.filterQuery response.filterQuery
)); ));

View File

@@ -9,7 +9,7 @@ import {
import { Metadata } from './metadata.utils'; import { Metadata } from './metadata.utils';
const mdValue = (value: string, language?: string): MetadataValue => { const mdValue = (value: string, language?: string): MetadataValue => {
return { uuid: uuidv4(), value: value, language: isUndefined(language) ? null : language }; return Object.assign(new MetadataValue(), { uuid: uuidv4(), value: value, language: isUndefined(language) ? null : language, place: 0, authority: undefined, confidence: undefined });
}; };
const dcDescription = mdValue('Some description'); const dcDescription = mdValue('Some description');

View File

@@ -16,17 +16,20 @@ import { VIEW_MODE_METADATA } from '../../../+item-page/simple/metadata-represen
const relationType = 'type'; const relationType = 'type';
const mockItem: Item = Object.assign(new Item(), { const mockItem: Item = Object.assign(new Item(), {
bitstreams: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))), bitstreams: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'test item' value: 'test item'
}, }
{ ],
key: 'relationship.type', 'relationship.type': [
language: 'en_US', {
value: relationType language: 'en_US',
}] value: relationType
}
]
}
}); });
const mockItemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(relationType), mockItem); const mockItemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(relationType), mockItem);
let viewMode = VIEW_MODE_FULL; let viewMode = VIEW_MODE_FULL;

View File

@@ -13,31 +13,37 @@ let fixture: ComponentFixture<JournalIssueListElementComponent>;
const mockItemWithMetadata: Item = Object.assign(new Item(), { const mockItemWithMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}, }
{ ],
key: 'journalvolume.identifier.volume', 'journalvolume.identifier.volume': [
language: 'en_US', {
value: '1234' language: 'en_US',
}, value: '1234'
{ }
key: 'journalissue.identifier.number', ],
language: 'en_US', 'journalissue.identifier.number': [
value: '5678' {
}] language: 'en_US',
value: '5678'
}
]
}
}); });
const mockItemWithoutMetadata: Item = Object.assign(new Item(), { const mockItemWithoutMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}] }
]
}
}); });
describe('JournalIssueListElementComponent', () => { describe('JournalIssueListElementComponent', () => {

View File

@@ -13,31 +13,37 @@ let fixture: ComponentFixture<JournalVolumeListElementComponent>;
const mockItemWithMetadata: Item = Object.assign(new Item(), { const mockItemWithMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}, }
{ ],
key: 'journal.title', 'journal.title': [
language: 'en_US', {
value: 'This is just another journal title' language: 'en_US',
}, value: 'This is just another journal title'
{ }
key: 'journalvolume.identifier.volume', ],
language: 'en_US', 'journalvolume.identifier.volume': [
value: '1234' {
}] language: 'en_US',
value: '1234'
}
]
}
}); });
const mockItemWithoutMetadata: Item = Object.assign(new Item(), { const mockItemWithoutMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}] }
]
}
}); });
describe('JournalVolumeListElementComponent', () => { describe('JournalVolumeListElementComponent', () => {

View File

@@ -13,26 +13,31 @@ let fixture: ComponentFixture<JournalListElementComponent>;
const mockItemWithMetadata: Item = Object.assign(new Item(), { const mockItemWithMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}, }
{ ],
key: 'journal.identifier.issn', 'journal.identifier.issn': [
language: 'en_US', {
value: '1234' language: 'en_US',
}] value: '1234'
}
]
}
}); });
const mockItemWithoutMetadata: Item = Object.assign(new Item(), { const mockItemWithoutMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}] }
]
}
}); });
describe('JournalListElementComponent', () => { describe('JournalListElementComponent', () => {

View File

@@ -13,26 +13,31 @@ let fixture: ComponentFixture<OrgUnitListElementComponent>;
const mockItemWithMetadata: Item = Object.assign(new Item(), { const mockItemWithMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}, }
{ ],
key: 'orgunit.identifier.description', 'orgunit.identifier.description': [
language: 'en_US', {
value: 'A description about the OrgUnit' language: 'en_US',
}] value: 'A description about the OrgUnit'
}
]
}
}); });
const mockItemWithoutMetadata: Item = Object.assign(new Item(), { const mockItemWithoutMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}] }
]
}
}); });
describe('OrgUnitListElementComponent', () => { describe('OrgUnitListElementComponent', () => {

View File

@@ -13,26 +13,31 @@ let fixture: ComponentFixture<PersonListElementComponent>;
const mockItemWithMetadata: Item = Object.assign(new Item(), { const mockItemWithMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}, }
{ ],
key: 'person.identifier.jobtitle', 'person.identifier.jobtitle': [
language: 'en_US', {
value: 'Developer' language: 'en_US',
}] value: 'Developer'
}
]
}
}); });
const mockItemWithoutMetadata: Item = Object.assign(new Item(), { const mockItemWithoutMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}] }
]
}
}); });
describe('PersonListElementComponent', () => { describe('PersonListElementComponent', () => {

View File

@@ -13,26 +13,31 @@ let fixture: ComponentFixture<ProjectListElementComponent>;
const mockItemWithMetadata: Item = Object.assign(new Item(), { const mockItemWithMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}, }
{ ],
key: 'project.identifier.status', 'project.identifier.status': [
language: 'en_US', {
value: 'A status about the project' language: 'en_US',
}] value: 'A status about the project'
}
]
}
}); });
const mockItemWithoutMetadata: Item = Object.assign(new Item(), { const mockItemWithoutMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}] }
]
}
}); });
describe('ProjectListElementComponent', () => { describe('ProjectListElementComponent', () => {

View File

@@ -4,9 +4,9 @@
[innerHTML]="firstMetadataValue('dc.title')"></a> [innerHTML]="firstMetadataValue('dc.title')"></a>
<span class="text-muted"> <span class="text-muted">
<ds-truncatable-part [id]="item.id" [minLines]="1"> <ds-truncatable-part [id]="item.id" [minLines]="1">
<ng-container *ngIf="item.allMetadata('dc.publisher') || item.allMetadata('dc.date.issued')">(<span class="item-list-publisher" <ng-container *ngIf="item.firstMetadataValue('dc.publisher') || item.firstMetadataValue('dc.date.issued')">(<span class="item-list-publisher"
[innerHTML]="firstMetadataValue('dc.publisher')">, </span><span [innerHTML]="firstMetadataValue('dc.publisher')">, </span><span
*ngIf="item.allMetadata('dc.date.issued')" class="item-list-date" *ngIf="item.firstMetadataValue('dc.date.issued')" class="item-list-date"
[innerHTML]="firstMetadataValue('dc.date.issued')"></span>)</ng-container> [innerHTML]="firstMetadataValue('dc.date.issued')"></span>)</ng-container>
<span *ngIf="item.allMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0" <span *ngIf="item.allMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0"
class="item-list-authors"> class="item-list-authors">
@@ -16,7 +16,7 @@
</span> </span>
</ds-truncatable-part> </ds-truncatable-part>
</span> </span>
<div *ngIf="item.allMetadata('dc.description.abstract')" class="item-list-abstract"> <div *ngIf="item.firstMetadataValue('dc.description.abstract')" class="item-list-abstract">
<ds-truncatable-part [id]="item.id" [minLines]="3"><span <ds-truncatable-part [id]="item.id" [minLines]="3"><span
[innerHTML]="firstMetadataValue('dc.description.abstract')"></span> [innerHTML]="firstMetadataValue('dc.description.abstract')"></span>
</ds-truncatable-part> </ds-truncatable-part>

View File

@@ -13,41 +13,49 @@ let fixture: ComponentFixture<PublicationListElementComponent>;
const mockItemWithMetadata: Item = Object.assign(new Item(), { const mockItemWithMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}, }
{ ],
key: 'dc.contributor.author', 'dc.contributor.author': [
language: 'en_US', {
value: 'Smith, Donald' language: 'en_US',
}, value: 'Smith, Donald'
{ }
key: 'dc.publisher', ],
language: 'en_US', 'dc.publisher': [
value: 'a publisher' {
}, language: 'en_US',
{ value: 'a publisher'
key: 'dc.date.issued', }
language: null, ],
value: '2015-06-26' 'dc.date.issued': [
}, {
{ language: 'en_US',
key: 'dc.description.abstract', value: '2015-06-26'
language: 'en_US', }
value: 'This is the abstract' ],
}] 'dc.description.abstract': [
{
language: 'en_US',
value: 'This is the abstract'
}
]
}
}); });
const mockItemWithoutMetadata: Item = Object.assign(new Item(), { const mockItemWithoutMetadata: Item = Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: observableOf({}),
metadata: [ metadata: {
{ 'dc.title': [
key: 'dc.title', {
language: 'en_US', language: 'en_US',
value: 'This is just another title' value: 'This is just another title'
}] }
]
}
}); });
describe('PublicationListElementComponent', () => { describe('PublicationListElementComponent', () => {