Skip to content

Commit

Permalink
fix: pr-review
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen committed Jan 31, 2024
1 parent ed705ad commit f0b7ad3
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 15 deletions.
58 changes: 58 additions & 0 deletions cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
});

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Then the user can see the program rules effect in the indicator widget
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ export const FEATURES = Object.freeze({
programStageWorkingList: 'programStageWorkingList',
storeProgramStageWorkingList: 'storeProgramStageWorkingList',
customIcons: 'customIcons',
newTransferQueryParam: 'newTransferQueryParam',
});

// The first minor version that supports the feature
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) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
},
};
Expand All @@ -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 },
Expand All @@ -64,7 +58,7 @@ export const useUpdateOwnership = ({
programId,
teiId,
orgUnitId,
apiVersion,
teiParamKey,
},
}),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const OrgUnitTreePlain = (props: Props) => {
<div className={classes.orgunitTree}>
<OrganisationUnitTree
key={treeKey}
dataTest={'widget-enrollment-transfer-orgunit-tree'}
roots={roots.map(item => item.id)}
expanded={expanded}
handleExpand={handleExpand}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ export const TransferModal = ({
ownerOrgUnitId,
});

const handleSelectOrgUnit = (orgUnit) => {
if (orgUnit.id === selectedOrgUnit?.id) return;
setSelectedOrgUnit(orgUnit);
};

return (
<Modal
large
onClose={() => setOpenTransfer(false)}
dataTest={'widget-enrollment-transfer-modal'}
>
<ModalTitle>{i18n.t('Transfer Ownership')}</ModalTitle>
<ModalContent>
Expand All @@ -45,7 +51,7 @@ export const TransferModal = ({

<OrgUnitField
selected={selectedOrgUnit}
onSelectClick={setSelectedOrgUnit}
onSelectClick={handleSelectOrgUnit}
/>

{/* Alert */}
Expand All @@ -65,6 +71,7 @@ export const TransferModal = ({
{i18n.t('Cancel')}
</Button>
<Button
dataTest={'widget-enrollment-transfer-button'}
primary
disabled={!selectedOrgUnit || !validOrgUnit}
loading={selectedOrgUnit && validOrgUnit?.id !== selectedOrgUnit?.id}
Expand Down

0 comments on commit f0b7ad3

Please sign in to comment.