From f0b7ad36bddc51e7ae9c26c53adf4c7b681ae90d Mon Sep 17 00:00:00 2001 From: eirikhaugstulen Date: Wed, 31 Jan 2024 19:19:01 +0100 Subject: [PATCH] fix: pr-review --- .../WidgetEnrollment/index.js | 58 +++++++++++++++++++ .../WidgetsForEnrollmentDashboard.feature | 31 +++++++++- .../featuresSupport/support.js | 2 + .../Transfer/hooks/useUpdateOwnership.js | 18 ++---- .../OrgUnitField/OrgUnitField.component.js | 1 + .../TransferModal/TransferModal.component.js | 9 ++- 6 files changed, 104 insertions(+), 15 deletions(-) diff --git a/cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js b/cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js index be1a87296a..d2a58e5e21 100644 --- a/cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js +++ b/cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js @@ -106,6 +106,10 @@ When(/^the user clicks on the delete action/, () => cy.get('[data-test="widget-enrollment-actions-delete"]').click(), ); +When(/^the user clicks on the transfer action/, () => { + cy.get('[data-test="widget-enrollment-actions-transfer"]').click(); +}); + Then(/^the user sees the delete enrollment modal/, () => cy.get('[data-test="widget-enrollment-actions-modal"]').within(() => { cy.contains('Delete enrollment').should('exist'); @@ -116,3 +120,57 @@ Then(/^the user sees the delete enrollment modal/, () => cy.contains('Yes, delete enrollment').should('exist'); }), ); + +Then(/^the user sees the transfer modal/, () => + cy.get('[data-test="widget-enrollment-transfer-modal"]').within(() => { + cy.contains('Transfer Ownership').should('exist'); + cy.contains( + 'Choose the organisation unit to which enrollment ownership should be transferred.', + ).should('exist'); + cy.contains('Cancel').should('exist'); + cy.contains('Transfer').should('exist'); + }), +); + +Then(/^the user sees the organisation unit tree/, () => + cy.get('[data-test="widget-enrollment-transfer-modal"]').within(() => { + cy.get('[data-test="widget-enrollment-transfer-orgunit-tree"]').should( + 'exist', + ); + }), +); + +// test step for scenario: the user clicks on the organisation unit with text: Sierra Leone +Then(/^the user clicks on the organisation unit with text: (.*)/, orgunit => + cy.get('[data-test="widget-enrollment-transfer-modal"]').within(() => { + cy.get('[data-test="widget-enrollment-transfer-orgunit-tree"]').within( + () => { + cy.contains(orgunit).click(); + }, + ); + }), +); + +Then(/^the user sees the organisation unit with text: (.*) is selected/, orgunit => + cy.get('[data-test="widget-enrollment-transfer-modal"]').within(() => { + cy.get('[data-test="widget-enrollment-transfer-orgunit-tree"]').within( + () => { + cy.contains(orgunit).should('have.class', 'checked'); + }, + ); + }), +); + +Then(/^the user successfully transfers the enrollment/, () => { + cy.intercept( + { method: 'PUT', url: '**/tracker/ownership/transfer**' }, + { statusCode: 200 }, + ).as('transferOwnership'); + + cy.get('[data-test="widget-enrollment-transfer-modal"]').within(() => { + cy.get('[data-test="widget-enrollment-transfer-button"]').click(); + }); + + cy.wait('@transferOwnership'); +}); + diff --git a/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentDashboard.feature b/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentDashboard.feature index 89af2a7ea9..d1d4e33488 100644 --- a/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentDashboard.feature +++ b/cypress/e2e/WidgetsForEnrollmentPages/WidgetsForEnrollmentDashboard.feature @@ -31,7 +31,7 @@ Feature: The user interacts with the widgets on the enrollment dashboard And the user sets the birthday date to the current date Then the user see the following text: The womans age is outside the normal range. With the birthdate entered, the age would be: 0 - Scenario: The user updates the TEI attributes. The changes are reflected in the whole page. + Scenario: The user updates the TEI attributes. The changes are reflected in the whole page. Given you land on the enrollment dashboard page by having typed #/enrollment?enrollmentId=TjP3J9cf0z1&orgUnitId=CgunjDKbM45&programId=WSGAb5XwJ3Y&teiId=jzIwoNXIZsK When the user clicks the element containing the text: Edit And the user sees the edit profile modal @@ -124,6 +124,33 @@ Feature: The user interacts with the widgets on the enrollment dashboard And the user clicks on the delete action Then the user sees the delete enrollment modal + Scenario: User can open the transfer modal + Given you land on the enrollment dashboard page by having typed #/enrollment?enrollmentId=wBU0RAsYjKE + Then the enrollment widget should be opened + When the user opens the enrollment actions menu + And the user clicks on the transfer action + Then the user sees the transfer modal + + Scenario: User can select an organisation unit in the transfer modal + Given you land on the enrollment dashboard page by having typed #/enrollment?enrollmentId=wBU0RAsYjKE + Then the enrollment widget should be opened + When the user opens the enrollment actions menu + And the user clicks on the transfer action + And the user sees the transfer modal + And the user sees the organisation unit tree + When the user clicks on the organisation unit with text: Sierra Leone + Then the user sees the organisation unit with text: Sierra Leone is selected + + Scenario: User can transfer the enrollment to another organisation unit + Given you land on the enrollment dashboard page by having typed #/enrollment?enrollmentId=wBU0RAsYjKE + Then the enrollment widget should be opened + When the user opens the enrollment actions menu + And the user clicks on the transfer action + And the user sees the transfer modal + And the user sees the organisation unit tree + When the user clicks on the organisation unit with text: Sierra Leone + Then the user successfully transfers the enrollment + Scenario: User can add note on enrollment dashboard page Given you land on the enrollment dashboard page by having typed #/enrollment?enrollmentId=wBU0RAsYjKE Then the stages and events should be loaded @@ -132,4 +159,4 @@ 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 \ No newline at end of file + Then the user can see the program rules effect in the indicator widget diff --git a/src/core_modules/capture-core-utils/featuresSupport/support.js b/src/core_modules/capture-core-utils/featuresSupport/support.js index 207c929c21..103a3348ff 100644 --- a/src/core_modules/capture-core-utils/featuresSupport/support.js +++ b/src/core_modules/capture-core-utils/featuresSupport/support.js @@ -3,6 +3,7 @@ export const FEATURES = Object.freeze({ programStageWorkingList: 'programStageWorkingList', storeProgramStageWorkingList: 'storeProgramStageWorkingList', customIcons: 'customIcons', + newTransferQueryParam: 'newTransferQueryParam', }); // The first minor version that supports the feature @@ -10,6 +11,7 @@ const MINOR_VERSION_SUPPORT = Object.freeze({ [FEATURES.programStageWorkingList]: 39, [FEATURES.storeProgramStageWorkingList]: 40, [FEATURES.customIcons]: 41, + [FEATURES.newTransferQueryParam]: 41, }); export const hasAPISupportForFeature = (minorVersion: string, featureName: string) => diff --git a/src/core_modules/capture-core/components/WidgetEnrollment/Actions/Transfer/hooks/useUpdateOwnership.js b/src/core_modules/capture-core/components/WidgetEnrollment/Actions/Transfer/hooks/useUpdateOwnership.js index acb5212f67..90fad37774 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollment/Actions/Transfer/hooks/useUpdateOwnership.js +++ b/src/core_modules/capture-core/components/WidgetEnrollment/Actions/Transfer/hooks/useUpdateOwnership.js @@ -1,10 +1,11 @@ // @flow import type { QueryRefetchFunction } from '@dhis2/app-runtime'; import i18n from '@dhis2/d2-i18n'; -import { useAlert, useDataEngine, useConfig } from '@dhis2/app-runtime'; +import { useAlert, useDataEngine } from '@dhis2/app-runtime'; import { useMutation } from 'react-query'; import { ProgramAccessLevels } from '../../../TransferModal/hooks/useProgramAccessLevel'; import { OrgUnitScopes } from '../../../TransferModal/hooks/useTransferValidation'; +import { FEATURES, useFeature } from '../../../../../../capture-core-utils'; type Props = { teiId: ?string, @@ -26,20 +27,13 @@ export type UpdateEnrollmentOwnership = {| const UpdateEnrollmentOwnershipMutation = { resource: 'tracker/ownership/transfer', type: 'update', - params: ({ teiId, programId, orgUnitId, apiVersion }) => { + params: ({ teiId, programId, orgUnitId, teiParamKey }) => { const params = { program: programId, ou: orgUnitId, - trackedEntityInstance: null, - trackedEntity: null, + [teiParamKey]: teiId, }; - if (apiVersion <= 40) { - params.trackedEntityInstance = teiId; - } else { - params.trackedEntity = teiId; - } - return params; }, }; @@ -51,7 +45,7 @@ export const useUpdateOwnership = ({ onTransferOutsideCaptureScope, }: Props): { updateEnrollmentOwnership: UpdateEnrollmentOwnership } => { const dataEngine = useDataEngine(); - const { apiVersion } = useConfig(); + const teiParamKey = useFeature(FEATURES.newTransferQueryParam) ? 'trackedEntity' : 'trackedEntityInstance'; const { show: showErrorAlert } = useAlert( i18n.t('An error occurred while transferring ownership'), { critical: true }, @@ -64,7 +58,7 @@ export const useUpdateOwnership = ({ programId, teiId, orgUnitId, - apiVersion, + teiParamKey, }, }), { diff --git a/src/core_modules/capture-core/components/WidgetEnrollment/TransferModal/OrgUnitField/OrgUnitField.component.js b/src/core_modules/capture-core/components/WidgetEnrollment/TransferModal/OrgUnitField/OrgUnitField.component.js index b71fafb8aa..6bc24461e0 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollment/TransferModal/OrgUnitField/OrgUnitField.component.js +++ b/src/core_modules/capture-core/components/WidgetEnrollment/TransferModal/OrgUnitField/OrgUnitField.component.js @@ -77,6 +77,7 @@ const OrgUnitTreePlain = (props: Props) => {
item.id)} expanded={expanded} handleExpand={handleExpand} diff --git a/src/core_modules/capture-core/components/WidgetEnrollment/TransferModal/TransferModal.component.js b/src/core_modules/capture-core/components/WidgetEnrollment/TransferModal/TransferModal.component.js index 1341321731..9165c0593c 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollment/TransferModal/TransferModal.component.js +++ b/src/core_modules/capture-core/components/WidgetEnrollment/TransferModal/TransferModal.component.js @@ -32,10 +32,16 @@ export const TransferModal = ({ ownerOrgUnitId, }); + const handleSelectOrgUnit = (orgUnit) => { + if (orgUnit.id === selectedOrgUnit?.id) return; + setSelectedOrgUnit(orgUnit); + }; + return ( setOpenTransfer(false)} + dataTest={'widget-enrollment-transfer-modal'} > {i18n.t('Transfer Ownership')} @@ -45,7 +51,7 @@ export const TransferModal = ({ {/* Alert */} @@ -65,6 +71,7 @@ export const TransferModal = ({ {i18n.t('Cancel')}