Skip to content

Commit 092cbbb

Browse files
cursoragentjherr
andcommitted
test(base): wait for an approved change to leave the review queue before reading
Four E2E steps clicked Approve & publish and read the result before the approval finished. approveFirstChange waits for the queue to shrink. Co-authored-by: jherr <jherr@pobox.com>
1 parent 7073625 commit 092cbbb

1 file changed

Lines changed: 21 additions & 24 deletions

File tree

‎app/base/e2e/base.spec.ts‎

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ async function op(page: Page, name: string, input: unknown) {
2222
expect(response.ok(), await response.text()).toBe(true)
2323
return (await response.json()).result
2424
}
25+
26+
/**
27+
* Approve the first change in `/review` and wait until it has left the
28+
* queue, so later reads see the approved state.
29+
*/
30+
async function approveFirstChange(page: Page) {
31+
await page.goto('/review')
32+
await page.waitForLoadState('networkidle')
33+
const approve = page.getByRole('button', {
34+
name: 'Approve & publish',
35+
exact: true,
36+
})
37+
const pending = await approve.count()
38+
expect(pending).toBeGreaterThan(0)
39+
await approve.first().click()
40+
await expect(approve).toHaveCount(pending - 1)
41+
}
2542
test('first-run owner setup, sign-out, and API protection', async ({
2643
page,
2744
}) => {
@@ -539,12 +556,7 @@ test('persistent recipe page: preview, review, filtering, details, and saved cod
539556
data: { id: 'recipe-book', kind: 'page' },
540557
})
541558
expect(before.ok()).toBe(false)
542-
await page.goto('/review')
543-
await page.waitForLoadState('networkidle')
544-
await page
545-
.getByRole('button', { name: 'Approve & publish', exact: true })
546-
.first()
547-
.click()
559+
await approveFirstChange(page)
548560
await page.goto('/p/recipe-book')
549561
await expect(
550562
page.getByRole('heading', { name: 'Recipe book', exact: true }),
@@ -608,12 +620,7 @@ test('saved report snapshots stay fixed while live pages refresh; revisions requ
608620
await expect(
609621
page.getByText('Submitted for review. Approve in Review to publish.'),
610622
).toBeVisible()
611-
await page.goto('/review')
612-
await page.waitForLoadState('networkidle')
613-
await page
614-
.getByRole('button', { name: 'Approve & publish', exact: true })
615-
.first()
616-
.click()
623+
await approveFirstChange(page)
617624
const initial = await op(page, 'readInterface', {
618625
id: 'recipe-count',
619626
kind: 'report',
@@ -653,12 +660,7 @@ test('saved report snapshots stay fixed while live pages refresh; revisions requ
653660
(await op(page, 'readInterface', { id: 'recipe-count', kind: 'report' }))
654661
.title,
655662
).toBe('Recipe count')
656-
await page.goto('/review')
657-
await page.waitForLoadState('networkidle')
658-
await page
659-
.getByRole('button', { name: 'Approve & publish', exact: true })
660-
.first()
661-
.click()
663+
await approveFirstChange(page)
662664
const updated = await op(page, 'readInterface', {
663665
id: 'recipe-count',
664666
kind: 'report',
@@ -794,12 +796,7 @@ test('admins enable a reviewed snapshot schedule, pause/resume it, and run the a
794796
await expect(
795797
page.getByText('Submitted for review. Approve in Review to publish.'),
796798
).toBeVisible()
797-
await page.goto('/review')
798-
await page.waitForLoadState('networkidle')
799-
await page
800-
.getByRole('button', { name: 'Approve & publish', exact: true })
801-
.first()
802-
.click()
799+
await approveFirstChange(page)
803800
await page.goto('/interfaces')
804801
await page
805802
.getByRole('button', { name: 'Edit Scheduled recipe total', exact: true })

0 commit comments

Comments
 (0)