@@ -19,7 +19,7 @@ import { NotificationsServiceStub } from '../../../testing/notifications-service
1919import { VarDirective } from '../../../utils/var.directive' ;
2020import { ComColFormComponent } from './comcol-form.component' ;
2121import { Operation } from 'fast-json-patch' ;
22- import { createFailedRemoteDataObject$ , createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils' ;
22+ import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils' ;
2323
2424describe ( 'ComColFormComponent' , ( ) => {
2525 let comp : ComColFormComponent < any > ;
@@ -61,7 +61,8 @@ describe('ComColFormComponent', () => {
6161 const logoEndpoint = 'rest/api/logo/endpoint' ;
6262 const dsoService = Object . assign ( {
6363 getLogoEndpoint : ( ) => observableOf ( logoEndpoint ) ,
64- deleteLogo : ( ) => createSuccessfulRemoteDataObject$ ( { } )
64+ deleteLogo : ( ) => createSuccessfulRemoteDataObject$ ( { } ) ,
65+ findById : ( ) => createSuccessfulRemoteDataObject$ ( { } )
6566 } ) ;
6667 const notificationsService = new NotificationsServiceStub ( ) ;
6768
@@ -70,7 +71,8 @@ describe('ComColFormComponent', () => {
7071 /* eslint-enable no-empty, @typescript-eslint/no-empty-function */
7172
7273 const requestServiceStub = jasmine . createSpyObj ( 'requestService' , {
73- removeByHrefSubstring : { }
74+ removeByHrefSubstring : { } ,
75+ setStaleByHrefSubstring : { }
7476 } ) ;
7577 const objectCacheStub = jasmine . createSpyObj ( 'objectCache' , {
7678 remove : { }
@@ -148,8 +150,6 @@ describe('ComColFormComponent', () => {
148150 type : Community . type ,
149151 }
150152 ) ,
151- uploader : undefined ,
152- deleteLogo : false ,
153153 operations : operations ,
154154 }
155155 ) ;
@@ -158,32 +158,22 @@ describe('ComColFormComponent', () => {
158158
159159 describe ( 'onCompleteItem' , ( ) => {
160160 beforeEach ( ( ) => {
161- spyOn ( comp . finish , 'emit' ) ;
162161 comp . onCompleteItem ( ) ;
163162 } ) ;
164163
165164 it ( 'should show a success notification' , ( ) => {
166165 expect ( notificationsService . success ) . toHaveBeenCalled ( ) ;
167166 } ) ;
168-
169- it ( 'should emit finish' , ( ) => {
170- expect ( comp . finish . emit ) . toHaveBeenCalled ( ) ;
171- } ) ;
172167 } ) ;
173168
174169 describe ( 'onUploadError' , ( ) => {
175170 beforeEach ( ( ) => {
176- spyOn ( comp . finish , 'emit' ) ;
177171 comp . onUploadError ( ) ;
178172 } ) ;
179173
180174 it ( 'should show an error notification' , ( ) => {
181175 expect ( notificationsService . error ) . toHaveBeenCalled ( ) ;
182176 } ) ;
183-
184- it ( 'should emit finish' , ( ) => {
185- expect ( comp . finish . emit ) . toHaveBeenCalled ( ) ;
186- } ) ;
187177 } ) ;
188178 } ) ;
189179
@@ -204,6 +194,11 @@ describe('ComColFormComponent', () => {
204194 it ( 'should initialize the uploadFilesOptions with a POST method' , ( ) => {
205195 expect ( comp . uploadFilesOptions . method ) . toEqual ( RestRequestMethod . POST ) ;
206196 } ) ;
197+
198+ it ( 'should not show the delete logo button' , ( ) => {
199+ const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-danger' ) ) ;
200+ expect ( button ) . toBeFalsy ( ) ;
201+ } ) ;
207202 } ) ;
208203
209204 describe ( 'and the dso contains a logo' , ( ) => {
@@ -222,96 +217,71 @@ describe('ComColFormComponent', () => {
222217 expect ( comp . uploadFilesOptions . url ) . toEqual ( logoEndpoint ) ;
223218 } ) ;
224219
225- it ( 'should initialize the uploadFilesOptions with a PUT method' , ( ) => {
226- expect ( comp . uploadFilesOptions . method ) . toEqual ( RestRequestMethod . PUT ) ;
220+ it ( 'should show the delete logo button' , ( ) => {
221+ const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-danger' ) ) ;
222+ expect ( button ) . toBeTruthy ( ) ;
227223 } ) ;
228224
229- describe ( 'submit with logo marked for deletion ' , ( ) => {
225+ describe ( 'when the delete logo button is clicked ' , ( ) => {
230226 beforeEach ( ( ) => {
231- spyOn ( dsoService , 'deleteLogo' ) . and . callThrough ( ) ;
232- comp . markLogoForDeletion = true ;
233- } ) ;
234-
235- it ( 'should call dsoService.deleteLogo on the DSO' , ( ) => {
236- comp . onSubmit ( ) ;
227+ spyOn ( dsoService , 'deleteLogo' ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( { } ) ) ;
228+ spyOn ( comp , 'handleLogoDeletion' ) . and . callThrough ( ) ;
229+ spyOn ( comp , 'createConfirmationModal' ) . and . callThrough ( ) ;
230+ spyOn ( comp , 'subscribeToConfirmationResponse' ) . and . callThrough ( ) ;
231+ const deleteButton = fixture . debugElement . query ( By . css ( '#logo-section .btn-danger' ) ) ;
232+ deleteButton . nativeElement . click ( ) ;
237233 fixture . detectChanges ( ) ;
238-
239- expect ( dsoService . deleteLogo ) . toHaveBeenCalledWith ( comp . dso ) ;
240234 } ) ;
241235
242- describe ( 'when dsoService.deleteLogo returns a successful response' , ( ) => {
243- beforeEach ( ( ) => {
244- dsoService . deleteLogo . and . returnValue ( createSuccessfulRemoteDataObject$ ( { } ) ) ;
245- comp . onSubmit ( ) ;
246- } ) ;
236+ it ( 'should create a confirmation modal with the correct labels and properties' , ( ) => {
237+ const modalServiceSpy = spyOn ( ( comp as any ) . modalService , 'open' ) . and . callThrough ( ) ;
247238
248- it ( 'should display a success notification' , ( ) => {
249- expect ( notificationsService . success ) . toHaveBeenCalled ( ) ;
250- } ) ;
251- } ) ;
239+ const modalRef = comp . createConfirmationModal ( ) ;
252240
253- describe ( 'when dsoService.deleteLogo returns an error response' , ( ) => {
254- beforeEach ( ( ) => {
255- dsoService . deleteLogo . and . returnValue ( createFailedRemoteDataObject$ ( 'Error' , 500 ) ) ;
256- comp . onSubmit ( ) ;
257- } ) ;
241+ expect ( modalServiceSpy ) . toHaveBeenCalled ( ) ;
258242
259- it ( 'should display an error notification' , ( ) => {
260- expect ( notificationsService . error ) . toHaveBeenCalled ( ) ;
261- } ) ;
262- } ) ;
263- } ) ;
243+ expect ( modalRef ) . toBeDefined ( ) ;
244+ expect ( modalRef . componentInstance ) . toBeDefined ( ) ;
264245
265- describe ( 'deleteLogo' , ( ) => {
266- beforeEach ( ( ) => {
267- comp . deleteLogo ( ) ;
268- fixture . detectChanges ( ) ;
246+ expect ( modalRef . componentInstance . headerLabel ) . toBe ( 'community-collection.edit.logo.delete.title' ) ;
247+ expect ( modalRef . componentInstance . infoLabel ) . toBe ( 'confirmation-modal.delete-community-collection-logo.info' ) ;
248+ expect ( modalRef . componentInstance . cancelLabel ) . toBe ( 'form.cancel' ) ;
249+ expect ( modalRef . componentInstance . confirmLabel ) . toBe ( 'community-collection.edit.logo.delete.title' ) ;
250+ expect ( modalRef . componentInstance . confirmIcon ) . toBe ( 'fas fa-trash' ) ;
269251 } ) ;
270252
271- it ( 'should set markLogoForDeletion to true ' , ( ) => {
272- expect ( comp . markLogoForDeletion ) . toEqual ( true ) ;
253+ it ( 'should call createConfirmationModal method ' , ( ) => {
254+ expect ( comp . createConfirmationModal ) . toHaveBeenCalled ( ) ;
273255 } ) ;
274256
275- it ( 'should mark the logo section with a danger alert' , ( ) => {
276- const logoSection = fixture . debugElement . query ( By . css ( '#logo-section.alert-danger' ) ) ;
277- expect ( logoSection ) . toBeTruthy ( ) ;
257+ it ( 'should call subscribeToConfirmationResponse method' , ( ) => {
258+ expect ( comp . subscribeToConfirmationResponse ) . toHaveBeenCalled ( ) ;
278259 } ) ;
279260
280- it ( 'should hide the delete button' , ( ) => {
281- const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-danger' ) ) ;
282- expect ( button ) . not . toBeTruthy ( ) ;
283- } ) ;
261+ describe ( 'when the modal is closed' , ( ) => {
284262
285- it ( 'should show the undo button' , ( ) => {
286- const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-warning' ) ) ;
287- expect ( button ) . toBeTruthy ( ) ;
288- } ) ;
289- } ) ;
263+ let modalRef ;
290264
291- describe ( 'undoDeleteLogo' , ( ) => {
292- beforeEach ( ( ) => {
293- comp . markLogoForDeletion = true ;
294- comp . undoDeleteLogo ( ) ;
295- fixture . detectChanges ( ) ;
296- } ) ;
265+ beforeEach ( ( ) => {
266+ modalRef = comp . createConfirmationModal ( ) ;
267+ comp . subscribeToConfirmationResponse ( modalRef ) ;
268+ } ) ;
297269
298- it ( 'should set markLogoForDeletion to false' , ( ) => {
299- expect ( comp . markLogoForDeletion ) . toEqual ( false ) ;
300- } ) ;
270+ it ( 'should call handleLogoDeletion and dsoService.deleteLogo methods when deletion is confirmed' , waitForAsync ( ( ) => {
271+ modalRef . componentInstance . confirmPressed ( ) ;
301272
302- it ( 'should disable the danger alert on the logo section' , ( ) => {
303- const logoSection = fixture . debugElement . query ( By . css ( '#logo-section.alert-danger' ) ) ;
304- expect ( logoSection ) . not . toBeTruthy ( ) ;
305- } ) ;
273+ expect ( comp . handleLogoDeletion ) . toHaveBeenCalled ( ) ;
274+ expect ( dsoService . deleteLogo ) . toHaveBeenCalled ( ) ;
306275
307- it ( 'should show the delete button' , ( ) => {
308- const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-danger' ) ) ;
309- expect ( button ) . toBeTruthy ( ) ;
310- } ) ;
276+ } ) ) ;
277+
278+ it ( 'should not call handleLogoDeletion and dsoService.deleteLogo methods when deletion is refused' , waitForAsync ( ( ) => {
279+ modalRef . componentInstance . cancelPressed ( ) ;
280+
281+ expect ( comp . handleLogoDeletion ) . not . toHaveBeenCalled ( ) ;
282+ expect ( dsoService . deleteLogo ) . not . toHaveBeenCalled ( ) ;
283+ } ) ) ;
311284
312- it ( 'should hide the undo button' , ( ) => {
313- const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-warning' ) ) ;
314- expect ( button ) . not . toBeTruthy ( ) ;
315285 } ) ;
316286 } ) ;
317287 } ) ;
0 commit comments