test_addressComponent_tel.js (3346B)
1 /* import-globals-from head_addressComponent.js */ 2 3 "use strict"; 4 5 // prettier-ignore 6 const VALID_TESTS = [ 7 // US Valid format (XXX-XXX-XXXX) and first digit is between 2-9 8 ["200-234-5678", true], // First digit should between 2-9 9 ["100-234-5678", true], // First digit is not between 2-9, but currently not being checked 10 // when no country code is specified 11 ["555-abc-1234", true], // Non-digit characters are normalized according to ITU E.161 standard 12 ["55-555-5555", false], // The national number is too short (9 digits) 13 14 ["2-800-555-1234", false], // "2" is not US country code so we treat 15 // 2-800-555-1234 as the national number, which is too long (11 digits) 16 17 // Phone numbers with country code 18 ["1-800-555-1234", true], // Country code without plus sign 19 ["+1 200-234-5678", true], // Country code with plus sign and with a valid national number 20 ["+1 100-234-5678", false], // National number should be between 2-9 21 ["+1 55-555-5555", false], // National number is too short (9 digits) 22 ["+1 1-800-555-1234", true], // "+1" and "1" are both treated as coutnry code so national number 23 // is a valid number (800-555-1234) 24 ["+1 2-800-555-1234", false], // The national number is too long (11 digits) 25 ["+1 555-abc-1234", true], // Non-digit characters are normalized according to ITU E.161 standard 26 ]; 27 28 const COMPARE_TESTS = [ 29 ["+1 520-248-6621", "+15202486621", SAME], 30 ["+1 520-248-6621", "1-520-248-6621", SAME], 31 ["+1 520-248-6621", "1(520)248-6621", SAME], 32 ["520-248-6621", "520-248-6621", SAME], // Both phone numbers don't have coutry code 33 ["520-248-6621", "+1 520-248-6621", SAME], // Compare phone number with and without country code 34 35 ["+1 520-248-6621", "248-6621", A_CONTAINS_B], 36 ["520-248-6621", "248-6621", A_CONTAINS_B], 37 ["0520-248-6621", "520-248-6621", A_CONTAINS_B], 38 ["48-6621", "6621", A_CONTAINS_B], // Both phone number are invalid 39 40 ["+1 520-248-6621", "+91 520-248-6622", DIFFERENT], // different national prefix and number 41 ["+1 520-248-6621", "+91 520-248-6621", DIFFERENT], // Same number, different national prefix 42 ["+1 520-248-6621", "+1 520-248-6622", DIFFERENT], // Same national prefix, different number 43 ["520-248-6621", "+91 520-248-6622", DIFFERENT], // Same test as above but with default region 44 ["520-248-6621", "+91 520-248-6621", DIFFERENT], // Same test as above but with default region 45 ["520-248-6621", "+1 520-248-6622", DIFFERENT], // Same test as above but with default region 46 ["520-248-6621", "520-248-6622", DIFFERENT], 47 48 // Normalize 49 ["+1 520-248-6621", "+1 ja0-bgt-mnc1", SAME], 50 ["+1 1-800-555-1234", "+1 800-555-1234", SAME], 51 52 // TODO: Support extension 53 //["+64 3 331-6005", "3 331 6005#1234", A_CONTAINS_B], 54 ]; 55 56 const TEST_FIELD_NAME = "tel"; 57 58 add_setup(async () => { 59 Services.prefs.setBoolPref("browser.search.region", "US"); 60 61 registerCleanupFunction(function head_cleanup() { 62 Services.prefs.clearUserPref("browser.search.region"); 63 }); 64 }); 65 66 add_task(async function test_isValid() { 67 runIsValidTest(VALID_TESTS, TEST_FIELD_NAME, value => { 68 return { tel: value }; 69 }); 70 }); 71 72 add_task(async function test_compare() { 73 runCompareTest(COMPARE_TESTS, TEST_FIELD_NAME, value => { 74 return { tel: value }; 75 }); 76 });