Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [DHIS2-13800] ask user to complete enrollment and events #3535

Merged
merged 13 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@ Feature: User interacts with the Enrollment New Event Workspace
And you select the schedule tab
When you add a comment to the event
And the events saves successfully

Scenario: User can add a new event and complete the enrollment
Given you land on the enrollment new event page by having typed #/enrollmentEventNew?enrollmentId=FZAa7j0muDj&orgUnitId=DiszpKrYNg8&programId=qDkgAbB5Jlk&stageId=eHvTba5ijAh&teiId=bj4UmUpqaSp
And the enrollment status is active
And you type 2021-10-15 in the input number 0
And you select Died in the select number 0
And the user completes the event
And the user completes the enrollment
Then the user sees the enrollment status and recently added event in Case outcome event status is completed
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@ import { Given, When, Then, defineStep as And } from '@badeball/cypress-cucumber
import '../sharedSteps';
import '../../sharedSteps';

const changeEnrollmentAndEventsStatus = () => (
cy.buildApiUrl(
'tracker',
'trackedEntities/bj4UmUpqaSp?program=qDkgAbB5Jlk&fields=enrollments[enrollment,events,orgUnit,program,enrolledAt,trackedEntity]',
)
.then(url => cy.request(url))
.then(({ body }) => {
const enrollment = body.enrollments && body.enrollments.find(e => e.enrollment === 'FZAa7j0muDj');
const eventToDelete = enrollment.events.find(e => e.programStage === 'eHvTba5ijAh');
const { events, ...rest } = enrollment;
const enrollmentToUpdate = { ...rest, status: 'ACTIVE' };

return cy
.buildApiUrl('tracker?async=false&importStrategy=UPDATE')
.then(enrollmentUrl => cy.request('POST', enrollmentUrl, { enrollments: [enrollmentToUpdate] }))
.then(() => {
if (eventToDelete) {
cy.buildApiUrl('events', eventToDelete.event)
.then((eventUrl) => {
cy.request('DELETE', eventUrl);
}).then(() => {
cy.reload();
cy.get('[data-test="widget-enrollment"]').within(() => {
cy.get('[data-test="widget-enrollment-status"]').contains('Active').should('exist');
});
});
} else {
cy.reload();
cy.get('[data-test="widget-enrollment"]').within(() => {
cy.get('[data-test="widget-enrollment-status"]').contains('Active').should('exist');
});
}
});
})
);

