Skip to content

Commit

Permalink
E2e/fix-flakiness (#1128)
Browse files Browse the repository at this point in the history
* fix: wait 500ms before asserting the outbox to be empty

* fix: add missing assertion

* fix: use age for deceased so declaration will not be marked as duplicate

* fix: use age for mother so declaration will not be marked as duplicate

* fix: send ageOfIndividual

* chore: wait 500ms when changing death date

* fix: add await before async function `goToSection()`

* fix: use ageOfIndividual in identity verification of mother

* fix: assert age of deceased instead of dob

* fix: wait 500ms where page loads twice

* fix: increase randomness of names

* chore: use constant time

---------

Co-authored-by: Riku Rouvila <[email protected]>
  • Loading branch information
jamil314 and rikukissa authored Sep 19, 2024
1 parent 92be9f8 commit be2b16d
Show file tree
Hide file tree
Showing 37 changed files with 255 additions and 171 deletions.
22 changes: 21 additions & 1 deletion e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,27 @@ export const drawSignature = async (page: Page) => {
}
}

export const expectOutboxToBeEmpty = async (page: Page) =>
export const expectOutboxToBeEmpty = async (page: Page) => {
/*
* This is to ensure the following condition is asserted
* after the outbox has the declaration
*/
await page.waitForTimeout(SAFE_INPUT_CHANGE_TIMEOUT_MS)

await expect(page.locator('#navigation_outbox')).not.toContainText('1', {
timeout: SAFE_OUTBOX_TIMEOUT_MS
})
}

// This suffix increases randomness of a name
export const generateRandomSuffix = () => {
const vowels = 'aeiou'
const consonants = 'bcdfghjklmnpqrstvwxyz'

const randomVowel = vowels.charAt(Math.floor(Math.random() * vowels.length))
const randomConsonant = consonants.charAt(
Math.floor(Math.random() * consonants.length)
)

return randomConsonant + randomVowel
}
14 changes: 12 additions & 2 deletions e2e/testcases/birth/1-birth-event-declaration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,12 @@ test.describe('1. Birth event declaration', () => {
/*
* Expected result: should be navigated to "in-progress" tab but no draft will be saved
*/
expect(page.locator('#content-name', { hasText: 'In progress' }))

await page.waitForTimeout(500) // This page renders twice at first

await expect(
page.locator('#content-name', { hasText: 'In progress' })
).toBeVisible()
await expect(page.getByText('0 seconds ago')).toBeHidden()
})
})
Expand Down Expand Up @@ -529,7 +534,12 @@ test.describe('1. Birth event declaration', () => {
/*
* Expected result: should be navigated to "in-progress" tab but no draft will be saved
*/
expect(page.locator('#content-name', { hasText: 'In progress' }))

await page.waitForTimeout(500) // This page renders twice at first

await expect(
page.locator('#content-name', { hasText: 'In progress' })
).toBeVisible()
await expect(page.getByText('0 seconds ago')).toBeHidden()
})
})
Expand Down
10 changes: 5 additions & 5 deletions e2e/testcases/birth/2-validate-the-child-details-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test.describe("2. Validate the child's details page", () => {
})

