summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/unit/test_addressComponent_postal_code.js
blob: a3150362d273f6f5cae1e45984169be8f199cb5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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 };
  });
});