@@ -224,39 +224,44 @@ describe('Station Login Utils', () => {
224224 mockSetDNErrorText . mockClear ( ) ;
225225 } ) ;
226226
227- it ( 'should return false for valid dial number with default regex' , ( ) => {
228- const validNumber = '15552234567' ; // Changed 4th digit from 1 to 2 to match [2-9] pattern
229- const result = validateDialNumber ( validNumber , null , mockSetDNErrorText , loggerMock ) ;
227+ it ( 'should return false for valid US dial number with default regex' , ( ) => {
228+ const validNumber = '15552234567' ;
229+ const result = validateDialNumber ( validNumber , mockSetDNErrorText , loggerMock ) ;
230230 expect ( result ) . toBe ( false ) ;
231231 expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
232232 } ) ;
233233
234- it ( 'should return true for invalid dial number and set error text ' , ( ) => {
235- const invalidNumber = '911 ' ; // This should be invalid for the default regex (too short and doesn't match pattern)
236- const result = validateDialNumber ( invalidNumber , null , mockSetDNErrorText , loggerMock ) ;
237- expect ( result ) . toBe ( true ) ;
238- expect ( mockSetDNErrorText ) . toHaveBeenCalledWith ( StationLoginLabels . DN_FORMAT_ERROR ) ;
234+ it ( 'should return false for valid international dial number with + prefix ' , ( ) => {
235+ const validNumber = '+442071234567 ' ; // UK number
236+ const result = validateDialNumber ( validNumber , mockSetDNErrorText , loggerMock ) ;
237+ expect ( result ) . toBe ( false ) ;
238+ expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
239239 } ) ;
240240
241- it ( 'should accept any input when empty string regex is provided ' , ( ) => {
242- const anyNumber = '911 ' ; // With empty string regex, this becomes /(?:)/ which matches everything
243- const result = validateDialNumber ( anyNumber , '' , mockSetDNErrorText , loggerMock ) ;
244- expect ( result ) . toBe ( false ) ; // Should return false (no error) because empty regex matches everything
241+ it ( 'should return false for valid international dial number without + prefix ' , ( ) => {
242+ const validNumber = '442071234567 ' ; // UK number without +
243+ const result = validateDialNumber ( validNumber , mockSetDNErrorText , loggerMock ) ;
244+ expect ( result ) . toBe ( false ) ;
245245 expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
246246 } ) ;
247247
248- it ( 'should use custom regex when provided' , ( ) => {
249- const customRegex = '^\\d{10}$' ;
250- const validNumber = '1234567890' ;
251- const result = validateDialNumber ( validNumber , customRegex , mockSetDNErrorText , loggerMock ) ;
248+ it ( 'should return false for valid short international dial number' , ( ) => {
249+ const validNumber = '1234567' ; // 7 digit minimum
250+ const result = validateDialNumber ( validNumber , mockSetDNErrorText , loggerMock ) ;
252251 expect ( result ) . toBe ( false ) ;
253252 expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
254253 } ) ;
255254
256- it ( 'should return true for invalid number with custom regex' , ( ) => {
257- const customRegex = '^\\d{10}$' ;
258- const invalidNumber = '123' ;
259- const result = validateDialNumber ( invalidNumber , customRegex , mockSetDNErrorText , loggerMock ) ;
255+ it ( 'should return true for invalid dial number (too short) and set error text' , ( ) => {
256+ const invalidNumber = '911' ; // Too short (less than 7 digits)
257+ const result = validateDialNumber ( invalidNumber , mockSetDNErrorText , loggerMock ) ;
258+ expect ( result ) . toBe ( true ) ;
259+ expect ( mockSetDNErrorText ) . toHaveBeenCalledWith ( StationLoginLabels . DN_FORMAT_ERROR ) ;
260+ } ) ;
261+
262+ it ( 'should return true for invalid dial number (too long) and set error text' , ( ) => {
263+ const invalidNumber = '1234567890123456' ; // Too long (more than 15 digits)
264+ const result = validateDialNumber ( invalidNumber , mockSetDNErrorText , loggerMock ) ;
260265 expect ( result ) . toBe ( true ) ;
261266 expect ( mockSetDNErrorText ) . toHaveBeenCalledWith ( StationLoginLabels . DN_FORMAT_ERROR ) ;
262267 } ) ;
@@ -830,7 +835,7 @@ describe('Station Login Utils', () => {
830835 } ) as unknown as typeof RegExp ;
831836
832837 const mockSetError = jest . fn ( ) ;
833- const result = validateDialNumber ( '15551234567' , null , mockSetError , loggerMock ) ;
838+ const result = validateDialNumber ( '15551234567' , mockSetError , loggerMock ) ;
834839
835840 expect ( loggerMock . error ) . toHaveBeenCalledWith ( 'CC-Widgets: StationLogin: Error in validateDialNumber' , {
836841 module : 'cc-components#station-login.utils.tsx' ,
0 commit comments