Skip to content

Commit afe41f9

Browse files
authored
Allow for optional types (#1261)
* Allow for optional types * Minor rename
1 parent 7923678 commit afe41f9

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

injected/integration-test/broker-protection.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,16 @@ test.describe('Broker Protection communications', () => {
353353
await dbp.isFormFilled();
354354
});
355355

356+
test('fillForm with optional information', async ({ page }, workerInfo) => {
357+
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
358+
await dbp.enabled();
359+
await dbp.navigatesTo('form.html');
360+
await dbp.receivesAction('fill-form-optional.json');
361+
const response = await dbp.collector.waitForMessage('actionCompleted');
362+
dbp.isSuccessMessage(response);
363+
await dbp.isFormFilled();
364+
});
365+
356366
test('click', async ({ page }, workerInfo) => {
357367
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
358368
await dbp.enabled();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"state": {
3+
"action": {
4+
"actionType": "fillForm",
5+
"id": "3",
6+
"selector": ".ahm",
7+
"dataSource": "userProfile",
8+
"elements": [
9+
{
10+
"type": "firstName",
11+
"selector": "#user_first_name"
12+
},
13+
{
14+
"type": "lastName",
15+
"selector": "#user_last_name"
16+
},
17+
{
18+
"type": "$generated_phone_number$",
19+
"selector": "#user_phone"
20+
},
21+
{
22+
"type": "$generated_street_address$",
23+
"selector": "#user_street_address"
24+
},
25+
{
26+
"type": "state",
27+
"selector": "#state"
28+
},
29+
{
30+
"type": "$generated_zip_code$",
31+
"selector": "#user_zip_code"
32+
},
33+
{
34+
"type": "$generated_random_number$",
35+
"selector": "#random_number",
36+
"min": "5",
37+
"max": "15"
38+
},
39+
{
40+
"type": "cityState",
41+
"selector": "#city_state"
42+
},
43+
{
44+
"type": "middleName",
45+
"selector": "#user_middle_name"
46+
}
47+
]
48+
},
49+
"data": {
50+
"userProfile": {
51+
"firstName": "John",
52+
"lastName": "Smith",
53+
"city": "Chicago",
54+
"state": "IL"
55+
}
56+
}
57+
}
58+
}
59+

injected/integration-test/test-pages/broker-protection/pages/form.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
First Name:
1919
<input type="text" name="first-name" id="user_first_name">
2020
</label>
21+
<label>
22+
Middle Name:
23+
<input type="text" name="middle-name" id="user_middle_name">
24+
</label>
2125
<label>
2226
Last Name:
2327
<input type="text" name="last-name" id="user_last_name">

injected/src/features/broker-protection/actions/fill-form.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export function fillMany(root, elements, data) {
8989
}
9090
results.push(setValueForInput(inputElem, data.city + ', ' + data.state));
9191
} else {
92+
if (isElementTypeOptional(element.type)) {
93+
continue;
94+
}
9295
if (!Object.prototype.hasOwnProperty.call(data, element.type)) {
9396
results.push({
9497
result: false,
@@ -110,6 +113,20 @@ export function fillMany(root, elements, data) {
110113
return results;
111114
}
112115

116+
/**
117+
* Returns whether an element type is optional, allowing some checks to be skipped
118+
*
119+
* @param { string } type
120+
* @returns Boolean
121+
*/
122+
function isElementTypeOptional(type) {
123+
if (type === 'middleName') {
124+
return true;
125+
}
126+
127+
return false;
128+
}
129+
113130
/**
114131
* NOTE: This code comes from Autofill, the reasoning is to make React autofilling work on Chrome and Safari.
115132
*

0 commit comments

Comments
 (0)