fixed existing tests

This commit is contained in:
lotte
2019-12-20 16:48:40 +01:00
parent 4f1dd88923
commit 65b648b000
4 changed files with 53 additions and 25 deletions

View File

@@ -1,6 +1,9 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ExistingMetadataListElementComponent } from './existing-metadata-list-element.component'; import { ExistingMetadataListElementComponent } from './existing-metadata-list-element.component';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { SelectableListService } from '../../../../object-list/selectable-list/selectable-list.service';
import { Store } from '@ngrx/store';
describe('ExistingMetadataListElementComponent', () => { describe('ExistingMetadataListElementComponent', () => {
let component: ExistingMetadataListElementComponent; let component: ExistingMetadataListElementComponent;
@@ -8,9 +11,14 @@ describe('ExistingMetadataListElementComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ ExistingMetadataListElementComponent ] declarations: [ExistingMetadataListElementComponent],
providers: [
{ provide: SelectableListService, useValue: {} },
{ provide: Store, useValue: {} },
],
schemas: [NO_ERRORS_SCHEMA]
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@@ -15,11 +15,13 @@ import { Store } from '@ngrx/store';
import { AppState } from '../../../../../app.reducer'; import { AppState } from '../../../../../app.reducer';
import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model'; import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model';
// tslint:disable:max-classes-per-file
export abstract class Reorderable { export abstract class Reorderable {
constructor(public oldIndex?: number, public newIndex?: number) { constructor(public oldIndex?: number, public newIndex?: number) {
} }
abstract getId(): string; abstract getId(): string;
abstract getPlace(): number; abstract getPlace(): number;
} }
@@ -84,7 +86,7 @@ export class ExistingMetadataListElementComponent implements OnChanges, OnDestro
const relationMD: MetadataValue = this.submissionItem.firstMetadata(this.relationshipOptions.metadataField, { value: this.relatedItem.uuid }); const relationMD: MetadataValue = this.submissionItem.firstMetadata(this.relationshipOptions.metadataField, { value: this.relatedItem.uuid });
if (hasValue(relationMD)) { if (hasValue(relationMD)) {
const metadataRepresentationMD: MetadataValue = this.submissionItem.firstMetadata(this.metadataFields, { authority: relationMD.authority }); const metadataRepresentationMD: MetadataValue = this.submissionItem.firstMetadata(this.metadataFields, { authority: relationMD.authority });
this.metadataRepresentation = Object.assign( this.metadataRepresentation = Object.assign(
new ItemMetadataRepresentation(metadataRepresentationMD), new ItemMetadataRepresentation(metadataRepresentationMD),
this.relatedItem this.relatedItem
) )
@@ -107,3 +109,4 @@ export class ExistingMetadataListElementComponent implements OnChanges, OnDestro
} }
} }
// tslint:enable:max-classes-per-file

View File

@@ -16,7 +16,7 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { of } from 'rxjs/internal/observable/of'; import { of } from 'rxjs/internal/observable/of';
fdescribe('ItemSelectComponent', () => { describe('ItemSelectComponent', () => {
let comp: ItemSelectComponent; let comp: ItemSelectComponent;
let fixture: ComponentFixture<ItemSelectComponent>; let fixture: ComponentFixture<ItemSelectComponent>;
let objectSelectService: ObjectSelectService; let objectSelectService: ObjectSelectService;

View File

@@ -1,8 +1,28 @@
import { ChangeDetectorRef, Component, EventEmitter, HostListener, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; import {
ChangeDetectorRef,
Component,
EventEmitter,
HostListener,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges
} from '@angular/core';
import { FormControl } from '@angular/forms'; import { FormControl } from '@angular/forms';
import { BehaviorSubject, combineLatest, Observable, of as observableOf, Subscription } from 'rxjs'; import { BehaviorSubject, combineLatest, Observable, of as observableOf, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged, filter, map, mergeMap, reduce, startWith, flatMap, find } from 'rxjs/operators'; import {
debounceTime,
distinctUntilChanged,
filter,
find,
flatMap,
map,
mergeMap,
reduce,
startWith
} from 'rxjs/operators';
import { Collection } from '../../../core/shared/collection.model'; import { Collection } from '../../../core/shared/collection.model';
import { CommunityDataService } from '../../../core/data/community-data.service'; import { CommunityDataService } from '../../../core/data/community-data.service';
@@ -197,23 +217,21 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
find((communities: RemoteData<PaginatedList<Community>>) => isNotEmpty(communities.payload)), find((communities: RemoteData<PaginatedList<Community>>) => isNotEmpty(communities.payload)),
mergeMap((communities: RemoteData<PaginatedList<Community>>) => communities.payload.page)); mergeMap((communities: RemoteData<PaginatedList<Community>>) => communities.payload.page));
const listCollection$ = observableOf([]); const listCollection$ = communities$.pipe(
flatMap((communityData: Community) => {
// const listCollection$ = communities$.pipe( return this.collectionDataService.getAuthorizedCollectionByCommunity(communityData.uuid, findOptions).pipe(
// flatMap((communityData: Community) => { find((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending && collections.hasSucceeded),
// return this.collectionDataService.getAuthorizedCollectionByCommunity(communityData.uuid, findOptions).pipe( mergeMap((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.page),
// find((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending && collections.hasSucceeded), filter((collectionData: Collection) => isNotEmpty(collectionData)),
// mergeMap((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.page), map((collectionData: Collection) => ({
// filter((collectionData: Collection) => isNotEmpty(collectionData)), communities: [{ id: communityData.id, name: communityData.name }],
// map((collectionData: Collection) => ({ collection: { id: collectionData.id, name: collectionData.name }
// communities: [{ id: communityData.id, name: communityData.name }], }))
// collection: { id: collectionData.id, name: collectionData.name } );
// })) }),
// ); reduce((acc: any, value: any) => [...acc, ...value], []),
// }), startWith([])
// reduce((acc: any, value: any) => [...acc, ...value], []), );
// startWith([])
// );
const searchTerm$ = this.searchField.valueChanges.pipe( const searchTerm$ = this.searchField.valueChanges.pipe(
debounceTime(200), debounceTime(200),
@@ -229,8 +247,7 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
} else { } else {
return listCollection.filter((v) => v.collection.name.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1).slice(0, 5); return listCollection.filter((v) => v.collection.name.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1).slice(0, 5);
} }
}) }));
);
} }
} }
} }