test('2.1.3 Enter Field as NULL', async ({ page }) => {
goToSection(page, 'preview')
await goToSection(page, 'preview')

/*
* Expected result: should throw error in application review page:
Expand Down Expand Up @@ -137,7 +137,7 @@ test.describe("2. Validate the child's details page", () => {
})

test('2.3.2 Set the field as null', async ({ page }) => {
goToSection(page, 'preview')
await goToSection(page, 'preview')

/*
* Expected result: should throw error in application review page:
Expand Down Expand Up @@ -203,7 +203,7 @@ test.describe("2. Validate the child's details page", () => {
})

test('2.4.4 Set the field as null', async ({ page }) => {
goToSection(page, 'preview')
await goToSection(page, 'preview')

/*
* Expected result: should throw error in application review page:
Expand Down Expand Up @@ -272,7 +272,7 @@ test.describe("2. Validate the child's details page", () => {
})

test('2.5.4 Set the field as null', async ({ page }) => {
goToSection(page, 'preview')
await goToSection(page, 'preview')

/*
* Expected result: should throw error in application review page:
Expand All @@ -288,7 +288,7 @@ test.describe("2. Validate the child's details page", () => {

test.describe('2.6 Validate place of delivery field', async () => {
test('2.6.1 Keep field as null', async ({ page }) => {
goToSection(page, 'preview')
await goToSection(page, 'preview')

/*
* Expected result: should throw error in application review page:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ test.describe.serial('8. Validate declaration review page', () => {

test.describe('8.1.1 Navigate to declaration preview page', async () => {
test('8.1.1.1 Verify information added on previous pages', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')

/*
* Expected result: should include
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ test.describe.serial('1. Birth declaration case - 1', () => {
})

test('1.1.5 Go to preview', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')
})

test('1.1.6 Verify information on preview page', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test.describe.serial('10. Birth declaration case - 10', () => {
})

test('10.1.5 Go to preview', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')
})

test('10.1.6 Verify information on preview page', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ test.describe.serial('2. Birth declaration case - 2', () => {
await page.getByRole('button', { name: 'Continue' }).click()
})
test('2.1.5 Go To Preview', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')
})

test('2.1.6 Verify information on preview page', async () => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/testcases/birth/declarations/birth-declaration-3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ test.describe.serial('3. Birth declaration case - 3', () => {

test.describe('3.1.5 Add supporting documents', async () => {
test('3.1.5.0 Go to supporting documents page', async () => {
goToSection(page, 'documents')
await goToSection(page, 'documents')
})

test('3.1.5.1 Upload proof of birth', async () => {
Expand Down Expand Up @@ -458,7 +458,7 @@ test.describe.serial('3. Birth declaration case - 3', () => {
})

test('3.1.6 Go to preview', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')
})

test('3.1.7 Verify information on preview page', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ test.describe.serial('4. Birth declaration case - 4', () => {
})

test('4.1.5 Go to preview', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')
})

test('4.1.6 Verify information on preview page', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ test.describe.serial('5. Birth declaration case - 5', () => {
})

test('5.1.5 Go to preview', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')
})

test('5.1.6 Verify information on preview page', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ test.describe.serial('6. Birth declaration case - 6', () => {
})

test('6.1.5 Go to preview', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')
})

test('6.1.6 Verify information on preview page', async () => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/testcases/birth/declarations/birth-declaration-7.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ test.describe.serial('7. Birth declaration case - 7', () => {
})

test('7.1.5 Add supporting documents', async () => {
goToSection(page, 'documents')
await goToSection(page, 'documents')
await uploadImage(
page,
page.locator('button[name="uploadDocForChildDOB"]')
Expand Down Expand Up @@ -124,7 +124,7 @@ test.describe.serial('7. Birth declaration case - 7', () => {
})

test('7.1.6 Go to preview', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')
})

test('7.1.7 Verify information on preview page', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ test.describe.serial('8. Birth declaration case - 8', () => {
})

test('8.1.5 Go to preview', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')
})

test('8.1.6 Verify information on preview page', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test.describe.serial('9. Birth declaration case - 9', () => {
})

test('9.1.5 Go to preview', async () => {
goToSection(page, 'preview')
await goToSection(page, 'preview')
})

test('9.1.6 Verify information on preview page', async () => {
Expand Down
15 changes: 6 additions & 9 deletions e2e/testcases/birth/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
GET_BIRTH_REGISTRATION_FOR_REVIEW,
REGISTER_BIRTH_DECLARATION
} from './queries'
import { random } from 'lodash'
import { generateRandomSuffix } from '../../helpers'

export type BirthDetails = {
informant: {
Expand All @@ -33,7 +35,7 @@ export type BirthDetails = {
mother: {
firstNames: string
familyName: string
birthDate?: string
age?: number
maritalStatus?: 'SINGLE' | 'MARRIED' | 'DIVORCED' | 'WIDOWED'
}
father: {
Expand Down Expand Up @@ -98,8 +100,8 @@ export async function createDeclaration(token: string, details: BirthDetails) {
name: [
{
use: 'en',
firstNames: details.child.firstNames,
familyName: details.child.familyName
firstNames: details.child.firstNames + generateRandomSuffix(),
familyName: details.child.familyName + generateRandomSuffix()
}
],
gender: details.child.gender,
Expand Down Expand Up @@ -160,12 +162,7 @@ export async function createDeclaration(token: string, details: BirthDetails) {
familyName: details.mother.familyName
}
],
birthDate:
details.mother.birthDate ||
format(
subYears(new Date(), 16 + Math.ceil(10 * Math.random())),
'yyyy-MM-dd'
),
ageOfIndividualInYears: details.mother.age || random(20, 100),
nationality: ['FAR'],
identifier: [
{
Expand Down
4 changes: 2 additions & 2 deletions e2e/testcases/correction-birth/correct-birth-record-1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ test.describe('1. Correct record - 1', () => {
).toBeVisible()
await expect(
page.getByText(
`Date of Birth:
${formatDateTo_ddMMMMyyyy(declaration.mother.birthDate)}
`Age:
${declaration.mother.ageOfIndividualInYears}
`
)
).toBeVisible()
Expand Down
59 changes: 35 additions & 24 deletions e2e/testcases/correction-birth/correct-birth-record-3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
formatName,
getToken,
goBackToReview,
joinValuesWith,
login
} from '../../helpers'
import faker from '@faker-js/faker'
Expand All @@ -16,8 +17,8 @@ import {
fetchDeclaration
} from '../birth/helpers'
import { BirthDeclaration, BirthInputDetails } from '../birth/types'
import { format, subDays } from 'date-fns'
import { CREDENTIALS } from '../../constants'
import { random } from 'lodash'

test.describe.serial(' Correct record - 3', () => {
let declaration: BirthDeclaration
Expand All @@ -28,10 +29,7 @@ test.describe.serial(' Correct record - 3', () => {
const updatedMotherDetails = {
firstNames: faker.name.firstName('female'),
familyName: faker.name.firstName('female'),
birthDate: format(
subDays(new Date(), Math.ceil(50 * Math.random() + 365 * 25)),
'yyyy-MM-dd'
),
age: random(20, 100),
email: faker.internet.email(),
nationality: 'Nauru',
id: faker.random.numeric(10),
Expand Down Expand Up @@ -262,26 +260,24 @@ test.describe.serial(' Correct record - 3', () => {
).toBeVisible()
})

test('3.4.2 Change date of birth', async () => {
test('3.4.2 Change age', async () => {
await page
.locator('#mother-content #Date')
.locator('#mother-content #Age')
.getByRole('button', { name: 'Change', exact: true })
.click()

/*
* Expected result: should
* - redirect to mother's details page
* - focus on mother's date of birth
* - focus on mother's age
*/
expect(page.url().includes('correction')).toBeTruthy()
expect(page.url().includes('mother-view-group')).toBeTruthy()
expect(page.url().includes('#motherBirthDate')).toBeTruthy()
expect(page.url().includes('#ageOfIndividualInYears')).toBeTruthy()

const birthDay = updatedMotherDetails.birthDate.split('-')

await page.getByPlaceholder('dd').fill(birthDay[2])
await page.getByPlaceholder('mm').fill(birthDay[1])
await page.getByPlaceholder('yyyy').fill(birthDay[0])
await page
.locator('#ageOfIndividualInYears')
.fill(updatedMotherDetails.age.toString())

await page.getByRole('button', { name: 'Back to review' }).click()

Expand All @@ -296,13 +292,18 @@ test.describe.serial(' Correct record - 3', () => {
expect(page.url().includes('review')).toBeTruthy()

await expect(
page.locator('#mother-content #Date').getByRole('deletion')
).toHaveText(formatDateTo_ddMMMMyyyy(declaration.mother.birthDate))
page.locator('#mother-content #Age').getByRole('deletion')
).toHaveText(
joinValuesWith(
[declaration.mother.ageOfIndividualInYears, 'years'],
' '
)
)

await expect(
page
.locator('#mother-content #Date')
.getByText(formatDateTo_ddMMMMyyyy(updatedMotherDetails.birthDate))
.locator('#mother-content #Age')
.getByText(joinValuesWith([updatedMotherDetails.age, 'years'], ' '))
).toBeVisible()
})

Expand Down Expand Up @@ -773,9 +774,14 @@ test.describe.serial(' Correct record - 3', () => {

await expect(
page.getByText(
'Date of birth (mother)' +
formatDateTo_ddMMMMyyyy(declaration.mother.birthDate) +
formatDateTo_ddMMMMyyyy(updatedMotherDetails.birthDate)
joinValuesWith(
[
'Age of mother (mother)',
declaration.mother.ageOfIndividualInYears,
updatedMotherDetails.age
],
''
)
)
).toBeVisible()

Expand Down Expand Up @@ -951,9 +957,14 @@ test.describe.serial(' Correct record - 3', () => {

await expect(
page.getByText(
'Date of birth (mother)' +
formatDateTo_ddMMMMyyyy(declaration.mother.birthDate) +
formatDateTo_ddMMMMyyyy(updatedMotherDetails.birthDate)
joinValuesWith(
[
'Age of mother (mother)',
declaration.mother.ageOfIndividualInYears,
updatedMotherDetails.age
],
''
)
)
).toBeVisible()

Expand Down
Loading

0 comments on commit be2b16d

Please sign in to comment.