mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
115046: Fixed same type entity relationships with same leftward/rightward type displaying twice
This commit is contained in:
@@ -318,23 +318,42 @@ describe('EditItemRelationshipsService', () => {
|
||||
const relationshipType = Object.assign(new RelationshipType(), {
|
||||
leftType: createSuccessfulRemoteDataObject$({id: 'sameType'}),
|
||||
rightType: createSuccessfulRemoteDataObject$({id:'sameType'}),
|
||||
leftwardType: 'isDepartmentOfDivision',
|
||||
rightwardType: 'isDivisionOfDepartment',
|
||||
});
|
||||
const itemType = Object.assign(new ItemType(), {id: 'sameType'} );
|
||||
|
||||
const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType);
|
||||
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
|
||||
result.subscribe((resultValue) => {
|
||||
expect(resultValue).toBeTrue();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should return false if both left and right type of the relationship type are the same and match the provided itemtype but the leftwardType & rightwardType is identical', (done) => {
|
||||
const relationshipType = Object.assign(new RelationshipType(), {
|
||||
leftType: createSuccessfulRemoteDataObject$({ id: 'sameType' }),
|
||||
rightType: createSuccessfulRemoteDataObject$({ id: 'sameType' }),
|
||||
leftwardType: 'isOrgUnitOfOrgUnit',
|
||||
rightwardType: 'isOrgUnitOfOrgUnit',
|
||||
});
|
||||
const itemType = Object.assign(new ItemType(), { id: 'sameType' });
|
||||
|
||||
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
|
||||
result.subscribe((resultValue) => {
|
||||
expect(resultValue).toBeFalse();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should return false if both left and right type of the relationship type are the same and do not match the provided itemtype', (done) => {
|
||||
const relationshipType = Object.assign(new RelationshipType(), {
|
||||
leftType: createSuccessfulRemoteDataObject$({id: 'sameType'}),
|
||||
rightType: createSuccessfulRemoteDataObject$({id: 'sameType'}),
|
||||
leftwardType: 'isDepartmentOfDivision',
|
||||
rightwardType: 'isDivisionOfDepartment',
|
||||
});
|
||||
const itemType = Object.assign(new ItemType(), {id: 'something-else'} );
|
||||
|
||||
const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType);
|
||||
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
|
||||
result.subscribe((resultValue) => {
|
||||
expect(resultValue).toBeFalse();
|
||||
done();
|
||||
@@ -344,10 +363,12 @@ describe('EditItemRelationshipsService', () => {
|
||||
const relationshipType = Object.assign(new RelationshipType(), {
|
||||
leftType: createSuccessfulRemoteDataObject$({id: 'leftType'}),
|
||||
rightType: createSuccessfulRemoteDataObject$({id: 'rightType'}),
|
||||
leftwardType: 'isAuthorOfPublication',
|
||||
rightwardType: 'isPublicationOfAuthor',
|
||||
});
|
||||
const itemType = Object.assign(new ItemType(), {id: 'leftType'} );
|
||||
|
||||
const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType);
|
||||
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
|
||||
result.subscribe((resultValue) => {
|
||||
expect(resultValue).toBeFalse();
|
||||
done();
|
||||
|
@@ -200,11 +200,17 @@ export class EditItemRelationshipsService {
|
||||
);
|
||||
}
|
||||
|
||||
relationshipMatchesBothSameTypes(relationshipType: RelationshipType, itemType: ItemType): Observable<boolean> {
|
||||
/**
|
||||
* Whether both side of the relationship need to be displayed on the edit relationship page or not.
|
||||
*
|
||||
* @param relationshipType The relationship type
|
||||
* @param itemType The item type
|
||||
*/
|
||||
shouldDisplayBothRelationshipSides(relationshipType: RelationshipType, itemType: ItemType): Observable<boolean> {
|
||||
return this.getRelationshipLeftAndRightType(relationshipType).pipe(
|
||||
map(([leftType, rightType]: [ItemType, ItemType]) => {
|
||||
return leftType.id === itemType.id && rightType.id === itemType.id;
|
||||
})
|
||||
return leftType.id === itemType.id && rightType.id === itemType.id && relationshipType.leftwardType !== relationshipType.rightwardType;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<ng-container *ngIf="bothItemsMatchType$ | async">
|
||||
<ng-container *ngIf="shouldDisplayBothRelationshipSides$ | async">
|
||||
<ds-edit-relationship-list
|
||||
[url]="url"
|
||||
[item]="item"
|
||||
@@ -6,6 +6,7 @@
|
||||
[relationshipType]="relationshipType"
|
||||
[hasChanges]="hasChanges"
|
||||
[currentItemIsLeftItem$]="isLeftItem$"
|
||||
class="d-block mb-4"
|
||||
></ds-edit-relationship-list>
|
||||
<ds-edit-relationship-list
|
||||
[url]="url"
|
||||
@@ -17,7 +18,7 @@
|
||||
></ds-edit-relationship-list>
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngIf="!(bothItemsMatchType$ | async)">
|
||||
<ng-container *ngIf="(shouldDisplayBothRelationshipSides$ | async) === false">
|
||||
<ds-edit-relationship-list
|
||||
[url]="url"
|
||||
[item]="item"
|
||||
|
@@ -8,6 +8,7 @@ import { RelationshipType } from '../../../../core/shared/item-relationships/rel
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
|
||||
import { ItemType } from '../../../../core/shared/item-relationships/item-type.model';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { cold } from 'jasmine-marbles';
|
||||
|
||||
describe('EditRelationshipListWrapperComponent', () => {
|
||||
let editItemRelationshipsService: EditItemRelationshipsService;
|
||||
@@ -36,7 +37,7 @@ describe('EditRelationshipListWrapperComponent', () => {
|
||||
|
||||
editItemRelationshipsService = jasmine.createSpyObj('editItemRelationshipsService', {
|
||||
isProvidedItemTypeLeftType: observableOf(true),
|
||||
relationshipMatchesBothSameTypes: observableOf(false)
|
||||
shouldDisplayBothRelationshipSides: observableOf(false),
|
||||
});
|
||||
|
||||
|
||||
@@ -69,10 +70,10 @@ describe('EditRelationshipListWrapperComponent', () => {
|
||||
});
|
||||
it('should set currentItemIsLeftItem$ and bothItemsMatchType$ based on the provided relationshipType, itemType and item', () => {
|
||||
expect(editItemRelationshipsService.isProvidedItemTypeLeftType).toHaveBeenCalledWith(relationshipType, leftType, item);
|
||||
expect(editItemRelationshipsService.relationshipMatchesBothSameTypes).toHaveBeenCalledWith(relationshipType, leftType);
|
||||
expect(editItemRelationshipsService.shouldDisplayBothRelationshipSides).toHaveBeenCalledWith(relationshipType, leftType);
|
||||
|
||||
expect(comp.currentItemIsLeftItem$.getValue()).toEqual(true);
|
||||
expect(comp.bothItemsMatchType$.getValue()).toEqual(false);
|
||||
expect(comp.shouldDisplayBothRelationshipSides$).toBeObservable(cold('(a|)', { a: false }));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -96,7 +97,7 @@ describe('EditRelationshipListWrapperComponent', () => {
|
||||
|
||||
describe('when the current item is both left and right', () => {
|
||||
it('should render two relationship list sections', () => {
|
||||
(editItemRelationshipsService.relationshipMatchesBothSameTypes as jasmine.Spy).and.returnValue(observableOf(true));
|
||||
(editItemRelationshipsService.shouldDisplayBothRelationshipSides as jasmine.Spy).and.returnValue(observableOf(true));
|
||||
comp.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
|
@@ -56,7 +56,7 @@ export class EditRelationshipListWrapperComponent implements OnInit, OnDestroy {
|
||||
|
||||
isRightItem$ = new BehaviorSubject(false);
|
||||
|
||||
bothItemsMatchType$: BehaviorSubject<boolean> = new BehaviorSubject(undefined);
|
||||
shouldDisplayBothRelationshipSides$: Observable<boolean>;
|
||||
|
||||
/**
|
||||
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||
@@ -76,10 +76,7 @@ export class EditRelationshipListWrapperComponent implements OnInit, OnDestroy {
|
||||
this.currentItemIsLeftItem$.next(nextValue);
|
||||
}));
|
||||
|
||||
this.subs.push(this.editItemRelationshipsService.relationshipMatchesBothSameTypes(this.relationshipType, this.itemType)
|
||||
.subscribe((nextValue: boolean) => {
|
||||
this.bothItemsMatchType$.next(nextValue);
|
||||
}));
|
||||
this.shouldDisplayBothRelationshipSides$ = this.editItemRelationshipsService.shouldDisplayBothRelationshipSides(this.relationshipType, this.itemType);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -90,13 +90,11 @@ export class EditRelationshipComponent implements OnChanges {
|
||||
getRemoteDataPayload(),
|
||||
filter((item: Item) => hasValue(item) && isNotEmpty(item.uuid))
|
||||
);
|
||||
this.relatedItem$ = observableCombineLatest(
|
||||
this.relatedItem$ = observableCombineLatest([
|
||||
this.leftItem$,
|
||||
this.rightItem$,
|
||||
).pipe(
|
||||
map((items: Item[]) =>
|
||||
items.find((item) => item.uuid !== this.editItem.uuid)
|
||||
)
|
||||
]).pipe(
|
||||
map(([leftItem, rightItem]: [Item, Item]) => leftItem.uuid === this.editItem.uuid ? rightItem : leftItem),
|
||||
);
|
||||
} else {
|
||||
this.relatedItem$ = of(this.update.relatedItem);
|
||||
|
Reference in New Issue
Block a user