Commit 982cc8d3 authored by Dimi's avatar Dimi
Browse files

Bug 1831127 - Add a test case for parsing index is out of range error in...

Bug 1831127 - Add a test case for parsing index is out of range error in _parseAddressFields r=issammani

Differential Revision: https://phabricator.services.mozilla.com/D177243
parent 11ff207d
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -293,11 +293,14 @@ async function runHeuristicsTest(patterns, fixturePathPrefix) {

  patterns.forEach(testPattern => {
    add_task(async function() {
      info("Starting test fixture: " + testPattern.fixturePath);
      const file = do_get_file(fixturePathPrefix + testPattern.fixturePath);
      const doc = MockDocument.createTestDocumentFromFile(
        "http://localhost:8080/test/",
        file
      info(`Starting test fixture: ${testPattern.fixturePath ?? ""}`);

      const url = "http://localhost:8080/test/";
      const doc = testPattern.fixtureData
        ? MockDocument.createTestDocument(url, testPattern.fixtureData)
        : MockDocument.createTestDocumentFromFile(
            url,
            do_get_file(fixturePathPrefix + testPattern.fixturePath)
          );

      let forms = [...doc.querySelectorAll("input, select")].reduce(
+72 −0
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

/* global runHeuristicsTest */

"use strict";

// This bug happens only when the last element is address-lineX and
// the field is identified by regular expressions in `HeuristicsRegExp` but is not
// identified by regular expressions defined in `_parseAddressFields`
const markup1 = `
  <html>
  <body>
    <form>
      <p><label>country: <input type="text" id="country" name="country" /></label></p>
      <p><label>tel: <input type="text" id="tel" name="tel" /></label></p>
      <p><label><input type="text" id="housenumber" /></label></p>
    </form>
  </body>
  </html>
`;

const markup2 = `
  <html>
  <body>
    <form>
      <p><label>country: <input type="text" id="country" name="country" /></label></p>
      <p><label>tel: <input type="text" id="tel" name="tel" /></label></p>
      <p><label><input type="text" id="housenumber" /></label></p>
      <p><label><input type="text" id="addrcomplement" /></label></p>
    </form>
  </body>
  </html>
`;

runHeuristicsTest(
  [
    {
      fixtureData: markup1,
      expectedResult: [
        {
          description: "Address Line1 in the last element and is not updated in _parsedAddressFields",
          default: {
            reason: "regex-heuristic",
          },
          fields: [
            { fieldName: "country" },
            { fieldName: "tel" },
            { fieldName: "address-line1" },
          ],
        },
      ],
    },
    {
      fixtureData: markup2,
      expectedResult: [
        {
          description: "Address Line2 in the last element and is not updated in _parsedAddressFields",
          default: {
            reason: "regex-heuristic",
          },
          fields: [
            { fieldName: "country" },
            { fieldName: "tel" },
            { fieldName: "address-line1" },
            { fieldName: "address-line2" },
          ],
        },
      ],
    },
  ]
);
+3 −0
Original line number Diff line number Diff line
@@ -14,7 +14,10 @@ skip-if = (os == "linux") && ccov # bug 1614100
[test_de_fields.js]
skip-if = (os == "linux") && ccov # bug 1614100
[test_fr_fields.js]
skip-if = (os == "linux") && ccov # bug 1614100
[test_known_strings.js]
skip-if = (os == "linux") && ccov # bug 1614100
[test_multiple_section.js]
skip-if = (os == "linux") && ccov # bug 1614100
[test_parseAddressFields.js]
skip-if = (os == "linux") && ccov # bug 1614100