Skip to content

Commit 0dc7308

Browse files
authored
Merge pull request #1845 from opencrvs/ocrvs-10890
Action conditionals
2 parents 23dca4c + 7f9b9c7 commit 0dc7308

File tree

6 files changed

+322
-226
lines changed

6 files changed

+322
-226
lines changed

e2e/testcases/action-menu/action-menu-options.spec.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ async function getActionMenuOptions(page: Page, declaration: Declaration) {
1616
return textContents
1717
}
1818

19-
// @TODO: these tests are disabled for now, as our work in custom actions temporarily affects these in a manner which is not intended
20-
// These will be brought back in to use after the custom actions are hidden on the action menu correctly.
21-
test.describe.skip('Action menu options', () => {
19+
test.describe('Action menu options', () => {
2220
let page: Page
2321

2422
test.beforeEach(async ({ browser }) => {
@@ -53,13 +51,7 @@ test.describe.skip('Action menu options', () => {
5351
await login(page, CREDENTIALS.LOCAL_REGISTRAR)
5452
await page.getByRole('button', { name: 'Ready for review' }).click()
5553
const options = await getActionMenuOptions(page, declaration)
56-
expect(options).toStrictEqual([
57-
'Assign',
58-
'Register',
59-
'Archive',
60-
'Reject',
61-
'Approve'
62-
])
54+
expect(options).toStrictEqual(['Assign', 'Register', 'Archive', 'Reject'])
6355
})
6456
})
6557

@@ -83,8 +75,7 @@ test.describe.skip('Action menu options', () => {
8375
'Unassign',
8476
'Register',
8577
'Archive',
86-
'Reject',
87-
'Approve'
78+
'Reject'
8879
])
8980
})
9081
})
@@ -105,12 +96,7 @@ test.describe.skip('Action menu options', () => {
10596
await login(page, CREDENTIALS.LOCAL_REGISTRAR)
10697
await page.getByRole('button', { name: 'Ready to print' }).click()
10798
const options = await getActionMenuOptions(page, declaration)
108-
expect(options).toStrictEqual([
109-
'Assign',
110-
'Print',
111-
'Correct record',
112-
'Approve'
113-
])
99+
expect(options).toStrictEqual(['Assign', 'Print', 'Correct record'])
114100
})
115101
})
116102
})

e2e/testcases/custom-actions-and-flags/approval-of-late-birth-registration.spec.ts

