Skip to content

Commit

Permalink
update tests (standard config): pregnancy
Browse files Browse the repository at this point in the history
  • Loading branch information
tatilepizs committed Dec 11, 2023
1 parent 7b8e54b commit 45efba6
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 107 deletions.
43 changes: 30 additions & 13 deletions tests/e2e/cht-form/standard/pregnancy.wdio-spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mockConfig = require('../mock-config');
const genericForm = require('@page-objects/default/enketo/generic-form.wdio.page');
const pregnancyForm = require('@page-objects/standard/enketo/pregnancy.wdio.page');
const commonEnketoPage = require('@page-objects/default/enketo/common-enketo.wdio.page');

describe('cht-form web component - Pregnancy Registration Form', () => {

Expand All @@ -27,26 +28,42 @@ describe('cht-form web component - Pregnancy Registration Form', () => {
'by the health facility. This is a high-risk pregnancy. You will receive ANC notifications for this patient. ' +
`Please follow up with the nurse to identify the patient. Thank you! ${note}`;

await pregnancyForm.selectKnowLMP();
await pregnancyForm.selectAproxLMP(pregnancyForm.APROX_LMP.b7To8Months);
await commonEnketoPage.selectRadioButton('Does the woman know the date of the last cycle?', 'No');
await commonEnketoPage.selectRadioButton('Approximate start date of last cycle', 'between 7 to 8 months ago');

expect(await (await pregnancyForm.getEstDeliveryDate()).isDisplayed()).to.be.true;
expect(await commonEnketoPage.isElementDisplayed('label', 'Estimated delivery date is')).to.be.true;

await genericForm.nextPage();
const riskFactors = await pregnancyForm.selectAllRiskFactors();
await pregnancyForm.selectAllRiskFactors();
await genericForm.nextPage();
const dangerSigns = await pregnancyForm.selectAllDangerSigns();
await pregnancyForm.selectAllDangerSigns();
await genericForm.nextPage();
await pregnancyForm.setNote(note);
await commonEnketoPage.setTextareaValue('You can add a personal note to the SMS here:', note);
await genericForm.nextPage();

const summaryDetails = await pregnancyForm.getSummaryDetails();
expect(summaryDetails.patientName).to.equal('Cleo');
expect(summaryDetails.patientId).to.equal('98765');
expect(summaryDetails.countRiskFactors).to.equal(riskFactors.length);
expect(summaryDetails.countDangerSigns).to.equal(dangerSigns.length);
expect(summaryDetails.followUpSmsNote1).to.equal('The following will be sent as a SMS to Luna +50689252525');
expect(summaryDetails.followUpSmsNote2).to.equal(followUpSms);
const summaryTexts = [
'Cleo', //patient name
'98765', //patient id
'More than 4 children',
'Last baby born less than 1 year before',
'Had previous miscarriages or previous difficulties in childbirth',
'One of the following conditions: heart conditions, asthma, high blood pressure, known diabetes',
'HIV positive',
'Pain or cramping in abdomen',
'Bleeding or fluid leaking from vagina or vaginal discharge with bad odour',
'Severe nausea or vomiting',
'Fever of 38 degrees or higher',
'Severe headache or new, blurry vision problems',
'Sudden weight gain or severe swelling of feet, ankles, face, or hands',
'Less movement and kicking from the baby (after week 20 of pregnancy)',
'Blood in the urine or painful, burning urination',
'Diarrhea that doesn\'t go away',
];

await commonEnketoPage.validateSummaryReport(summaryTexts);
expect(await commonEnketoPage.isElementDisplayed('label',
'The following will be sent as a SMS to Luna +50689252525')).to.be.true;
expect(await commonEnketoPage.isElementDisplayed('label', followUpSms)).to.be.true;

const data = await mockConfig.submitForm();
const jsonObj = data[0].fields;
Expand Down
41 changes: 29 additions & 12 deletions tests/e2e/standard/enketo/pregnancy.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const reportsPage = require('@page-objects/default/reports/reports.wdio.page');
const analyticsPage = require('@page-objects/default/analytics/analytics.wdio.page');
const genericForm = require('@page-objects/default/enketo/generic-form.wdio.page');
const pregnancyForm = require('@page-objects/standard/enketo/pregnancy.wdio.page');
const commonEnketoPage = require('@page-objects/default/enketo/common-enketo.wdio.page');
const { TARGET_MET_COLOR } = analyticsPage;

describe('New pregnancy', () => {
Expand Down Expand Up @@ -55,25 +56,41 @@ describe('New pregnancy', () => {
const medicIDW1 = await contactPage.contactPageDefault.getContactMedicID();
await commonPage.openFastActionReport('pregnancy');

await pregnancyForm.selectKnowLMP();
await pregnancyForm.selectAproxLMP(pregnancyForm.APROX_LMP.b7To8Months);
await commonEnketoPage.selectRadioButton('Does the woman know the date of the last cycle?', 'No');
await commonEnketoPage.selectRadioButton('Approximate start date of last cycle', 'between 7 to 8 months ago');

expect(await (await pregnancyForm.getEstDeliveryDate()).isDisplayed()).to.be.true;
expect(await commonEnketoPage.isElementDisplayed('label', 'Estimated delivery date is')).to.be.true;

await genericForm.nextPage();
const riskFactors = await pregnancyForm.selectAllRiskFactors();
await pregnancyForm.selectAllRiskFactors();
await genericForm.nextPage();
const dangerSigns = await pregnancyForm.selectAllDangerSigns();
await pregnancyForm.selectAllDangerSigns();
await genericForm.nextPage();
await pregnancyForm.setNote(note);
await commonEnketoPage.setTextareaValue('You can add a personal note to the SMS here:', note);
await genericForm.nextPage();

const summaryDetails = await pregnancyForm.getSummaryDetails();
expect(summaryDetails.countRiskFactors).to.equal(riskFactors.length);
expect(summaryDetails.countDangerSigns).to.equal(dangerSigns.length);
expect(summaryDetails.followUpSmsNote2).to.include(pregnantWoman1);
expect(summaryDetails.followUpSmsNote2).to.include(medicIDW1);
expect(summaryDetails.followUpSmsNote2).to.include(note);
const summaryTexts = [
'More than 4 children',
'Last baby born less than 1 year before',
'Had previous miscarriages or previous difficulties in childbirth',
'One of the following conditions: heart conditions, asthma, high blood pressure, known diabetes',
'HIV positive',
'Pain or cramping in abdomen',
'Bleeding or fluid leaking from vagina or vaginal discharge with bad odour',
'Severe nausea or vomiting',
'Fever of 38 degrees or higher',
'Severe headache or new, blurry vision problems',
'Sudden weight gain or severe swelling of feet, ankles, face, or hands',
'Less movement and kicking from the baby (after week 20 of pregnancy)',
'Blood in the urine or painful, burning urination',
'Diarrhea that doesn\'t go away',
];

await commonEnketoPage.validateSummaryReport(summaryTexts);
expect(await commonEnketoPage.isElementDisplayed('label',
`Hi , a pregnancy with danger signs for ${pregnantWoman1} (${medicIDW1}) has been registered ` +
`by the health facility. This is a high-risk pregnancy. You will receive ANC notifications for this patient. ` +
`Please follow up with the nurse to identify the patient. Thank you! ${note}`)).to.be.true;

await genericForm.submitForm();
await commonPage.waitForPageLoaded();
Expand Down
106 changes: 24 additions & 82 deletions tests/page-objects/standard/enketo/pregnancy.wdio.page.js
Original file line number Diff line number Diff line change
@@ -1,108 +1,50 @@
const genericForm = require('@page-objects/default/enketo/generic-form.wdio.page');
const commonPage = require('@page-objects/default/common/common.wdio.page');
const enketoCommonPage = require('@page-objects/standard/enketo/enketo.wdio.page.js');

const APROX_LMP = { up2Months: 61, up3Months: 91, up4Months: 122, b5To6Months: 183, b7To8Months: 244 };

const FORM = enketoCommonPage.form('pregnancy');
const { ACTIVE } = enketoCommonPage;

const knowLMP = (value) => $(`${FORM} input[name="/pregnancy/group_lmp/g_lmp_method"][value="${value}"]`);
const aproxLMP = (value) => $(`${FORM} input[name="/pregnancy/group_lmp/g_lmp_approx"][value="${value}"]`);
const getEstDeliveryDate = () => {
return $(`${FORM} span[data-itext-id="/pregnancy/group_lmp/g_display_edd:label"]${ACTIVE}`);
};
const risksFac = () => $$(`${FORM} [name="/pregnancy/group_risk_factors"] label:not(:first-child) > [type="checkbox"]`);
const dangerSigns = () => $$(`${FORM} input[name="/pregnancy/group_danger_signs/g_danger_signs"]`);
const smsNote = () => $(`${FORM} ${enketoCommonPage.smsNote('pregnancy')}`);
const patientNameSummary = () => {
const nameSum = enketoCommonPage.patientNameSummary('pregnancy');
return $(`${FORM} span[data-itext-id="/pregnancy/group_review/r_pregnancy_details:label"]${ACTIVE} ${nameSum}`);
};
const patientIdSummary = () => {
const idSum = enketoCommonPage.patientIdSummary('pregnancy', 'review');
return $(`${FORM} span[data-itext-id="/pregnancy/group_review/r_pregnancy_details:label"]${ACTIVE} ${idSum}`);
};
const riskFactorsSummary = () => {
const parent = ':not(label.disabled):not(label.or-appearance-yellow)';
return $$(`${FORM} ${parent} > span[data-itext-id*="/pregnancy/group_review/r_risk_factor"]${ACTIVE}`);
};
const dangerSignsSummary = () => {
return $$(`${FORM} span[data-itext-id*="/pregnancy/group_review/r_danger_sign"]${ACTIVE}`);
};
const followUpSmsNote1 = () => $(`${FORM} ${enketoCommonPage.followUpSmsNote1('pregnancy', 'review')}`);
const followUpSmsNote2 = () => $(`${FORM} ${enketoCommonPage.followUpSmsNote2('pregnancy', 'review')}`);

const selectKnowLMP = async (value = 'approx') => {
const lmpOption = await knowLMP(value);
await lmpOption.waitForDisplayed();
await lmpOption.click();
};

const selectAproxLMP = async (value = APROX_LMP.up2Months) => {
const aproxLMPOption = await aproxLMP(value);
await aproxLMPOption.waitForDisplayed();
await aproxLMPOption.click();
};
const commonEnketoPage = require('@page-objects/default/enketo/common-enketo.wdio.page');

// Select all the risk factors except the first one, because there is a constraint in the code.
const selectAllRiskFactors = async () => {
const riskFactors = await risksFac();
for (const rfactor of riskFactors) {
await rfactor.click();
}
return riskFactors;
const dangerSignsQuestion = 'Does the woman have any of the following risk factors?';
await commonEnketoPage.selectCheckBox(dangerSignsQuestion, 'More than 4 children');
await commonEnketoPage.selectCheckBox(dangerSignsQuestion, 'Last baby born less than 1 year before');
await commonEnketoPage.selectCheckBox(dangerSignsQuestion,
'Had previous miscarriages or previous difficulties in childbirth');
await commonEnketoPage.selectCheckBox(dangerSignsQuestion, 'Has any of the following conditions:');
await commonEnketoPage.selectCheckBox(dangerSignsQuestion, 'HIV positive');
};

const selectAllDangerSigns = async () => {
const dangerSig = await dangerSigns();
for (const dangerSign of dangerSig) {
await dangerSign.click();
}
return dangerSig;
};

const setNote = async (text = 'Test note') => {
const note = await smsNote();
await note.waitForDisplayed();
await note.setValue(text);
};

const getSummaryDetails = async () => {
return {
patientName: await patientNameSummary().getText(),
patientId: await patientIdSummary().getText(),
countRiskFactors: await riskFactorsSummary().length,
countDangerSigns: await dangerSignsSummary().length,
followUpSmsNote1: await followUpSmsNote1().getText(),
followUpSmsNote2: await followUpSmsNote2().getText(),
};
const riskFactorsQuestion = 'Does the woman have any of the following danger signs?';
await commonEnketoPage.selectCheckBox(riskFactorsQuestion, 'Pain or cramping in abdomen');
await commonEnketoPage.selectCheckBox(riskFactorsQuestion,
'Bleeding or fluid leaking from vagina or vaginal discharge with bad odour');
await commonEnketoPage.selectCheckBox(riskFactorsQuestion, 'Severe nausea or vomiting');
await commonEnketoPage.selectCheckBox(riskFactorsQuestion, 'Fever of 38 degrees or higher');
await commonEnketoPage.selectCheckBox(riskFactorsQuestion, 'Severe headache or new, blurry vision problems');
await commonEnketoPage.selectCheckBox(riskFactorsQuestion,
'Sudden weight gain or severe swelling of feet, ankles, face, or hands');
await commonEnketoPage.selectCheckBox(riskFactorsQuestion,
'Less movement and kicking from the baby (after week 20 of pregnancy)');
await commonEnketoPage.selectCheckBox(riskFactorsQuestion, 'Blood in the urine or painful, burning urination');
await commonEnketoPage.selectCheckBox(riskFactorsQuestion, 'Diarrhea that doesn\'t go away');
};

const submitPregnancy = async () => {
await commonPage.openFastActionReport('pregnancy');
await selectKnowLMP();
await selectAproxLMP(APROX_LMP.b7To8Months);
await commonEnketoPage.selectRadioButton('Does the woman know the date of the last cycle?', 'No');
await commonEnketoPage.selectRadioButton('Approximate start date of last cycle', 'between 7 to 8 months ago');
await genericForm.nextPage();
await selectAllRiskFactors();
await genericForm.nextPage();
await selectAllDangerSigns();
await genericForm.nextPage();
await setNote('Test note');
await commonEnketoPage.setTextareaValue('You can add a personal note to the SMS here:', 'Test note');
await genericForm.nextPage();
await genericForm.submitForm();
};

module.exports = {
APROX_LMP,
selectKnowLMP,
selectAproxLMP,
getEstDeliveryDate,
selectAllRiskFactors,
selectAllDangerSigns,
setNote,
riskFactorsSummary,
dangerSignsSummary,
getSummaryDetails,
submitPregnancy,
};

0 comments on commit 45efba6

Please sign in to comment.