diff --git a/src/app/+item-page/edit-item-page/item-delete/item-delete.component.spec.ts b/src/app/+item-page/edit-item-page/item-delete/item-delete.component.spec.ts index 116a0feb21..ea78767df5 100644 --- a/src/app/+item-page/edit-item-page/item-delete/item-delete.component.spec.ts +++ b/src/app/+item-page/edit-item-page/item-delete/item-delete.component.spec.ts @@ -173,6 +173,19 @@ describe('ItemDeleteComponent', () => { .toHaveBeenCalledWith(mockItem.id, types.filter((type) => typesSelection[type]).map((type) => type.id)); expect(comp.notify).toHaveBeenCalled(); }); + + it('should call delete function from the ItemDataService with empty types', () => { + + spyOn(comp, 'notify'); + jasmine.getEnv().allowRespy(true); + spyOn(entityTypeService, 'getEntityTypeRelationships').and.returnValue([]); + comp.ngOnInit(); + + comp.performAction(); + + expect(mockItemDataService.delete).toHaveBeenCalledWith(mockItem.id, []); + expect(comp.notify).toHaveBeenCalled(); + }); }); describe('notify', () => { it('should navigate to the homepage on successful deletion of the item', () => { diff --git a/src/app/+item-page/edit-item-page/item-delete/item-delete.component.ts b/src/app/+item-page/edit-item-page/item-delete/item-delete.component.ts index 366b22bec7..a05ffec4f5 100644 --- a/src/app/+item-page/edit-item-page/item-delete/item-delete.component.ts +++ b/src/app/+item-page/edit-item-page/item-delete/item-delete.component.ts @@ -1,5 +1,5 @@ import { Component, Input, OnInit } from '@angular/core'; -import { defaultIfEmpty, filter, map, switchMap, take } from 'rxjs/operators'; +import {defaultIfEmpty, filter, map, switchMap, take} from 'rxjs/operators'; import { AbstractSimpleItemActionComponent } from '../simple-item-action/abstract-simple-item-action.component'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { @@ -121,8 +121,11 @@ export class ItemDeleteComponent getFirstSucceededRemoteData(), getRemoteDataPayload(), map((relationshipTypes) => relationshipTypes.page), - switchMap((types) => - combineLatest(types.map((type) => this.getRelationships(type))).pipe( + switchMap((types) => { + if (types.length === 0) { + return observableOf(types); + } + return combineLatest(types.map((type) => this.getRelationships(type))).pipe( map((relationships) => types.reduce((includedTypes, type, index) => { if (!includedTypes.some((includedType) => includedType.id === type.id) @@ -133,8 +136,8 @@ export class ItemDeleteComponent } }, []) ), - ) - ), + ); + }) ); } else { this.types$ = observableOf([]);