Skip to content

Commit

Permalink
feat(#8181): add automation tests for report's filter (#9338)
Browse files Browse the repository at this point in the history
  • Loading branch information
latin-panda authored Aug 19, 2024
1 parent 4779672 commit 26f3d3f
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 49 deletions.
150 changes: 101 additions & 49 deletions tests/e2e/default/reports/sidebar-filter.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,57 @@ describe('Reports Sidebar Filter', () => {

const patient = personFactory.build({ parent: healthCenterUser });
const today = moment();
const pregnancyHealthCenter = reportFactory
.report()
.build(
{
form: 'pregnancy',
verified: true,
reported_date: moment([today.year(), today.month(), 1, 23, 30]).subtract(4, 'month').valueOf()
},
{ patient, submitter: healthCenterContact, fields: { lmp_date: 'Feb 3, 2022' } }
);
const pregnancyDistrictHospital = reportFactory
.report()
.build(
{
form: 'pregnancy',
reported_date: moment([today.year(), today.month(), 12, 10, 30]).subtract(1, 'month').valueOf()
},
{ patient, submitter: districtHospitalContact, fields: { lmp_date: 'Feb 16, 2022' } }
);
const visitHealthCenter = reportFactory
.report()
.build(
{
form: 'pregnancy_home_visit',
verified: false,
reported_date: moment([today.year(), today.month(), 15, 0, 30]).subtract(5, 'month').valueOf()
},
{ patient, submitter: healthCenterContact, fields: { ok: 'Yes!' } }
);
const visitDistrictHospital = reportFactory
.report()
.build(
{
form: 'pregnancy_home_visit',
verified: true,
reported_date: moment([today.year(), today.month(), 16, 9, 10]).subtract(1, 'month').valueOf()
},
{ patient, submitter: districtHospitalContact, fields: { ok: 'Yes!' } }
);
const reports = [
reportFactory
.report()
.build(
{
form: 'P',
reported_date: moment([today.year(), today.month(), 1, 23, 30]).subtract(4, 'month').valueOf()
},
{ patient, submitter: healthCenterContact, fields: { lmp_date: 'Feb 3, 2022' }}
),
reportFactory
.report()
.build(
{
form: 'P',
reported_date: moment([today.year(), today.month(), 12, 10, 30]).subtract(1, 'month').valueOf()
},
{ patient, submitter: districtHospitalContact, fields: { lmp_date: 'Feb 16, 2022' }}
),
reportFactory
.report()
.build(
{
form: 'V',
reported_date: moment([today.year(), today.month(), 15, 0, 30]).subtract(5, 'month').valueOf()
},
{ patient, submitter: healthCenterContact, fields: { ok: 'Yes!' }}
),
reportFactory
.report()
.build(
{
form: 'V',
reported_date: moment([today.year(), today.month(), 16, 9, 10]).subtract(1, 'month').valueOf()
},
{ patient, submitter: districtHospitalContact, fields: { ok: 'Yes!' }}
),
pregnancyHealthCenter,
pregnancyDistrictHospital,
visitHealthCenter,
visitDistrictHospital
];
let savedReports;

before(async () => {
await utils.saveDocs([ ...places.values(), patient ]);
savedReports = (await utils.saveDocs(reports)).map(result => result.id);
await utils.createUsers([ districtHospitalUser, healthCenterUser ]);
const savedReports = await utils.saveDocs(reports);
savedReports.forEach((savedReport, index) => reports[index]._id = savedReport.id);
});

afterEach(async () => {
Expand All @@ -84,15 +91,12 @@ describe('Reports Sidebar Filter', () => {
});

it('should filter by date', async () => {
const pregnancyDistrictHospital = savedReports[1];
const visitDistrictHospital = savedReports[3];

await loginPage.login(districtHospitalUser);
await commonPage.waitForPageLoaded();

await commonPage.goToReports();
await (await reportsPage.firstReport()).waitForDisplayed();
expect((await reportsPage.allReports()).length).to.equal(savedReports.length);
expect((await reportsPage.allReports()).length).to.equal(reports.length);

await reportsPage.openSidebarFilter();
await reportsPage.openSidebarFilterDateAccordion();
Expand All @@ -101,14 +105,62 @@ describe('Reports Sidebar Filter', () => {
await commonPage.waitForPageLoaded();

expect((await reportsPage.allReports()).length).to.equal(2);
expect(await (await reportsPage.reportByUUID(pregnancyDistrictHospital)).isDisplayed()).to.be.true;
expect(await (await reportsPage.reportByUUID(visitDistrictHospital)).isDisplayed()).to.be.true;
expect(await (await reportsPage.reportByUUID(pregnancyDistrictHospital._id)).isDisplayed()).to.be.true;
expect(await (await reportsPage.reportByUUID(visitDistrictHospital._id)).isDisplayed()).to.be.true;
});

it('should filter by user associated place when the permission to default filter is enabled', async () => {
const pregnancyHealthCenter = savedReports[0];
const visitHealthCenter = savedReports[2];
it('should filter by form', async () => {
await loginPage.login(districtHospitalUser);
await commonPage.waitForPageLoaded();

await commonPage.goToReports();
await (await reportsPage.firstReport()).waitForDisplayed();
expect((await reportsPage.allReports()).length).to.equal(reports.length);

await reportsPage.openSidebarFilter();
await reportsPage.filterByForm('Pregnancy home visit');
await commonPage.waitForPageLoaded();

expect((await reportsPage.allReports()).length).to.equal(2);
expect(await (await reportsPage.reportByUUID(visitHealthCenter._id)).isDisplayed()).to.be.true;
expect(await (await reportsPage.reportByUUID(visitDistrictHospital._id)).isDisplayed()).to.be.true;
});

it('should filter by place', async () => {
await loginPage.login(districtHospitalUser);
await commonPage.waitForPageLoaded();

await commonPage.goToReports();
await (await reportsPage.firstReport()).waitForDisplayed();
expect((await reportsPage.allReports()).length).to.equal(reports.length);

await reportsPage.openSidebarFilter();
await reportsPage.filterByFacility(districtHospital.name, healthCenter.name);
await commonPage.waitForPageLoaded();

expect((await reportsPage.allReports()).length).to.equal(2);
expect(await (await reportsPage.reportByUUID(visitHealthCenter._id)).isDisplayed()).to.be.true;
expect(await (await reportsPage.reportByUUID(pregnancyHealthCenter._id)).isDisplayed()).to.be.true;
});

it('should filter by status', async () => {
await loginPage.login(districtHospitalUser);
await commonPage.waitForPageLoaded();

await commonPage.goToReports();
await (await reportsPage.firstReport()).waitForDisplayed();
expect((await reportsPage.allReports()).length).to.equal(reports.length);

await reportsPage.openSidebarFilter();
await reportsPage.filterByStatus('Reviewed: correct');
await commonPage.waitForPageLoaded();

expect((await reportsPage.allReports()).length).to.equal(2);
expect(await (await reportsPage.reportByUUID(pregnancyHealthCenter._id)).isDisplayed()).to.be.true;
expect(await (await reportsPage.reportByUUID(visitDistrictHospital._id)).isDisplayed()).to.be.true;
});

it('should filter by user associated place when the permission to default filter is enabled', async () => {
await loginPage.login(healthCenterUser);
await commonPage.waitForPageLoaded();

Expand All @@ -122,8 +174,8 @@ describe('Reports Sidebar Filter', () => {
await (await reportsPage.firstReport()).waitForDisplayed();

expect((await reportsPage.allReports()).length).to.equal(2);
expect(await (await reportsPage.reportByUUID(pregnancyHealthCenter)).isDisplayed()).to.be.true;
expect(await (await reportsPage.reportByUUID(visitHealthCenter)).isDisplayed()).to.be.true;
expect(await (await reportsPage.reportByUUID(pregnancyHealthCenter._id)).isDisplayed()).to.be.true;
expect(await (await reportsPage.reportByUUID(visitHealthCenter._id)).isDisplayed()).to.be.true;
});
});

44 changes: 44 additions & 0 deletions tests/page-objects/default/reports/reports.wdio.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const reviewReportCloseButton = () => $(`${REVIEW_REPORT_CONTAINER} .panel-heade

const sidebarFilterDateAccordionHeader = () => $('#date-filter-accordion mat-expansion-panel-header');
const sidebarFilterDateAccordionBody = () => $('#date-filter-accordion mat-panel-description');
const sidebarFilterFormAccordionHeader = () => $('#form-filter-accordion mat-expansion-panel-header');
const sidebarFilterFormAccordionBody = () => $('#form-filter-accordion mat-panel-description');
const sidebarFilterFacilityAccordionHeader = () => $('#place-filter-accordion mat-expansion-panel-header');
const sidebarFilterFacilityAccordionBody = () => $('#place-filter-accordion mat-panel-description');
const sidebarFilterStatusAccordionHeader = () => $('#status-filter-accordion mat-expansion-panel-header');
const sidebarFilterStatusAccordionBody = () => $('#status-filter-accordion mat-panel-description');
const sidebarFilterToDate = () => $('#toDateFilter');
const sidebarFilterFromDate = () => $('#fromDateFilter');
const sidebarFilterOpenBtn = () => $('mm-search-bar .open-filter');
Expand Down Expand Up @@ -252,8 +258,43 @@ const openSidebarFilterDateAccordion = async () => {
return (await sidebarFilterDateAccordionBody()).waitForDisplayed();
};

const filterByForm = async (formName) => {
await (await sidebarFilterFormAccordionHeader()).click();
await (await sidebarFilterFormAccordionBody()).waitForDisplayed();
const option = sidebarFilterFormAccordionBody().$(`a*=${formName}`);
await (await option).waitForDisplayed();
await (await option).waitForClickable();
await (await option).click();
};

const filterByStatus = async (statusOption) => {
await (await sidebarFilterStatusAccordionHeader()).click();
await (await sidebarFilterStatusAccordionBody()).waitForDisplayed();
const option = sidebarFilterStatusAccordionBody().$(`a*=${statusOption}`);
await (await option).waitForDisplayed();
await (await option).waitForClickable();
await (await option).click();
};

const filterByFacility = async (parentFacility, reportFacility) => {
await (await sidebarFilterFacilityAccordionHeader()).click();
await (await sidebarFilterFacilityAccordionBody()).waitForDisplayed();

const parent = sidebarFilterFacilityAccordionBody().$(`a*=${parentFacility}`);
await parent.waitForDisplayed();
await parent.waitForClickable();
await (await parent).click();

const facility = await sidebarFilterFacilityAccordionBody().$('.mm-dropdown-submenu').$(`a*=${reportFacility}`);
await facility.waitForDisplayed();
await facility.waitForClickable();
const checkbox = facility.previousElement();
await (await checkbox).click();
};

const setSidebarFilterDate = async (fieldPromise, calendarIdx, date) => {
await (await fieldPromise).waitForDisplayed();
await (await fieldPromise).waitForClickable();
await (await fieldPromise).click();

const dateRangePicker = `.daterangepicker:nth-of-type(${calendarIdx})`;
Expand Down Expand Up @@ -464,6 +505,9 @@ module.exports = {
openSidebarFilterDateAccordion,
setSidebarFilterFromDate,
setSidebarFilterToDate,
filterByForm,
filterByFacility,
filterByStatus,
setDateInput,
getFieldValue,
setBikDateInput,
Expand Down

0 comments on commit 26f3d3f

Please sign in to comment.