From dbfab94a47c153c2c359eb92b6845133283347b3 Mon Sep 17 00:00:00 2001 From: Marie Verdonck Date: Thu, 7 Jan 2021 14:10:31 +0100 Subject: [PATCH 1/3] 75413: collection/item mapper pages as tab in edit pages --- .../collection-item-mapper.component.html | 2 +- .../collection-item-mapper.component.ts | 21 +++++++++++++++---- .../edit-collection-page.routing.module.ts | 8 ++++++- .../edit-item-page.routing.module.ts | 5 +++++ .../item-collection-mapper.component.html | 2 +- .../item-collection-mapper.component.spec.ts | 19 ++++++++++------- .../item-collection-mapper.component.ts | 21 +++++++++++++++---- src/assets/i18n/en.json5 | 7 +++++++ 8 files changed, 67 insertions(+), 18 deletions(-) diff --git a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.html b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.html index af4153220f..8cdd99e70f 100644 --- a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.html +++ b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.html @@ -2,7 +2,7 @@

{{'collection.edit.item-mapper.head' | translate}}

-

+

{{'collection.edit.item-mapper.description' | translate}}

diff --git a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts index f824c99b37..c4d3f07167 100644 --- a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts +++ b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts @@ -1,12 +1,13 @@ import { BehaviorSubject, combineLatest as observableCombineLatest, Observable } from 'rxjs'; import { ChangeDetectionStrategy, Component, Inject, OnInit, ViewChild } from '@angular/core'; +import { DSONameService } from '../../core/breadcrumbs/dso-name.service'; import { fadeIn, fadeInOut } from '../../shared/animations/fade'; import { ActivatedRoute, Router } from '@angular/router'; import { RemoteData } from '../../core/data/remote-data'; import { Collection } from '../../core/shared/collection.model'; import { PaginatedList } from '../../core/data/paginated-list.model'; -import { map, startWith, switchMap, take } from 'rxjs/operators'; +import { filter, map, startWith, switchMap, take } from 'rxjs/operators'; import { getRemoteDataPayload, getFirstSucceededRemoteData, @@ -19,7 +20,7 @@ import { NotificationsService } from '../../shared/notifications/notifications.s import { ItemDataService } from '../../core/data/item-data.service'; import { TranslateService } from '@ngx-translate/core'; import { CollectionDataService } from '../../core/data/collection-data.service'; -import { isNotEmpty } from '../../shared/empty.util'; +import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component'; import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service'; import { PaginatedSearchOptions } from '../../shared/search/paginated-search-options.model'; @@ -58,6 +59,7 @@ export class CollectionItemMapperComponent implements OnInit { * The collection to map items to */ collectionRD$: Observable>; + collectionName$: Observable; /** * Search options @@ -101,11 +103,22 @@ export class CollectionItemMapperComponent implements OnInit { private notificationsService: NotificationsService, private itemDataService: ItemDataService, private collectionDataService: CollectionDataService, - private translateService: TranslateService) { + private translateService: TranslateService, + private dsoNameService: DSONameService) { } ngOnInit(): void { - this.collectionRD$ = this.route.data.pipe(map((data) => data.dso)).pipe(getFirstSucceededRemoteData()) as Observable>; + this.collectionRD$ = this.route.data.pipe( + take(1), + map((data) => data.dso), + ); + + this.collectionName$ = this.collectionRD$.pipe( + filter((rd: RemoteData) => hasValue(rd)), + map((rd: RemoteData) => { + return this.dsoNameService.getName(rd.payload); + }) + ); this.searchOptions$ = this.searchConfigService.paginatedSearchOptions; this.loadItemLists(); } diff --git a/src/app/+collection-page/edit-collection-page/edit-collection-page.routing.module.ts b/src/app/+collection-page/edit-collection-page/edit-collection-page.routing.module.ts index 818f064104..e41f0ebda4 100644 --- a/src/app/+collection-page/edit-collection-page/edit-collection-page.routing.module.ts +++ b/src/app/+collection-page/edit-collection-page/edit-collection-page.routing.module.ts @@ -1,5 +1,6 @@ import { RouterModule } from '@angular/router'; import { NgModule } from '@angular/core'; +import { CollectionItemMapperComponent } from '../collection-item-mapper/collection-item-mapper.component'; import { EditCollectionPageComponent } from './edit-collection-page.component'; import { CollectionMetadataComponent } from './collection-metadata/collection-metadata.component'; import { CollectionRolesComponent } from './collection-roles/collection-roles.component'; @@ -86,7 +87,12 @@ import { ResourcePolicyEditComponent } from '../../shared/resource-policies/edit data: { title: 'collection.edit.tabs.authorizations.title', showBreadcrumbs: true } } ] - } + }, + { + path: 'mapper', + component: CollectionItemMapperComponent, + data: { title: 'collection.edit.tabs.item-mapper.title', showBreadcrumbs: true } + }, ] } ]) diff --git a/src/app/+item-page/edit-item-page/edit-item-page.routing.module.ts b/src/app/+item-page/edit-item-page/edit-item-page.routing.module.ts index 3acbd77c40..20056a9ea4 100644 --- a/src/app/+item-page/edit-item-page/edit-item-page.routing.module.ts +++ b/src/app/+item-page/edit-item-page/edit-item-page.routing.module.ts @@ -90,6 +90,11 @@ import { ItemPageWithdrawGuard } from './item-page-withdraw.guard'; path: 'versionhistory', component: ItemVersionHistoryComponent, data: { title: 'item.edit.tabs.versionhistory.title', showBreadcrumbs: true } + }, + { + path: 'mapper', + component: ItemCollectionMapperComponent, + data: { title: 'item.edit.tabs.item-mapper.title', showBreadcrumbs: true } } ] }, diff --git a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.html b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.html index 43bf7ecd02..a65111eaec 100644 --- a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.html +++ b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.html @@ -2,7 +2,7 @@

