@@ -7,6 +7,7 @@ import { screen } from '@testing-library/react';
77import { renderWithLocalizationProvider } from 'fxa-react/lib/test-utils/localizationProvider' ; // import { getFtlBundle, testAllL10n } from 'fxa-react/lib/test-utils';
88// import { FluentBundle } from '@fluent/bundle';
99import { Subject } from './mocks' ;
10+ import { InputModeEnum } from '.' ;
1011import userEvent from '@testing-library/user-event' ;
1112
1213jest . mock ( '../../lib/metrics' , ( ) => ( {
@@ -200,5 +201,41 @@ describe('FormVerifyCode component', () => {
200201 } ) ;
201202 } ) ;
202203
204+ describe ( 'Numeric input filtering' , ( ) => {
205+ it ( 'strips non-numeric characters when inputMode is numeric (default)' , async ( ) => {
206+ const user = userEvent . setup ( ) ;
207+ renderWithLocalizationProvider ( < Subject /> ) ;
208+ const input = screen . getByRole ( 'textbox' , {
209+ name : 'Enter your 4-digit code' ,
210+ } ) ;
211+
212+ await user . type ( input , 'ab12cd34' ) ;
213+ expect ( input ) . toHaveValue ( '1234' ) ;
214+ } ) ;
215+
216+ it ( 'allows alphanumeric characters when inputMode is text' , async ( ) => {
217+ const user = userEvent . setup ( ) ;
218+ const alphanumericFormAttributes = {
219+ inputFtlId : 'demo-input-label-id' ,
220+ inputLabelText : 'Enter backup code' ,
221+ inputMode : InputModeEnum . text ,
222+ pattern : '[a-zA-Z0-9]' ,
223+ maxLength : 10 ,
224+ submitButtonFtlId : 'demo-submit-button-id' ,
225+ submitButtonText : 'Check that code' ,
226+ } ;
227+
228+ renderWithLocalizationProvider (
229+ < Subject formAttributes = { alphanumericFormAttributes } />
230+ ) ;
231+ const input = screen . getByRole ( 'textbox' , {
232+ name : 'Enter backup code' ,
233+ } ) ;
234+
235+ await user . type ( input , 'abc123' ) ;
236+ expect ( input ) . toHaveValue ( 'abc123' ) ;
237+ } ) ;
238+ } ) ;
239+
203240 // TODO Add tests for (engage, success, etc.) metrics events once submit button enabled
204241} ) ;
0 commit comments