Lines changed: 144 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { ensureAssigned, ensureOutboxIsEmpty, selectAction } from '../../utils'
1414
test.describe.serial('Approval of late birth registration', () => {
1515
let page: Page
1616
const childName = {
17-
firstNames: faker.person.firstName('male'),
18-
familyName: faker.person.lastName('male')
17+
firstNames: faker.person.firstName('female'),
18+
familyName: faker.person.lastName('female')
1919
}
2020

2121
const childNameFormatted = formatName(childName)
@@ -41,7 +41,7 @@ test.describe.serial('Approval of late birth registration', () => {
4141
await page.locator('#firstname').fill(childName.firstNames)
4242
await page.locator('#surname').fill(childName.familyName)
4343
await page.locator('#child____gender').click()
44-
await page.getByText('Male', { exact: true }).click()
44+
await page.getByText('Female', { exact: true }).click()
4545

4646
await page.getByPlaceholder('dd').fill('12')
4747
await page.getByPlaceholder('mm').fill('05')
@@ -137,7 +137,6 @@ test.describe.serial('Approval of late birth registration', () => {
137137
).toBeVisible()
138138
})
139139

140-
// @TODO: This test should be added after action conditionals are implemented
141140
test.skip('RA should not have the option to Approve', async () => {
142141
await page.getByRole('button', { name: 'Action', exact: true }).click()
143142
await expect(page.getByText('Approve', { exact: true })).not.toBeVisible()
@@ -151,6 +150,15 @@ test.describe.serial('Approval of late birth registration', () => {
151150
await page.getByRole('button', { name: childNameFormatted }).click()
152151
})
153152

153+
test('Unassign', async () => {
154+
await page.getByRole('button', { name: 'Action', exact: true }).click()
155+
await page.getByText('Unassign', { exact: true }).click()
156+
await page.getByRole('button', { name: 'Unassign', exact: true }).click()
157+
await expect(
158+
page.getByText('Not assigned', { exact: true })
159+
).toBeVisible()
160+
})
161+
154162
test('Approve action should be disabled before assignment', async () => {
155163
await page.getByRole('button', { name: 'Action', exact: true }).click()
156164
const approveButton = page.getByText('Approve', { exact: true })
@@ -203,6 +211,11 @@ test.describe.serial('Approval of late birth registration', () => {
203211
).not.toBeVisible()
204212
})
205213

214+
test("Validate that the 'Approve' action is no longer available", async () => {
215+
await page.getByRole('button', { name: 'Action', exact: true }).click()
216+
await expect(page.getByText('Approve', { exact: true })).not.toBeVisible()
217+
})
218+
206219
test('Validate that action and form field value appearing in audit trail', async () => {
207220
await switchEventTab(page, 'Audit')
208221
await page.getByRole('button', { name: 'Approved', exact: true }).click()
@@ -212,3 +225,130 @@ test.describe.serial('Approval of late birth registration', () => {
212225
})
213226
})
214227
})
228+
229+
test.describe('Birth with non-late registration will not have flag or Approve-action available', () => {
230+
let page: Page
231+
const childName = {
232+
firstNames: faker.person.firstName('female'),
233+
familyName: faker.person.lastName('female')
234+
}
235+
236+
const childNameFormatted = formatName(childName)
237+
238+
test.beforeAll(async ({ browser }) => {
239+
page = await browser.newPage()
240+
})
241+
242+
test.afterAll(async () => {
243+
await page.close()
244+
})
245+
246+
test.describe.serial('Declaration started by FA', async () => {
247+
test.beforeAll(async () => {
248+
await login(page, CREDENTIALS.FIELD_AGENT)
249+
await page.click('#header-new-event')
250+
await page.getByLabel('Birth').click()
251+
await page.getByRole('button', { name: 'Continue' }).click()
252+
await page.getByRole('button', { name: 'Continue' }).click()
253+
})
254+
255+
test('Fill child details with birth date from over a year ago', async () => {
256+
await page.locator('#firstname').fill(childName.firstNames)
257+
await page.locator('#surname').fill(childName.familyName)
258+
await page.locator('#child____gender').click()
259+
await page.getByText('Female', { exact: true }).click()
260+
261+
await page.getByPlaceholder('dd').fill('12')
262+
await page.getByPlaceholder('mm').fill('05')
263+
await page.getByPlaceholder('yyyy').fill('2019')
264+
await page.locator('#child____reason').fill('Late registration reason')
265+
266+
await page.locator('#child____placeOfBirth').click()
267+
await page.getByText('Health Institution', { exact: true }).click()
268+
await page
269+
.locator('#child____birthLocation')
270+
.fill('Golden Valley Rural Health Centre'.slice(0, 3))
271+
await page.getByText('Golden Valley Rural Health Centre').click()
272+
273+
await continueForm(page)
274+
})
275+
276+
test('Fill informant details', async () => {
277+
await page.locator('#informant____relation').click()
278+
await page.getByText('Mother', { exact: true }).click()
279+
280+
await page.locator('#informant____email').fill('[email protected]')
281+
282+
await continueForm(page)
283+
})
284+
285+
test("Fill mother's details", async () => {
286+
await page.locator('#firstname').fill(faker.person.firstName('female'))
287+
await page.locator('#surname').fill(faker.person.lastName('female'))
288+
289+
await page.getByPlaceholder('dd').fill('25')
290+
await page.getByPlaceholder('mm').fill('11')
291+
await page.getByPlaceholder('yyyy').fill('2025')
292+
293+
await page.locator('#mother____idType').click()
294+
await page.getByText('None', { exact: true }).click()
295+
296+
await continueForm(page)
297+
})
298+
299+
test("Fill father's details", async () => {
300+
await page.locator('#firstname').fill(faker.person.firstName('male'))
301+
await page.locator('#surname').fill(faker.person.lastName('male'))
302+
303+
await page.getByPlaceholder('dd').fill('12')
304+
await page.getByPlaceholder('mm').fill('05')
305+
await page.getByPlaceholder('yyyy').fill('1985')
306+
307+
await page.locator('#father____idType').click()
308+
await page.getByText('None', { exact: true }).click()
309+
310+
await page.locator('#father____nationality').click()
311+
await page.getByText('Gabon', { exact: true }).click()
312+
313+
await page.locator('#father____addressSameAs_YES').click()
314+
315+
await page.getByRole('button', { name: 'Continue' }).click()
316+
})
317+
318+
test('Go to review', async () => {
319+
await goToSection(page, 'review')
320+
})
321+
322+
test('Fill up informant comment & signature', async () => {
323+
await page.locator('#review____comment').fill(faker.lorem.sentence())
324+
await page.getByRole('button', { name: 'Sign', exact: true }).click()
325+
await drawSignature(page, 'review____signature_canvas_element', false)
326+
await page
327+
.locator('#review____signature_modal')
328+
.getByRole('button', { name: 'Apply' })
329+
.click()
330+
})
331+
332+
test('Send for review', async () => {
333+
await page.getByRole('button', { name: 'Send for review' }).click()
334+
await page.getByRole('button', { name: 'Confirm' }).click()
335+
await ensureOutboxIsEmpty(page)
336+
})
337+
338+
test('Navigate to the record', async () => {
339+
await page.getByText('Sent for review').click()
340+
await page.getByRole('button', { name: childNameFormatted }).click()
341+
})
342+
343+
test("Record should not have the 'Approval required for late registration' -flag", async () => {
344+
await expect(
345+
page.getByText('Approval required for late registration')
346+
).not.toBeVisible()
347+
})
348+
349+
test('Record should not have the "Approve"-action available', async () => {
350+
await page.getByRole('button', { name: 'Action', exact: true }).click()
351+
await expect(page.getByText('Approve', { exact: true })).not.toBeVisible()
352+
})
353+
})
354+
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"@hapi/hapi": "^20.0.1",
8181
"@hapi/inert": "^6.0.3",
8282
"@opencrvs/mosip": "1.9.0-beta.7",
83-
"@opencrvs/toolkit": "1.9.0-rc.8476ac9",
83+
"@opencrvs/toolkit": "1.9.0-rc.8a42cc8",
8484
"@types/chalk": "^2.2.0",
8585
"@types/code": "^4.0.3",
8686
"@types/csv2json": "^1.4.0",

src/form/tennis-club-membership.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -892,15 +892,6 @@ export const tennisClubMembershipEvent = defineConfig({
892892
},
893893
review: TENNIS_CLUB_DECLARATION_REVIEW
894894
},
895-
{
896-
type: ActionType.DELETE,
897-
label: {
898-
defaultMessage: 'Delete draft',
899-
description:
900-
'This is shown as the action name anywhere the user can trigger the action from',
901-
id: 'event.tennis-club-membership.action.delete.label'
902-
}
903-
},
904895
{
905896
type: ActionType.VALIDATE,
906897
label: {

src/form/v2/birth/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ConditionalType,
1515
defineConfig,
1616
field,
17+
flag,
1718
not
1819
} from '@opencrvs/toolkit/events'
1920
import {
@@ -228,12 +229,6 @@ export const birthEvent = defineConfig({
228229
'This is shown as the action name anywhere the user can trigger the action from',
229230
id: 'event.birth.action.approve.label'
230231
},
231-
supportingCopy: {
232-
defaultMessage:
233-
'This birth has been registered late. You are now approving it for further validation and registration.',
234-
description: 'This is the confirmation text for the approve action',
235-
id: 'event.birth.action.approve.confirmationText'
236-
},
237232
form: [
238233
{
239234
id: 'notes',
@@ -249,11 +244,23 @@ export const birthEvent = defineConfig({
249244
flags: [
250245
{ id: 'approval-required-for-late-registration', operation: 'remove' }
251246
],
247+
conditionals: [
248+
{
249+
type: ConditionalType.SHOW,
250+
conditional: flag('approval-required-for-late-registration')
251+
}
252+
],
252253
auditHistoryLabel: {
253254
defaultMessage: 'Approved',
254255
description:
255256
'The label to show in audit history for the approve action',
256257
id: 'event.birth.action.approve.audit-history-label'
258+
},
259+
supportingCopy: {
260+
defaultMessage:
261+
'This birth has been registered late. You are now approving it for further validation and registration.',
262+
description: 'This is the confirmation text for the approve action',
263+
id: 'event.birth.action.approve.confirmationText'
257264
}
258265
},
259266
{

0 commit comments

Comments
 (0)