From 5d091e69255ee74dccc2be0bb92f627507a03ec2 Mon Sep 17 00:00:00 2001 From: Kristof De Langhe Date: Fri, 15 Mar 2019 13:57:19 +0100 Subject: [PATCH] 61133: Post-merge test fixing and refactoring --- .../metadata-uri-values.component.spec.ts | 8 +-- .../full/full-item-page.component.spec.ts | 16 +++-- .../item-page-field.component.spec.ts | 15 ++-- .../search-fixed-filter.service.spec.ts | 7 +- .../search-fixed-filter.service.ts | 7 +- src/app/core/shared/metadata.utils.spec.ts | 2 +- .../item-type-switcher.component.spec.ts | 25 ++++--- ...urnal-issue-list-element.component.spec.ts | 50 +++++++------ ...rnal-volume-list-element.component.spec.ts | 50 +++++++------ .../journal-list-element.component.spec.ts | 39 +++++----- .../orgunit-list-element.component.spec.ts | 39 +++++----- .../person-list-element.component.spec.ts | 39 +++++----- .../project-list-element.component.spec.ts | 39 +++++----- .../publication-list-element.component.html | 6 +- ...publication-list-element.component.spec.ts | 72 ++++++++++--------- 15 files changed, 233 insertions(+), 181 deletions(-) diff --git a/src/app/+item-page/field-components/metadata-uri-values/metadata-uri-values.component.spec.ts b/src/app/+item-page/field-components/metadata-uri-values/metadata-uri-values.component.spec.ts index d12a73a885..2b32ece3c3 100644 --- a/src/app/+item-page/field-components/metadata-uri-values/metadata-uri-values.component.spec.ts +++ b/src/app/+item-page/field-components/metadata-uri-values/metadata-uri-values.component.spec.ts @@ -5,21 +5,21 @@ 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'; +import { MetadataValue } from '../../../core/shared/metadata.models'; let comp: MetadataUriValuesComponent; let fixture: ComponentFixture; 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' - }]; + } +] as MetadataValue[]; const mockSeperator = '
'; const mockLabel = 'fake.message'; const mockLinkText = 'fake link text'; @@ -43,7 +43,7 @@ describe('MetadataUriValuesComponent', () => { beforeEach(async(() => { fixture = TestBed.createComponent(MetadataUriValuesComponent); comp = fixture.componentInstance; - comp.values = mockMetadata; + comp.mdValues = mockMetadata; comp.separator = mockSeperator; comp.label = mockLabel; fixture.detectChanges(); diff --git a/src/app/+item-page/full/full-item-page.component.spec.ts b/src/app/+item-page/full/full-item-page.component.spec.ts index 3377dec6db..15dd001964 100644 --- a/src/app/+item-page/full/full-item-page.component.spec.ts +++ b/src/app/+item-page/full/full-item-page.component.spec.ts @@ -20,12 +20,14 @@ import { By } from '@angular/platform-browser'; const mockItem: Item = Object.assign(new Item(), { bitstreams: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'test item' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'test item' + } + ] + } }); const routeStub = Object.assign(new ActivatedRouteStub(), { data: observableOf({ item: new RemoteData(false, false, true, null, mockItem) }) @@ -69,7 +71,7 @@ describe('FullItemPageComponent', () => { it('should display the item\'s metadata', () => { 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); } }) diff --git a/src/app/+item-page/simple/field-components/specific-field/item-page-field.component.spec.ts b/src/app/+item-page/simple/field-components/specific-field/item-page-field.component.spec.ts index a0d24387cf..b1b6d3095e 100644 --- a/src/app/+item-page/simple/field-components/specific-field/item-page-field.component.spec.ts +++ b/src/app/+item-page/simple/field-components/specific-field/item-page-field.component.spec.ts @@ -10,6 +10,7 @@ import { RemoteData } from '../../../../core/data/remote-data'; import { ItemPageFieldComponent } from './item-page-field.component'; import { MetadataValuesComponent } from '../../../field-components/metadata-values/metadata-values.component'; import { of as observableOf } from 'rxjs'; +import { MetadataMap } from '../../../../core/shared/metadata.models'; let comp: ItemPageFieldComponent; let fixture: ComponentFixture; @@ -50,13 +51,13 @@ describe('ItemPageFieldComponent', () => { }); 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(), []))), - metadata: [ - { - key: field, - language: 'en_US', - value: value - }] + metadata: new MetadataMap() }); + item.metadata[field] = [{ + language: 'en_US', + value: value + }]; + return item; } diff --git a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.spec.ts b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.spec.ts index 119fca594b..2957b32c7f 100644 --- a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.spec.ts +++ b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.spec.ts @@ -3,6 +3,8 @@ import { RouteService } from '../../../shared/services/route.service'; import { RequestService } from '../../../core/data/request.service'; import { HALEndpointService } from '../../../core/shared/hal-endpoint.service'; import { of as observableOf } from 'rxjs'; +import { RequestEntry } from '../../../core/data/request.reducer'; +import { FilteredDiscoveryQueryResponse, RestResponse } from '../../../core/cache/response.models'; describe('SearchFixedFilterService', () => { let service: SearchFixedFilterService; @@ -14,7 +16,10 @@ describe('SearchFixedFilterService', () => { /* tslint:disable:no-empty */ configure: () => {}, /* tslint:enable:no-empty */ - generateRequestId: () => 'fake-id' + generateRequestId: () => 'fake-id', + getByUUID: () => observableOf(Object.assign(new RequestEntry(), { + response: new FilteredDiscoveryQueryResponse(filterQuery, '200') + })) }) as RequestService; const halServiceStub = Object.assign(new HALEndpointService(requestServiceStub, undefined), { getEndpoint: () => observableOf('fake-url') diff --git a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts index 24688b798c..7d59e5a446 100644 --- a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts +++ b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts @@ -8,7 +8,7 @@ import { ResponseParsingService } from '../../../core/data/parsing.service'; import { GenericConstructor } from '../../../core/shared/generic-constructor'; import { FilteredDiscoveryPageResponseParsingService } from '../../../core/data/filtered-discovery-page-response-parsing.service'; 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 { FilteredDiscoveryQueryResponse } from '../../../core/cache/response.models'; @@ -33,7 +33,7 @@ export class SearchFixedFilterService { getQueryByFilterName(filterName: string): Observable { if (hasValue(filterName)) { const requestUuid = this.requestService.generateRequestId(); - const requestObs = this.halService.getEndpoint(this.queryByFilterPath).pipe( + this.halService.getEndpoint(this.queryByFilterPath).pipe( map((url: string) => { url += ('/' + filterName); const request = new GetRequest(requestUuid, url); @@ -44,10 +44,11 @@ export class SearchFixedFilterService { }); }), configureRequest(this.requestService) - ); + ).subscribe(); // get search results from response cache const filterQuery: Observable = this.requestService.getByUUID(requestUuid).pipe( + getResponseFromEntry(), map((response: FilteredDiscoveryQueryResponse) => response.filterQuery )); diff --git a/src/app/core/shared/metadata.utils.spec.ts b/src/app/core/shared/metadata.utils.spec.ts index 7fbea14b13..1e1d7f86d5 100644 --- a/src/app/core/shared/metadata.utils.spec.ts +++ b/src/app/core/shared/metadata.utils.spec.ts @@ -9,7 +9,7 @@ import { import { Metadata } from './metadata.utils'; 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'); diff --git a/src/app/shared/items/switcher/item-type-switcher.component.spec.ts b/src/app/shared/items/switcher/item-type-switcher.component.spec.ts index cb657b1625..bc6950a446 100644 --- a/src/app/shared/items/switcher/item-type-switcher.component.spec.ts +++ b/src/app/shared/items/switcher/item-type-switcher.component.spec.ts @@ -16,17 +16,20 @@ import { VIEW_MODE_METADATA } from '../../../+item-page/simple/metadata-represen const relationType = 'type'; const mockItem: Item = Object.assign(new Item(), { bitstreams: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'test item' - }, - { - key: 'relationship.type', - language: 'en_US', - value: relationType - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'test item' + } + ], + 'relationship.type': [ + { + language: 'en_US', + value: relationType + } + ] + } }); const mockItemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(relationType), mockItem); let viewMode = VIEW_MODE_FULL; diff --git a/src/app/shared/object-list/item-list-element/item-types/journal-issue/journal-issue-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/item-types/journal-issue/journal-issue-list-element.component.spec.ts index 4f829a6818..05de6c814b 100644 --- a/src/app/shared/object-list/item-list-element/item-types/journal-issue/journal-issue-list-element.component.spec.ts +++ b/src/app/shared/object-list/item-list-element/item-types/journal-issue/journal-issue-list-element.component.spec.ts @@ -13,31 +13,37 @@ let fixture: ComponentFixture; const mockItemWithMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }, - { - key: 'journalvolume.identifier.volume', - language: 'en_US', - value: '1234' - }, - { - key: 'journalissue.identifier.number', - language: 'en_US', - value: '5678' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'journalvolume.identifier.volume': [ + { + language: 'en_US', + value: '1234' + } + ], + 'journalissue.identifier.number': [ + { + language: 'en_US', + value: '5678' + } + ] + } }); const mockItemWithoutMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ] + } }); describe('JournalIssueListElementComponent', () => { diff --git a/src/app/shared/object-list/item-list-element/item-types/journal-volume/journal-volume-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/item-types/journal-volume/journal-volume-list-element.component.spec.ts index 93071289b8..4cdfb0d732 100644 --- a/src/app/shared/object-list/item-list-element/item-types/journal-volume/journal-volume-list-element.component.spec.ts +++ b/src/app/shared/object-list/item-list-element/item-types/journal-volume/journal-volume-list-element.component.spec.ts @@ -13,31 +13,37 @@ let fixture: ComponentFixture; const mockItemWithMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }, - { - key: 'journal.title', - language: 'en_US', - value: 'This is just another journal title' - }, - { - key: 'journalvolume.identifier.volume', - language: 'en_US', - value: '1234' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'journal.title': [ + { + language: 'en_US', + value: 'This is just another journal title' + } + ], + 'journalvolume.identifier.volume': [ + { + language: 'en_US', + value: '1234' + } + ] + } }); const mockItemWithoutMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ] + } }); describe('JournalVolumeListElementComponent', () => { diff --git a/src/app/shared/object-list/item-list-element/item-types/journal/journal-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/item-types/journal/journal-list-element.component.spec.ts index abdeb9c00f..fc7ef06fa0 100644 --- a/src/app/shared/object-list/item-list-element/item-types/journal/journal-list-element.component.spec.ts +++ b/src/app/shared/object-list/item-list-element/item-types/journal/journal-list-element.component.spec.ts @@ -13,26 +13,31 @@ let fixture: ComponentFixture; const mockItemWithMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }, - { - key: 'journal.identifier.issn', - language: 'en_US', - value: '1234' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'journal.identifier.issn': [ + { + language: 'en_US', + value: '1234' + } + ] + } }); const mockItemWithoutMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ] + } }); describe('JournalListElementComponent', () => { diff --git a/src/app/shared/object-list/item-list-element/item-types/orgunit/orgunit-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/item-types/orgunit/orgunit-list-element.component.spec.ts index 14b86d720a..8e74c389e9 100644 --- a/src/app/shared/object-list/item-list-element/item-types/orgunit/orgunit-list-element.component.spec.ts +++ b/src/app/shared/object-list/item-list-element/item-types/orgunit/orgunit-list-element.component.spec.ts @@ -13,26 +13,31 @@ let fixture: ComponentFixture; const mockItemWithMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }, - { - key: 'orgunit.identifier.description', - language: 'en_US', - value: 'A description about the OrgUnit' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'orgunit.identifier.description': [ + { + language: 'en_US', + value: 'A description about the OrgUnit' + } + ] + } }); const mockItemWithoutMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ] + } }); describe('OrgUnitListElementComponent', () => { diff --git a/src/app/shared/object-list/item-list-element/item-types/person/person-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/item-types/person/person-list-element.component.spec.ts index 836588c565..67dc4e92ac 100644 --- a/src/app/shared/object-list/item-list-element/item-types/person/person-list-element.component.spec.ts +++ b/src/app/shared/object-list/item-list-element/item-types/person/person-list-element.component.spec.ts @@ -13,26 +13,31 @@ let fixture: ComponentFixture; const mockItemWithMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }, - { - key: 'person.identifier.jobtitle', - language: 'en_US', - value: 'Developer' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'person.identifier.jobtitle': [ + { + language: 'en_US', + value: 'Developer' + } + ] + } }); const mockItemWithoutMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ] + } }); describe('PersonListElementComponent', () => { diff --git a/src/app/shared/object-list/item-list-element/item-types/project/project-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/item-types/project/project-list-element.component.spec.ts index cd0cce95f2..1dd3c42042 100644 --- a/src/app/shared/object-list/item-list-element/item-types/project/project-list-element.component.spec.ts +++ b/src/app/shared/object-list/item-list-element/item-types/project/project-list-element.component.spec.ts @@ -13,26 +13,31 @@ let fixture: ComponentFixture; const mockItemWithMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }, - { - key: 'project.identifier.status', - language: 'en_US', - value: 'A status about the project' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'project.identifier.status': [ + { + language: 'en_US', + value: 'A status about the project' + } + ] + } }); const mockItemWithoutMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ] + } }); describe('ProjectListElementComponent', () => { diff --git a/src/app/shared/object-list/item-list-element/item-types/publication/publication-list-element.component.html b/src/app/shared/object-list/item-list-element/item-types/publication/publication-list-element.component.html index 3062e6110f..aff19aec1d 100644 --- a/src/app/shared/object-list/item-list-element/item-types/publication/publication-list-element.component.html +++ b/src/app/shared/object-list/item-list-element/item-types/publication/publication-list-element.component.html @@ -4,9 +4,9 @@ [innerHTML]="firstMetadataValue('dc.title')"> - ((, ) @@ -16,7 +16,7 @@ -
+
diff --git a/src/app/shared/object-list/item-list-element/item-types/publication/publication-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/item-types/publication/publication-list-element.component.spec.ts index 6f596d1938..732fd0d4e4 100644 --- a/src/app/shared/object-list/item-list-element/item-types/publication/publication-list-element.component.spec.ts +++ b/src/app/shared/object-list/item-list-element/item-types/publication/publication-list-element.component.spec.ts @@ -13,41 +13,49 @@ let fixture: ComponentFixture; const mockItemWithMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }, - { - key: 'dc.contributor.author', - language: 'en_US', - value: 'Smith, Donald' - }, - { - key: 'dc.publisher', - language: 'en_US', - value: 'a publisher' - }, - { - key: 'dc.date.issued', - language: null, - value: '2015-06-26' - }, - { - key: 'dc.description.abstract', - language: 'en_US', - value: 'This is the abstract' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'dc.contributor.author': [ + { + language: 'en_US', + value: 'Smith, Donald' + } + ], + 'dc.publisher': [ + { + language: 'en_US', + value: 'a publisher' + } + ], + 'dc.date.issued': [ + { + language: 'en_US', + value: '2015-06-26' + } + ], + 'dc.description.abstract': [ + { + language: 'en_US', + value: 'This is the abstract' + } + ] + } }); const mockItemWithoutMetadata: Item = Object.assign(new Item(), { bitstreams: observableOf({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }] + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ] + } }); describe('PublicationListElementComponent', () => {