@@ -23,16 +23,23 @@ import { LinkService } from '../../../core/cache/builders/link.service';
2323import { EntityTypeDataService } from '../../../core/data/entity-type-data.service' ;
2424import { ItemDataService } from '../../../core/data/item-data.service' ;
2525import { ObjectUpdatesService } from '../../../core/data/object-updates/object-updates.service' ;
26+ import {
27+ DSPACE_OBJECT_DELETION_SCRIPT_NAME ,
28+ ScriptDataService ,
29+ } from '../../../core/data/processes/script-data.service' ;
2630import { RelationshipDataService } from '../../../core/data/relationship-data.service' ;
2731import { RelationshipTypeDataService } from '../../../core/data/relationship-type-data.service' ;
2832import { Item } from '../../../core/shared/item.model' ;
2933import { ItemType } from '../../../core/shared/item-relationships/item-type.model' ;
3034import { Relationship } from '../../../core/shared/item-relationships/relationship.model' ;
3135import { RelationshipType } from '../../../core/shared/item-relationships/relationship-type.model' ;
36+ import { Process } from '../../../process-page/processes/process.model' ;
37+ import { ProcessParameter } from '../../../process-page/processes/process-parameter.model' ;
3238import { getMockThemeService } from '../../../shared/mocks/theme-service.mock' ;
3339import { NotificationsService } from '../../../shared/notifications/notifications.service' ;
3440import { ListableObjectComponentLoaderComponent } from '../../../shared/object-collection/shared/listable-object/listable-object-component-loader.component' ;
3541import {
42+ createFailedRemoteDataObject ,
3643 createSuccessfulRemoteDataObject ,
3744 createSuccessfulRemoteDataObject$ ,
3845} from '../../../shared/remote-data.utils' ;
@@ -64,10 +71,13 @@ let linkService;
6471let entityTypeService ;
6572let notificationsServiceStub ;
6673let typesSelection ;
74+ let scriptDataService ;
6775
6876describe ( 'ItemDeleteComponent' , ( ) => {
6977 beforeEach ( waitForAsync ( ( ) => {
70-
78+ scriptDataService = {
79+ invoke : jasmine . createSpy ( 'invoke' ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( { processId : '123' } ) ) ,
80+ } ;
7181 mockItem = Object . assign ( new Item ( ) , {
7282 id : 'fake-id' ,
7383 uuid : 'fake-uuid' ,
@@ -176,6 +186,7 @@ describe('ItemDeleteComponent', () => {
176186 { provide : RelationshipTypeDataService , useValue : { } } ,
177187 { provide : LinkService , useValue : linkService } ,
178188 { provide : ThemeService , useValue : getMockThemeService ( ) } ,
189+ { provide : ScriptDataService , useValue : scriptDataService } ,
179190 ] , schemas : [
180191 CUSTOM_ELEMENTS_SCHEMA ,
181192 ] ,
@@ -205,15 +216,17 @@ describe('ItemDeleteComponent', () => {
205216
206217 describe ( 'performAction' , ( ) => {
207218 describe ( `when there are entitytypes` , ( ) => {
208- it ( 'should call delete function from the ItemDataService ' , ( ) => {
219+ it ( 'should call delete function from the scriptDataService ' , ( ) => {
209220 spyOn ( comp , 'notify' ) ;
210221 comp . performAction ( ) ;
211- expect ( mockItemDataService . delete )
212- . toHaveBeenCalledWith ( mockItem . id , types . filter ( ( type ) => typesSelection [ type ] ) . map ( ( type ) => type . id ) ) ;
222+ expect ( scriptDataService . invoke )
223+ . toHaveBeenCalledWith ( DSPACE_OBJECT_DELETION_SCRIPT_NAME , [
224+ Object . assign ( new ProcessParameter ( ) , { name : '-i' , value : mockItem . uuid } ) ,
225+ ] , [ ] ) ;
213226 expect ( comp . notify ) . toHaveBeenCalled ( ) ;
214227 } ) ;
215228
216- it ( 'should call delete function from the ItemDataService with empty types' , ( ) => {
229+ it ( 'should call delete function from the scriptDataService with empty types' , ( ) => {
217230
218231 spyOn ( comp , 'notify' ) ;
219232 jasmine . getEnv ( ) . allowRespy ( true ) ;
@@ -222,7 +235,10 @@ describe('ItemDeleteComponent', () => {
222235
223236 comp . performAction ( ) ;
224237
225- expect ( mockItemDataService . delete ) . toHaveBeenCalledWith ( mockItem . id , [ ] ) ;
238+ expect ( scriptDataService . invoke )
239+ . toHaveBeenCalledWith ( DSPACE_OBJECT_DELETION_SCRIPT_NAME , [
240+ Object . assign ( new ProcessParameter ( ) , { name : '-i' , value : mockItem . uuid } ) ,
241+ ] , [ ] ) ;
226242 expect ( comp . notify ) . toHaveBeenCalled ( ) ;
227243 } ) ;
228244 } ) ;
@@ -236,25 +252,27 @@ describe('ItemDeleteComponent', () => {
236252 ) ;
237253 } ) ;
238254
239- it ( 'should call delete function from the ItemDataService ' , ( ) => {
255+ it ( 'should call delete function from the scriptDataService ' , waitForAsync ( ( ) => {
240256 spyOn ( comp , 'notify' ) ;
241257 comp . performAction ( ) ;
242- expect ( mockItemDataService . delete )
243- . toHaveBeenCalledWith ( mockItem . id , types . filter ( ( type ) => typesSelection [ type ] ) . map ( ( type ) => type . id ) ) ;
258+ expect ( scriptDataService . invoke ) . toHaveBeenCalledWith ( DSPACE_OBJECT_DELETION_SCRIPT_NAME , [
259+ Object . assign ( new ProcessParameter ( ) , { name : '-i' , value : mockItem . uuid } ) ,
260+ ] , [ ] ) ;
244261 expect ( comp . notify ) . toHaveBeenCalled ( ) ;
245- } ) ;
262+ } ) ) ;
246263 } ) ;
247- } ) ;
248- describe ( 'notify ', ( ) => {
249- it ( 'should navigate to the homepage on successful deletion of the item' , ( ) => {
250- comp . notify ( true ) ;
251- expect ( routerStub . navigate ) . toHaveBeenCalledWith ( [ '' ] ) ;
264+ describe ( 'notify' , ( ) => {
265+ it ( 'should navigate to the homepage on successful deletion of the item ', ( ) => {
266+ comp . notify ( createSuccessfulRemoteDataObject ( Object . assign ( new Process ( ) , { id : '123' } ) ) ) ;
267+ expect ( routerStub . navigate ) . toHaveBeenCalledWith ( [ '' ] ) ;
268+ } ) ;
252269 } ) ;
253- } ) ;
254- describe ( 'notify' , ( ) => {
255- it ( 'should navigate to the item edit page on failed deletion of the item' , ( ) => {
256- comp . notify ( false ) ;
257- expect ( routerStub . navigate ) . toHaveBeenCalledWith ( [ getItemEditRoute ( mockItem ) ] ) ;
270+ describe ( 'notify' , ( ) => {
271+ it ( 'should navigate to the item edit page on failed deletion of the item' , ( ) => {
272+ comp . item = mockItem ;
273+ comp . notify ( createFailedRemoteDataObject ( ) ) ;
274+ expect ( routerStub . navigate ) . toHaveBeenCalledWith ( [ getItemEditRoute ( mockItem ) ] ) ;
275+ } ) ;
258276 } ) ;
259277 } ) ;
260278} ) ;
0 commit comments