Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [DHIS2-17853] Related stages Cypress tests (#3939)
Browse files Browse the repository at this point in the history
simonadomnisoru authored Jan 27, 2025
1 parent 3e9f419 commit 874ed03
Showing 8 changed files with 374 additions and 3 deletions.
100 changes: 100 additions & 0 deletions cypress/e2e/RelatedStages/RelatedStages.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Feature: Related stages

Scenario: Edit event -> User is able to link and unlink an existing event
Given you land on a enrollment page domain by having typed #/enrollmentEventEdit?eventId=TwoGi1mUFFw&orgUnitId=lyONqUkY1Bq
And the Related stages Actions is visible at the bottom of the page
And the schedule and enter details actions are disabled
And you select the Link to an existing event action
When you select the first existing Baby Postnatal event in the list
And you click the Link button
Then you can see the Baby Postnatal linked event
And the Related stages Actions is not visible at the bottom of the page
When you unlink the Baby Postnatal linked event
And the Related stages Actions is visible at the bottom of the page

Scenario: Edit event -> User is able to schedule an event in a different orgUnit
Given you land on a enrollment page domain by having typed #/enrollment?enrollmentId=VOU2Qe7T49r&orgUnitId=VFF7f43dJv4&programId=IpHINAT79UW&teiId=rBqwRgXvjk0
And you delete the events of the enrollmentId VOU2Qe7T49r
And you open the Birth new event page and fill in the required data in the form
And you click the Complete button
And you open the Birth event edit page
And the Related stages Actions is visible at the bottom of the page
And the link to an existing actions is disabled
And you select the Schedule event action
When you fill in the required values for the Baby postnatal event when scheduling
And you click the Schedule action button
Then you can see the Baby Postnatal linked event
And the Related stages Actions is not visible at the bottom of the page

Scenario: Edit event -> User is able to enter details in a different orgUnit
Given you land on a enrollment page domain by having typed #/enrollment?enrollmentId=VOU2Qe7T49r&orgUnitId=VFF7f43dJv4&programId=IpHINAT79UW&teiId=rBqwRgXvjk0
And you delete the events of the enrollmentId VOU2Qe7T49r
And you open the Birth new event page and fill in the required data in the form
And you click the Complete button
And you open the Birth event edit page
And the Related stages Actions is visible at the bottom of the page
And the link to an existing actions is disabled
And you select the Enter details now action
When you fill in the required values for the Baby postnatal event when entering details
And you click the Enter details action button
Then you can see the Birth linked event
And you can see the Baby postnatal new event form where you can enter details

Scenario: New event -> User is able to link and unlink an existing event
Given you land on a enrollment page domain by having typed #/enrollment?enrollmentId=EOxeNf2MdBf&orgUnitId=VFF7f43dJv4&programId=IpHINAT79UW&teiId=QhoMgzeGuGq
And you delete the Birth event
And you open the Birth new event page and fill in the required data in the form
And the Related stages Actions is visible at the bottom of the page
And the schedule and enter details actions are disabled
And you select the Link to an existing event action
When you select the first existing Baby Postnatal event in the list
And you click the Complete button
And you open the Birth event edit page
Then you can see the Baby Postnatal linked event
And the Related stages Actions is not visible at the bottom of the page
When you unlink the Baby Postnatal linked event
And the Related stages Actions is visible at the bottom of the page

Scenario: New event -> User is able to schedule an event in a different orgUnit
Given you land on a enrollment page domain by having typed #/enrollment?enrollmentId=EOxeNf2MdBf&orgUnitId=VFF7f43dJv4&programId=IpHINAT79UW&teiId=QhoMgzeGuGq
And you delete the events of the enrollmentId EOxeNf2MdBf
And you open the Birth new event page and fill in the required data in the form
And the Related stages Actions is visible at the bottom of the page
And the link to an existing actions is disabled
And you select the Schedule event action
When you fill in the required values for the Baby postnatal event when scheduling
And you click the Complete button
Then you are redirect to the enrollment dasboard and you see the 2 linked events in different orgUnits

Scenario: New event -> User is able to enter details in a different orgUnit
Given you land on a enrollment page domain by having typed #/enrollment?enrollmentId=YRgcBLZbsb6&orgUnitId=VFF7f43dJv4&programId=IpHINAT79UW&teiId=zFbWLBo4jta
And you delete the events of the enrollmentId YRgcBLZbsb6
And you open the Birth new event page and fill in the required data in the form
And the Related stages Actions is visible at the bottom of the page
And the link to an existing actions is disabled
And you select the Enter details now action
When you fill in the required values for the Baby postnatal event when entering details
And you click the Complete button
Then you can see the Birth linked event
And you can see the Baby postnatal new event form where you can enter details

Scenario: Enroll trackedEntity -> User is able to schedule an event in a different orgUnit
Given you are in Child programme and Tombo Wallah CHP organization unit registration page
When you fill the Child Program program registration form with unique values
And you select the Schedule event action
And you fill in the required values for the Baby postnatal event when scheduling
And you click the save person submit button
Then you are redirect to the enrollment dasboard and you see the 2 linked events in different orgUnits
And you delete the recently added tracked entity

Scenario: Enroll trackedEntity -> User is able to enter details in a different orgUnit
Given you are in Child programme and Tombo Wallah CHP organization unit registration page
When you fill the Child Program program registration form with unique values
And you select the Enter details now action
And you fill in the required values for the Baby postnatal event when entering details
And you click the save person submit button
Then you can see the Birth linked event
And you can see the Baby postnatal new event form where you can enter details
And you navigate to the Enrollment dashboard
And you are redirect to the enrollment dasboard and you see the 2 linked events in different orgUnits
And you delete the recently added tracked entity
258 changes: 258 additions & 0 deletions cypress/e2e/RelatedStages/RelatedStages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
import { Given, Then, When, defineStep as And } from '@badeball/cypress-cucumber-preprocessor';
import { getCurrentYear } from '../../support/date';

Given(/^you land on a enrollment page domain by having typed (.*)$/, (url) => {
cy.visit(url);
cy.get('[data-test="person-selector-container"]').contains('Person');
});

And(/^the Related stages Actions is ?(.*) visible at the bottom of the page/, (not) => {
cy.get('[data-test="related-stages-section"]')
.should(not ? 'not.exist' : 'exist');
});

And('you select the Link to an existing event action', () => {
cy.get('[data-test="related-stages-section"]')
.and('contain', 'Actions - Birth to Baby postnatal');
cy.get('[data-test="related-stages-actions-link-existing-response"]')
.click();
});

And('you select the Schedule event action', () => {
cy.get('[data-test="related-stages-section"]')
.and('contain', 'Actions - Birth to Baby postnatal');
cy.get('[data-test="related-stages-actions-schedule"]')
.click();
});

And('you select the Enter details now action', () => {
cy.get('[data-test="related-stages-section"]')
.and('contain', 'Actions - Birth to Baby postnatal');
cy.get('[data-test="related-stages-actions-enter-details"]')
.click();
});

When('you select the first existing Baby Postnatal event in the list', () => {
cy.get('[data-test="related-stages-existing-response-list-content"]')
.click();
cy.get('[data-test="dhis2-uicore-singleselectoption"]')
.eq(0)
.click();
});

When('you click the Link button', () => {
cy.get('[data-test="related-stages-buttons-link-existing-response"]')
.click();
});

Then('you can see the Baby Postnatal linked event', () => {
cy.get('[data-test="enrollment-viewEvent-page"]')
.should('contain', 'This Birth event is linked to a Baby Postnatal event. Review the linked event details before entering data below');
});

Then('you can see the Birth linked event', () => {
cy.get('[data-test="enrollment-editEvent-page"]')
.should('contain', 'This Baby Postnatal event is linked to a Birth event. Review the linked event details before entering data below');
});

When('you unlink the Baby Postnatal linked event', () => {
cy.get('[data-test="widget-linked-event-overflow-menu"]')
.click();
cy.get('[data-test="event-overflow-unlink-event"]')
.click();
cy.get('[data-test="event-overflow-unlink-event-confirm"]')
.click();
});

And('you delete the Birth event', () => {
cy.get('[data-test="overflow-button"]')
.eq(0)
.click();
cy.get('[data-test="stages-and-events-delete"]')
.click();
cy.get('[data-test="dhis2-uicore-modal"]').within(() => {
cy.contains('button', 'Yes, delete event')
.click();
});
});

And('you open the Birth event edit page', () => {
cy.get('[data-test="stages-and-events-widget"]')
.find('[data-test="widget-contents"]')
.contains('[data-test="stage-content"]', 'Birth')
.find('[data-test="dhis2-uicore-datatablerow"]')
.eq(1)
.click();
});

And('you open the Birth new event page and fill in the required data in the form', () => {
cy.get('[data-test="stages-and-events-widget"]')
.find('[data-test="widget-contents"]')
.contains('[data-test="stage-content"]', 'Birth')
.find('[data-test="create-new-button"]')
.click();

cy.get('[data-test="dataentry-field-occurredAt"]')
.within(() => {
cy.get('input[type="text"]')
.eq(0)
.type(`${getCurrentYear()}-07-01`)
.blur();
});
});

When('you fill in the required values for the Baby postnatal event when scheduling', () => {
cy.get('[data-test="related-stages-section"]')
.within(() => {
cy.get('input[type="text"]')
.eq(0)
.type(`${getCurrentYear()}-08-01`)
.blur();

cy.get('input[type="text"]')
.eq(1)
.type('Barmoi CH');

cy.contains('Barmoi CHP')
.click();
});
});

And('you click the Schedule action button', () => {
cy.get('[data-test="related-stages-buttons-schedule"]')
.click();
});

When('you fill in the required values for the Baby postnatal event when entering details', () => {
cy.get('[data-test="related-stages-section"]')
.within(() => {
cy.get('input[type="text"]')
.eq(0)
.type('Barmoi CH');

cy.contains('Barmoi CHP')
.click();
});
});

And('you click the Enter details action button', () => {
cy.get('[data-test="related-stages-buttons-enter-details"]')
.click();
});

Then('you can see the Baby postnatal new event form where you can enter details', () => {
cy.get('[data-test="edit-event-report-tab"]')
.should('contain', 'Report');
cy.get('[data-test="edit-event-schedule-tab"]')
.should('contain', 'Schedule');
cy.get('[data-test="dhis2-uicore-button"]')
.contains('Cancel')
.should('exist');
});

And('the schedule and enter details actions are disabled', () => {
cy.get('input[name="related-stage-action-SCHEDULE_IN_ORG"]')
.should('be.disabled');
cy.get('input[name="related-stage-action-ENTER_DATA"]')
.should('be.disabled');
});

And('the link to an existing actions is disabled', () => {
cy.get('input[name="related-stage-action-LINK_EXISTING_RESPONSE"]')
.should('be.disabled');
});

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

Then('you are redirect to the enrollment dasboard and you see the 2 linked events in different orgUnits', () => {
cy.get('[data-test="stages-and-events-widget"]')
.find('[data-test="widget-contents"]')
.contains('[data-test="stage-content"]', 'Birth')
.find('[data-test="dhis2-uicore-datatablerow"]')
.eq(1)
.contains('Tombo Wallah CHP');

cy.get('[data-test="stages-and-events-widget"]')
.find('[data-test="widget-contents"]')
.contains('[data-test="stage-content"]', 'Baby Postnatal')
.find('[data-test="dhis2-uicore-datatablerow"]')
.eq(1)
.contains('Barmoi CHP');
});

And('you fill the Child Program program registration form with unique values', () => {
cy.get('input[type="text"]')
.eq(1)
.type('2021-01-01')
.blur();
cy.get('input[type="text"]')
.eq(2)
.type(20);
cy.get('input[type="text"]')
.eq(3)
.type(30)
.blur();
cy.get('input[type="text"]')
.eq(4)
.type(`Sarah-${Math.round((new Date()).getTime() / 1000)}`)
.blur();
cy.get('input[type="text"]')
.eq(5)
.type(`Beth-${Math.round((new Date()).getTime() / 1000)}`)
.blur();
cy.get('input[type="text"]')
.eq(7)
.type('2021-01-01')
.blur();
});

And('you delete the recently added tracked entity', () => {
cy.get('[data-test="profile-widget"]')
.contains('Person profile')
.should('exist');
cy.get('[data-test="widget-profile-overflow-menu"]')
.click();
cy.contains('Delete Person')
.click();
cy.get('[data-test="widget-profile-delete-modal"]').within(() => {
cy.contains('Yes, delete Person')
.click();
});
cy.url().should('include', 'selectedTemplateId=IpHINAT79UW');
});

And(/^you click the save (.*) submit button$/, (TEType) => {
cy.contains(`Save ${TEType}`)
.click();
});

And('you navigate to the Enrollment dashboard', () => {
cy.contains('Enrollment dashboard')
.click();
cy.contains('Yes, discard changes')
.click();
});

And('you are in Child programme and Tombo Wallah CHP organization unit registration page', () => {
cy.visit('/#/new?programId=IpHINAT79UW&orgUnitId=VFF7f43dJv4');
});

And(/^you delete the events of the enrollmentId (.*)$/, (enrollmentId) => {
cy.buildApiUrl('tracker', `enrollments/${enrollmentId}?fields=events[event]`)
.then(url => cy.request(url))
.then(({ body }) => {
const { events } = body;

if (events) {
cy.buildApiUrl('tracker?async=false&importStrategy=DELETE').then((eventUrl) => {
cy.request('POST', eventUrl, { events });
cy.reload();
});
}
});
});

Original file line number Diff line number Diff line change
@@ -51,7 +51,8 @@ type Props = {
debounceFieldContainer: string,
orgUnitTreeContainer: string,
},
previousOrgUnitId?: string
previousOrgUnitId?: string,
dataTest?: string,
};

const OrgUnitFieldPlain = (props: Props) => {
@@ -63,6 +64,7 @@ const OrgUnitFieldPlain = (props: Props) => {
maxTreeHeight,
disabled,
previousOrgUnitId,
dataTest,
} = props;
const [searchText, setSearchText] = React.useState(undefined);
const [key, setKey] = React.useState(undefined);
@@ -156,6 +158,7 @@ const OrgUnitFieldPlain = (props: Props) => {
placeholder={i18n.t('Search')}
classes={classes}
disabled={disabled}
dataTest={dataTest}
/>
</div>
{!disabled &&
Original file line number Diff line number Diff line change
@@ -72,6 +72,7 @@ export const OrgUnitSelectorForRelatedStages = ({
onBlur={handleDeselect}
styles={baseInputStyles}
errorMessage={shouldShowError && errorMessages?.orgUnit}
data-test="relates-stages-org-unit"
/>
);
};
Loading

0 comments on commit 874ed03

Please sign in to comment.