Skip to content

Commit

Permalink
fix: cypress for TopBarActions
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Feb 23, 2024
1 parent a86b61e commit fcd6dd4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
22 changes: 10 additions & 12 deletions cypress/e2e/TopBarActions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ Feature: User uses the TopBarActions to navigate

Scenario: Enrollment page > You go to the new page without a program selected
Given you land on a enrollment page domain by having typed /#/enrollment?programId=IpHINAT79UW&orgUnitId=DiszpKrYNg8&teiId=pybd813kIWx&enrollmentId=FS085BEkJo2
When the user clicks the element containing the text: New
And the user clicks the element containing the text: New...
When the user clicks the arrow button to see the dropdown
And the user clicks the element containing the text: Create new in another program...
Then the current url is /#/new?orgUnitId=DiszpKrYNg8

Scenario: Enrollment page > You go to the new page inside the same program
Given you land on a enrollment page domain by having typed /#/enrollment?programId=IpHINAT79UW&orgUnitId=DiszpKrYNg8&teiId=pybd813kIWx&enrollmentId=FS085BEkJo2
When the user clicks the element containing the text: New
And the user clicks the element containing the text: New person in Child Programme
When the user clicks the element containing the text: Create new
Then the current url is /#/new?orgUnitId=DiszpKrYNg8&programId=IpHINAT79UW

Scenario: Enrollment Event Edit page > Clear selections
Expand All @@ -48,14 +47,14 @@ Feature: User uses the TopBarActions to navigate

Scenario: Enrollment Event Edit page > You go to the new page without a program selected
Given you land on a enrollment page domain by having typed /#/enrollmentEventEdit?orgUnitId=DwpbWkiqjMy&eventId=KNbStF7YTon
When the user clicks the element containing the text: New
And the user clicks the element containing the text: New...
When the user clicks the arrow button to see the dropdown
And the user clicks the element containing the text: Create new in another program...
Then the current url is /#/new?orgUnitId=DwpbWkiqjMy

Scenario: Enrollment Event Edit page > You go to the new page inside the same program
Given you land on a enrollment page domain by having typed /#/enrollmentEventEdit?orgUnitId=DwpbWkiqjMy&eventId=KNbStF7YTon
When the user clicks the element containing the text: New
And the user clicks the element containing the text: New person in WHO RMNCH Tracker
When the user clicks the element containing the text: Create new
And the user clicks the element containing the text: Create new person
Then the current url is /#/new?orgUnitId=DwpbWkiqjMy&programId=WSGAb5XwJ3Y

Scenario: Enrollment Event edit page > When the user performs any actions in edit mood a popup warning message will appear.
Expand Down Expand Up @@ -88,15 +87,14 @@ Feature: User uses the TopBarActions to navigate
Scenario: Enrollment Event New page > You go to the new page without a program selected
Given you land on a enrollment page domain by having typed #/enrollmentEventNew?programId=WSGAb5XwJ3Y&orgUnitId=DwpbWkiqjMy&teiId=yFcOhsM1Yoa&enrollmentId=ek4WWAgXX5i&stageId=edqlbukwRfQ
And the user see the following text: Clear selections
When the user clicks the element containing the text: New
And the user clicks the element containing the text: New...
When the user clicks the arrow button to see the dropdown
And the user clicks the element containing the text: Create new in another program...
Then the current url is /#/new?orgUnitId=DwpbWkiqjMy

Scenario: Enrollment Event New page > You go to the new page inside the same program
Given you land on a enrollment page domain by having typed #/enrollmentEventNew?programId=WSGAb5XwJ3Y&orgUnitId=DwpbWkiqjMy&teiId=yFcOhsM1Yoa&enrollmentId=ek4WWAgXX5i&stageId=edqlbukwRfQ
And the user see the following text: Clear selections
When the user clicks the element containing the text: New
And the user clicks the element containing the text: New person in WHO RMNCH Tracker
When the user clicks the element containing the text: Create new person
Then the current url is /#/new?orgUnitId=DwpbWkiqjMy&programId=WSGAb5XwJ3Y

Scenario: Enrollment Event New page > When the user performs any actions after it interacts with the form a popup warning message will appear.
Expand Down
5 changes: 5 additions & 0 deletions cypress/e2e/TopBarActions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ When(/^the user clicks on the edit button/, () =>
cy.get('[data-test="widget-enrollment-event"]').find('[data-test="dhis2-uicore-button"]').eq(1).click(),
);

When('the user clicks the arrow button to see the dropdown', () => {
cy.get('[data-test="new-button-toggle"]')
.click();
});

Then('the user sees the warning popup', () => {
cy.contains('Discard unsaved changes?');
cy.contains('This event has unsaved changes. Leaving this page without saving will lose these changes. Are you sure you want to discard unsaved changes?');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const styles = () => ({
});

const ActionButtonsPlain = ({
onNewClick,
onNewClickWithoutProgramId,
onFindClick,
onFindClickWithoutProgramId,
Expand All @@ -26,11 +27,9 @@ const ActionButtonsPlain = ({
openConfirmDialog,
}: PlainProps & CssClasses) => {
const { trackedEntityName, scopeType, programName } = useScopeInfo(selectedProgramId);
const [openNew, setOpenNew] = useState(false);
const [openSearch, setOpenSearch] = useState(false);

useEffect(() => {
setOpenNew(false);
setOpenSearch(false);
}, [openConfirmDialog]);

Expand All @@ -52,14 +51,13 @@ const ActionButtonsPlain = ({
secondary
dataTest="new-button"
className={classes.marginRight}
open={openNew}
onClick={() => setOpenNew(prev => !prev)}
onClick={() => { onNewClick(); }}
component={
<FlyoutMenu dense maxWidth="250px">
<MenuItem
dataTest="new-menuitem-one"
label={`${i18n.t('Create new in another program')}...`}
onClick={() => { setOpenNew(prev => !prev); onNewClickWithoutProgramId(); }}
onClick={() => { onNewClickWithoutProgramId(); }}
/>
</FlyoutMenu>
}
Expand Down Expand Up @@ -101,12 +99,12 @@ const ActionButtonsPlain = ({
programName,
interpolation: { escapeValue: false },
})}
onClick={() => { setOpenSearch(prev => !prev); onFindClick(); }}
onClick={() => { onFindClick(); setOpenSearch(prev => !prev); }} // Rekkefølge endret
/>
<MenuItem
dataTest="find-menuitem-two"
label={`${i18n.t('Search')}...`}
onClick={() => { setOpenSearch(prev => !prev); onFindClickWithoutProgramId(); }}
onClick={() => { onFindClickWithoutProgramId(); setOpenSearch(prev => !prev); }} // Rekkefølge endret
/>
</FlyoutMenu>
}
Expand Down

0 comments on commit fcd6dd4

Please sign in to comment.