Skip to content

Commit 556e04d

Browse files
115046: Fixed same type entity relationships with same leftward/rightward type displaying twice
1 parent 4ccd459 commit 556e04d

6 files changed

Lines changed: 44 additions & 20 deletions

File tree

src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.spec.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,25 +316,44 @@ describe('EditItemRelationshipsService', () => {
316316
describe('relationshipMatchesBothSameTypes', () => {
317317
it('should return true if both left and right type of the relationship type are the same and match the provided itemtype', (done) => {
318318
const relationshipType = Object.assign(new RelationshipType(), {
319-
leftType: createSuccessfulRemoteDataObject$({ id: 'sameType' }),
319+
leftType: createSuccessfulRemoteDataObject$({ id: 'sameType' }),
320320
rightType: createSuccessfulRemoteDataObject$({ id:'sameType' }),
321+
leftwardType: 'isDepartmentOfDivision',
322+
rightwardType: 'isDivisionOfDepartment',
321323
});
322324
const itemType = Object.assign(new ItemType(), { id: 'sameType' } );
323325

324-
const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType);
326+
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
325327
result.subscribe((resultValue) => {
326328
expect(resultValue).toBeTrue();
327329
done();
328330
});
329331
});
332+
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) => {
333+
const relationshipType = Object.assign(new RelationshipType(), {
334+
leftType: createSuccessfulRemoteDataObject$({ id: 'sameType' }),
335+
rightType: createSuccessfulRemoteDataObject$({ id: 'sameType' }),
336+
leftwardType: 'isOrgUnitOfOrgUnit',
337+
rightwardType: 'isOrgUnitOfOrgUnit',
338+
});
339+
const itemType = Object.assign(new ItemType(), { id: 'sameType' });
340+
341+
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
342+
result.subscribe((resultValue) => {
343+
expect(resultValue).toBeFalse();
344+
done();
345+
});
346+
});
330347
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) => {
331348
const relationshipType = Object.assign(new RelationshipType(), {
332349
leftType: createSuccessfulRemoteDataObject$({ id: 'sameType' }),
333350
rightType: createSuccessfulRemoteDataObject$({ id: 'sameType' }),
351+
leftwardType: 'isDepartmentOfDivision',
352+
rightwardType: 'isDivisionOfDepartment',
334353
});
335354
const itemType = Object.assign(new ItemType(), { id: 'something-else' } );
336355

337-
const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType);
356+
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
338357
result.subscribe((resultValue) => {
339358
expect(resultValue).toBeFalse();
340359
done();
@@ -344,10 +363,12 @@ describe('EditItemRelationshipsService', () => {
344363
const relationshipType = Object.assign(new RelationshipType(), {
345364
leftType: createSuccessfulRemoteDataObject$({ id: 'leftType' }),
346365
rightType: createSuccessfulRemoteDataObject$({ id: 'rightType' }),
366+
leftwardType: 'isAuthorOfPublication',
367+
rightwardType: 'isPublicationOfAuthor',
347368
});
348369
const itemType = Object.assign(new ItemType(), { id: 'leftType' } );
349370

350-
const result = service.relationshipMatchesBothSameTypes(relationshipType, itemType);
371+
const result = service.shouldDisplayBothRelationshipSides(relationshipType, itemType);
351372
result.subscribe((resultValue) => {
352373
expect(resultValue).toBeFalse();
353374
done();

src/app/item-page/edit-item-page/item-relationships/edit-item-relationships.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,16 @@ export class EditItemRelationshipsService {
216216
);
217217
}
218218

219-
relationshipMatchesBothSameTypes(relationshipType: RelationshipType, itemType: ItemType): Observable<boolean> {
219+
/**
220+
* Whether both side of the relationship need to be displayed on the edit relationship page or not.
221+
*
222+
* @param relationshipType The relationship type
223+
* @param itemType The item type
224+
*/
225+
shouldDisplayBothRelationshipSides(relationshipType: RelationshipType, itemType: ItemType): Observable<boolean> {
220226
return this.getRelationshipLeftAndRightType(relationshipType).pipe(
221227
map(([leftType, rightType]: [ItemType, ItemType]) => {
222-
return leftType.id === itemType.id && rightType.id === itemType.id;
228+
return leftType.id === itemType.id && rightType.id === itemType.id && relationshipType.leftwardType !== relationshipType.rightwardType;
223229
}),
224230
);
225231
}

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<ng-container *ngIf="bothItemsMatchType$ | async">
1+
<ng-container *ngIf="shouldDisplayBothRelationshipSides$ | async">
22
<ds-edit-relationship-list
33
[url]="url"
44
[item]="item"
55
[itemType]="itemType"
66
[relationshipType]="relationshipType"
77
[hasChanges]="hasChanges"
88
[currentItemIsLeftItem$]="isLeftItem$"
9+
class="d-block mb-4"
910
></ds-edit-relationship-list>
1011
<ds-edit-relationship-list
1112
[url]="url"
@@ -17,7 +18,7 @@
1718
></ds-edit-relationship-list>
1819
</ng-container>
1920

20-
<ng-container *ngIf="(bothItemsMatchType$ | async) === false">
21+
<ng-container *ngIf="(shouldDisplayBothRelationshipSides$ | async) === false">
2122
<ds-edit-relationship-list
2223
[url]="url"
2324
[item]="item"

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
waitForAsync,
66
} from '@angular/core/testing';
77
import { By } from '@angular/platform-browser';
8+
import { cold } from 'jasmine-marbles';
89
import { of as observableOf } from 'rxjs';
910

1011
import { Item } from '../../../../core/shared/item.model';
@@ -42,7 +43,7 @@ describe('EditRelationshipListWrapperComponent', () => {
4243

4344
editItemRelationshipsService = jasmine.createSpyObj('editItemRelationshipsService', {
4445
isProvidedItemTypeLeftType: observableOf(true),
45-
relationshipMatchesBothSameTypes: observableOf(false),
46+
shouldDisplayBothRelationshipSides: observableOf(false),
4647
});
4748

4849

@@ -82,10 +83,10 @@ describe('EditRelationshipListWrapperComponent', () => {
8283
});
8384
it('should set currentItemIsLeftItem$ and bothItemsMatchType$ based on the provided relationshipType, itemType and item', () => {
8485
expect(editItemRelationshipsService.isProvidedItemTypeLeftType).toHaveBeenCalledWith(relationshipType, leftType, item);
85-
expect(editItemRelationshipsService.relationshipMatchesBothSameTypes).toHaveBeenCalledWith(relationshipType, leftType);
86+
expect(editItemRelationshipsService.shouldDisplayBothRelationshipSides).toHaveBeenCalledWith(relationshipType, leftType);
8687

8788
expect(comp.currentItemIsLeftItem$.getValue()).toEqual(true);
88-
expect(comp.bothItemsMatchType$.getValue()).toEqual(false);
89+
expect(comp.shouldDisplayBothRelationshipSides$).toBeObservable(cold('(a|)', { a: false }));
8990
});
9091
});
9192

@@ -109,7 +110,7 @@ describe('EditRelationshipListWrapperComponent', () => {
109110

110111
describe('when the current item is both left and right', () => {
111112
it('should render two relationship list sections', () => {
112-
(editItemRelationshipsService.relationshipMatchesBothSameTypes as jasmine.Spy).and.returnValue(observableOf(true));
113+
(editItemRelationshipsService.shouldDisplayBothRelationshipSides as jasmine.Spy).and.returnValue(observableOf(true));
113114
comp.ngOnInit();
114115
fixture.detectChanges();
115116

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list-wrapper/edit-relationship-list-wrapper.component.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class EditRelationshipListWrapperComponent implements OnInit, OnDestroy {
7979

8080
isRightItem$ = new BehaviorSubject(false);
8181

82-
bothItemsMatchType$: BehaviorSubject<boolean> = new BehaviorSubject(undefined);
82+
shouldDisplayBothRelationshipSides$: Observable<boolean>;
8383

8484
/**
8585
* Array to track all subscriptions and unsubscribe them onDestroy
@@ -99,10 +99,7 @@ export class EditRelationshipListWrapperComponent implements OnInit, OnDestroy {
9999
this.currentItemIsLeftItem$.next(nextValue);
100100
}));
101101

102-
this.subs.push(this.editItemRelationshipsService.relationshipMatchesBothSameTypes(this.relationshipType, this.itemType)
103-
.subscribe((nextValue: boolean) => {
104-
this.bothItemsMatchType$.next(nextValue);
105-
}));
102+
this.shouldDisplayBothRelationshipSides$ = this.editItemRelationshipsService.shouldDisplayBothRelationshipSides(this.relationshipType, this.itemType);
106103
}
107104

108105

src/app/item-page/edit-item-page/item-relationships/edit-relationship/edit-relationship.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ export class EditRelationshipComponent implements OnChanges {
131131
this.leftItem$,
132132
this.rightItem$,
133133
]).pipe(
134-
map((items: Item[]) =>
135-
items.find((item) => item.uuid !== this.editItem.uuid),
136-
),
134+
map(([leftItem, rightItem]: [Item, Item]) => leftItem.uuid === this.editItem.uuid ? rightItem : leftItem),
137135
take(1),
138136
).subscribe((relatedItem) => {
139137
this.relatedItem$.next(relatedItem);

0 commit comments

Comments
 (0)