diff --git a/cypress/e2e/RelatedStages/RelatedStages.feature b/cypress/e2e/RelatedStages/RelatedStages.feature index 125c1968f6..72b40fa68c 100644 --- a/cypress/e2e/RelatedStages/RelatedStages.feature +++ b/cypress/e2e/RelatedStages/RelatedStages.feature @@ -2,6 +2,7 @@ Feature: Related stages Scenario: Edit event -> User is able to link and unlink an existing event Given you make sure the event TwoGi1mUFFw is unlinked + And you make sure the enrollment ZlWJ5HwZLeQ has a Baby Postnatal event And 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 @@ -42,7 +43,8 @@ Feature: Related stages And you can see the Baby postnatal new event form 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 + Given you make sure the enrollment EOxeNf2MdBf has a Baby Postnatal event + And 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 @@ -79,6 +81,7 @@ Feature: Related stages Then you can see the Birth linked event And you can see the Baby postnatal new event form + @with-tracked-entity-cleanup 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 @@ -86,8 +89,8 @@ Feature: Related stages 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 + @with-tracked-entity-cleanup 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 @@ -98,4 +101,3 @@ Feature: Related stages And you can see the Baby postnatal new event form 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 \ No newline at end of file diff --git a/cypress/e2e/RelatedStages/RelatedStages.js b/cypress/e2e/RelatedStages/RelatedStages.js index 85d13507e1..9957c0cdbe 100644 --- a/cypress/e2e/RelatedStages/RelatedStages.js +++ b/cypress/e2e/RelatedStages/RelatedStages.js @@ -1,26 +1,95 @@ -import { Given, Then, When, defineStep as And } from '@badeball/cypress-cucumber-preprocessor'; +import { After, Given, Then, When, defineStep as And } from '@badeball/cypress-cucumber-preprocessor'; import { getCurrentYear } from '../../support/date'; +const BABY_POSTNATAL_STAGE = 'ZzYYXq4fJie'; +const BIRTH_STAGE = 'A03MvHHogjR'; +const CHILD_PROGRAMME = 'IpHINAT79UW'; +const FIRST_NAME_ATTRIBUTE = 'w75KJ2mc4zz'; + +let enrolledEntityFirstName; + +const unlinkEvent = eventId => + cy.buildApiUrl('tracker', `events/${eventId}?fields=relationships[relationship]`) + .then(url => cy.request(url)) + .then(({ body }) => { + const relationships = body.relationships ?? []; + + if (!relationships.length) { + return undefined; + } + + return cy + .buildApiUrl('tracker?async=false&importStrategy=DELETE') + .then(deleteUrl => cy.request('POST', deleteUrl, { + relationships: relationships.map(({ relationship }) => ({ relationship })), + })); + }); + +const clearEnrolledEntity = () => { + if (!enrolledEntityFirstName) { + return undefined; + } + + return cy + .buildApiUrl( + 'tracker', + `trackedEntities?program=${CHILD_PROGRAMME}&orgUnitMode=ACCESSIBLE` + + `&filter=${FIRST_NAME_ATTRIBUTE}:eq:${enrolledEntityFirstName}` + + '&fields=trackedEntity&page=1&pageSize=5', + ) + .then(url => cy.request(url)) + .then(({ body }) => { + const trackedEntities = (body.trackedEntities ?? []).map(({ trackedEntity }) => ({ trackedEntity })); + + if (!trackedEntities.length) { + return undefined; + } + + return cy + .buildApiUrl('tracker?async=false&importStrategy=DELETE') + .then(deleteUrl => cy.request('POST', deleteUrl, { trackedEntities })); + }); +}; + +After({ tags: '@with-tracked-entity-cleanup' }, () => { + clearEnrolledEntity(); + enrolledEntityFirstName = undefined; +}); + Given(/^you land on a enrollment page domain by having typed (.*)$/, (url) => { cy.visit(url); cy.get('[data-test="person-selector-container"]').contains('Person'); }); -Given(/^you make sure the event (.+) is unlinked$/, (eventId) => { - cy.buildApiUrl('tracker', `events/${eventId}?fields=relationships[relationship]`) +Given(/^you make sure the enrollment (.+) has a Baby Postnatal event$/, (enrollmentId) => { + cy.buildApiUrl('tracker', `enrollments/${enrollmentId}?fields=orgUnit,program,events[event,programStage]`) .then(url => cy.request(url)) .then(({ body }) => { - const relationships = body.relationships ?? []; - if (relationships.length) { - cy.buildApiUrl('tracker?async=false&importStrategy=DELETE').then((deleteUrl) => { - cy.request('POST', deleteUrl, { - relationships: relationships.map(({ relationship }) => ({ relationship })), - }); - }); + const events = body.events ?? []; + + if (events.some(({ programStage }) => programStage === BABY_POSTNATAL_STAGE)) { + return undefined; } + + return cy + .buildApiUrl('tracker?async=false&importStrategy=CREATE') + .then(createUrl => cy.request('POST', createUrl, { + events: [{ + program: body.program, + programStage: BABY_POSTNATAL_STAGE, + enrollment: enrollmentId, + orgUnit: body.orgUnit, + occurredAt: `${getCurrentYear()}-07-01`, + status: 'ACTIVE', + }], + })); }); }); +Given(/^you make sure the event (.+) is unlinked$/, (eventId) => { + unlinkEvent(eventId); +}); + 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'); @@ -85,18 +154,17 @@ And('you delete the Birth event', () => { cy.buildApiUrl('tracker', 'enrollments/EOxeNf2MdBf?fields=events[event,programStage]') .then(url => cy.request(url)) .then(({ body }) => { - const { events } = body; - - if (events) { - const eventToDelete = events.find(event => event.programStage === 'A03MvHHogjR'); - if (eventToDelete) { - cy.buildApiUrl('tracker?async=false&importStrategy=DELETE').then((eventUrl) => { - cy.request('POST', eventUrl, { events: [eventToDelete] }); - cy.reload(); - }); - } + const eventToDelete = (body.events ?? []).find(event => event.programStage === BIRTH_STAGE); + + if (!eventToDelete) { + return undefined; } - }); + + return cy + .buildApiUrl('tracker?async=false&importStrategy=DELETE') + .then(eventUrl => cy.request('POST', eventUrl, { events: [eventToDelete] })); + }) + .then(() => cy.reload()); }); And('you open the Birth event edit page', () => { @@ -207,6 +275,8 @@ Then('you are redirect to the enrollment dasboard and you see the 2 linked event }); And('you fill the Child Program program registration form with unique values', () => { + enrolledEntityFirstName = `Sarah-${Date.now()}`; + cy.get('input[type="text"]') .eq(1) .type('2021-01-01') @@ -220,11 +290,11 @@ And('you fill the Child Program program registration form with unique values', ( .blur(); cy.get('input[type="text"]') .eq(4) - .type(`Sarah-${Math.round((new Date()).getTime() / 1000)}`) + .type(enrolledEntityFirstName) .blur(); cy.get('input[type="text"]') .eq(5) - .type(`Beth-${Math.round((new Date()).getTime() / 1000)}`) + .type(`Beth-${Date.now()}`) .blur(); cy.get('input[type="text"]') .eq(7) @@ -232,21 +302,6 @@ And('you fill the Child Program program registration form with unique values', ( .blur(); }); -And('you delete the recently added tracked entity', () => { - cy.get('[data-test="profile-widget"]') - .contains('Person profile') - .should('exist'); - cy.get('[data-test="tracked-entity-profile-overflow-button"]') - .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(); @@ -265,14 +320,16 @@ 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; + const events = body.events ?? []; - if (events) { - cy.buildApiUrl('tracker?async=false&importStrategy=DELETE').then((eventUrl) => { - cy.request('POST', eventUrl, { events }); - cy.reload(); - }); + if (!events.length) { + return undefined; } - }); + + return cy + .buildApiUrl('tracker?async=false&importStrategy=DELETE') + .then(eventUrl => cy.request('POST', eventUrl, { events })); + }) + .then(() => cy.reload()); }); diff --git a/cypress/e2e/WidgetsForEnrollmentPages/WidgetAssignee/index.js b/cypress/e2e/WidgetsForEnrollmentPages/WidgetAssignee/index.js index ea9f9fb411..7df3fcb1ae 100644 --- a/cypress/e2e/WidgetsForEnrollmentPages/WidgetAssignee/index.js +++ b/cypress/e2e/WidgetsForEnrollmentPages/WidgetAssignee/index.js @@ -1,4 +1,20 @@ -import { When, Then } from '@badeball/cypress-cucumber-preprocessor'; +import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'; + +Given(/^you make sure the event (.+) has no assigned user$/, (eventId) => { + cy.buildApiUrl('tracker', `events/${eventId}`) + .then(url => cy.request(url)) + .then(({ body }) => { + if (!body.assignedUser) { + return undefined; + } + + const eventToUpdate = { ...body, assignedUser: null }; + + return cy + .buildApiUrl('tracker?async=false&importStrategy=UPDATE') + .then(eventUrl => cy.request('POST', eventUrl, { events: [eventToUpdate] })); + }); +}); When('you assign the user Geetha in the view mode', () => { cy.get('[data-test="widget-assignee"]').within(() => { diff --git a/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentEditEvent/WidgetsForEnrollmentEditEvent.feature b/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentEditEvent/WidgetsForEnrollmentEditEvent.feature index 896acfb495..f370b5ef17 100644 --- a/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentEditEvent/WidgetsForEnrollmentEditEvent.feature +++ b/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentEditEvent/WidgetsForEnrollmentEditEvent.feature @@ -58,14 +58,16 @@ Feature: The user interacts with the widgets on the enrollment edit event Then list should contain the new note: edit mode note Scenario: You can assign a user to a event in the view mode - Given you land on the enrollment edit event page by having typed /#/enrollmentEventEdit?eventId=z4PCgdaBXFh&orgUnitId=g8upMTyEZGZ + Given you make sure the event z4PCgdaBXFh has no assigned user + And you land on the enrollment edit event page by having typed /#/enrollmentEventEdit?eventId=z4PCgdaBXFh&orgUnitId=g8upMTyEZGZ When you assign the user Geetha in the view mode Then the event has the user Geetha Alwan assigned When you remove the assigned user Then the event has no assignd user Scenario: You can assign a user to a event in the edit mode - Given you land on the enrollment edit event page by having typed /#/enrollmentEventEdit?eventId=TMw2x87EZmo&orgUnitId=g8upMTyEZGZ + Given you make sure the event TMw2x87EZmo has no assigned user + And you land on the enrollment edit event page by having typed /#/enrollmentEventEdit?eventId=TMw2x87EZmo&orgUnitId=g8upMTyEZGZ When you assign the user Tracker demo User in the edit mode Then the event has the user Tracker demo User assigned When you remove the assigned user diff --git a/cypress/e2e/WorkingLists/sharedSteps.js b/cypress/e2e/WorkingLists/sharedSteps.js index 5a4f48c094..003aa086b5 100644 --- a/cypress/e2e/WorkingLists/sharedSteps.js +++ b/cypress/e2e/WorkingLists/sharedSteps.js @@ -235,7 +235,10 @@ Then(/^you can load the view with the name ?(.*)$/, (name) => { When('you change the sharing settings', () => { cy.get('[data-test="list-view-menu-button"]').click(); cy.contains('Share view').click(); - cy.get('[placeholder="Search"]').type('Boateng'); + cy.get('[data-test="sharing-dialog"]') + .find('[placeholder="Search"]') + .should('be.enabled') + .type('Boateng'); cy.contains('Kevin Boateng').click(); cy.contains('Choose a level').click(); cy.contains('View and edit').click({ force: true });