@@ -10,7 +10,10 @@ import { of } from 'rxjs';
1010import { provideHttpClient } from '@angular/common/http' ;
1111import { provideHttpClientTesting } from '@angular/common/http/testing' ;
1212import { ComponentFixture , TestBed } from '@angular/core/testing' ;
13- import { ActivatedRoute } from '@angular/router' ;
13+ import { ActivatedRoute , NavigationEnd , Router } from '@angular/router' ;
14+
15+ import { CustomConfirmationService } from '@osf/shared/services' ;
16+ import { IS_XSMALL } from '@osf/shared/utils' ;
1417
1518import { DeveloperAppsState } from '../../store' ;
1619
@@ -19,6 +22,13 @@ import { DeveloperAppDetailsComponent } from './developer-app-details.component'
1922describe ( 'DeveloperAppDetailsComponent' , ( ) => {
2023 let component : DeveloperAppDetailsComponent ;
2124 let fixture : ComponentFixture < DeveloperAppDetailsComponent > ;
25+ let router : Router ;
26+ let customConfirmationService : CustomConfirmationService ;
27+
28+ const mockRouter = {
29+ url : '/test/path' ,
30+ events : of ( new NavigationEnd ( 1 , '/test/path' , '/test/path' ) ) ,
31+ } ;
2232
2333 beforeEach ( async ( ) => {
2434 await TestBed . configureTestingModule ( {
@@ -29,16 +39,57 @@ describe('DeveloperAppDetailsComponent', () => {
2939 provideHttpClientTesting ( ) ,
3040 provideStore ( [ DeveloperAppsState ] ) ,
3141 MockProvider ( TranslateService ) ,
32- MockProvider ( ActivatedRoute , { params : of ( { } ) } ) ,
42+ MockProvider ( ActivatedRoute , { params : of ( { id : 'test-client-id' } ) } ) ,
43+ MockProvider ( Router , mockRouter ) ,
44+ MockProvider ( CustomConfirmationService ) ,
45+ MockProvider ( IS_XSMALL , of ( false ) ) ,
3346 ] ,
3447 } ) . compileComponents ( ) ;
3548
3649 fixture = TestBed . createComponent ( DeveloperAppDetailsComponent ) ;
3750 component = fixture . componentInstance ;
51+
52+ customConfirmationService = TestBed . inject ( CustomConfirmationService ) ;
53+ router = TestBed . inject ( Router ) ;
54+
3855 fixture . detectChanges ( ) ;
3956 } ) ;
4057
4158 it ( 'should create' , ( ) => {
4259 expect ( component ) . toBeTruthy ( ) ;
4360 } ) ;
61+
62+ it ( 'should not dispatch delete when user cancels confirmation' , ( ) => {
63+ const navigateSpy = jest . spyOn ( router , 'navigate' ) ;
64+
65+ jest . spyOn ( customConfirmationService , 'confirmDelete' ) . mockImplementation ( ( ) => {
66+ // Simulate cancelling the confirmation
67+ } ) ;
68+
69+ component . deleteApp ( ) ;
70+
71+ expect ( customConfirmationService . confirmDelete ) . toHaveBeenCalledWith ( {
72+ headerKey : 'settings.developerApps.confirmation.delete.title' ,
73+ headerParams : { name : undefined } ,
74+ messageKey : 'settings.developerApps.confirmation.delete.message' ,
75+ onConfirm : expect . any ( Function ) ,
76+ } ) ;
77+ expect ( navigateSpy ) . not . toHaveBeenCalled ( ) ;
78+ } ) ;
79+
80+ it ( 'should not dispatch resetClientSecret when user cancels confirmation' , ( ) => {
81+ jest . spyOn ( customConfirmationService , 'confirmDelete' ) . mockImplementation ( ( ) => {
82+ // Simulate cancelling the confirmation
83+ } ) ;
84+
85+ component . resetClientSecret ( ) ;
86+
87+ expect ( customConfirmationService . confirmDelete ) . toHaveBeenCalledWith ( {
88+ headerKey : 'settings.developerApps.confirmation.resetSecret.title' ,
89+ headerParams : { name : undefined } ,
90+ messageKey : 'settings.developerApps.confirmation.resetSecret.message' ,
91+ acceptLabelKey : 'settings.developerApps.details.clientSecret.reset' ,
92+ onConfirm : expect . any ( Function ) ,
93+ } ) ;
94+ } ) ;
4495} ) ;
0 commit comments