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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
<!DOCTYPE HTML>
<html>
<!--
Test the payment-method-picker component
-->
<head>
<meta charset="utf-8">
<title>Test the payment-method-picker 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>
<link rel="stylesheet" type="text/css" href="../../res/containers/rich-picker.css"/>
<link rel="stylesheet" type="text/css" href="../../res/components/rich-select.css"/>
<link rel="stylesheet" type="text/css" href="../../res/components/basic-card-option.css"/>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display">
<payment-method-picker id="picker1"
data-invalid-label="picker1: Missing or invalid"
selected-state-key="selectedPaymentCard"></payment-method-picker>
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script type="module">
/** Test the payment-method-picker component **/
import "../../res/components/basic-card-option.js";
import "../../res/containers/payment-method-picker.js";
let picker1 = document.getElementById("picker1");
add_task(async function test_empty() {
ok(picker1, "Check picker1 exists");
let {savedBasicCards} = picker1.requestStore.getState();
is(Object.keys(savedBasicCards).length, 0, "Check empty initial state");
is(picker1.dropdown.popupBox.children.length, 0, "Check dropdown is empty");
});
add_task(async function test_initialSet() {
await picker1.requestStore.setState({
savedBasicCards: {
"48bnds6854t": {
"cc-exp": "2017-02",
"cc-exp-month": 2,
"cc-exp-year": 2017,
"cc-name": "John Doe",
"cc-number": "************9999",
"cc-type": "mastercard",
"guid": "48bnds6854t",
timeLastUsed: 300,
},
"68gjdh354j": {
"cc-exp": "2017-08",
"cc-exp-month": 8,
"cc-exp-year": 2017,
"cc-name": "J Smith",
"cc-number": "***********1234",
"cc-type": "visa",
"guid": "68gjdh354j",
timeLastUsed: 100,
},
"123456789abc": {
"cc-name": "Jane Fields",
"cc-given-name": "Jane",
"cc-additional-name": "",
"cc-family-name": "Fields",
"cc-number": "************9876",
"guid": "123456789abc",
timeLastUsed: 200,
},
},
});
await asyncElementRendered();
let options = picker1.dropdown.popupBox.children;
is(options.length, 3, "Check dropdown has all three cards");
ok(options[0].textContent.includes("John Doe"), "Check first card based on timeLastUsed");
ok(options[1].textContent.includes("Jane Fields"), "Check second card based on timeLastUsed");
ok(options[2].textContent.includes("J Smith"), "Check third card based on timeLastUsed");
});
add_task(async function test_update() {
await picker1.requestStore.setState({
savedBasicCards: {
"48bnds6854t": {
// Same GUID, different values to trigger an update
"cc-exp": "2017-09",
"cc-exp-month": 9,
"cc-exp-year": 2017,
// cc-name was cleared which means it's not returned
"cc-number": "************9876",
"cc-type": "amex",
"guid": "48bnds6854t",
},
"68gjdh354j": {
"cc-exp": "2017-08",
"cc-exp-month": 8,
"cc-exp-year": 2017,
"cc-name": "J Smith",
"cc-number": "***********1234",
"cc-type": "visa",
"guid": "68gjdh354j",
},
"123456789abc": {
"cc-name": "Jane Fields",
"cc-given-name": "Jane",
"cc-additional-name": "",
"cc-family-name": "Fields",
"cc-number": "************9876",
"guid": "123456789abc",
},
},
});
await asyncElementRendered();
let options = picker1.dropdown.popupBox.children;
is(options.length, 3, "Check dropdown still has three cards");
ok(!options[0].textContent.includes("John Doe"), "Check cleared first cc-name");
ok(options[0].textContent.includes("9876"), "Check updated first cc-number");
ok(options[0].textContent.includes("09"), "Check updated first exp-month");
ok(options[1].textContent.includes("J Smith"), "Check second card is the same");
ok(options[2].textContent.includes("Jane Fields"), "Check third card is the same");
});
add_task(async function test_change_selected_card() {
let options = picker1.dropdown.popupBox.children;
is(picker1.dropdown.selectedOption, null, "Should default to no selected option");
let {
selectedPaymentCard,
selectedPaymentCardSecurityCode,
} = picker1.requestStore.getState();
is(selectedPaymentCard, null, "store should have no option selected");
is(selectedPaymentCardSecurityCode, null, "store should have no security code");
ok(!picker1.classList.contains("invalid-selected-option"), "No validation on an empty selection");
ok(isHidden(picker1.invalidLabel), "The invalid label should be hidden");
await SimpleTest.promiseFocus();
picker1.dropdown.popupBox.focus();
synthesizeKey("************9876", {});
await asyncElementRendered();
ok(true, "Focused the security code field");
ok(!picker1.open, "Picker should be closed");
let selectedOption = picker1.dropdown.selectedOption;
is(selectedOption, options[2], "Selected option should now be the third option");
selectedPaymentCard = picker1.requestStore.getState().selectedPaymentCard;
is(selectedPaymentCard, selectedOption.getAttribute("guid"),
"store should have third option selected");
selectedPaymentCardSecurityCode = picker1.requestStore.getState().selectedPaymentCardSecurityCode;
is(selectedPaymentCardSecurityCode, null, "store should have empty security code");
ok(picker1.classList.contains("invalid-selected-option"), "Missing fields for the third option");
ok(!isHidden(picker1.invalidLabel), "The invalid label should be visible");
is(picker1.invalidLabel.innerText, picker1.dataset.invalidLabel, "Check displayed error text");
await SimpleTest.promiseFocus();
picker1.dropdown.popupBox.focus();
synthesizeKey("visa", {});
await asyncElementRendered();
ok(true, "Focused the security code field");
ok(!picker1.open, "Picker should be closed");
selectedOption = picker1.dropdown.selectedOption;
is(selectedOption, options[1], "Selected option should now be the second option");
selectedPaymentCard = picker1.requestStore.getState().selectedPaymentCard;
is(selectedPaymentCard, selectedOption.getAttribute("guid"),
"store should have second option selected");
selectedPaymentCardSecurityCode = picker1.requestStore.getState().selectedPaymentCardSecurityCode;
is(selectedPaymentCardSecurityCode, null, "store should have empty security code");
ok(!picker1.classList.contains("invalid-selected-option"), "The second option has all fields");
ok(isHidden(picker1.invalidLabel), "The invalid label should be hidden");
let stateChangePromise = promiseStateChange(picker1.requestStore);
// Type in the security code field
picker1.securityCodeInput.querySelector("input").focus();
sendString("836");
sendKey("Tab");
let state = await stateChangePromise;
is(state.selectedPaymentCardSecurityCode, "836", "Check security code in state");
});
add_task(async function test_delete() {
await picker1.requestStore.setState({
savedBasicCards: {
// 48bnds6854t was deleted
"68gjdh354j": {
"cc-exp": "2017-08",
"cc-exp-month": 8,
"cc-exp-year": 2017,
"cc-name": "J Smith",
"cc-number": "***********1234",
"cc-type": "visa",
"guid": "68gjdh354j",
},
"123456789abc": {
"cc-name": "Jane Fields",
"cc-given-name": "Jane",
"cc-additional-name": "",
"cc-family-name": "Fields",
"cc-number": "************9876",
"guid": "123456789abc",
},
},
});
await asyncElementRendered();
let options = picker1.dropdown.popupBox.children;
is(options.length, 2, "Check dropdown has two remaining cards");
ok(options[0].textContent.includes("J Smith"), "Check remaining card #1");
ok(options[1].textContent.includes("Jane Fields"), "Check remaining card #2");
});
add_task(async function test_supportedNetworks_tempCards() {
await picker1.requestStore.reset();
let request = Object.assign({}, picker1.requestStore.getState().request);
request.paymentMethods = [
{
supportedMethods: "basic-card",
data: {
supportedNetworks: [
"mastercard",
"visa",
],
},
},
];
await picker1.requestStore.setState({
request,
selectedPaymentCard: "68gjdh354j",
tempBasicCards: {
"68gjdh354j": {
"cc-exp": "2017-08",
"cc-exp-month": 8,
"cc-exp-year": 2017,
"cc-name": "J Smith",
"cc-number": "***********1234",
"cc-type": "discover",
"guid": "68gjdh354j",
},
},
});
await asyncElementRendered();
let options = picker1.dropdown.popupBox.children;
is(options.length, 1, "Check dropdown has one card");
ok(options[0].textContent.includes("J Smith"), "Check remaining card #1");
ok(picker1.classList.contains("invalid-selected-option"),
"Check discover is recognized as not supported");
is(picker1.invalidLabel.innerText, picker1.dataset.invalidLabel, "Check displayed error text");
info("change the card to be a visa");
await picker1.requestStore.setState({
tempBasicCards: {
"68gjdh354j": {
"cc-exp": "2017-08",
"cc-exp-month": 8,
"cc-exp-year": 2017,
"cc-name": "J Smith",
"cc-number": "***********1234",
"cc-type": "visa",
"guid": "68gjdh354j",
},
},
});
await asyncElementRendered();
ok(!picker1.classList.contains("invalid-selected-option"),
"Check visa is recognized as supported");
});
</script>
</body>
</html>
|