@@ -15,6 +15,8 @@ import {
1515 handleTeamSelectChanged ,
1616 handleOnCCSignOut ,
1717 handleCCSignoutKeyDown ,
18+ DEFAULT_US_DIAL_NUMBER_REGEX ,
19+ INTERNATIONAL_DIAL_NUMBER_REGEX ,
1820} from '../../../src/components/StationLogin/station-login.utils' ;
1921import { StationLoginLabels } from '../../../src/components/StationLogin/constants' ;
2022
@@ -224,46 +226,90 @@ describe('Station Login Utils', () => {
224226 mockSetDNErrorText . mockClear ( ) ;
225227 } ) ;
226228
227- it ( 'should return false for valid US dial number with default regex' , ( ) => {
228- const validNumber = '15552234567' ;
229- const result = validateDialNumber ( validNumber , mockSetDNErrorText , loggerMock ) ;
230- expect ( result ) . toBe ( false ) ;
231- expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
232- } ) ;
229+ describe ( 'with international regex' , ( ) => {
230+ it ( 'should return false for valid international dial number with + prefix' , ( ) => {
231+ const validNumber = '+442071234567' ; // UK number
232+ const result = validateDialNumber ( validNumber , INTERNATIONAL_DIAL_NUMBER_REGEX , mockSetDNErrorText , loggerMock ) ;
233+ expect ( result ) . toBe ( false ) ;
234+ expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
235+ } ) ;
233236
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 ( ) ;
239- } ) ;
237+ it ( 'should return false for valid international dial number without + prefix' , ( ) => {
238+ const validNumber = '442071234567' ; // UK number without +
239+ const result = validateDialNumber ( validNumber , INTERNATIONAL_DIAL_NUMBER_REGEX , mockSetDNErrorText , loggerMock ) ;
240+ expect ( result ) . toBe ( false ) ;
241+ expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
242+ } ) ;
240243
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 ) ;
245- expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
246- } ) ;
244+ it ( 'should return false for valid short international dial number (7 digits)' , ( ) => {
245+ const validNumber = '1234567' ; // 7 digit minimum
246+ const result = validateDialNumber ( validNumber , INTERNATIONAL_DIAL_NUMBER_REGEX , mockSetDNErrorText , loggerMock ) ;
247+ expect ( result ) . toBe ( false ) ;
248+ expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
249+ } ) ;
250+
251+ it ( 'should return true for invalid dial number (too short) and set error text' , ( ) => {
252+ const invalidNumber = '911' ; // Too short (less than 7 digits)
253+ const result = validateDialNumber (
254+ invalidNumber ,
255+ INTERNATIONAL_DIAL_NUMBER_REGEX ,
256+ mockSetDNErrorText ,
257+ loggerMock
258+ ) ;
259+ expect ( result ) . toBe ( true ) ;
260+ expect ( mockSetDNErrorText ) . toHaveBeenCalledWith ( StationLoginLabels . DN_FORMAT_ERROR ) ;
261+ } ) ;
247262
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 ) ;
251- expect ( result ) . toBe ( false ) ;
252- expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
263+ it ( 'should return true for invalid dial number (too long) and set error text' , ( ) => {
264+ const invalidNumber = '1234567890123456' ; // Too long (more than 15 digits)
265+ const result = validateDialNumber (
266+ invalidNumber ,
267+ INTERNATIONAL_DIAL_NUMBER_REGEX ,
268+ mockSetDNErrorText ,
269+ loggerMock
270+ ) ;
271+ expect ( result ) . toBe ( true ) ;
272+ expect ( mockSetDNErrorText ) . toHaveBeenCalledWith ( StationLoginLabels . DN_FORMAT_ERROR ) ;
273+ } ) ;
253274 } ) ;
254275
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 ) ;
276+ describe ( 'with US regex (null fallback)' , ( ) => {
277+ it ( 'should return false for valid US dial number with null regex (uses default US)' , ( ) => {
278+ const validNumber = '15552234567' ;
279+ const result = validateDialNumber ( validNumber , null , mockSetDNErrorText , loggerMock ) ;
280+ expect ( result ) . toBe ( false ) ;
281+ expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
282+ } ) ;
283+
284+ it ( 'should return true for international number when using US regex fallback' , ( ) => {
285+ const internationalNumber = '+442071234567' ; // UK number - invalid for US regex
286+ const result = validateDialNumber ( internationalNumber , null , mockSetDNErrorText , loggerMock ) ;
287+ expect ( result ) . toBe ( true ) ;
288+ expect ( mockSetDNErrorText ) . toHaveBeenCalledWith ( StationLoginLabels . DN_FORMAT_ERROR ) ;
289+ } ) ;
290+
291+ it ( 'should return true for short number when using US regex fallback' , ( ) => {
292+ const shortNumber = '1234567' ; // Too short for US format
293+ const result = validateDialNumber ( shortNumber , null , mockSetDNErrorText , loggerMock ) ;
294+ expect ( result ) . toBe ( true ) ;
295+ expect ( mockSetDNErrorText ) . toHaveBeenCalledWith ( StationLoginLabels . DN_FORMAT_ERROR ) ;
296+ } ) ;
260297 } ) ;
261298
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 ) ;
265- expect ( result ) . toBe ( true ) ;
266- expect ( mockSetDNErrorText ) . toHaveBeenCalledWith ( StationLoginLabels . DN_FORMAT_ERROR ) ;
299+ describe ( 'with custom regex from agentConfig' , ( ) => {
300+ it ( 'should return false for valid number matching custom regex' , ( ) => {
301+ const validNumber = '15552234567' ;
302+ const result = validateDialNumber ( validNumber , DEFAULT_US_DIAL_NUMBER_REGEX , mockSetDNErrorText , loggerMock ) ;
303+ expect ( result ) . toBe ( false ) ;
304+ expect ( mockSetDNErrorText ) . not . toHaveBeenCalled ( ) ;
305+ } ) ;
306+
307+ it ( 'should return true for invalid number not matching custom regex' , ( ) => {
308+ const invalidNumber = '911' ;
309+ const result = validateDialNumber ( invalidNumber , DEFAULT_US_DIAL_NUMBER_REGEX , mockSetDNErrorText , loggerMock ) ;
310+ expect ( result ) . toBe ( true ) ;
311+ expect ( mockSetDNErrorText ) . toHaveBeenCalledWith ( StationLoginLabels . DN_FORMAT_ERROR ) ;
312+ } ) ;
267313 } ) ;
268314 } ) ;
269315
@@ -835,7 +881,7 @@ describe('Station Login Utils', () => {
835881 } ) as unknown as typeof RegExp ;
836882
837883 const mockSetError = jest . fn ( ) ;
838- const result = validateDialNumber ( '15551234567' , mockSetError , loggerMock ) ;
884+ const result = validateDialNumber ( '15551234567' , null , mockSetError , loggerMock ) ;
839885
840886 expect ( loggerMock . error ) . toHaveBeenCalledWith ( 'CC-Widgets: StationLogin: Error in validateDialNumber' , {
841887 module : 'cc-components#station-login.utils.tsx' ,
0 commit comments