Skip to content

Commit

Permalink
Fix test issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Pauwels committed Nov 29, 2024
1 parent f040d4d commit 222b1a2
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import {

import { APP_CONFIG } from '../../../../../../config/app-config.interface';
import { environment } from '../../../../../../environments/environment';
import { BrowseService } from '../../../../../core/browse/browse.service';
import { BrowseDefinitionDataService } from '../../../../../core/browse/browse-definition-data.service';
import { BrowseDefinitionDataServiceStub } from '../../../../../shared/testing/browse-definition-data-service.stub';
import { BrowseServiceStub } from '../../../../../shared/testing/browse-service.stub';
import { TranslateLoaderMock } from '../../../../../shared/testing/translate-loader.mock';
import { ItemPageAbstractFieldComponent } from './item-page-abstract-field.component';

Expand All @@ -38,6 +40,7 @@ describe('ItemPageAbstractFieldComponent', () => {
providers: [
{ provide: APP_CONFIG, useValue: environment },
{ provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub },
{ provide: BrowseService, useValue: BrowseServiceStub },
],
schemas: [NO_ERRORS_SCHEMA],
}).overrideComponent(ItemPageAbstractFieldComponent, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import {

import { APP_CONFIG } from '../../../../../../config/app-config.interface';
import { environment } from '../../../../../../environments/environment';
import { BrowseService } from '../../../../../core/browse/browse.service';
import { BrowseDefinitionDataService } from '../../../../../core/browse/browse-definition-data.service';
import { ActivatedRouteStub } from '../../../../../shared/testing/active-router.stub';
import { BrowseDefinitionDataServiceStub } from '../../../../../shared/testing/browse-definition-data-service.stub';
import { BrowseServiceStub } from '../../../../../shared/testing/browse-service.stub';
import { TranslateLoaderMock } from '../../../../../shared/testing/translate-loader.mock';
import { MetadataValuesComponent } from '../../../../field-components/metadata-values/metadata-values.component';
import { mockItemWithMetadataFieldsAndValue } from '../item-page-field.component.spec';
Expand All @@ -41,6 +43,7 @@ describe('ItemPageAuthorFieldComponent', () => {
providers: [
{ provide: APP_CONFIG, useValue: environment },
{ provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub },
{ provide: BrowseService, useValue: BrowseServiceStub },
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
],
schemas: [NO_ERRORS_SCHEMA],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import {

import { APP_CONFIG } from '../../../../../../config/app-config.interface';
import { environment } from '../../../../../../environments/environment';
import { BrowseService } from '../../../../../core/browse/browse.service';
import { BrowseDefinitionDataService } from '../../../../../core/browse/browse-definition-data.service';
import { ActivatedRouteStub } from '../../../../../shared/testing/active-router.stub';
import { BrowseDefinitionDataServiceStub } from '../../../../../shared/testing/browse-definition-data-service.stub';
import { BrowseServiceStub } from '../../../../../shared/testing/browse-service.stub';
import { TranslateLoaderMock } from '../../../../../shared/testing/translate-loader.mock';
import { MetadataValuesComponent } from '../../../../field-components/metadata-values/metadata-values.component';
import { mockItemWithMetadataFieldsAndValue } from '../item-page-field.component.spec';
Expand All @@ -41,8 +43,8 @@ describe('ItemPageDateFieldComponent', () => {
providers: [
{ provide: APP_CONFIG, useValue: environment },
{ provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub },
{ provide: BrowseService, useValue: BrowseServiceStub },
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },

],
schemas: [NO_ERRORS_SCHEMA],
}).overrideComponent(ItemPageDateFieldComponent, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import {

import { APP_CONFIG } from '../../../../../../config/app-config.interface';
import { environment } from '../../../../../../environments/environment';
import { BrowseService } from '../../../../../core/browse/browse.service';
import { BrowseDefinitionDataService } from '../../../../../core/browse/browse-definition-data.service';
import { ActivatedRouteStub } from '../../../../../shared/testing/active-router.stub';
import { BrowseDefinitionDataServiceStub } from '../../../../../shared/testing/browse-definition-data-service.stub';
import { BrowseServiceStub } from '../../../../../shared/testing/browse-service.stub';
import { TranslateLoaderMock } from '../../../../../shared/testing/translate-loader.mock';
import { MetadataValuesComponent } from '../../../../field-components/metadata-values/metadata-values.component';
import { mockItemWithMetadataFieldsAndValue } from '../item-page-field.component.spec';
Expand All @@ -43,6 +45,7 @@ describe('GenericItemPageFieldComponent', () => {
providers: [
{ provide: APP_CONFIG, useValue: environment },
{ provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub },
{ provide: BrowseService, useValue: BrowseServiceStub },
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
],
schemas: [NO_ERRORS_SCHEMA],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import {

import { APP_CONFIG } from '../../../../../../config/app-config.interface';
import { environment } from '../../../../../../environments/environment';
import { BrowseService } from '../../../../../core/browse/browse.service';
import { BrowseDefinitionDataService } from '../../../../../core/browse/browse-definition-data.service';
import { BrowseDefinitionDataServiceStub } from '../../../../../shared/testing/browse-definition-data-service.stub';
import { BrowseServiceStub } from '../../../../../shared/testing/browse-service.stub';
import { TranslateLoaderMock } from '../../../../../shared/testing/translate-loader.mock';
import { MetadataValuesComponent } from '../../../../field-components/metadata-values/metadata-values.component';
import { GenericItemPageFieldComponent } from '../generic/generic-item-page-field.component';
Expand Down Expand Up @@ -49,6 +51,7 @@ describe('ItemPageImgFieldComponent', () => {
providers: [
{ provide: APP_CONFIG, useValue: environment },
{ provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub },
{ provide: BrowseService, useValue: BrowseServiceStub },
],
schemas: [NO_ERRORS_SCHEMA],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {

import { APP_CONFIG } from '../../../../../config/app-config.interface';
import { environment } from '../../../../../environments/environment';
import { BrowseService } from '../../../../core/browse/browse.service';
import { BrowseDefinitionDataService } from '../../../../core/browse/browse-definition-data.service';
import { Item } from '../../../../core/shared/item.model';
import { MathService } from '../../../../core/shared/math.service';
Expand All @@ -26,6 +27,7 @@ import {
import { TranslateLoaderMock } from '../../../../shared/mocks/translate-loader.mock';
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
import { BrowseDefinitionDataServiceStub } from '../../../../shared/testing/browse-definition-data-service.stub';
import { BrowseServiceStub } from '../../../../shared/testing/browse-service.stub';
import { createPaginatedList } from '../../../../shared/testing/utils.test';
import { MarkdownDirective } from '../../../../shared/utils/markdown.directive';
import { MetadataValuesComponent } from '../../../field-components/metadata-values/metadata-values.component';
Expand Down Expand Up @@ -66,6 +68,7 @@ describe('ItemPageFieldComponent', () => {
providers: [
{ provide: APP_CONFIG, useValue: appConfig },
{ provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub },
{ provide: BrowseService, useValue: BrowseServiceStub },
{ provide: MathService, useValue: {} },
],
schemas: [NO_ERRORS_SCHEMA],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import intersectionWith from 'lodash/intersectionWith';
import { Observable } from 'rxjs';
import {
filter,
first,
mergeAll,
take,
} from 'rxjs/operators';

import { BrowseService } from '../../../../core/browse/browse.service';
import { BrowseDefinitionDataService } from '../../../../core/browse/browse-definition-data.service';
import { BrowseDefinition } from '../../../../core/shared/browse-definition.model';
import { Item } from '../../../../core/shared/item.model';
import {
getFirstSucceededRemoteData,
getFirstCompletedRemoteData,
getPaginatedListPayload,
getRemoteDataPayload,
} from '../../../../core/shared/operators';
Expand Down Expand Up @@ -85,17 +85,23 @@ export class ItemPageFieldComponent {
*/
get browseDefinition(): Observable<BrowseDefinition> {
return this.browseService.getBrowseDefinitions().pipe(
getFirstSucceededRemoteData(),
getFirstCompletedRemoteData(),
getRemoteDataPayload(),
getPaginatedListPayload(),
mergeAll(),
filter((def: BrowseDefinition) =>
intersectionWith(def.metadataKeys, this.fields, ItemPageFieldComponent.fieldMatch).length > 0,
),
first(),
take(1),
);
}

/**
* Returns true iff the spec and field match.
* @param spec Specification of a metadata field name: either a metadata field, or a prefix ending in ".*".
* @param field A metadata field name.
* @private
*/
private static fieldMatch(spec: string, field: string): boolean {
return field === spec
|| (spec.endsWith('.*') && field.substring(0, spec.length - 1) === spec.substring(0, spec.length - 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import {

import { APP_CONFIG } from '../../../../../../config/app-config.interface';
import { environment } from '../../../../../../environments/environment';
import { BrowseService } from '../../../../../core/browse/browse.service';
import { BrowseDefinitionDataService } from '../../../../../core/browse/browse-definition-data.service';
import { BrowseDefinitionDataServiceStub } from '../../../../../shared/testing/browse-definition-data-service.stub';
import { BrowseServiceStub } from '../../../../../shared/testing/browse-service.stub';
import { TranslateLoaderMock } from '../../../../../shared/testing/translate-loader.mock';
import { MetadataUriValuesComponent } from '../../../../field-components/metadata-uri-values/metadata-uri-values.component';
import { mockItemWithMetadataFieldsAndValue } from '../item-page-field.component.spec';
Expand All @@ -40,6 +42,7 @@ describe('ItemPageUriFieldComponent', () => {
providers: [
{ provide: APP_CONFIG, useValue: environment },
{ provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub },
{ provide: BrowseService, useValue: BrowseServiceStub },
],
schemas: [NO_ERRORS_SCHEMA],
}).overrideComponent(ItemPageUriFieldComponent, {
Expand Down
91 changes: 91 additions & 0 deletions src/app/shared/testing/browse-service.stub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {
EMPTY,
Observable,
} from 'rxjs';

import {
buildPaginatedList,
PaginatedList,
} from '../../core/data/paginated-list.model';
import { RemoteData } from '../../core/data/remote-data';
import { BrowseDefinition } from '../../core/shared/browse-definition.model';
import { FlatBrowseDefinition } from '../../core/shared/flat-browse-definition.model';
import { HierarchicalBrowseDefinition } from '../../core/shared/hierarchical-browse-definition.model';
import { PageInfo } from '../../core/shared/page-info.model';
import { ValueListBrowseDefinition } from '../../core/shared/value-list-browse-definition.model';
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';

const mockData = [
Object.assign(new FlatBrowseDefinition(), {
'id': 'dateissued',
'browseType': 'flatBrowse',
'dataType': 'date',
'sortOptions': EMPTY,
'order': 'ASC',
'type': 'browse',
'metadataKeys': [
'dc.date.issued',
],
'_links': EMPTY,
}),

Object.assign(new ValueListBrowseDefinition(), {
'id': 'author',
'browseType': 'valueList',
'dataType': 'text',
'sortOptions': EMPTY,
'order': 'ASC',
'type': 'browse',
'metadataKeys': [
'dc.contributor.*',
'dc.creator',
],
'_links': EMPTY,
}),

Object.assign(new FlatBrowseDefinition(), {
'id': 'title',
'browseType': 'flatBrowse',
'dataType': 'title',
'sortOptions': EMPTY,
'order': 'ASC',
'type': 'browse',
'metadataKeys': [
'dc.title',
],
'_links': EMPTY,
}),

Object.assign(new ValueListBrowseDefinition(), {
'id': 'subject',
'browseType': 'valueList',
'dataType': 'text',
'sortOptions': EMPTY,
'order': 'ASC',
'type': 'browse',
'metadataKeys': [
'dc.subject.*',
],
'_links': EMPTY,
}),

Object.assign(new HierarchicalBrowseDefinition(), {
'id': 'srsc',
'browseType': 'hierarchicalBrowse',
'facetType': 'subject',
'vocabulary': 'srsc',
'type': 'browse',
'metadataKeys': [
'dc.subject',
],
'_links': EMPTY,
}),
];
export const BrowseServiceStub: any = {
/**
* Get all browse definitions.
*/
getBrowseDefinitions(): Observable<RemoteData<PaginatedList<BrowseDefinition>>> {
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), mockData));
},
};

0 comments on commit 222b1a2

Please sign in to comment.