Skip to content

Commit

Permalink
refactor: move date formatting logic in helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jamil314 committed Sep 4, 2024
1 parent 349bc9d commit 0a2997a
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 191 deletions.
27 changes: 13 additions & 14 deletions e2e/testcases/correction-birth/correct-birth-record-1.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { expect, test, type Page } from '@playwright/test'
import {
createPIN,
formatDateTo_ddMMMMyyyy,
formatDateTo_yyyyMMdd,
getLocationNameFromFhirId,
getToken,
goToSection,
Expand Down Expand Up @@ -196,7 +198,7 @@ test.describe('1. Correct record - 1', () => {
await expect(
page.getByText(
`Date of Birth:
${format(parseISO(declaration.mother.birthDate), 'dd MMMM yyyy')}
${formatDateTo_ddMMMMyyyy(declaration.mother.birthDate)}
`
)
).toBeVisible()
Expand Down Expand Up @@ -384,17 +386,14 @@ test.describe('1. Correct record - 1', () => {

await expect(
page.locator('#child-content #Date').getByRole('deletion')
).toHaveText(
format(parseISO(declaration.child.birthDate), 'dd MMMM yyyy'),
{ ignoreCase: true }
)
).toHaveText(formatDateTo_ddMMMMyyyy(declaration.child.birthDate), {
ignoreCase: true
})

await expect(
page
.locator('#child-content #Date')
.getByText(
format(parseISO(updatedChildDetails.birthDate), 'dd MMMM yyyy')
)
.getByText(formatDateTo_ddMMMMyyyy(updatedChildDetails.birthDate))
).toBeVisible()
})

Expand Down Expand Up @@ -720,8 +719,8 @@ test.describe('1. Correct record - 1', () => {
await expect(
page.getByText(
'Date of birth (Child)' +
format(parseISO(declaration.child.birthDate), 'dd MMMM yyyy') +
format(parseISO(updatedChildDetails.birthDate), 'dd MMMM yyyy')
formatDateTo_ddMMMMyyyy(declaration.child.birthDate) +
formatDateTo_ddMMMMyyyy(updatedChildDetails.birthDate)
)
).toBeVisible()

Expand Down Expand Up @@ -888,8 +887,8 @@ test.describe('1. Correct record - 1', () => {
await expect(
page.getByText(
'Date of birth (Child)' +
format(parseISO(declaration.child.birthDate), 'dd MMMM yyyy') +
format(parseISO(updatedChildDetails.birthDate), 'dd MMMM yyyy')
formatDateTo_ddMMMMyyyy(declaration.child.birthDate) +
formatDateTo_ddMMMMyyyy(updatedChildDetails.birthDate)
)
).toBeVisible()

Expand Down Expand Up @@ -1061,8 +1060,8 @@ test.describe('1. Correct record - 1', () => {
await expect(
page.getByText(
'Date of birth (Child)' +
format(parseISO(declaration.child.birthDate), 'yyyy-MM-dd') +
format(parseISO(updatedChildDetails.birthDate), 'yyyy-MM-dd')
formatDateTo_yyyyMMdd(declaration.child.birthDate) +
formatDateTo_yyyyMMdd(updatedChildDetails.birthDate)
)
).toBeVisible()

Expand Down
29 changes: 17 additions & 12 deletions e2e/testcases/correction-birth/correct-birth-record-2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { expect, test, type Page } from '@playwright/test'
import { createPIN, getToken, login } from '../../helpers'
import {
createPIN,
formatDateTo_ddMMMMyyyy,
formatDateTo_yyyyMMdd,
getToken,
login
} from '../../helpers'
import faker from '@faker-js/faker'
import {
ConvertEnumsToStrings,
Expand Down Expand Up @@ -140,7 +146,7 @@ test.describe.serial(' Correct record - 2', () => {
await expect(
page.getByText(
`Date of Birth:
${format(parseISO(declaration.father.birthDate), 'dd MMMM yyyy')}
${formatDateTo_ddMMMMyyyy(declaration.father.birthDate)}
`
)
).toBeVisible()
Expand Down Expand Up @@ -319,10 +325,9 @@ test.describe.serial(' Correct record - 2', () => {

await expect(
page.locator('#informant-content #Date').getByRole('deletion')
).toHaveText(
format(parseISO(declaration.informant.birthDate), 'dd MMMM yyyy'),
{ ignoreCase: true }
)
).toHaveText(formatDateTo_ddMMMMyyyy(declaration.informant.birthDate), {
ignoreCase: true
})

await expect(
page
Expand Down Expand Up @@ -881,8 +886,8 @@ test.describe.serial(' Correct record - 2', () => {
await expect(
page.getByText(
'Date of birth (informant)' +
format(parseISO(declaration.informant.birthDate), 'dd MMMM yyyy') +
format(parseISO(updatedInformantDetails.birthDate), 'dd MMMM yyyy')
formatDateTo_ddMMMMyyyy(declaration.informant.birthDate) +
formatDateTo_ddMMMMyyyy(updatedInformantDetails.birthDate)
)
).toBeVisible()

Expand Down Expand Up @@ -1067,8 +1072,8 @@ test.describe.serial(' Correct record - 2', () => {
await expect(
page.getByText(
'Date of birth (informant)' +
format(parseISO(declaration.informant.birthDate), 'dd MMMM yyyy') +
format(parseISO(updatedInformantDetails.birthDate), 'dd MMMM yyyy')
formatDateTo_ddMMMMyyyy(declaration.informant.birthDate) +
formatDateTo_ddMMMMyyyy(updatedInformantDetails.birthDate)
)
).toBeVisible()

Expand Down Expand Up @@ -1313,8 +1318,8 @@ test.describe.serial(' Correct record - 2', () => {
await expect(
page.getByText(
'Date of birth (informant)' +
format(parseISO(declaration.informant.birthDate), 'yyyy-MM-dd') +
format(parseISO(updatedInformantDetails.birthDate), 'yyyy-MM-dd')
formatDateTo_yyyyMMdd(declaration.informant.birthDate) +
formatDateTo_yyyyMMdd(updatedInformantDetails.birthDate)
)
).toBeVisible()

Expand Down
28 changes: 15 additions & 13 deletions e2e/testcases/correction-birth/correct-birth-record-3.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { expect, test, type Page } from '@playwright/test'
import { createPIN, getToken, login } from '../../helpers'
import {
createPIN,
formatDateTo_ddMMMMyyyy,
getToken,
login
} from '../../helpers'
import faker from '@faker-js/faker'
import {
ConvertEnumsToStrings,
Expand Down Expand Up @@ -185,7 +190,7 @@ test.describe.serial(' Correct record - 3', () => {
await expect(
page.getByText(
`Date of Birth:
${format(parseISO(declaration.child.birthDate), 'dd MMMM yyyy')}
${formatDateTo_ddMMMMyyyy(declaration.child.birthDate)}
`
)
).toBeVisible()
Expand Down Expand Up @@ -299,17 +304,14 @@ test.describe.serial(' Correct record - 3', () => {

await expect(
page.locator('#mother-content #Date').getByRole('deletion')
).toHaveText(
format(parseISO(declaration.mother.birthDate), 'dd MMMM yyyy'),
{ ignoreCase: true }
)
).toHaveText(formatDateTo_ddMMMMyyyy(declaration.mother.birthDate), {
ignoreCase: true
})

await expect(
page
.locator('#mother-content #Date')
.getByText(
format(parseISO(updatedMotherDetails.birthDate), 'dd MMMM yyyy')
)
.getByText(formatDateTo_ddMMMMyyyy(updatedMotherDetails.birthDate))
).toBeVisible()
})

Expand Down Expand Up @@ -891,8 +893,8 @@ test.describe.serial(' Correct record - 3', () => {
await expect(
page.getByText(
'Date of birth (mother)' +
format(parseISO(declaration.mother.birthDate), 'dd MMMM yyyy') +
format(parseISO(updatedMotherDetails.birthDate), 'dd MMMM yyyy')
formatDateTo_ddMMMMyyyy(declaration.mother.birthDate) +
formatDateTo_ddMMMMyyyy(updatedMotherDetails.birthDate)
)
).toBeVisible()

Expand Down Expand Up @@ -1083,8 +1085,8 @@ test.describe.serial(' Correct record - 3', () => {
await expect(
page.getByText(
'Date of birth (mother)' +
format(parseISO(declaration.mother.birthDate), 'dd MMMM yyyy') +
format(parseISO(updatedMotherDetails.birthDate), 'dd MMMM yyyy')
formatDateTo_ddMMMMyyyy(declaration.mother.birthDate) +
formatDateTo_ddMMMMyyyy(updatedMotherDetails.birthDate)
)
).toBeVisible()

Expand Down
28 changes: 16 additions & 12 deletions e2e/testcases/correction-birth/correct-birth-record-4.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { expect, test, type Page } from '@playwright/test'
import { createPIN, getToken, login, uploadImage } from '../../helpers'
import {
createPIN,
formatDateTo_ddMMMMyyyy,
formatDateTo_yyyyMMdd,
getToken,
login,
uploadImage
} from '../../helpers'
import faker from '@faker-js/faker'
import {
ConvertEnumsToStrings,
Expand Down Expand Up @@ -231,17 +238,14 @@ test.describe.serial(' Correct record - 4', () => {

await expect(
page.locator('#father-content #Date').getByRole('deletion')
).toHaveText(
format(parseISO(declaration.father.birthDate), 'dd MMMM yyyy'),
{ ignoreCase: true }
)
).toHaveText(formatDateTo_ddMMMMyyyy(declaration.father.birthDate), {
ignoreCase: true
})

await expect(
page
.locator('#father-content #Date')
.getByText(
format(parseISO(updatedFatherDetails.birthDate), 'dd MMMM yyyy')
)
.getByText(formatDateTo_ddMMMMyyyy(updatedFatherDetails.birthDate))
).toBeVisible()
})

Expand Down Expand Up @@ -761,8 +765,8 @@ test.describe.serial(' Correct record - 4', () => {
await expect(
page.getByText(
'Date of birth (father)' +
format(parseISO(declaration.father.birthDate), 'dd MMMM yyyy') +
format(parseISO(updatedFatherDetails.birthDate), 'dd MMMM yyyy')
formatDateTo_ddMMMMyyyy(declaration.father.birthDate) +
formatDateTo_ddMMMMyyyy(updatedFatherDetails.birthDate)
)
).toBeVisible()

Expand Down Expand Up @@ -957,8 +961,8 @@ test.describe.serial(' Correct record - 4', () => {
await expect(
page.getByText(
'Date of birth (father)' +
format(parseISO(declaration.father.birthDate), 'yyyy-MM-dd') +
format(parseISO(updatedFatherDetails.birthDate), 'yyyy-MM-dd')
formatDateTo_yyyyMMdd(declaration.father.birthDate) +
formatDateTo_yyyyMMdd(updatedFatherDetails.birthDate)
)
).toBeVisible()

Expand Down
22 changes: 12 additions & 10 deletions e2e/testcases/correction-birth/correct-birth-record-5.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { expect, test, type Page } from '@playwright/test'
import { createPIN, getToken, login } from '../../helpers'
import {
createPIN,
formatDateTo_ddMMMMyyyy,
getToken,
login
} from '../../helpers'
import faker from '@faker-js/faker'
import {
BirthDetails,
Expand Down Expand Up @@ -259,17 +264,14 @@ test.describe.serial(' Correct record - 5', () => {

await expect(
page.locator('#child-content #Date').getByRole('deletion')
).toHaveText(
format(parseISO(declaration.child.birthDate), 'dd MMMM yyyy'),
{ ignoreCase: true }
)
).toHaveText(formatDateTo_ddMMMMyyyy(declaration.child.birthDate), {
ignoreCase: true
})

await expect(
page
.locator('#child-content #Date')
.getByText(
format(parseISO(updatedChildDetails.birthDate), 'dd MMMM yyyy')
)
.getByText(formatDateTo_ddMMMMyyyy(updatedChildDetails.birthDate))
).toBeVisible()
})

Expand Down Expand Up @@ -632,8 +634,8 @@ test.describe.serial(' Correct record - 5', () => {
await expect(
page.getByText(
'Date of birth (Child)' +
format(parseISO(declaration.child.birthDate), 'dd MMMM yyyy') +
format(parseISO(updatedChildDetails.birthDate), 'dd MMMM yyyy')
formatDateTo_ddMMMMyyyy(declaration.child.birthDate) +
formatDateTo_ddMMMMyyyy(updatedChildDetails.birthDate)
)
).toBeVisible()

Expand Down
22 changes: 12 additions & 10 deletions e2e/testcases/correction-birth/correct-birth-record-6.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { expect, test, type Page } from '@playwright/test'
import { createPIN, getToken, login } from '../../helpers'
import {
createPIN,
formatDateTo_ddMMMMyyyy,
getToken,
login
} from '../../helpers'
import faker from '@faker-js/faker'
import {
ConvertEnumsToStrings,
Expand Down Expand Up @@ -300,17 +305,14 @@ test.describe.serial(' Correct record - 6', () => {

await expect(
page.locator('#informant-content #Date').getByRole('deletion')
).toHaveText(
format(parseISO(declaration.informant.birthDate), 'dd MMMM yyyy'),
{ ignoreCase: true }
)
).toHaveText(formatDateTo_ddMMMMyyyy(declaration.informant.birthDate), {
ignoreCase: true
})

await expect(
page
.locator('#informant-content #Date')
.getByText(
format(parseISO(updatedInformantDetails.birthDate), 'dd MMMM yyyy')
)
.getByText(formatDateTo_ddMMMMyyyy(updatedInformantDetails.birthDate))
).toBeVisible()
})

Expand Down Expand Up @@ -712,8 +714,8 @@ test.describe.serial(' Correct record - 6', () => {
await expect(
page.getByText(
'Date of birth (informant)' +
format(parseISO(declaration.informant.birthDate), 'dd MMMM yyyy') +
format(parseISO(updatedInformantDetails.birthDate), 'dd MMMM yyyy')
formatDateTo_ddMMMMyyyy(declaration.informant.birthDate) +
formatDateTo_ddMMMMyyyy(updatedInformantDetails.birthDate)
)
).toBeVisible()

Expand Down
Loading

0 comments on commit 0a2997a

Please sign in to comment.