Skip to content

Commit

Permalink
115046: Fixed same type entity relationships with same leftward/right…
Browse files Browse the repository at this point in the history
…ward type displaying twice
  • Loading branch information
alexandrevryghem committed Jun 7, 2024
1 parent 6d1e6f9 commit 813db7c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<ng-container *ngIf="bothItemsMatchType$ | async">
<ng-container *ngIf="shouldDisplayBothRelationshipSides$ | async">
<ds-edit-relationship-list
[url]="url"
[item]="item"
[itemType]="itemType"
[relationshipType]="relationshipType"
[hasChanges]="hasChanges"
[currentItemIsLeftItem$]="isLeftItem$"
class="d-block mb-4"
></ds-edit-relationship-list>
<ds-edit-relationship-list
[url]="url"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,7 +37,7 @@ describe('EditRelationshipListWrapperComponent', () => {

editItemRelationshipsService = jasmine.createSpyObj('editItemRelationshipsService', {
isProvidedItemTypeLeftType: observableOf(true),
relationshipMatchesBothSameTypes: observableOf(false)
shouldDisplayBothRelationshipSides: observableOf(false),
});


Expand Down Expand Up @@ -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 }));
});
});

Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 813db7c

Please sign in to comment.