const showAllEventsInProgramStage = () => {
cy.get('[data-test="dhis2-uicore-tablefoot"]')
.then(($footer) => {
Expand Down Expand Up @@ -157,3 +193,41 @@ Then('the user clicks the first second antenatal care visit event', () => {
cy.contains('[data-test="stage-content"]', 'Last updated a few seconds ago')
.should('exist');
});

And('the enrollment status is active', () => {
changeEnrollmentAndEventsStatus();
});

And('the user completes the event', () => {
cy.get('[data-test="dhis2-uicore-button"]')
.contains('Complete')
.click();
});

When('the user completes the enrollment', () => {
cy.get('[data-test="enrollment-complete-modal"]').within(() => {
cy.contains('Case outcome completed').should('exist');
cy.contains('Would you like to complete the enrollment and all active events as well?').should('exist');
cy.contains('The following events will be completed:').should('exist');
cy.contains('1 event in Case investigation & classification').should('exist');
cy.contains('1 event in Diagnosis & treatment').should('exist');
cy.contains('No, cancel').should('exist');
cy.contains('Complete enrollment only').should('exist');
cy.contains('Yes, complete enrollment and events').should('exist');
});
cy.get('[data-test="enrollment-actions-complete-button"]').click();
});

Then('the user sees the enrollment status and recently added event in Case outcome event status is completed', () => {
cy.url().should('include', `${Cypress.config().baseUrl}/#/enrollment?`);
cy.get('[data-test="widget-enrollment"]').within(() => {
cy.get('[data-test="widget-enrollment-status"]').contains('Completed').should('exist');
});

cy.get('[data-test="stage-content"]')
.eq(2)
.within(() => {
cy.get('[data-test="dhis2-uicore-tag-text"]').contains('Completed').should('exist');
});
changeEnrollmentAndEventsStatus();
});
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,11 @@ Scenario: User can see disabled scheduled date for active event
When the user clicks on the edit button
Then the user see the following text: Enrollment: Edit Event
Then the user see the schedule date field with tooltip: Scheduled date cannot be changed for Active events


Scenario: User can edit the event and complete the enrollment
Given you land on the enrollment event page with selected Malaria Entity by having typed #/enrollmentEventEdit?eventId=MHR4Zj6KLz0&orgUnitId=DiszpKrYNg8
And the enrollment status is active
And the user clicks on the edit button
And the user completes the event
And the user completes the enrollment
Then the user sees the enrollment status and recently edited event in Case outcome event status is completed
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
import { Given, When, Then, defineStep as And } from '@badeball/cypress-cucumber-preprocessor';
import { getCurrentYear } from '../../../support/date';
import '../../sharedSteps';

const changeEnrollmentAndEventsStatus = () => (
cy.buildApiUrl(
'tracker',
'trackedEntities/JM29jwvw8Ub?program=qDkgAbB5Jlk&fields=enrollments[enrollment,events,orgUnit,program,enrolledAt,trackedEntity]',
)
.then(url => cy.request(url))
.then(({ body }) => {
const enrollment = body.enrollments && body.enrollments.find(e => e.enrollment === 'C4iB0VTbfrK');
const eventToUpdate = enrollment.events.find((e => e.programStage === 'eHvTba5ijAh'));
const enrollmentToUpdate = {
...enrollment,
status: 'ACTIVE',
events: [{ ...eventToUpdate, status: 'ACTIVE' }],
};

return cy
.buildApiUrl('tracker?async=false&importStrategy=UPDATE')
.then(enrollmentUrl => cy.request('POST', enrollmentUrl, { enrollments: [enrollmentToUpdate] }))
.then(() => {
cy.reload();
cy.get('[data-test="widget-enrollment"]').within(() => {
cy.get('[data-test="widget-enrollment-status"]').contains('Active').should('exist');
});
});
})
);

Given(/^you land on the enrollment event page with selected (.*) by having typed (.*)$/, (tet, url) => {
cy.visit(url);
cy.get('[data-test="scope-selector"]').contains(`${tet}`);
Expand Down Expand Up @@ -95,3 +122,49 @@ Then(/^the user see the schedule date field with tooltip: (.*)$/, (tooltipConten
cy.get('[data-test="dhis2-uicore-tooltip-reference"]').eq(0).trigger('mouseover');
cy.get('[data-test="dhis2-uicore-tooltip-content"]').contains(tooltipContent).should('exist');
});

And('the enrollment status is active', () => {
changeEnrollmentAndEventsStatus();
});

And('the user completes the event', () => {
cy.get('[data-test="dataentry-field-complete"]')
.find('input')
.click()
.blur();

cy
.get('[data-test="widget-enrollment-event"]')
.find('[data-test="dhis2-uicore-button"]')
.contains('Save')
.click();
});

When('the user completes the enrollment', () => {
cy.get('[data-test="enrollment-complete-modal"]').within(() => {
cy.contains('Case outcome completed').should('exist');
cy.contains('Would you like to complete the enrollment and all active events as well?').should('exist');
cy.contains('The following events will be completed:').should('exist');
cy.contains('1 event in Case outcome').should('exist');
cy.contains('1 event in Diagnosis & treatment').should('exist');
cy.contains('No, cancel').should('exist');
cy.contains('Complete enrollment only').should('exist');
cy.contains('Yes, complete enrollment and events').should('exist');
});
cy.get('[data-test="enrollment-actions-complete-button"]').click();
});

Then('the user sees the enrollment status and recently edited event in Case outcome event status is completed', () => {
cy.url().should('include', `${Cypress.config().baseUrl}/#/enrollment?`);
cy.get('[data-test="widget-enrollment"]').within(() => {
cy.get('[data-test="widget-enrollment-status"]').contains('Completed').should('exist');
});

cy.get('[data-test="stage-content"]')
.eq(2)
.within(() => {
cy.get('[data-test="dhis2-uicore-tag-text"]').contains('Completed').should('exist');
});
changeEnrollmentAndEventsStatus();
});

52 changes: 52 additions & 0 deletions cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ After({ tags: '@with-transfer-ownership-data-cleanup' }, () => {
.then(url => cy.request('PUT', url));
});

const changeEnrollmentAndEventsStatus = () => (
cy.buildApiUrl('tracker', 'trackedEntities/osF4RF4EiqP?program=IpHINAT79UW&fields=enrollments')
.then(url => cy.request(url))
.then(({ body }) => {
const enrollment = body.enrollments && body.enrollments.find(e => e.enrollment === 'qyx7tscVpVB');
const eventsToUpdate = enrollment.events.map(e => ({ ...e, status: 'ACTIVE' }));
const enrollmentToUpdate = { ...enrollment, status: 'ACTIVE', events: eventsToUpdate };

return cy
.buildApiUrl('tracker?async=false&importStrategy=UPDATE')
.then(enrollmentUrl => cy.request('POST', enrollmentUrl, { enrollments: [enrollmentToUpdate] }))
.then(() => {
cy.reload();
cy.get('[data-test="widget-enrollment"]').within(() => {
cy.get('[data-test="widget-enrollment-status"]').contains('Active').should('exist');
});
});
})
);

When('you click the enrollment widget toggle open close button', () => {
cy.get('[data-test="widget-enrollment"]').within(() => {
cy.get('[data-test="widget-open-close-toggle-button"]').click();
Expand Down Expand Up @@ -128,6 +148,38 @@ Then(/^the user sees the delete enrollment modal/, () =>
}),
);

Then('the user sees the enrollment status and the Baby Postnatal event status is active', () => {
changeEnrollmentAndEventsStatus();
});

Then('the user sees the enrollment status and the Baby Postnatal event status is completed', () => {
cy.url().should('include', `${Cypress.config().baseUrl}/#/enrollment?`);
cy.get('[data-test="widget-enrollment"]').within(() => {
cy.get('[data-test="widget-enrollment-status"]').contains('Completed').should('exist');
});

cy.get('[data-test="stage-content"]')
.eq(1)
.within(() => {
cy.get('[data-test="dhis2-uicore-tag-text"]').contains('Completed').should('exist');
});
changeEnrollmentAndEventsStatus();
});

When('the user completes the enrollment and the active events', () => {
cy.get('[data-test="widget-enrollment-actions-complete"]').click();

cy.get('[data-test="widget-enrollment-complete-modal"]').within(() => {
cy.contains('Would you like to complete the enrollment and all active events as well?').should('exist');
cy.contains('The following events will be completed:').should('exist');
cy.contains('1 event in Baby Postnatal').should('exist');
cy.contains('No, cancel').should('exist');
cy.contains('Complete enrollment only').should('exist');
cy.contains('Yes, complete enrollment and events').should('exist');
});
cy.get('[data-test="widget-enrollment-actions-complete-button"]').click();
});

Then(/^the user sees the transfer modal/, () =>
cy.get('[data-test="widget-enrollment-transfer-modal"]').within(() => {
cy.contains('Transfer Ownership').should('exist');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,11 @@ Feature: The user interacts with the widgets on the enrollment add event page
Given you land on the enrollment edit event page by having typed /#/enrollmentEventNew?enrollmentId=zRfAPUpjoG3&orgUnitId=DiszpKrYNg8&programId=M3xtLkYBlKI&stageId=uvMKOn1oWvd&teiId=S3JjTA4QMNe
When you click switch tab to Schedule
Then you can assign a user when scheduling the event

Scenario: User can complete the enrollment and the active events
Given you land on the enrollment edit event page by having typed #/enrollmentEventNew?enrollmentId=qyx7tscVpVB&orgUnitId=DiszpKrYNg8&programId=IpHINAT79UW&teiId=osF4RF4EiqP
And the enrollment widget should be opened
And the user sees the enrollment status and the Baby Postnatal event status is active
And the user opens the enrollment actions menu
When the user completes the enrollment and the active events
Then the user sees the enrollment status and the Baby Postnatal event status is completed
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,11 @@ Feature: The user interacts with the widgets on the enrollment dashboard
Scenario: The program rules are triggered and the effects are displayed in the sidebar widgets
Given you land on the enrollment dashboard page by having typed #/enrollment?enrollmentId=wBU0RAsYjKE
Then the user can see the program rules effect in the indicator widget

Scenario: User can complete the enrollment and the active events
Given you land on the enrollment dashboard page by having typed #/enrollment?enrollmentId=qyx7tscVpVB
And the enrollment widget should be opened
And the user sees the enrollment status and the Baby Postnatal event status is active
And the user opens the enrollment actions menu
When the user completes the enrollment and the active events
Then the user sees the enrollment status and the Baby Postnatal event status is completed
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,11 @@ Feature: The user interacts with the widgets on the enrollment edit event
Then the event has the user Tracker demo User assigned
When you remove the assigned user
Then the event has no assignd user

Scenario: User can complete the enrollment and the active events
Given you land on the enrollment edit event page by having typed #/enrollmentEventEdit?eventId=OWpIzQ4xabC&orgUnitId=DiszpKrYNg8
And the enrollment widget should be opened
And the user sees the enrollment status and the Baby Postnatal event status is active
And the user opens the enrollment actions menu
When the user completes the enrollment and the active events
Then the user sees the enrollment status and the Baby Postnatal event status is completed
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading