File tree Expand file tree Collapse file tree
packages/fxa-settings/src/components/Settings/MfaGuard Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -220,4 +220,20 @@ describe('MfaGuard', () => {
220220 expect ( mockAlertBar . error ) . toHaveBeenCalledWith ( 'Unexpected error' ) ;
221221 } ) ;
222222 } ) ;
223+
224+ it ( 'invokes onDismiss when dialog is dismissed' , async ( ) => {
225+ const mockOnDismiss = jest . fn ( ) . mockResolvedValue ( undefined ) ;
226+
227+ renderWithRouter (
228+ < AppContext . Provider value = { mockAppContext ( ) } >
229+ < MfaGuard requiredScope = { mockScope } onDismissCallback = { mockOnDismiss } >
230+ < div > secured</ div >
231+ </ MfaGuard >
232+ </ AppContext . Provider >
233+ ) ;
234+
235+ await userEvent . click ( screen . getByRole ( 'button' , { name : 'Cancel' } ) ) ;
236+
237+ expect ( mockOnDismiss ) . toHaveBeenCalledTimes ( 1 ) ;
238+ } ) ;
223239} ) ;
Original file line number Diff line number Diff line change @@ -38,9 +38,11 @@ import { getLocalizedErrorMessage } from '../../../lib/error-utils';
3838export const MfaGuard = ( {
3939 children,
4040 requiredScope,
41+ onDismissCallback = async ( ) => { } ,
4142} : {
4243 children : ReactNode ;
4344 requiredScope : MfaScope ;
45+ onDismissCallback ?: ( ) => Promise < void > ;
4446} ) => {
4547 // Let errors be handled by error boundaries in async contexts
4648 const handleError = useErrorHandler ( ) ;
@@ -76,9 +78,11 @@ export const MfaGuard = ({
7678 const alertBar = useAlertBar ( ) ;
7779
7880 const onDismiss = useCallback ( ( ) => {
79- resetStates ( ) ;
80- navigate ( '/settings' ) ;
81- } , [ navigate , resetStates ] ) ;
81+ onDismissCallback ( ) . then ( ( ) => {
82+ resetStates ( ) ;
83+ navigate ( '/settings' ) ;
84+ } ) ;
85+ } , [ navigate , resetStates , onDismissCallback ] ) ;
8286
8387 // If no session token exists, kick them to sign-in
8488 if ( ! sessionToken ) {
You can’t perform that action at this time.
0 commit comments