From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test/unit/test_addressComponent_postal_code.js | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 browser/extensions/formautofill/test/unit/test_addressComponent_postal_code.js (limited to 'browser/extensions/formautofill/test/unit/test_addressComponent_postal_code.js') diff --git a/browser/extensions/formautofill/test/unit/test_addressComponent_postal_code.js b/browser/extensions/formautofill/test/unit/test_addressComponent_postal_code.js new file mode 100644 index 0000000000..a3150362d2 --- /dev/null +++ b/browser/extensions/formautofill/test/unit/test_addressComponent_postal_code.js @@ -0,0 +1,57 @@ +"use strict"; + +const VALID_TESTS = [ + { region: "US" }, + ["1234", false], // too short + ["12345", true], + ["123456", false], // too long + ["1234A", false], // contain non-digit character + ["12345-123", false], + ["12345-1234", true], + ["12345-12345", false], + ["12345-1234A", false], + ["12345 1234", true], // Do we want to allow this? + ["12345_1234", false], // Do we want to allow this? + + { region: "CA" }, + ["M5T 1R5", true], + ["M5T1R5", true], // no space between the first and second parts is allowed + ["S4S 6X3", true], + ["M5T", false], // Only the first part + ["1R5", false], // Only the second part + ["D1B 1A1", false], // invalid first character, D + ["M5T 1R5A", false], // extra character at the end + ["M5T 1R5-", false], // extra character at the end + ["M5T-1R5", false], // hyphen in the wrong place + ["MT5 1R5", false], // missing letter in the first part + ["M5T 1R", false], // missing letter in the second part + ["M5T 1R55", false], // extra digit at the end + ["M5T 1R", false], // missing digit in the second part + ["M5T 1R5Q", false], // invalid second-to-last letter, Q +]; + +const COMPARE_TESTS = [ + { region: "US" }, + ["12345", "12345", SAME], + ["M5T 1R5", "m5t 1r5", SAME], + ["12345-1234", "12345 1234", SAME], + ["12345-1234", "12345", A_CONTAINS_B], + ["12345-1234", "12345#1234", SAME], // B is invalid + ["12345-1234", "1234", A_CONTAINS_B], // B is invalid +]; + +const TEST_FIELD_NAME = "PostalCode"; + +add_setup(async () => {}); + +add_task(async function test_isValid() { + runIsValidTest(VALID_TESTS, TEST_FIELD_NAME, value => { + return { "postal-code": value }; + }); +}); + +add_task(async function test_compare() { + runCompareTest(COMPARE_TESTS, TEST_FIELD_NAME, value => { + return { "postal-code": value }; + }); +}); -- cgit v1.2.3