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:
Tim Donohue
2021-04-01 14:07:35 -05:00
committed by GitHub
2 changed files with 21 additions and 5 deletions

View File

@@ -173,6 +173,19 @@ describe('ItemDeleteComponent', () => {
.toHaveBeenCalledWith(mockItem.id, types.filter((type) => typesSelection[type]).map((type) => type.id)); .toHaveBeenCalledWith(mockItem.id, types.filter((type) => typesSelection[type]).map((type) => type.id));
expect(comp.notify).toHaveBeenCalled(); 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', () => { describe('notify', () => {
it('should navigate to the homepage on successful deletion of the item', () => { it('should navigate to the homepage on successful deletion of the item', () => {

View File

@@ -121,8 +121,11 @@ export class ItemDeleteComponent
getFirstSucceededRemoteData(), getFirstSucceededRemoteData(),
getRemoteDataPayload(), getRemoteDataPayload(),
map((relationshipTypes) => relationshipTypes.page), map((relationshipTypes) => relationshipTypes.page),
switchMap((types) => switchMap((types) => {
combineLatest(types.map((type) => this.getRelationships(type))).pipe( if (types.length === 0) {
return observableOf(types);
}
return combineLatest(types.map((type) => this.getRelationships(type))).pipe(
map((relationships) => map((relationships) =>
types.reduce<RelationshipType[]>((includedTypes, type, index) => { types.reduce<RelationshipType[]>((includedTypes, type, index) => {
if (!includedTypes.some((includedType) => includedType.id === type.id) if (!includedTypes.some((includedType) => includedType.id === type.id)
@@ -133,8 +136,8 @@ export class ItemDeleteComponent
} }
}, []) }, [])
), ),
) );
), })
); );
} else { } else {
this.types$ = observableOf([]); this.types$ = observableOf([]);