Skip to content

Commit 05da6a4

Browse files
committed
test: add example for checking checkbox in table row
1 parent 4ecf17d commit 05da6a4

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

test/fixture/locators.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,20 @@ test.describe('lib/fixture.ts (locators)', () => {
253253
expect(text).toEqual(['Hello h1', 'Hello h2'])
254254
})
255255

256+
test.describe('accessible tables?', () => {
257+
test.use({asyncUtilTimeout: 3000})
258+
259+
test.only('matches table row with `RegExp` text matcher', async ({screen, within}) => {
260+
const table = await screen.findByTestId('editable-nested-table-GroupCode')
261+
const row = within(table).getByRole('row', {name: /LINEHOLDER/})
262+
const checkbox = within(row).getByRole('checkbox')
263+
264+
await expect(checkbox).not.toBeChecked()
265+
await checkbox.check()
266+
await expect(checkbox).toBeChecked()
267+
})
268+
})
269+
256270
test('throws Testing Library error when locator times out', async ({queries}) => {
257271
const query = async () => queries.findByText(/Loaded!/, undefined, {timeout: 500})
258272

test/fixtures/late-page.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@
33
<body>
44
<span>Loading...</span>
55
<span id="hidden" style="visibility: hidden">Hidden</span>
6+
7+
<table data-testid="editable-nested-table-GroupCode" class="css-1n5gbw2" style="display: none;" id="table">
8+
<tbody>
9+
<tr data-testid="erow-GroupCode-0" class="css-105800b">
10+
<td data-testid="etd-GroupCode-active-0" class="css-1f7ypku">
11+
<label
12+
for="input-GroupCode-active-0"
13+
data-testid="checkbox-input-GroupCode-active-0"
14+
class="css-1lua7zz"
15+
>
16+
<input type="checkbox" id="input-GroupCode-active-0" name="input-GroupCode-active-0" aria-labelledby="input-GroupCode-active-0" class="css-38lalc">
17+
<span tabindex="0" class="css-12234rr"></span>
18+
<span class="css-1008avk"></span>
19+
</label>
20+
</td>
21+
<td data-testid="td-GroupCode-code-0" class="css-1f7voku">01</td>
22+
<td data-testid="td-GroupCode-description-0" class="css-1f7vpku">LINEHOLDER</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
627
<script>
728
setTimeout(() => {
829
const loaded = document.createElement('span')
@@ -44,6 +65,9 @@
4465
modal.appendChild(modalHeader)
4566

4667
document.body.appendChild(modal)
68+
69+
// Deferred Table
70+
document.querySelector('#table').style = 'display: table'
4771
}, 2000)
4872
</script>
4973
</body>

0 commit comments

Comments
 (0)