Skip to content

Commit d7defcc

Browse files
committed
fix: update tests to use shared checks. Update checks
1 parent d381b4b commit d7defcc

File tree

7 files changed

+50
-43
lines changed

7 files changed

+50
-43
lines changed

e2e/testcases/v2-birth/8-validate-declaration-review-page.spec.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '../../helpers'
1111
import { faker } from '@faker-js/faker'
1212
import { CREDENTIALS } from '../../constants'
13-
import { fillDate } from './helpers'
13+
import { assertRecordInWorkqueue, fillDate } from './helpers'
1414
import { ensureOutboxIsEmpty, selectAction } from '../../v2-utils'
1515

1616
test.describe.serial('8. Validate declaration review page', () => {
@@ -1439,14 +1439,11 @@ test.describe.serial('8. Validate declaration review page', () => {
14391439
await ensureOutboxIsEmpty(page)
14401440
await page.getByText('Ready to print').click()
14411441

1442-
/*
1443-
* @TODO: When workflows are implemented on V2, this should navigate to correct workflow first.
1444-
*/
1445-
await expect(
1446-
page.getByRole('button', {
1447-
name: `${declaration.child.name.firstNames} ${newFamilyNameForChild}`
1448-
})
1449-
).toBeVisible()
1442+
await assertRecordInWorkqueue({
1443+
page,
1444+
name: `${declaration.child.name.firstNames} ${newFamilyNameForChild}`,
1445+
workqueues: [{ title: 'Ready to print', exists: true }]
1446+
})
14501447
})
14511448
})
14521449
})

e2e/testcases/v2-birth/helpers.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { formatName, joinValuesWith } from '../../helpers'
44
import { faker } from '@faker-js/faker'
55
import { ensureOutboxIsEmpty } from '../../v2-utils'
66
import { getRowByTitle } from '../v2-print-certificate/birth/helpers'
7-
import { SAFE_OUTBOX_TIMEOUT_MS } from '../../constants'
7+
import {
8+
SAFE_OUTBOX_TIMEOUT_MS,
9+
SAFE_WORKQUEUE_TIMEOUT_MS
10+
} from '../../constants'
811

