mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #1066 from 4Science/CSTPER-321-deleteitem
Error deleting an item when its entity type has no relations
This commit is contained in:
@@ -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', () => {
|
||||
|
@@ -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<RelationshipType[]>((includedTypes, type, index) => {
|
||||
if (!includedTypes.some((includedType) => includedType.id === type.id)
|
||||
@@ -133,8 +136,8 @@ export class ItemDeleteComponent
|
||||
}
|
||||
}, [])
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
})
|
||||
);
|
||||
} else {
|
||||
this.types$ = observableOf([]);
|
||||
|
Reference in New Issue
Block a user