diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/extensions/formautofill/test/unit/test_parseAddressFormat.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/extensions/formautofill/test/unit/test_parseAddressFormat.js')
-rw-r--r-- | browser/extensions/formautofill/test/unit/test_parseAddressFormat.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/browser/extensions/formautofill/test/unit/test_parseAddressFormat.js b/browser/extensions/formautofill/test/unit/test_parseAddressFormat.js new file mode 100644 index 0000000000..df6c3e3069 --- /dev/null +++ b/browser/extensions/formautofill/test/unit/test_parseAddressFormat.js @@ -0,0 +1,66 @@ +"use strict"; + +var FormAutofillUtils; +add_setup(async () => { + ({ FormAutofillUtils } = ChromeUtils.importESModule( + "resource://gre/modules/shared/FormAutofillUtils.sys.mjs" + )); +}); + +add_task(async function test_parseAddressFormat() { + const TEST_CASES = [ + { + fmt: "%N%n%O%n%A%n%C, %S %Z", // US + parsed: [ + { fieldId: "name", newLine: true }, + { fieldId: "organization", newLine: true }, + { fieldId: "street-address", newLine: true }, + { fieldId: "address-level2" }, + { fieldId: "address-level1" }, + { fieldId: "postal-code" }, + ], + }, + { + fmt: "%N%n%O%n%A%n%C %S %Z", // CA + parsed: [ + { fieldId: "name", newLine: true }, + { fieldId: "organization", newLine: true }, + { fieldId: "street-address", newLine: true }, + { fieldId: "address-level2" }, + { fieldId: "address-level1" }, + { fieldId: "postal-code" }, + ], + }, + { + fmt: "%N%n%O%n%A%n%Z %C", // DE + parsed: [ + { fieldId: "name", newLine: true }, + { fieldId: "organization", newLine: true }, + { fieldId: "street-address", newLine: true }, + { fieldId: "postal-code" }, + { fieldId: "address-level2" }, + ], + }, + { + fmt: "%N%n%O%n%A%n%D%n%C%n%S %Z", // IE + parsed: [ + { fieldId: "name", newLine: true }, + { fieldId: "organization", newLine: true }, + { fieldId: "street-address", newLine: true }, + { fieldId: "address-level3", newLine: true }, + { fieldId: "address-level2", newLine: true }, + { fieldId: "address-level1" }, + { fieldId: "postal-code" }, + ], + }, + ]; + + Assert.throws( + () => FormAutofillUtils.parseAddressFormat(), + /fmt string is missing./, + "Should throw if fmt is empty" + ); + for (let tc of TEST_CASES) { + Assert.deepEqual(FormAutofillUtils.parseAddressFormat(tc.fmt), tc.parsed); + } +}); |