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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
<!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,
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>
|