{{'item.edit.item-mapper.head' | translate}}

-

+

{{'item.edit.item-mapper.description' | translate}}

diff --git a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.spec.ts b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.spec.ts index d134da18d0..12c694517d 100644 --- a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.spec.ts +++ b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.spec.ts @@ -7,7 +7,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { TranslateModule, TranslateService } from '@ngx-translate/core'; -import { of } from 'rxjs'; +import { of as observableOf } from 'rxjs/internal/observable/of'; import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; import { CollectionDataService } from '../../../core/data/collection-data.service'; import { ItemDataService } from '../../../core/data/item-data.service'; @@ -26,7 +26,6 @@ import { PaginationComponentOptions } from '../../../shared/pagination/paginatio import { PaginationComponent } from '../../../shared/pagination/pagination.component'; import { SearchFormComponent } from '../../../shared/search-form/search-form.component'; import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model'; -import { ActivatedRouteStub } from '../../../shared/testing/active-router.stub'; import { HostWindowServiceStub } from '../../../shared/testing/host-window-service.stub'; import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub'; import { ObjectSelectServiceStub } from '../../../shared/testing/object-select-service.stub'; @@ -59,7 +58,7 @@ describe('ItemCollectionMapperComponent', () => { name: 'test-item' }); const mockItemRD: RemoteData = createSuccessfulRemoteDataObject(mockItem); - const mockSearchOptions = of(new PaginatedSearchOptions({ + const mockSearchOptions = observableOf(new PaginatedSearchOptions({ pagination: Object.assign(new PaginationComponentOptions(), { id: 'search-page-configuration', pageSize: 10, @@ -82,7 +81,7 @@ describe('ItemCollectionMapperComponent', () => { mapToCollection: () => createSuccessfulRemoteDataObject$({}), removeMappingFromCollection: () => createSuccessfulRemoteDataObject$({}), getMappedCollectionsEndpoint: () => of('rest/api/mappedCollectionsEndpoint'), - getMappedCollections: () => of(mockCollectionsRD), + getMappedCollections: () => observableOf(mockCollectionsRD), /* tslint:disable:no-empty */ clearMappedCollectionsRequests: () => {} /* tslint:enable:no-empty */ @@ -91,14 +90,20 @@ describe('ItemCollectionMapperComponent', () => { findAllByHref: () => of(mockCollectionsRD) }; const searchServiceStub = Object.assign(new SearchServiceStub(), { - search: () => of(mockCollectionsRD), + search: () => observableOf(mockCollectionsRD), /* tslint:disable:no-empty */ clearDiscoveryRequests: () => {} /* tslint:enable:no-empty */ }); - const activatedRouteStub = new ActivatedRouteStub({}, { dso: mockItemRD }); + const activatedRouteStub = { + parent: { + data: observableOf({ + dso: mockItemRD + }) + } + }; const translateServiceStub = { - get: () => of('test-message of item ' + mockItem.name), + get: () => observableOf('test-message of item ' + mockItem.name), onLangChange: new EventEmitter(), onTranslationChange: new EventEmitter(), onDefaultLangChange: new EventEmitter() diff --git a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts index b78fe49897..6f55c6e9c3 100644 --- a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts +++ b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts @@ -1,6 +1,7 @@ import { BehaviorSubject, combineLatest as observableCombineLatest, Observable } from 'rxjs'; import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core'; +import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; import { CollectionDataService } from '../../../core/data/collection-data.service'; import { fadeIn, fadeInOut } from '../../../shared/animations/fade'; import { RemoteData } from '../../../core/data/remote-data'; @@ -15,12 +16,12 @@ import { getAllSucceededRemoteData } from '../../../core/shared/operators'; import { ActivatedRoute, Router } from '@angular/router'; -import { map, startWith, switchMap, take } from 'rxjs/operators'; +import { filter, map, startWith, switchMap, take } from 'rxjs/operators'; import { ItemDataService } from '../../../core/data/item-data.service'; import { TranslateService } from '@ngx-translate/core'; import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model'; -import { isNotEmpty } from '../../../shared/empty.util'; +import { hasValue, isNotEmpty } from '../../../shared/empty.util'; import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model'; import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service'; import { SearchService } from '../../../core/shared/search/search.service'; @@ -51,6 +52,7 @@ export class ItemCollectionMapperComponent implements OnInit { * The item to map to collections */ itemRD$: Observable>; + itemName$: Observable; /** * Search options @@ -88,11 +90,22 @@ export class ItemCollectionMapperComponent implements OnInit { private notificationsService: NotificationsService, private itemDataService: ItemDataService, private collectionDataService: CollectionDataService, - private translateService: TranslateService) { + private translateService: TranslateService, + private dsoNameService: DSONameService) { } ngOnInit(): void { - this.itemRD$ = this.route.data.pipe(map((data) => data.dso)).pipe(getFirstSucceededRemoteData()) as Observable>; + this.itemRD$ = this.route.parent.data.pipe( + take(1), + map((data) => data.dso), + ); + + this.itemName$ = this.itemRD$.pipe( + filter((rd: RemoteData) => hasValue(rd)), + map((rd: RemoteData) => { + return this.dsoNameService.getName(rd.payload); + }) + ); this.searchOptions$ = this.searchConfigService.paginatedSearchOptions; this.loadCollectionLists(); } diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 603acb3f48..0ec88e8ecd 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -649,6 +649,10 @@ + "collection.edit.tabs.mapper.head": "Item Mapper", + + "collection.edit.tabs.item-mapper.title": "Collection Edit - Item Mapper", + "collection.edit.item-mapper.cancel": "Cancel", "collection.edit.item-mapper.collection": "Collection: \"{{name}}\"", @@ -1462,6 +1466,9 @@ "item.edit.breadcrumbs": "Edit Item", + "item.edit.tabs.mapper.head": "Collection Mapper", + + "item.edit.tabs.item-mapper.title": "Item Edit - Collection Mapper", "item.edit.item-mapper.buttons.add": "Map item to selected collections", From 8efbaebc9cf509992109744a38d82f66d560c9d8 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Wed, 13 Jan 2021 17:56:07 +0100 Subject: [PATCH 2/3] fix issues regarding item and collection mappings --- .../collection-item-mapper.component.ts | 62 +++++++++++-------- .../collection-page-routing.module.ts | 7 --- .../item-collection-mapper.component.ts | 18 ++++-- 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts index c4d3f07167..61494c983a 100644 --- a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts +++ b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts @@ -7,11 +7,12 @@ import { ActivatedRoute, Router } from '@angular/router'; import { RemoteData } from '../../core/data/remote-data'; import { Collection } from '../../core/shared/collection.model'; import { PaginatedList } from '../../core/data/paginated-list.model'; -import { filter, map, startWith, switchMap, take } from 'rxjs/operators'; +import { map, startWith, switchMap, take } from 'rxjs/operators'; import { - getRemoteDataPayload, - getFirstSucceededRemoteData, - toDSpaceObjectListRD + getRemoteDataPayload, + getFirstSucceededRemoteData, + toDSpaceObjectListRD, + getFirstCompletedRemoteData, getAllSucceededRemoteData } from '../../core/shared/operators'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model'; @@ -20,7 +21,7 @@ import { NotificationsService } from '../../shared/notifications/notifications.s import { ItemDataService } from '../../core/data/item-data.service'; import { TranslateService } from '@ngx-translate/core'; import { CollectionDataService } from '../../core/data/collection-data.service'; -import { hasValue, isNotEmpty } from '../../shared/empty.util'; +import { isNotEmpty } from '../../shared/empty.util'; import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component'; import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service'; import { PaginatedSearchOptions } from '../../shared/search/paginated-search-options.model'; @@ -53,7 +54,7 @@ export class CollectionItemMapperComponent implements OnInit { * A view on the tabset element * Used to switch tabs programmatically */ - @ViewChild('tabs') tabs; + @ViewChild('tabs', {static: false}) tabs; /** * The collection to map items to @@ -108,13 +109,12 @@ export class CollectionItemMapperComponent implements OnInit { } ngOnInit(): void { - this.collectionRD$ = this.route.data.pipe( - take(1), - map((data) => data.dso), + this.collectionRD$ = this.route.parent.data.pipe( + map((data) => data.dso as RemoteData), + getFirstSucceededRemoteData() ); this.collectionName$ = this.collectionRD$.pipe( - filter((rd: RemoteData) => hasValue(rd)), map((rd: RemoteData) => { return this.dsoNameService.getName(rd.payload); }) @@ -136,27 +136,27 @@ export class CollectionItemMapperComponent implements OnInit { ); this.collectionItemsRD$ = collectionAndOptions$.pipe( switchMap(([collectionRD, options, shouldUpdate]) => { - if (shouldUpdate) { + if (shouldUpdate === true) { this.shouldUpdate$.next(false); } return this.itemDataService.findAllByHref(collectionRD.payload._links.mappedItems.href, Object.assign(options, { sort: this.defaultSortOptions - }),!shouldUpdate, true, followLink('owningCollection')); + }),!shouldUpdate, false, followLink('owningCollection')).pipe( + getAllSucceededRemoteData() + ) }) ); this.mappedItemsRD$ = collectionAndOptions$.pipe( switchMap(([collectionRD, options, shouldUpdate]) => { - if (shouldUpdate) { - return this.searchService.search(Object.assign(new PaginatedSearchOptions(options), { - query: this.buildQuery(collectionRD.payload.id, options.query), - scope: undefined, - dsoTypes: [DSpaceObjectType.ITEM], - sort: this.defaultSortOptions - }), 10000).pipe( - toDSpaceObjectListRD(), - startWith(undefined) - ); - } + return this.searchService.search(Object.assign(new PaginatedSearchOptions(options), { + query: this.buildQuery(collectionRD.payload.id, options.query), + scope: undefined, + dsoTypes: [DSpaceObjectType.ITEM], + sort: this.defaultSortOptions + }), 10000).pipe( + toDSpaceObjectListRD(), + startWith(undefined) + ); }) ); } @@ -171,8 +171,17 @@ export class CollectionItemMapperComponent implements OnInit { getFirstSucceededRemoteData(), map((collectionRD: RemoteData) => collectionRD.payload), switchMap((collection: Collection) => - observableCombineLatest(ids.map((id: string) => - remove ? this.itemDataService.removeMappingFromCollection(id, collection.id) : this.itemDataService.mapToCollection(id, collection._links.self.href) + observableCombineLatest(ids.map((id: string) => { + if (remove) { + return this.itemDataService.removeMappingFromCollection(id, collection.id).pipe( + getFirstCompletedRemoteData() + ); + } else { + return this.itemDataService.mapToCollection(id, collection._links.self.href).pipe( + getFirstCompletedRemoteData() + ); + } + } )) ) ); @@ -200,6 +209,7 @@ export class CollectionItemMapperComponent implements OnInit { successMessages.subscribe(([head, content]) => { this.notificationsService.success(head, content); }); + this.shouldUpdate$.next(true); } if (unsuccessful.length > 0) { const unsuccessMessages = observableCombineLatest( @@ -211,8 +221,6 @@ export class CollectionItemMapperComponent implements OnInit { this.notificationsService.error(head, content); }); } - // Force an update on all lists and switch back to the first tab - this.shouldUpdate$.next(true); this.switchToFirstTab(); }); } diff --git a/src/app/+collection-page/collection-page-routing.module.ts b/src/app/+collection-page/collection-page-routing.module.ts index 9d1df9b95d..7e44883a53 100644 --- a/src/app/+collection-page/collection-page-routing.module.ts +++ b/src/app/+collection-page/collection-page-routing.module.ts @@ -9,7 +9,6 @@ import { CreateCollectionPageGuard } from './create-collection-page/create-colle import { DeleteCollectionPageComponent } from './delete-collection-page/delete-collection-page.component'; import { EditItemTemplatePageComponent } from './edit-item-template-page/edit-item-template-page.component'; import { ItemTemplatePageResolver } from './edit-item-template-page/item-template-page.resolver'; -import { CollectionItemMapperComponent } from './collection-item-mapper/collection-item-mapper.component'; import { CollectionBreadcrumbResolver } from '../core/breadcrumbs/collection-breadcrumb.resolver'; import { DSOBreadcrumbsService } from '../core/breadcrumbs/dso-breadcrumbs.service'; import { LinkService } from '../core/cache/builders/link.service'; @@ -65,12 +64,6 @@ import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model'; path: '', component: CollectionPageComponent, pathMatch: 'full', - }, - { - path: '/edit/mapper', - component: CollectionItemMapperComponent, - pathMatch: 'full', - canActivate: [AuthenticatedGuard] } ], data: { diff --git a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts index 6f55c6e9c3..e712ff2e35 100644 --- a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts +++ b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts @@ -13,7 +13,7 @@ import { getRemoteDataPayload, getFirstSucceededRemoteData, toDSpaceObjectListRD, - getAllSucceededRemoteData + getAllSucceededRemoteData, getFirstCompletedRemoteData } from '../../../core/shared/operators'; import { ActivatedRoute, Router } from '@angular/router'; import { filter, map, startWith, switchMap, take } from 'rxjs/operators'; @@ -135,7 +135,8 @@ export class ItemCollectionMapperComponent implements OnInit { const owningCollectionRD$ = this.itemRD$.pipe( getFirstSucceededRemoteDataPayload(), - switchMap((item: Item) => this.collectionDataService.findOwningCollectionFor(item)) + switchMap((item: Item) => this.collectionDataService.findOwningCollectionFor(item)), + getAllSucceededRemoteData(), ); const itemCollectionsAndOptions$ = observableCombineLatest( this.itemCollectionsRD$, @@ -175,7 +176,12 @@ export class ItemCollectionMapperComponent implements OnInit { // Map the item to the collections found in ids, excluding the collections the item is already mapped to const responses$ = itemIdAndExcludingIds$.pipe( - switchMap(([itemId, excludingIds]) => observableCombineLatest(this.filterIds(ids, excludingIds).map((id: string) => this.itemDataService.mapToCollection(itemId, id)))) + switchMap(([itemId, excludingIds]) => + observableCombineLatest( + this.filterIds(ids, excludingIds).map((id: string) => + this.itemDataService.mapToCollection(itemId, id).pipe(getFirstCompletedRemoteData()) + )) + ) ); this.showNotifications(responses$, 'item.edit.item-mapper.notifications.add'); @@ -189,7 +195,11 @@ export class ItemCollectionMapperComponent implements OnInit { const responses$ = this.itemRD$.pipe( getFirstSucceededRemoteData(), map((itemRD: RemoteData) => itemRD.payload.id), - switchMap((itemId: string) => observableCombineLatest(ids.map((id: string) => this.itemDataService.removeMappingFromCollection(itemId, id)))) + switchMap((itemId: string) => observableCombineLatest( + ids.map((id: string) => + this.itemDataService.removeMappingFromCollection(itemId, id).pipe(getFirstCompletedRemoteData()) + )) + ) ); this.showNotifications(responses$, 'item.edit.item-mapper.notifications.remove'); From 62bd8fd2787cba17629646e067559b350ce3baef Mon Sep 17 00:00:00 2001 From: Marie Verdonck Date: Thu, 14 Jan 2021 11:52:42 +0100 Subject: [PATCH 3/3] 75413: test fixes --- .../collection-item-mapper.component.spec.ts | 26 +++++++++++++------ .../collection-item-mapper.component.ts | 2 +- .../item-collection-mapper.component.spec.ts | 4 +-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.spec.ts b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.spec.ts index 71bf5c2ac4..49b6a0d63c 100644 --- a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.spec.ts +++ b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.spec.ts @@ -6,7 +6,6 @@ import { CommonModule } from '@angular/common'; import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { SearchFormComponent } from '../../shared/search-form/search-form.component'; import { ActivatedRoute, Router } from '@angular/router'; -import { ActivatedRouteStub } from '../../shared/testing/active-router.stub'; import { RouterStub } from '../../shared/testing/router.stub'; import { SearchServiceStub } from '../../shared/testing/search-service.stub'; import { NotificationsService } from '../../shared/notifications/notifications.service'; @@ -28,7 +27,7 @@ import { ItemSelectComponent } from '../../shared/object-select/item-select/item import { ObjectSelectService } from '../../shared/object-select/object-select.service'; import { ObjectSelectServiceStub } from '../../shared/testing/object-select-service.stub'; import { VarDirective } from '../../shared/utils/var.directive'; -import { of as observableOf, of } from 'rxjs'; +import { of as observableOf } from 'rxjs/internal/observable/of'; import { RouteService } from '../../core/services/route.service'; import { ErrorComponent } from '../../shared/error/error.component'; import { LoadingComponent } from '../../shared/loading/loading.component'; @@ -66,7 +65,7 @@ describe('CollectionItemMapperComponent', () => { } }); const mockCollectionRD: RemoteData = createSuccessfulRemoteDataObject(mockCollection); - const mockSearchOptions = of(new PaginatedSearchOptions({ + const mockSearchOptions = observableOf(new PaginatedSearchOptions({ pagination: Object.assign(new PaginationComponentOptions(), { id: 'search-page-configuration', pageSize: 10, @@ -88,23 +87,34 @@ describe('CollectionItemMapperComponent', () => { const emptyList = createSuccessfulRemoteDataObject(createPaginatedList([])); const itemDataServiceStub = { mapToCollection: () => createSuccessfulRemoteDataObject$({}), - findAllByHref: () => of(emptyList) + findAllByHref: () => observableOf(emptyList) + }; + const activatedRouteStub = { + parent: { + data: observableOf({ + dso: mockCollectionRD + }) + }, + snapshot: { + queryParamMap: new Map([ + ['query', 'test'], + ]) + } }; - const activatedRouteStub = new ActivatedRouteStub({}, { dso: mockCollectionRD }); const translateServiceStub = { - get: () => of('test-message of collection ' + mockCollection.name), + get: () => observableOf('test-message of collection ' + mockCollection.name), onLangChange: new EventEmitter(), onTranslationChange: new EventEmitter(), onDefaultLangChange: new EventEmitter() }; const searchServiceStub = Object.assign(new SearchServiceStub(), { - search: () => of(emptyList), + search: () => observableOf(emptyList), /* tslint:disable:no-empty */ clearDiscoveryRequests: () => {} /* tslint:enable:no-empty */ }); const collectionDataServiceStub = { - getMappedItems: () => of(emptyList), + getMappedItems: () => observableOf(emptyList), /* tslint:disable:no-empty */ clearMappedItemsRequests: () => {} /* tslint:enable:no-empty */ diff --git a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts index 61494c983a..571b755897 100644 --- a/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts +++ b/src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts @@ -143,7 +143,7 @@ export class CollectionItemMapperComponent implements OnInit { sort: this.defaultSortOptions }),!shouldUpdate, false, followLink('owningCollection')).pipe( getAllSucceededRemoteData() - ) + ); }) ); this.mappedItemsRD$ = collectionAndOptions$.pipe( diff --git a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.spec.ts b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.spec.ts index 12c694517d..21c1879828 100644 --- a/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.spec.ts +++ b/src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.spec.ts @@ -80,14 +80,14 @@ describe('ItemCollectionMapperComponent', () => { const itemDataServiceStub = { mapToCollection: () => createSuccessfulRemoteDataObject$({}), removeMappingFromCollection: () => createSuccessfulRemoteDataObject$({}), - getMappedCollectionsEndpoint: () => of('rest/api/mappedCollectionsEndpoint'), + getMappedCollectionsEndpoint: () => observableOf('rest/api/mappedCollectionsEndpoint'), getMappedCollections: () => observableOf(mockCollectionsRD), /* tslint:disable:no-empty */ clearMappedCollectionsRequests: () => {} /* tslint:enable:no-empty */ }; const collectionDataServiceStub = { - findAllByHref: () => of(mockCollectionsRD) + findAllByHref: () => observableOf(mockCollectionsRD) }; const searchServiceStub = Object.assign(new SearchServiceStub(), { search: () => observableOf(mockCollectionsRD),