@@ -17,7 +17,7 @@ import {
1717 Subject ,
1818 createMockOAuthNativeIntegration ,
1919 createMockOAuthWebIntegration ,
20- createMockWebIntegration ,
20+ createMockWebIntegration , MOCK_AUTH_ERROR_INVALID_CODE , MOCK_AUTH_ERROR_RATE_LIMIT ,
2121} from './mocks' ;
2222import {
2323 MOCK_OAUTH_FLOW_HANDLER_RESPONSE ,
@@ -64,6 +64,7 @@ jest.mock('../../../lib/glean', () => ({
6464 signupConfirmation : {
6565 view : jest . fn ( ) ,
6666 submit : jest . fn ( ) ,
67+ error : jest . fn ( ) ,
6768 } ,
6869 isDone : jest . fn ( ) ,
6970 } ,
@@ -317,6 +318,7 @@ describe('ConfirmSignupCode page', () => {
317318 } ) ;
318319 } ) ;
319320 } ) ;
321+
320322 it ( 'sends expected web channel messages when service=relay' , async ( ) => {
321323 const integration = createMockOAuthNativeIntegration ( false ) ;
322324 renderWithSession ( {
@@ -421,7 +423,52 @@ describe('ConfirmSignupCode page with error states', () => {
421423 } ) ;
422424 } ) ;
423425
424- // TODO add test for expected behaviour on verifySession fail in FXA-8303
426+ it ( 'renders an error tooltip when the form is submitted with invalid code' , async ( ) => {
427+ session = {
428+ verifySession : jest . fn ( ) . mockRejectedValue ( MOCK_AUTH_ERROR_INVALID_CODE ) ,
429+ } as unknown as Session ;
430+
431+ renderWithSession ( { session, integration : createMockWebIntegration ( { } ) } ) ;
432+
433+ const codeInput = screen . getByLabelText ( 'Enter 6-digit code' ) ;
434+ fireEvent . change ( codeInput , {
435+ target : { value : '123123' } ,
436+ } ) ;
437+
438+ const submitButton = screen . getByRole ( 'button' , { name : 'Confirm' } ) ;
439+ fireEvent . click ( submitButton ) ;
440+ await waitFor ( ( ) => {
441+ expect ( screen . getByTestId ( 'tooltip' ) ) . toHaveTextContent (
442+ 'Invalid or expired confirmation code'
443+ ) ;
444+ expect ( GleanMetrics . signupConfirmation . submit ) . toHaveBeenCalled ( ) ;
445+ expect ( GleanMetrics . signupConfirmation . error ) . toHaveBeenCalledWith ( {
446+ event : { reason : MOCK_AUTH_ERROR_INVALID_CODE . errno . toString ( ) }
447+ } ) ;
448+ } ) ;
449+ } ) ;
450+
451+ it ( 'renders an error when the form is submitted with rate limit' , async ( ) => {
452+ session = {
453+ verifySession : jest . fn ( ) . mockRejectedValue ( MOCK_AUTH_ERROR_RATE_LIMIT ) ,
454+ } as unknown as Session ;
455+
456+ renderWithSession ( { session, integration : createMockWebIntegration ( { } ) } ) ;
457+
458+ const codeInput = screen . getByLabelText ( 'Enter 6-digit code' ) ;
459+ fireEvent . change ( codeInput , {
460+ target : { value : '123123' } ,
461+ } ) ;
462+
463+ const submitButton = screen . getByRole ( 'button' , { name : 'Confirm' } ) ;
464+ fireEvent . click ( submitButton ) ;
465+ await waitFor ( ( ) => {
466+ expect ( GleanMetrics . signupConfirmation . submit ) . toHaveBeenCalled ( ) ;
467+ expect ( GleanMetrics . signupConfirmation . error ) . toHaveBeenCalledWith ( {
468+ event : { reason : MOCK_AUTH_ERROR_RATE_LIMIT . errno . toString ( ) }
469+ } ) ;
470+ } ) ;
471+ } ) ;
425472} ) ;
426473
427474describe ( 'Resending a new code from ConfirmSignupCode page' , ( ) => {
0 commit comments