Skip to content

Commit 86e48ae

Browse files
test: bulk edit flaky selectors (#12950)
#12861 introduced some flaky test selectors. Specifically bulk editing values and then looking for the previous values in the table rows. This PR fixes the flakes and fixes eslint errors in `findTableRow` and `findTableCell` helper funcitons.
1 parent 7ebac63 commit 86e48ae

File tree

3 files changed

+47
-39
lines changed

3 files changed

+47
-39
lines changed

test/bulk-edit/e2e.spec.ts

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ test.describe('Bulk Edit', () => {
128128
'Updated 2 Posts successfully.',
129129
)
130130

131-
await expect(findTableCell(page, '_status', titleOfPostToPublish1)).toContainText('Published')
132-
await expect(findTableCell(page, '_status', titleOfPostToPublish2)).toContainText('Published')
131+
await expect(await findTableCell(page, '_status', titleOfPostToPublish1)).toContainText(
132+
'Published',
133+
)
134+
await expect(await findTableCell(page, '_status', titleOfPostToPublish2)).toContainText(
135+
'Published',
136+
)
133137
})
134138

135139
test('should unpublish many', async () => {
@@ -154,8 +158,12 @@ test.describe('Bulk Edit', () => {
154158
await page.locator('.list-selection__button[aria-label="Unpublish"]').click()
155159
await page.locator('#unpublish-posts #confirm-action').click()
156160

157-
await expect(findTableCell(page, '_status', titleOfPostToUnpublish1)).toContainText('Draft')
158-
await expect(findTableCell(page, '_status', titleOfPostToUnpublish2)).toContainText('Draft')
161+
await expect(await findTableCell(page, '_status', titleOfPostToUnpublish1)).toContainText(
162+
'Draft',
163+
)
164+
await expect(await findTableCell(page, '_status', titleOfPostToUnpublish2)).toContainText(
165+
'Draft',
166+
)
159167
})
160168

161169
test('should update many', async () => {
@@ -234,8 +242,12 @@ test.describe('Bulk Edit', () => {
234242
'Updated 2 Posts successfully.',
235243
)
236244

237-
await expect(findTableCell(page, '_status', titleOfPostToPublish1)).toContainText('Published')
238-
await expect(findTableCell(page, '_status', titleOfPostToPublish2)).toContainText('Published')
245+
await expect(await findTableCell(page, '_status', titleOfPostToPublish1)).toContainText(
246+
'Published',
247+
)
248+
await expect(await findTableCell(page, '_status', titleOfPostToPublish2)).toContainText(
249+
'Published',
250+
)
239251
})
240252

241253
test('should draft many from drawer', async () => {
@@ -272,8 +284,8 @@ test.describe('Bulk Edit', () => {
272284
'Updated 2 Posts successfully.',
273285
)
274286

275-
await expect(findTableCell(page, '_status', titleOfPostToDraft1)).toContainText('Draft')
276-
await expect(findTableCell(page, '_status', titleOfPostToDraft2)).toContainText('Draft')
287+
await expect(await findTableCell(page, '_status', titleOfPostToDraft1)).toContainText('Draft')
288+
await expect(await findTableCell(page, '_status', titleOfPostToDraft2)).toContainText('Draft')
277289
})
278290

279291
test('should delete all on page', async () => {
@@ -507,15 +519,12 @@ test.describe('Bulk Edit', () => {
507519
`Updated ${postCount} Posts successfully.`,
508520
)
509521

510-
// eslint-disable-next-line jest-dom/prefer-checked
511-
await expect(page.locator('input#select-all')).not.toHaveAttribute('checked', '')
522+
await expect(page.locator('.table input#select-all[checked]')).toBeHidden()
512523

513-
for (let i = 0; i < postCount; i++) {
514-
// eslint-disable-next-line jest-dom/prefer-checked
515-
await expect(findTableCell(page, '_select', `Post ${i + 1}`)).not.toHaveAttribute(
516-
'checked',
517-
'',
518-
)
524+
for (let i = 1; i < postCount + 1; i++) {
525+
await expect(
526+
page.locator(`table tbody tr .row-${i} input[type="checkbox"][checked]`),
527+
).toBeHidden()
519528
}
520529
})
521530

@@ -537,20 +546,18 @@ test.describe('Bulk Edit', () => {
537546
`Updated ${postCount} Posts successfully.`,
538547
)
539548

540-
// eslint-disable-next-line jest-dom/prefer-checked
541-
await expect(page.locator('input#select-all')).not.toHaveAttribute('checked', '')
549+
await expect(page.locator('.table input#select-all[checked]')).toBeHidden()
542550

543-
for (let i = 0; i < postCount; i++) {
544-
// eslint-disable-next-line jest-dom/prefer-checked
545-
await expect(findTableCell(page, '_select', `Post ${i + 1}`)).not.toHaveAttribute(
546-
'checked',
547-
'',
548-
)
551+
for (let i = 1; i < postCount + 1; i++) {
552+
await expect(
553+
page.locator(`table tbody tr .row-${i} input[type="checkbox"][checked]`),
554+
).toBeHidden()
549555
}
550556
})
551557

552558
test('should toggle list selections off on successful edit', async () => {
553559
await deleteAllPosts()
560+
const bulkEditValue = 'test'
554561

555562
const postCount = 3
556563
Array.from({ length: postCount }).forEach(async (_, i) => {
@@ -575,23 +582,20 @@ test.describe('Bulk Edit', () => {
575582
const titleOption = fieldSelect.locator('.rs__option:has-text("Title")').first()
576583
await titleOption.click()
577584

578-
await editDrawer.locator('input#field-title').fill('test')
585+
await editDrawer.locator('input#field-title').fill(bulkEditValue)
579586

580587
await editDrawer.locator('button[type="submit"]:has-text("Publish changes")').click()
581588

582589
await expect(page.locator('.payload-toast-container .toast-success')).toContainText(
583590
`Updated ${postCount} Posts successfully.`,
584591
)
585592

586-
// eslint-disable-next-line jest-dom/prefer-checked
587-
await expect(page.locator('input#select-all')).not.toHaveAttribute('checked', '')
593+
await expect(page.locator('.table input#select-all[checked]')).toBeHidden()
588594

589-
for (let i = 0; i < postCount; i++) {
590-
// eslint-disable-next-line jest-dom/prefer-checked
591-
await expect(findTableCell(page, '_select', `Post ${i + 1}`)).not.toHaveAttribute(
592-
'checked',
593-
'',
594-
)
595+
for (let i = 1; i < postCount + 1; i++) {
596+
await expect(
597+
page.locator(`table tbody tr .row-${i} input[type="checkbox"][checked]`),
598+
).toBeHidden()
595599
}
596600
})
597601
})

test/helpers.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,20 @@ export const selectTableRow = async (page: Page, title: string): Promise<void> =
361361
await expect(page.locator(selector)).toBeChecked()
362362
}
363363

364-
export const findTableCell = (page: Page, fieldName: string, rowTitle?: string): Locator => {
365-
const parentEl = rowTitle ? findTableRow(page, rowTitle) : page.locator('tbody tr')
364+
export const findTableCell = async (
365+
page: Page,
366+
fieldName: string,
367+
rowTitle?: string,
368+
): Promise<Locator> => {
369+
const parentEl = rowTitle ? await findTableRow(page, rowTitle) : page.locator('tbody tr')
366370
const cell = parentEl.locator(`td.cell-${fieldName}`)
367-
expect(cell).toBeTruthy()
371+
await expect(cell).toBeVisible()
368372
return cell
369373
}
370374

371-
export const findTableRow = (page: Page, title: string): Locator => {
375+
export const findTableRow = async (page: Page, title: string): Promise<Locator> => {
372376
const row = page.locator(`tbody tr:has-text("${title}")`)
373-
expect(row).toBeTruthy()
377+
await expect(row).toBeVisible()
374378
return row
375379
}
376380

test/localization/e2e.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('Localization', () => {
122122
await page.locator('#action-save').click()
123123

124124
await page.locator('text=Versions').click()
125-
const firstVersion = findTableRow(page, 'Currently Published')
125+
const firstVersion = await findTableRow(page, 'Currently Published')
126126
await firstVersion.locator('a').click()
127127

128128
await expect(page.locator('.view-version__toggle-locales')).toBeVisible()

0 commit comments

Comments
 (0)