Commits

Yana De Pauw authored and Alexandre Vryghem committed 33b59c739dc
115284: Fix issue with same type relationships
No tags

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

Modified
1 1 import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
2 2 import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
3 3 import { By } from '@angular/platform-browser';
4 4 import { TranslateModule } from '@ngx-translate/core';
5 -import { of as observableOf } from 'rxjs';
5 +import { BehaviorSubject, of as observableOf } from 'rxjs';
6 6 import { LinkService } from '../../../../core/cache/builders/link.service';
7 7 import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service';
8 8 import { RelationshipDataService } from '../../../../core/data/relationship-data.service';
9 9 import { ItemType } from '../../../../core/shared/item-relationships/item-type.model';
10 10 import { RelationshipType } from '../../../../core/shared/item-relationships/relationship-type.model';
11 11 import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
12 12 import { Item } from '../../../../core/shared/item.model';
13 13 import { SelectableListService } from '../../../../shared/object-list/selectable-list/selectable-list.service';
14 14 import { SharedModule } from '../../../../shared/shared.module';
15 15 import { EditRelationshipListComponent } from './edit-relationship-list.component';
56 56 let itemLeft: Item;
57 57 let entityTypeLeft: ItemType;
58 58 let entityTypeRight: ItemType;
59 59 let itemRight1: Item;
60 60 let itemRight2: Item;
61 61 let fieldUpdate1;
62 62 let fieldUpdate2;
63 63 let relationships: Relationship[];
64 64 let relationshipType: RelationshipType;
65 65 let paginationOptions: PaginationComponentOptions;
66 + let currentItemIsLeftItem$ = new BehaviorSubject<boolean>(true);
66 67
67 68 const resetComponent = () => {
68 69 fixture = TestBed.createComponent(EditRelationshipListComponent);
69 70 comp = fixture.componentInstance;
70 71 de = fixture.debugElement;
71 72 comp.item = itemLeft;
72 73 comp.itemType = entityTypeLeft;
73 74 comp.url = url;
74 75 comp.relationshipType = relationshipType;
75 76 comp.hasChanges = observableOf(false);
77 + comp.currentItemIsLeftItem$ = currentItemIsLeftItem$;
76 78 fixture.detectChanges();
77 79 };
78 80
79 81 function init(leftType: string, rightType: string): void {
80 82 entityTypeLeft = Object.assign(new ItemType(), {
81 83 id: leftType,
82 84 uuid: leftType,
83 85 label: leftType,
84 86 });
85 87
286 288 describe('when the publication is on the left side of the relationship', () => {
287 289 beforeEach(() => {
288 290 relationshipType = Object.assign(new RelationshipType(), {
289 291 id: '1',
290 292 uuid: '1',
291 293 leftType: createSuccessfulRemoteDataObject$(entityTypeLeft), // publication
292 294 rightType: createSuccessfulRemoteDataObject$(entityTypeRight), // author
293 295 leftwardType: 'isAuthorOfPublication',
294 296 rightwardType: 'isPublicationOfAuthor',
295 297 });
298 + currentItemIsLeftItem$ = new BehaviorSubject<boolean>(true);
296 299 relationshipService.getItemRelationshipsByLabel.calls.reset();
297 300 resetComponent();
298 301 });
299 302
300 303 it('should fetch isAuthorOfPublication', () => {
301 304 expect(relationshipService.getItemRelationshipsByLabel).toHaveBeenCalledTimes(1);
302 305
303 306 const callArgs = relationshipService.getItemRelationshipsByLabel.calls.mostRecent().args;
304 307 const label = callArgs[1];
305 308
310 313 describe('when the publication is on the right side of the relationship', () => {
311 314 beforeEach(() => {
312 315 relationshipType = Object.assign(new RelationshipType(), {
313 316 id: '1',
314 317 uuid: '1',
315 318 leftType: createSuccessfulRemoteDataObject$(entityTypeRight), // author
316 319 rightType: createSuccessfulRemoteDataObject$(entityTypeLeft), // publication
317 320 leftwardType: 'isPublicationOfAuthor',
318 321 rightwardType: 'isAuthorOfPublication',
319 322 });
323 + currentItemIsLeftItem$ = new BehaviorSubject<boolean>(false);
320 324 relationshipService.getItemRelationshipsByLabel.calls.reset();
321 325 resetComponent();
322 326 });
323 327
324 328 it('should fetch isAuthorOfPublication', () => {
325 329 expect(relationshipService.getItemRelationshipsByLabel).toHaveBeenCalledTimes(1);
326 330
327 331 const callArgs = relationshipService.getItemRelationshipsByLabel.calls.mostRecent().args;
328 332 const label = callArgs[1];
329 333

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut