@@ -29,10 +29,7 @@ import { hasValue } from '../../../empty.util';
2929import { FormComponent } from '../../../form/form.component' ;
3030import { AuthServiceMock } from '../../../mocks/auth.service.mock' ;
3131import { NotificationsService } from '../../../notifications/notifications.service' ;
32- import {
33- createFailedRemoteDataObject$ ,
34- createSuccessfulRemoteDataObject$ ,
35- } from '../../../remote-data.utils' ;
32+ import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils' ;
3633import { NotificationsServiceStub } from '../../../testing/notifications-service.stub' ;
3734import { UploaderComponent } from '../../../upload/uploader/uploader.component' ;
3835import { VarDirective } from '../../../utils/var.directive' ;
@@ -80,6 +77,7 @@ describe('ComColFormComponent', () => {
8077 const dsoService = Object . assign ( {
8178 getLogoEndpoint : ( ) => observableOf ( logoEndpoint ) ,
8279 deleteLogo : ( ) => createSuccessfulRemoteDataObject$ ( { } ) ,
80+ findById : ( ) => createSuccessfulRemoteDataObject$ ( { } ) ,
8381 } ) ;
8482 const notificationsService = new NotificationsServiceStub ( ) ;
8583
@@ -89,6 +87,7 @@ describe('ComColFormComponent', () => {
8987
9088 const requestServiceStub = jasmine . createSpyObj ( 'requestService' , {
9189 removeByHrefSubstring : { } ,
90+ setStaleByHrefSubstring : { } ,
9291 } ) ;
9392 const objectCacheStub = jasmine . createSpyObj ( 'objectCache' , {
9493 remove : { } ,
@@ -175,8 +174,6 @@ describe('ComColFormComponent', () => {
175174 type : Community . type ,
176175 } ,
177176 ) ,
178- uploader : undefined ,
179- deleteLogo : false ,
180177 operations : operations ,
181178 } ,
182179 ) ;
@@ -185,32 +182,22 @@ describe('ComColFormComponent', () => {
185182
186183 describe ( 'onCompleteItem' , ( ) => {
187184 beforeEach ( ( ) => {
188- spyOn ( comp . finish , 'emit' ) ;
189185 comp . onCompleteItem ( ) ;
190186 } ) ;
191187
192188 it ( 'should show a success notification' , ( ) => {
193189 expect ( notificationsService . success ) . toHaveBeenCalled ( ) ;
194190 } ) ;
195-
196- it ( 'should emit finish' , ( ) => {
197- expect ( comp . finish . emit ) . toHaveBeenCalled ( ) ;
198- } ) ;
199191 } ) ;
200192
201193 describe ( 'onUploadError' , ( ) => {
202194 beforeEach ( ( ) => {
203- spyOn ( comp . finish , 'emit' ) ;
204195 comp . onUploadError ( ) ;
205196 } ) ;
206197
207198 it ( 'should show an error notification' , ( ) => {
208199 expect ( notificationsService . error ) . toHaveBeenCalled ( ) ;
209200 } ) ;
210-
211- it ( 'should emit finish' , ( ) => {
212- expect ( comp . finish . emit ) . toHaveBeenCalled ( ) ;
213- } ) ;
214201 } ) ;
215202 } ) ;
216203
@@ -231,6 +218,11 @@ describe('ComColFormComponent', () => {
231218 it ( 'should initialize the uploadFilesOptions with a POST method' , ( ) => {
232219 expect ( comp . uploadFilesOptions . method ) . toEqual ( RestRequestMethod . POST ) ;
233220 } ) ;
221+
222+ it ( 'should not show the delete logo button' , ( ) => {
223+ const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-danger' ) ) ;
224+ expect ( button ) . toBeFalsy ( ) ;
225+ } ) ;
234226 } ) ;
235227
236228 describe ( 'and the dso contains a logo' , ( ) => {
@@ -249,96 +241,71 @@ describe('ComColFormComponent', () => {
249241 expect ( comp . uploadFilesOptions . url ) . toEqual ( logoEndpoint ) ;
250242 } ) ;
251243
252- it ( 'should initialize the uploadFilesOptions with a PUT method' , ( ) => {
253- expect ( comp . uploadFilesOptions . method ) . toEqual ( RestRequestMethod . PUT ) ;
244+ it ( 'should show the delete logo button' , ( ) => {
245+ const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-danger' ) ) ;
246+ expect ( button ) . toBeTruthy ( ) ;
254247 } ) ;
255248
256- describe ( 'submit with logo marked for deletion ' , ( ) => {
249+ describe ( 'when the delete logo button is clicked ' , ( ) => {
257250 beforeEach ( ( ) => {
258- spyOn ( dsoService , 'deleteLogo' ) . and . callThrough ( ) ;
259- comp . markLogoForDeletion = true ;
260- } ) ;
261-
262- it ( 'should call dsoService.deleteLogo on the DSO' , ( ) => {
263- comp . onSubmit ( ) ;
251+ spyOn ( dsoService , 'deleteLogo' ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( { } ) ) ;
252+ spyOn ( comp , 'handleLogoDeletion' ) . and . callThrough ( ) ;
253+ spyOn ( comp , 'createConfirmationModal' ) . and . callThrough ( ) ;
254+ spyOn ( comp , 'subscribeToConfirmationResponse' ) . and . callThrough ( ) ;
255+ const deleteButton = fixture . debugElement . query ( By . css ( '#logo-section .btn-danger' ) ) ;
256+ deleteButton . nativeElement . click ( ) ;
264257 fixture . detectChanges ( ) ;
265-
266- expect ( dsoService . deleteLogo ) . toHaveBeenCalledWith ( comp . dso ) ;
267258 } ) ;
268259
269- describe ( 'when dsoService.deleteLogo returns a successful response' , ( ) => {
270- beforeEach ( ( ) => {
271- dsoService . deleteLogo . and . returnValue ( createSuccessfulRemoteDataObject$ ( { } ) ) ;
272- comp . onSubmit ( ) ;
273- } ) ;
260+ it ( 'should create a confirmation modal with the correct labels and properties' , ( ) => {
261+ const modalServiceSpy = spyOn ( ( comp as any ) . modalService , 'open' ) . and . callThrough ( ) ;
274262
275- it ( 'should display a success notification' , ( ) => {
276- expect ( notificationsService . success ) . toHaveBeenCalled ( ) ;
277- } ) ;
278- } ) ;
263+ const modalRef = comp . createConfirmationModal ( ) ;
279264
280- describe ( 'when dsoService.deleteLogo returns an error response' , ( ) => {
281- beforeEach ( ( ) => {
282- dsoService . deleteLogo . and . returnValue ( createFailedRemoteDataObject$ ( 'Error' , 500 ) ) ;
283- comp . onSubmit ( ) ;
284- } ) ;
265+ expect ( modalServiceSpy ) . toHaveBeenCalled ( ) ;
285266
286- it ( 'should display an error notification' , ( ) => {
287- expect ( notificationsService . error ) . toHaveBeenCalled ( ) ;
288- } ) ;
289- } ) ;
290- } ) ;
267+ expect ( modalRef ) . toBeDefined ( ) ;
268+ expect ( modalRef . componentInstance ) . toBeDefined ( ) ;
291269
292- describe ( 'deleteLogo' , ( ) => {
293- beforeEach ( ( ) => {
294- comp . deleteLogo ( ) ;
295- fixture . detectChanges ( ) ;
270+ expect ( modalRef . componentInstance . headerLabel ) . toBe ( 'community-collection.edit.logo.delete.title' ) ;
271+ expect ( modalRef . componentInstance . infoLabel ) . toBe ( 'confirmation-modal.delete-community-collection-logo.info' ) ;
272+ expect ( modalRef . componentInstance . cancelLabel ) . toBe ( 'form.cancel' ) ;
273+ expect ( modalRef . componentInstance . confirmLabel ) . toBe ( 'community-collection.edit.logo.delete.title' ) ;
274+ expect ( modalRef . componentInstance . confirmIcon ) . toBe ( 'fas fa-trash' ) ;
296275 } ) ;
297276
298- it ( 'should set markLogoForDeletion to true ' , ( ) => {
299- expect ( comp . markLogoForDeletion ) . toEqual ( true ) ;
277+ it ( 'should call createConfirmationModal method ' , ( ) => {
278+ expect ( comp . createConfirmationModal ) . toHaveBeenCalled ( ) ;
300279 } ) ;
301280
302- it ( 'should mark the logo section with a danger alert' , ( ) => {
303- const logoSection = fixture . debugElement . query ( By . css ( '#logo-section.alert-danger' ) ) ;
304- expect ( logoSection ) . toBeTruthy ( ) ;
281+ it ( 'should call subscribeToConfirmationResponse method' , ( ) => {
282+ expect ( comp . subscribeToConfirmationResponse ) . toHaveBeenCalled ( ) ;
305283 } ) ;
306284
307- it ( 'should hide the delete button' , ( ) => {
308- const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-danger' ) ) ;
309- expect ( button ) . not . toBeTruthy ( ) ;
310- } ) ;
285+ describe ( 'when the modal is closed' , ( ) => {
311286
312- it ( 'should show the undo button' , ( ) => {
313- const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-warning' ) ) ;
314- expect ( button ) . toBeTruthy ( ) ;
315- } ) ;
316- } ) ;
287+ let modalRef ;
317288
318- describe ( 'undoDeleteLogo' , ( ) => {
319- beforeEach ( ( ) => {
320- comp . markLogoForDeletion = true ;
321- comp . undoDeleteLogo ( ) ;
322- fixture . detectChanges ( ) ;
323- } ) ;
289+ beforeEach ( ( ) => {
290+ modalRef = comp . createConfirmationModal ( ) ;
291+ comp . subscribeToConfirmationResponse ( modalRef ) ;
292+ } ) ;
324293
325- it ( 'should set markLogoForDeletion to false' , ( ) => {
326- expect ( comp . markLogoForDeletion ) . toEqual ( false ) ;
327- } ) ;
294+ it ( 'should call handleLogoDeletion and dsoService.deleteLogo methods when deletion is confirmed' , waitForAsync ( ( ) => {
295+ modalRef . componentInstance . confirmPressed ( ) ;
328296
329- it ( 'should disable the danger alert on the logo section' , ( ) => {
330- const logoSection = fixture . debugElement . query ( By . css ( '#logo-section.alert-danger' ) ) ;
331- expect ( logoSection ) . not . toBeTruthy ( ) ;
332- } ) ;
297+ expect ( comp . handleLogoDeletion ) . toHaveBeenCalled ( ) ;
298+ expect ( dsoService . deleteLogo ) . toHaveBeenCalled ( ) ;
333299
334- it ( 'should show the delete button' , ( ) => {
335- const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-danger' ) ) ;
336- expect ( button ) . toBeTruthy ( ) ;
337- } ) ;
300+ } ) ) ;
301+
302+ it ( 'should not call handleLogoDeletion and dsoService.deleteLogo methods when deletion is refused' , waitForAsync ( ( ) => {
303+ modalRef . componentInstance . cancelPressed ( ) ;
304+
305+ expect ( comp . handleLogoDeletion ) . not . toHaveBeenCalled ( ) ;
306+ expect ( dsoService . deleteLogo ) . not . toHaveBeenCalled ( ) ;
307+ } ) ) ;
338308
339- it ( 'should hide the undo button' , ( ) => {
340- const button = fixture . debugElement . query ( By . css ( '#logo-section .btn-warning' ) ) ;
341- expect ( button ) . not . toBeTruthy ( ) ;
342309 } ) ;
343310 } ) ;
344311 } ) ;
0 commit comments