@@ -185,6 +185,7 @@ describe('EditItemRelationshipsService', () => {
185185
186186 expect ( itemService . invalidateByHref ) . toHaveBeenCalledWith ( currentItem . self ) ;
187187 expect ( itemService . invalidateByHref ) . toHaveBeenCalledWith ( relationshipItem1 . self ) ;
188+ expect ( itemService . invalidateByHref ) . toHaveBeenCalledWith ( relationshipItem2 . self ) ;
188189
189190 expect ( notificationsService . success ) . toHaveBeenCalledTimes ( 1 ) ;
190191 } ) ;
@@ -265,6 +266,116 @@ describe('EditItemRelationshipsService', () => {
265266 } ) ;
266267 } ) ;
267268
269+ describe ( 'isProvidedItemTypeLeftType' , ( ) => {
270+ it ( 'should return true if the provided item corresponds to the left type of the relationship' , ( done ) => {
271+ const relationshipType = Object . assign ( new RelationshipType ( ) , {
272+ leftType : createSuccessfulRemoteDataObject$ ( { id : 'leftType' } ) ,
273+ rightType : createSuccessfulRemoteDataObject$ ( { id : 'rightType' } ) ,
274+ } ) ;
275+ const itemType = Object . assign ( new ItemType ( ) , { id : 'leftType' } ) ;
276+ const item = Object . assign ( new Item ( ) , { uuid : 'item-uuid' } ) ;
277+
278+ const result = service . isProvidedItemTypeLeftType ( relationshipType , itemType , item ) ;
279+ result . subscribe ( ( resultValue ) => {
280+ expect ( resultValue ) . toBeTrue ( ) ;
281+ done ( ) ;
282+ } ) ;
283+ } ) ;
284+
285+ it ( 'should return false if the provided item corresponds to the right type of the relationship' , ( done ) => {
286+ const relationshipType = Object . assign ( new RelationshipType ( ) , {
287+ leftType : createSuccessfulRemoteDataObject$ ( { id : 'leftType' } ) ,
288+ rightType : createSuccessfulRemoteDataObject$ ( { id : 'rightType' } ) ,
289+ } ) ;
290+ const itemType = Object . assign ( new ItemType ( ) , { id : 'rightType' } ) ;
291+ const item = Object . assign ( new Item ( ) , { uuid : 'item-uuid' } ) ;
292+
293+ const result = service . isProvidedItemTypeLeftType ( relationshipType , itemType , item ) ;
294+ result . subscribe ( ( resultValue ) => {
295+ expect ( resultValue ) . toBeFalse ( ) ;
296+ done ( ) ;
297+ } ) ;
298+ } ) ;
299+
300+ it ( 'should return undefined if the provided item corresponds does not match any of the relationship types' , ( done ) => {
301+ const relationshipType = Object . assign ( new RelationshipType ( ) , {
302+ leftType : createSuccessfulRemoteDataObject$ ( { id : 'leftType' } ) ,
303+ rightType : createSuccessfulRemoteDataObject$ ( { id : 'rightType' } ) ,
304+ } ) ;
305+ const itemType = Object . assign ( new ItemType ( ) , { id : 'something-else' } ) ;
306+ const item = Object . assign ( new Item ( ) , { uuid : 'item-uuid' } ) ;
307+
308+ const result = service . isProvidedItemTypeLeftType ( relationshipType , itemType , item ) ;
309+ result . subscribe ( ( resultValue ) => {
310+ expect ( resultValue ) . toBeUndefined ( ) ;
311+ done ( ) ;
312+ } ) ;
313+ } ) ;
314+ } ) ;
315+
316+ describe ( 'relationshipMatchesBothSameTypes' , ( ) => {
317+ it ( 'should return true if both left and right type of the relationship type are the same and match the provided itemtype' , ( done ) => {
318+ const relationshipType = Object . assign ( new RelationshipType ( ) , {
319+ leftType : createSuccessfulRemoteDataObject$ ( { id : 'sameType' } ) ,
320+ rightType : createSuccessfulRemoteDataObject$ ( { id :'sameType' } ) ,
321+ leftwardType : 'isDepartmentOfDivision' ,
322+ rightwardType : 'isDivisionOfDepartment' ,
323+ } ) ;
324+ const itemType = Object . assign ( new ItemType ( ) , { id : 'sameType' } ) ;
325+
326+ const result = service . shouldDisplayBothRelationshipSides ( relationshipType , itemType ) ;
327+ result . subscribe ( ( resultValue ) => {
328+ expect ( resultValue ) . toBeTrue ( ) ;
329+ done ( ) ;
330+ } ) ;
331+ } ) ;
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+ } ) ;
347+ 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 ) => {
348+ const relationshipType = Object . assign ( new RelationshipType ( ) , {
349+ leftType : createSuccessfulRemoteDataObject$ ( { id : 'sameType' } ) ,
350+ rightType : createSuccessfulRemoteDataObject$ ( { id : 'sameType' } ) ,
351+ leftwardType : 'isDepartmentOfDivision' ,
352+ rightwardType : 'isDivisionOfDepartment' ,
353+ } ) ;
354+ const itemType = Object . assign ( new ItemType ( ) , { id : 'something-else' } ) ;
355+
356+ const result = service . shouldDisplayBothRelationshipSides ( relationshipType , itemType ) ;
357+ result . subscribe ( ( resultValue ) => {
358+ expect ( resultValue ) . toBeFalse ( ) ;
359+ done ( ) ;
360+ } ) ;
361+ } ) ;
362+ it ( 'should return false if both left and right type of the relationship type are different' , ( done ) => {
363+ const relationshipType = Object . assign ( new RelationshipType ( ) , {
364+ leftType : createSuccessfulRemoteDataObject$ ( { id : 'leftType' } ) ,
365+ rightType : createSuccessfulRemoteDataObject$ ( { id : 'rightType' } ) ,
366+ leftwardType : 'isAuthorOfPublication' ,
367+ rightwardType : 'isPublicationOfAuthor' ,
368+ } ) ;
369+ const itemType = Object . assign ( new ItemType ( ) , { id : 'leftType' } ) ;
370+
371+ const result = service . shouldDisplayBothRelationshipSides ( relationshipType , itemType ) ;
372+ result . subscribe ( ( resultValue ) => {
373+ expect ( resultValue ) . toBeFalse ( ) ;
374+ done ( ) ;
375+ } ) ;
376+ } ) ;
377+ } ) ;
378+
268379 describe ( 'displayNotifications' , ( ) => {
269380 it ( 'should show one success notification when multiple requests succeeded' , ( ) => {
270381 service . displayNotifications ( [
0 commit comments