912
export const REQUIRED_VALIDATION_ERROR = 'Required'
1013
export const NAME_VALIDATION_ERROR =
@@ -85,24 +88,32 @@ export const assertRecordInWorkqueue = async ({
8588
name: string
8689
workqueues: { title: string; exists: boolean }[]
8790
}) => {
88-
await page.getByRole('button', { name: 'Outbox' }).click()
8991
await ensureOutboxIsEmpty(page)
9092

9193
for (const { title, exists } of workqueues) {
94+
// NOTE: These tests are quite flaky. See if waiting unnecessarily long between page changes
95+
await page.waitForTimeout(SAFE_WORKQUEUE_TIMEOUT_MS)
9296
await page
9397
.getByRole('button', {
9498
name: title
9599
})
96100
.click()
97101

98-
await expect(page.getByTestId('search-result')).toContainText(title, {
102+
const workqueue = page.getByTestId('search-result')
103+
104+
await expect(workqueue).toContainText(title, {
99105
timeout: SAFE_OUTBOX_TIMEOUT_MS
100106
})
101107

108+
const recordButton = workqueue.getByRole('button', { name })
109+
102110
if (exists) {
103-
await expect(page.getByRole('button', { name })).toBeVisible()
111+
await recordButton.waitFor({ state: 'visible' })
112+
await expect(recordButton).toBeVisible()
104113
} else {
105-
await expect(page.getByRole('button', { name })).toBeHidden()
114+
await expect(recordButton).toHaveCount(0, {
115+
timeout: SAFE_OUTBOX_TIMEOUT_MS
116+
})
106117
}
107118
}
108119
}

e2e/testcases/v2-correction-birth/birth-correction-flow.spec.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
type
1515
} from '../../v2-utils'
1616
import {
17+
assertRecordInWorkqueue,
1718
formatV2ChildName,
1819
REQUIRED_VALIDATION_ERROR
1920
} from '../v2-birth/helpers'
@@ -245,14 +246,17 @@ test.describe.serial('Birth correction flow', () => {
245246
})
246247

247248
test("Event appears in 'Sent for approval' workqueue", async () => {
249+
await ensureOutboxIsEmpty(page)
248250
await page.getByTestId('navigation_workqueue_sent-for-approval').click()
249251

250-
await expect(
251-
page.getByRole('button', { name: formatV2ChildName(declaration) })
252-
).toBeVisible()
252+
await assertRecordInWorkqueue({
253+
page,
254+
name: formatV2ChildName(declaration),
255+
workqueues: [{ title: 'Sent for approval', exists: true }]
256+
})
253257
})
254258

255-
test.describe('Approve correction request', () => {
259+
test.describe.serial('Approve correction request', () => {
256260
test('Login as Local Registrar', async () => {
257261
await logout(page)
258262
await loginToV2(page, CREDENTIALS.LOCAL_REGISTRAR)
@@ -261,9 +265,11 @@ test.describe.serial('Birth correction flow', () => {
261265
test("Find the event in the 'Ready for review' workflow", async () => {
262266
await page.getByRole('button', { name: 'Ready for review' }).click()
263267

264-
await page
265-
.getByRole('button', { name: formatV2ChildName(declaration) })
266-
.click()
268+
await assertRecordInWorkqueue({
269+
page,
270+
name: formatV2ChildName(declaration),
271+
workqueues: [{ title: 'review', exists: true }]
272+
})
267273
})
268274

269275
test('Correction request action appears in audit history', async () => {

e2e/testcases/v2-correction-birth/correct-birth-record-1.spec.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@ import {
1515
createDeclaration,
1616
Declaration
1717
} from '../v2-test-data/birth-declaration-with-mother-father'
18-
import {
19-
ensureAssigned,
20-
ensureOutboxIsEmpty,
21-
expectInUrl,
22-
selectAction,
23-
type
24-
} from '../../v2-utils'
25-
import { formatV2ChildName } from '../v2-birth/helpers'
18+
import { ensureAssigned, expectInUrl, selectAction, type } from '../../v2-utils'
19+
import { assertRecordInWorkqueue, formatV2ChildName } from '../v2-birth/helpers'
2620

2721
test.describe('1. Correct record - 1', () => {
2822
let declaration: Declaration
@@ -659,11 +653,11 @@ test.describe('1. Correct record - 1', () => {
659653
* - be navigated to Sent for approval workqueue
660654
* - include the declaration in this tab
661655
*/
662-
await page.getByTestId('navigation_workqueue_sent-for-approval').click()
663-
await ensureOutboxIsEmpty(page)
664-
await expect(
665-
page.getByRole('button', { name: formatV2ChildName(declaration) })
666-
).toBeVisible()
656+
await assertRecordInWorkqueue({
657+
page,
658+
name: formatV2ChildName(declaration),
659+
workqueues: [{ title: 'Sent for approval', exists: true }]
660+
})
667661
})
668662
})
669663

e2e/testcases/v2-correction-birth/correct-birth-record-3.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,8 @@ test.describe.serial(' Correct record - 3', () => {
10761076
})
10771077

10781078
test('3.8.4 Validate history in record audit', async () => {
1079+
await ensureOutboxIsEmpty(page)
1080+
// @TODO: why the reload
10791081
await page.reload()
10801082
await ensureAssigned(page)
10811083
await page.getByRole('button', { name: 'Next page' }).click()

e2e/testcases/v2-correction-birth/correct-birth-record-4.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,6 @@ test.describe.serial(' Correct record - 4', () => {
312312
expect(page.url().includes('correction')).toBeTruthy()
313313
expect(page.url().includes('review')).toBeTruthy()
314314

315-
console.log(declaration)
316-
console.log(updatedFatherDetails.birthDate)
317315
await expect(
318316
await page.getByTestId('row-value-father.dob').getByRole('deletion')
319317
).toHaveText(formatDateTo_dMMMMyyyy(declaration['father.dob']!))

e2e/v2-utils.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,17 @@ export async function ensureAssigned(page: Page) {
104104
}
105105

106106
export async function expectInUrl(page: Page, assertionString: string) {
107-
await expect(page.url().includes(assertionString)).toBeTruthy()
107+
await page.waitForURL((url) => url.pathname.includes(assertionString))
108108
}
109109

110110
export async function ensureOutboxIsEmpty(page: Page) {
111111
await page.waitForTimeout(SAFE_INPUT_CHANGE_TIMEOUT_MS)
112112

113-
await expect(page.locator('#navigation_workqueue_outbox')).toHaveText(
114-
'Outbox',
115-
{
116-
timeout: SAFE_OUTBOX_TIMEOUT_MS
117-
}
118-
)
113+
const outbox = page.locator('#navigation_workqueue_outbox')
114+
115+
await expect(outbox).toHaveText('Outbox', {
116+
timeout: SAFE_OUTBOX_TIMEOUT_MS
117+
})
119118
}
120119

121120
export async function type(page: Page, locator: string, text: string) {

0 commit comments

Comments
 (0)