Skip to content

Commit 4864e9e

Browse files
committed
chore: add tests for conditionals
1 parent 93945a0 commit 4864e9e

File tree

4 files changed

+208
-3
lines changed

4 files changed

+208
-3
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import { test, expect, type Page } from '@playwright/test'
2+
import {
3+
continueForm,
4+
formatName,
5+
getRandomDate,
6+
loginToV2
7+
} from '../../helpers'
8+
import { faker } from '@faker-js/faker'
9+
import { CREDENTIALS } from '../../constants'
10+
11+
import { ensureOutboxIsEmpty, selectAction } from '../../v2-utils'
12+
13+
test.describe.serial('1. User conditional form flow', () => {
14+
let page: Page
15+
const declaration = {
16+
applicant: {
17+
name: {
18+
firstName: faker.person.firstName('male'),
19+
middleName: faker.person.firstName('male'),
20+
familyName: faker.person.lastName('male')
21+
},
22+
gender: 'Male',
23+
birthDate: getRandomDate(0, 200)
24+
},
25+
recommender: {
26+
name: {
27+
firstName: faker.person.firstName('male'),
28+
familyName: faker.person.lastName('male')
29+
},
30+
id: '123456789'
31+
}
32+
}
33+
test.beforeAll(async ({ browser }) => {
34+
page = await browser.newPage()
35+
})
36+
37+
test.afterAll(async () => {
38+
await page.close()
39+
})
40+
41+
test.describe('1.1 Declaration started by FA', async () => {
42+
test.beforeAll(async () => {
43+
await loginToV2(page, CREDENTIALS.FIELD_AGENT)
44+
await page.click('#header-new-event')
45+
await page.getByLabel('Tennis club membership application').click()
46+
await page.getByRole('button', { name: 'Continue' }).click()
47+
})
48+
49+
test('1.1.1 Fill applicant details', async () => {
50+
await page
51+
.locator('#firstname')
52+
.fill(declaration.applicant.name.firstName)
53+
await page.locator('#surname').fill(declaration.applicant.name.familyName)
54+
55+
await page.getByPlaceholder('dd').fill(declaration.applicant.birthDate.dd)
56+
await page.getByPlaceholder('mm').fill(declaration.applicant.birthDate.mm)
57+
await page
58+
.getByPlaceholder('yyyy')
59+
.fill(declaration.applicant.birthDate.yyyy)
60+
61+
await page
62+
.getByLabel('Field shown when field agent is submitting application.')
63+
.click()
64+
65+
await continueForm(page)
66+
})
67+
68+
test('1.1.2 Fill senior pass details', async () => {
69+
await page.locator('#senior-pass____id').fill('123123')
70+
71+
await continueForm(page)
72+
})
73+
74+
test('1.1.3 Fill recommender details', async () => {
75+
await page
76+
.locator('#firstname')
77+
.fill(declaration.applicant.name.firstName)
78+
await page.locator('#surname').fill(declaration.applicant.name.familyName)
79+
await page.locator('#recommender____id').fill(declaration.recommender.id)
80+
81+
await continueForm(page)
82+
})
83+
84+
test('1.1.4 Review details', async () => {
85+
await page
86+
.getByText('Field shown when field agent is submitting application.')
87+
.isVisible()
88+
89+
await expect(
90+
page.getByTestId('row-value-applicant.isRecommendedByFieldAgent')
91+
).toHaveText('Yes')
92+
})
93+
94+
test('1.1.5 Send for review', async () => {
95+
await page.getByRole('button', { name: 'Send for review' }).click()
96+
await expect(page.getByText('Send for review?')).toBeVisible()
97+
await page.getByRole('button', { name: 'Confirm' }).click()
98+
99+
await ensureOutboxIsEmpty(page)
100+
101+
await page.getByText('Sent for review').click()
102+
await expect(
103+
page.getByRole('button', {
104+
name: formatName(declaration.applicant.name)
105+
})
106+
).toBeVisible()
107+
})
108+
109+
test('1.1.6 Navigate to the declaration "read-only" page', async () => {
110+
await page
111+
.getByRole('button', {
112+
name: formatName(declaration.applicant.name)
113+
})
114+
.click()
115+
116+
await selectAction(page, 'View')
117+
118+
await expect(
119+
page.getByText(
120+
'Field shown when field agent is submitting application.'
121+
)
122+
).toBeVisible()
123+
})
124+
})
125+
126+
test.describe('1.2 Declaration Review by RA', async () => {
127+
test('1.2.1 Navigate to the declaration "read-only" page', async () => {
128+
await loginToV2(page, CREDENTIALS.REGISTRATION_AGENT)
129+
await page.getByText('Ready for review').click()
130+
await page
131+
.getByRole('button', {
132+
name: formatName(declaration.applicant.name)
133+
})
134+
.click()
135+
136+
await selectAction(page, 'View')
137+
138+
await expect(
139+
page.getByText(
140+
'Field shown when field agent is submitting application.'
141+
)
142+
).not.toBeVisible()
143+
})
144+
145+
test('1.2.1 Navigate to the declaration "read-only" page', async () => {
146+
await loginToV2(page, CREDENTIALS.REGISTRATION_AGENT)
147+
await page.getByText('Ready for review').click()
148+
await page
149+
.getByRole('button', {
150+
name: formatName(declaration.applicant.name)
151+
})
152+
.click()
153+
154+
await selectAction(page, 'View')
155+
156+
await expect(
157+
page.getByText(
158+
'Field shown when field agent is submitting application.'
159+
)
160+
).not.toBeVisible()
161+
162+
await page.getByTestId('exit-button').click()
163+
})
164+
165+
test('1.2.2 Navigate to the declaration "Review" page', async () => {
166+
await page.getByText('Ready for review').click()
167+
await page
168+
.getByRole('button', {
169+
name: formatName(declaration.applicant.name)
170+
})
171+
.click()
172+
173+
await selectAction(page, 'Review')
174+
175+
await expect(
176+
page.getByText(
177+
'Field shown when field agent is submitting application.'
178+
)
179+
).not.toBeVisible()
180+
})
181+
})
182+
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"@hapi/hapi": "^20.0.1",
8585
"@hapi/inert": "^6.0.3",
8686
"@opencrvs/mosip": "^1.8.0",
87-
"@opencrvs/toolkit": "1.8.1-rc.fa0e315",
87+
"@opencrvs/toolkit": "1.8.1-rc.4cfe084",
8888
"@types/chalk": "^2.2.0",
8989
"@types/code": "^4.0.3",
9090
"@types/csv2json": "^1.4.0",

src/api/notification/informantNotification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async function getNotificationParams(
9898
const locations = await getLocations(token)
9999

100100
const declaration = deepMerge(
101-
aggregateActionDeclarations(event, getEventConfig(event.type)),
101+
aggregateActionDeclarations(event),
102102
pendingAction.declaration
103103
)
104104

src/form/tennis-club-membership.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import {
1919
FieldType,
2020
PageTypes,
2121
field,
22-
event
22+
event,
23+
user,
24+
or
2325
} from '@opencrvs/toolkit/events'
2426
import { Event } from './types/types'
2527
import { MAX_NAME_LENGTH } from './v2/birth/validators'
@@ -148,6 +150,27 @@ const TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
148150
description: 'This is the label for the field',
149151
id: 'event.tennis-club-membership.action.declare.form.section.who.field.image.label'
150152
}
153+
},
154+
{
155+
id: 'applicant.isRecommendedByFieldAgent',
156+
type: FieldType.CHECKBOX,
157+
analytics: true,
158+
required: false,
159+
label: {
160+
defaultMessage:
161+
'Field shown when field agent is submitting application.',
162+
description: 'This is the label for the field',
163+
id: 'event.tennis-club-membership.action.declare.form.section.who.field.isRecommendedByFieldAgent.label'
164+
},
165+
conditionals: [
166+
{
167+
type: ConditionalType.SHOW,
168+
conditional: or(
169+
user.hasRole('SOCIAL_WORKER'),
170+
user.hasRole('FIELD_AGENT')
171+
)
172+
}
173+
]
151174
}
152175
]
153176
},

0 commit comments

Comments
 (0)