Skip to content

Commit fae9dce

Browse files
authored
Support a city/state composite value (#1158)
* Support a city/state composite value * Remove debugging statement
1 parent e50190e commit fae9dce

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

injected/integration-test/page-objects/broker-protection.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,21 @@ export class BrokerProtectionPage {
5252
* @return {Promise<void>}
5353
*/
5454
async isFormFilled () {
55-
await expect(this.page.getByLabel('First Name:')).toHaveValue('John')
56-
await expect(this.page.getByLabel('Last Name:')).toHaveValue('Smith')
57-
await expect(this.page.getByLabel('Phone Number:')).toHaveValue(/^\d{10}$/)
58-
await expect(this.page.getByLabel('Street Address:')).toHaveValue(/^\d+ [A-Za-z]+(?: [A-Za-z]+)?$/)
59-
await expect(this.page.getByLabel('State:')).toHaveValue('IL')
60-
await expect(this.page.getByLabel('Zip Code:')).toHaveValue(/^\d{5}$/)
55+
await expect(this.page.getByLabel('First Name:', { exact: true })).toHaveValue('John')
56+
await expect(this.page.getByLabel('Last Name:', { exact: true })).toHaveValue('Smith')
57+
await expect(this.page.getByLabel('Phone Number:', { exact: true })).toHaveValue(/^\d{10}$/)
58+
await expect(this.page.getByLabel('Street Address:', { exact: true })).toHaveValue(/^\d+ [A-Za-z]+(?: [A-Za-z]+)?$/)
59+
await expect(this.page.locator('#state')).toHaveValue('IL')
60+
await expect(this.page.getByLabel('Zip Code:', { exact: true })).toHaveValue(/^\d{5}$/)
6161

6262
const randomValue = await this.page.getByLabel('Random number between 5 and 15:').inputValue()
6363
const randomValueInt = parseInt(randomValue)
6464

6565
expect(Number.isInteger(randomValueInt)).toBe(true)
6666
expect(randomValueInt).toBeGreaterThanOrEqual(5)
6767
expect(randomValueInt).toBeLessThanOrEqual(15)
68+
69+
await expect(this.page.getByLabel('City & State:', { exact: true })).toHaveValue('Chicago, IL')
6870
}
6971

7072
/**

injected/integration-test/test-pages/broker-protection/actions/fill-form.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
"selector": "#random_number",
3535
"min": "5",
3636
"max": "15"
37+
},
38+
{
39+
"type": "cityState",
40+
"selector": "#city_state"
3741
}
3842
]
3943
},

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
Random number between 5 and 15:
5252
<input type="text" name="random_number" id="random_number">
5353
</label>
54+
<label>
55+
City & State:
56+
<input type="text" name="city_state" id="city_state">
57+
</label>
5458
<button class="btn-sbmt">Submit</button>
5559
</form>
5660
<script>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ export function fillMany (root, elements, data) {
6969
results.push(setValueForInput(inputElem, generateRandomInt(parseInt(element.min), parseInt(element.max)).toString()))
7070
} else if (element.type === '$generated_street_address$') {
7171
results.push(setValueForInput(inputElem, generateStreetAddress()))
72+
73+
// This is a composite of existing (but separate) city and state fields
74+
} else if (element.type === 'cityState') {
75+
if (!Object.prototype.hasOwnProperty.call(data, 'city') || !Object.prototype.hasOwnProperty.call(data, 'state')) {
76+
results.push({ result: false, error: `element found with selector '${element.selector}', but data didn't contain the keys 'city' and 'state'` })
77+
continue
78+
}
79+
results.push(setValueForInput(inputElem, data.city + ', ' + data.state))
7280
} else {
7381
if (!Object.prototype.hasOwnProperty.call(data, element.type)) {
7482
results.push({ result: false, error: `element found with selector '${element.selector}', but data didn't contain the key '${element.type}'` })

0 commit comments

Comments
 (0)