Mypal68/browser/components/payments/test/mochitest/test_address_option.html
2022-04-16 07:41:55 +03:00

178 lines
7.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
Test the address-option component
-->
<head>
<meta charset="utf-8">
<title>Test the address-option component</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="payments_common.js"></script>
<script src="../../res/unprivileged-fallbacks.js"></script>
<script src="autofillEditForms.js"></script>
<link rel="stylesheet" type="text/css" href="../../res/components/rich-select.css"/>
<link rel="stylesheet" type="text/css" href="../../res/components/address-option.css"/>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display">
<option id="option1"
data-field-separator=", "
address-level1="MI"
address-level2="Some City"
country="US"
email="foo@bar.com"
name="John Smith"
postal-code="90210"
street-address="123 Sesame Street,&#xA;Apt 40"
tel="+1 519 555-5555"
value="option1"
guid="option1"></option>
<option id="option2"
data-field-separator=", "
value="option2"
guid="option2"></option>
<rich-select id="richSelect1"
option-type="address-option"></rich-select>
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script type="module">
/** Test the address-option component **/
import "../../res/components/address-option.js";
import "../../res/components/rich-select.js";
let option1 = document.getElementById("option1");
let option2 = document.getElementById("option2");
let richSelect1 = document.getElementById("richSelect1");
add_task(async function test_populated_option_rendering() {
richSelect1.popupBox.appendChild(option1);
richSelect1.value = option1.value;
await asyncElementRendered();
let richOption = richSelect1.selectedRichOption;
is(richOption.name, "John Smith", "Check name getter");
is(richOption.streetAddress, "123 Sesame Street,\nApt 40", "Check streetAddress getter");
is(richOption.addressLevel2, "Some City", "Check addressLevel2 getter");
ok(!richOption.innerText.includes("undefined"), "Check for presence of 'undefined'");
ok(!richOption.innerText.includes("null"), "Check for presence of 'null'");
ok(!richOption._line1.innerText.trim().endsWith(","), "Line 1 should not end with a comma");
ok(!richOption._line2.innerText.trim().endsWith(","), "Line 2 should not end with a comma");
is(richOption._line1.innerText, "John Smith, 123 Sesame Street, Apt 40", "Line 1 text");
is(richOption._line2.innerText, "Some City, MI, 90210, US", "Line 2 text");
// Note that innerText takes visibility into account so that's why it's used over textContent here
is(richOption._name.innerText, "John Smith", "name text");
is(richOption["_street-address"].innerText, "123 Sesame Street, Apt 40", "street-address text");
is(richOption["_address-level2"].innerText, "Some City", "address-level2 text");
is(richOption._email.parentElement, null,
"Check email field isn't in the document for a mailing-address option");
});
// Same option as the last test but with @break-after-nth-field=1
add_task(async function test_breakAfterNthField() {
richSelect1.popupBox.appendChild(option1);
richSelect1.value = option1.value;
await asyncElementRendered();
let richOption = richSelect1.selectedRichOption;
richOption.breakAfterNthField = 1;
await asyncElementRendered();
ok(!richOption.innerText.includes("undefined"), "Check for presence of 'undefined'");
ok(!richOption.innerText.includes("null"), "Check for presence of 'null'");
ok(!richOption._line1.innerText.trim().endsWith(","), "Line 1 should not end with a comma");
ok(!richOption._line2.innerText.trim().endsWith(","), "Line 2 should not end with a comma");
is(richOption._line1.innerText, "John Smith", "Line 1 text with breakAfterNthField = 1");
is(richOption._line2.innerText, "123 Sesame Street, Apt 40, Some City, MI, 90210, US",
"Line 2 text with breakAfterNthField = 1");
});
add_task(async function test_addressField_mailingAddress() {
richSelect1.popupBox.appendChild(option1);
richSelect1.value = option1.value;
await asyncElementRendered();
let richOption = richSelect1.selectedRichOption;
richOption.addressFields = "mailing-address";
await asyncElementRendered();
is(richOption.getAttribute("address-fields"), "mailing-address", "Check @address-fields");
ok(!richOption.innerText.includes("undefined"), "Check for presence of 'undefined'");
ok(!richOption.innerText.includes("null"), "Check for presence of 'null'");
ok(!richOption._line1.innerText.trim().endsWith(","), "Line 1 should not end with a comma");
ok(!richOption._line2.innerText.trim().endsWith(","), "Line 2 should not end with a comma");
is(richOption._line1.innerText, "John Smith, 123 Sesame Street, Apt 40", "Line 1 text");
is(richOption._line2.innerText, "Some City, MI, 90210, US", "Line 2 text");
ok(!isHidden(richOption._line2), "Line 2 should be visible when it's used");
is(richOption._email.parentElement, null,
"Check email field isn't in the document for a mailing-address option");
});
add_task(async function test_addressField_nameEmail() {
richSelect1.popupBox.appendChild(option1);
richSelect1.value = option1.value;
await asyncElementRendered();
let richOption = richSelect1.selectedRichOption;
richOption.addressFields = "name email";
await asyncElementRendered();
is(richOption.getAttribute("address-fields"), "name email", "Check @address-fields");
ok(!richOption.innerText.includes("undefined"), "Check for presence of 'undefined'");
ok(!richOption.innerText.includes("null"), "Check for presence of 'null'");
ok(!richOption._line1.innerText.trim().endsWith(","), "Line 1 should not end with a comma");
ok(!richOption._line2.innerText.trim().endsWith(","), "Line 2 should not end with a comma");
is(richOption._line1.innerText, "John Smith, foo@bar.com", "Line 1 text");
is(richOption._line2.innerText, "", "Line 2 text");
ok(isHidden(richOption._line2), "Line 2 should be hidden when it's not used");
isnot(richOption._email.parentElement, null,
"Check email field is in the document for a 'name email' option");
});
add_task(async function test_missing_fields_option_rendering() {
richSelect1.popupBox.appendChild(option2);
richSelect1.value = option2.value;
await asyncElementRendered();
let richOption = richSelect1.selectedRichOption;
is(richOption.name, null, "Check name getter");
is(richOption.streetAddress, null, "Check streetAddress getter");
is(richOption.addressLevel2, null, "Check addressLevel2 getter");
ok(!richOption.innerText.includes("undefined"), "Check for presence of 'undefined'");
ok(!richOption.innerText.includes("null"), "Check for presence of 'null'");
is(richOption._name.innerText, "", "name text");
is(window.getComputedStyle(richOption._name, "::before").content, "attr(data-missing-string)",
"Check missing field pseudo content");
is(richOption._name.getAttribute("data-missing-string"), "Name Missing",
"Check @data-missing-string");
is(richOption._email.parentElement, null,
"Check email field isn't in the document for a mailing-address option");
});
</script>
</body>
</html>