@@ -3,7 +3,7 @@ import { ItemType } from '../../../core/shared/item-relationships/item-type.mode
33import { Relationship } from '../../../core/shared/item-relationships/relationship.model' ;
44import { Item } from '../../../core/shared/item.model' ;
55import { RouterStub } from '../../../shared/testing/router.stub' ;
6- import { of as observableOf } from 'rxjs' ;
6+ import { of as observableOf , EMPTY } from 'rxjs' ;
77import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub' ;
88import { CommonModule } from '@angular/common' ;
99import { FormsModule } from '@angular/forms' ;
@@ -24,6 +24,8 @@ import { RelationshipType } from '../../../core/shared/item-relationships/relati
2424import { EntityTypeService } from '../../../core/data/entity-type.service' ;
2525import { getItemEditRoute } from '../../item-page-routing-paths' ;
2626import { createPaginatedList } from '../../../shared/testing/utils.test' ;
27+ import { RelationshipTypeService } from '../../../core/data/relationship-type.service' ;
28+ import { LinkService } from '../../../core/cache/builders/link.service' ;
2729
2830let comp : ItemDeleteComponent ;
2931let fixture : ComponentFixture < ItemDeleteComponent > ;
@@ -40,6 +42,7 @@ let mockItemDataService: ItemDataService;
4042let routeStub ;
4143let objectUpdatesServiceStub ;
4244let relationshipService ;
45+ let linkService ;
4346let entityTypeService ;
4447let notificationsServiceStub ;
4548let typesSelection ;
@@ -52,7 +55,12 @@ describe('ItemDeleteComponent', () => {
5255 uuid : 'fake-uuid' ,
5356 handle : 'fake/handle' ,
5457 lastModified : '2018' ,
55- isWithdrawn : true
58+ isWithdrawn : true ,
59+ metadata : {
60+ 'dspace.entity.type' : [
61+ { value : 'Person' }
62+ ]
63+ }
5664 } ) ;
5765
5866 itemType = Object . assign ( new ItemType ( ) , {
@@ -129,6 +137,12 @@ describe('ItemDeleteComponent', () => {
129137 }
130138 ) ;
131139
140+ linkService = jasmine . createSpyObj ( 'linkService' ,
141+ {
142+ resolveLinks : relationships [ 0 ] ,
143+ }
144+ ) ;
145+
132146 notificationsServiceStub = new NotificationsServiceStub ( ) ;
133147
134148 TestBed . configureTestingModule ( {
@@ -142,6 +156,8 @@ describe('ItemDeleteComponent', () => {
142156 { provide : ObjectUpdatesService , useValue : objectUpdatesServiceStub } ,
143157 { provide : RelationshipService , useValue : relationshipService } ,
144158 { provide : EntityTypeService , useValue : entityTypeService } ,
159+ { provide : RelationshipTypeService , useValue : { } } ,
160+ { provide : LinkService , useValue : linkService } ,
145161 ] , schemas : [
146162 CUSTOM_ELEMENTS_SCHEMA
147163 ]
@@ -166,25 +182,45 @@ describe('ItemDeleteComponent', () => {
166182 } ) ;
167183
168184 describe ( 'performAction' , ( ) => {
169- it ( 'should call delete function from the ItemDataService' , ( ) => {
170- spyOn ( comp , 'notify' ) ;
171- comp . performAction ( ) ;
172- expect ( mockItemDataService . delete )
173- . toHaveBeenCalledWith ( mockItem . id , types . filter ( ( type ) => typesSelection [ type ] ) . map ( ( type ) => type . id ) ) ;
174- expect ( comp . notify ) . toHaveBeenCalled ( ) ;
185+ describe ( `when there are entitytypes` , ( ) => {
186+ it ( 'should call delete function from the ItemDataService' , ( ) => {
187+ spyOn ( comp , 'notify' ) ;
188+ comp . performAction ( ) ;
189+ expect ( mockItemDataService . delete )
190+ . toHaveBeenCalledWith ( mockItem . id , types . filter ( ( type ) => typesSelection [ type ] ) . map ( ( type ) => type . id ) ) ;
191+ expect ( comp . notify ) . toHaveBeenCalled ( ) ;
192+ } ) ;
193+
194+ it ( 'should call delete function from the ItemDataService with empty types' , ( ) => {
195+
196+ spyOn ( comp , 'notify' ) ;
197+ jasmine . getEnv ( ) . allowRespy ( true ) ;
198+ spyOn ( entityTypeService , 'getEntityTypeRelationships' ) . and . returnValue ( [ ] ) ;
199+ comp . ngOnInit ( ) ;
200+
201+ comp . performAction ( ) ;
202+
203+ expect ( mockItemDataService . delete ) . toHaveBeenCalledWith ( mockItem . id , [ ] ) ;
204+ expect ( comp . notify ) . toHaveBeenCalled ( ) ;
205+ } ) ;
175206 } ) ;
176207
177- it ( 'should call delete function from the ItemDataService with empty types' , ( ) => {
178-
179- spyOn ( comp , 'notify' ) ;
180- jasmine . getEnv ( ) . allowRespy ( true ) ;
181- spyOn ( entityTypeService , 'getEntityTypeRelationships' ) . and . returnValue ( [ ] ) ;
182- comp . ngOnInit ( ) ;
183-
184- comp . performAction ( ) ;
185-
186- expect ( mockItemDataService . delete ) . toHaveBeenCalledWith ( mockItem . id , [ ] ) ;
187- expect ( comp . notify ) . toHaveBeenCalled ( ) ;
208+ describe ( `when there are no entity types` , ( ) => {
209+ beforeEach ( ( ) => {
210+ ( comp as any ) . entityTypeService = jasmine . createSpyObj ( 'entityTypeService' ,
211+ {
212+ getEntityTypeByLabel : EMPTY ,
213+ }
214+ ) ;
215+ } ) ;
216+
217+ it ( 'should call delete function from the ItemDataService' , ( ) => {
218+ spyOn ( comp , 'notify' ) ;
219+ comp . performAction ( ) ;
220+ expect ( mockItemDataService . delete )
221+ . toHaveBeenCalledWith ( mockItem . id , types . filter ( ( type ) => typesSelection [ type ] ) . map ( ( type ) => type . id ) ) ;
222+ expect ( comp . notify ) . toHaveBeenCalled ( ) ;
223+ } ) ;
188224 } ) ;
189225 } ) ;
190226 describe ( 'notify' , ( ) => {
0 commit comments