Skip to content

Commit 7851d21

Browse files
DavertMikclaude
andcommitted
test: add tests for context parameter on appendField, clearField, attachFile
Add shared webapi tests verifying that context scoping works for appendField, clearField, and attachFile. Extended the context.php test page with pre-filled values and file inputs to support the tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 29af2d9 commit 7851d21

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

test/data/app/view/form/context.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
<body>
33
<div id="area1">
44
<label for="name1">Name</label>
5-
<input type="text" id="name1" name="name" value="" />
5+
<input type="text" id="name1" name="name" value="old1" />
66
<select name="age" id="age1">
77
<option value="child">below 13</option>
88
<option value="teenage">13-21</option>
99
<option value="adult">21-60</option>
1010
</select>
11+
<label for="file1">Avatar</label>
12+
<input type="file" id="file1" name="avatar" />
1113
<button type="button">Submit</button>
1214
</div>
1315
<div id="area2">
1416
<label for="name2">Name</label>
15-
<input type="text" id="name2" name="name" value="" />
17+
<input type="text" id="name2" name="name" value="old2" />
1618
<select name="age" id="age2">
1719
<option value="child">below 13</option>
1820
<option value="teenage">13-21</option>
1921
<option value="adult">21-60</option>
2022
</select>
23+
<label for="file2">Avatar</label>
24+
<input type="file" id="file2" name="avatar" />
2125
<span class="unique-element">Only here</span>
2226
</div>
2327
</body>

test/helper/webapi.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,35 @@ export function tests() {
634634
const val1 = await I.grabValueFrom('#age1')
635635
assert.equal(val1, 'child')
636636
})
637+
638+
it('should append field within context', async () => {
639+
await I.amOnPage('/form/context')
640+
await I.appendField('Name', '_appended', '#area2')
641+
const val = await I.grabValueFrom('#name2')
642+
assert.equal(val, 'old2_appended')
643+
const val1 = await I.grabValueFrom('#name1')
644+
assert.equal(val1, 'old1')
645+
})
646+
647+
it('should clear field within context', async () => {
648+
await I.amOnPage('/form/context')
649+
if (isHelper('Playwright')) {
650+
await I.clearField('Name', {}, '#area2')
651+
} else {
652+
await I.clearField('Name', '#area2')
653+
}
654+
await I.seeInField('#name2', '')
655+
await I.seeInField('#name1', 'old1')
656+
})
657+
658+
it('should attach file within context', async () => {
659+
await I.amOnPage('/form/context')
660+
await I.attachFile('Avatar', 'app/avatar.jpg', '#area2')
661+
const val2 = await I.executeScript(() => document.getElementById('file2').files.length)
662+
assert.equal(val2, 1, 'file2 should have a file attached')
663+
const val1 = await I.executeScript(() => document.getElementById('file1').files.length)
664+
assert.equal(val1, 0, 'file1 should have no files')
665+
})
637666
})
638667

639668
describe('#shadow DOM', () => {

0 commit comments

Comments
 (0)