Skip to content

Commit

Permalink
chore: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen committed Oct 2, 2023
1 parent debba9e commit bc37417
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ When(/^you click the checkbox number (.*)$/, (eq) => {
.click();
});

When(/^you click the (.*) button/, (buttonText) => {
cy.intercept({
method: 'POST',
url: '**/tracker?async=false',
}).as('postEvents');

cy.get('[data-test="dhis2-uicore-button"]')
.contains(buttonText)
.click();

cy.wait('@postEvents');
});

When(/^you click the button to (.*) without post request/, (buttonText) => {
cy.get('[data-test="dhis2-uicore-button"]')
.contains(buttonText)
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/EnrollmentPage/BreakingTheGlass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ And('you log out', () => {
});

And('you log in as tracker2 user', () => {
cy.clearCookies();
cy.visit('/').then(() => {
cy.get('#j_username').type('tracker2');
cy.get('#j_password').type('Tracker@123');
Expand Down
25 changes: 15 additions & 10 deletions cypress/e2e/EnrollmentPage/StagesAndEventsWidget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Then('the stages and events widget should be closed', () => {
cy.get('[data-test="stages-and-events-widget"]')
.within(() => {
cy.get('[data-test="widget-contents"]')
.children()
.should('not.exist');
cy.contains('Birth').should('not.exist');
});
Expand Down Expand Up @@ -115,23 +114,29 @@ Then('the default list should be displayed', () => {
});

When(/^you sort list asc by (.*)$/, (columnName) => {
cy.get('[data-test="stages-and-events-widget"]')
.find('[data-test="widget-contents"]')
cy.get('[data-test="stages-and-events-widget"]').should('exist')
.find('[data-test="widget-contents"]').should('exist')
.find('[data-test="stage-content"]')
.should('exist')
.eq(2)
.find('thead')
.should('exist')
.find('th')
.should('exist')
.contains(columnName)
.parent()
.should('exist')
.within(() => {
cy.contains('th', columnName)
.find('button')
.click();
cy.wait(100);
cy.contains('th', columnName)
.find('button')
.click();
cy.get('button').should('exist') // Use cy.get() instead of cy.find()
.click()
.then(() => {
// Perform further actions or assertions if needed
cy.get('button').should('exist').click();
});
});
});


Then(/^the sorted list by (.*) asc should be displayed$/, () => {
const rows = [
'07-13|Bumbeh MCHP',
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/MainPage.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: User interacts with Main page

Scenario: The Working list is displayed
Scenario: The Working list is displayed
Given you are in the main page with no selections made
And the user selects the program Child Programme
And the user selects the org unit Ngelehun CHC
Expand Down Expand Up @@ -29,7 +29,7 @@ Feature: User interacts with Main page
Then the current url is /#/?orgUnitId=DiszpKrYNg8&programId=M3xtLkYBlKI&selectedTemplateId=PpGINOT00UX

Scenario: You are redirected to create a custom working list
Given you are in the search page with Ngelehun and MNCH / PNC context
Given you are in the search page with Ngelehun and MNCH PNC context
And the search form is displayed
When the user clicks the element containing the text: Create saved list
Then the current url is /#/?orgUnitId=DiszpKrYNg8&programId=uy2gU8kT1jF&selectedTemplateId=uy2gU8kT1jF-default
Expand All @@ -41,4 +41,4 @@ Feature: User interacts with Main page
When you opt in to use the new enrollment Dashboard for Child Programme
Then you see the opt out component for Child Programme
When you opt out to use the new enrollment Dashboard for Child Programme
Then you see the opt in component for Child Programme
Then you see the opt in component for Child Programme
2 changes: 1 addition & 1 deletion cypress/e2e/MainPage/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Given, Then, defineStep as And } from '@badeball/cypress-cucumber-preprocessor';
import '../sharedSteps';

Given('you are in the search page with Ngelehun and MNCH / PNC context', () => {
Given('you are in the search page with Ngelehun and MNCH PNC context', () => {
cy.visit('/#/search?orgUnitId=DiszpKrYNg8&programId=uy2gU8kT1jF');
});

Expand Down
5 changes: 2 additions & 3 deletions cypress/e2e/NewEventThroughAddRelationship/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ When('you add data to the form', () => {
});

When('you submit the form', () => {
cy.server();
cy.route('POST', '**/tracker?async=false').as('postData');
cy.intercept('POST', '**/tracker?async=false').as('postData');
cy.get('[data-test="dhis2-uicore-splitbutton-button"]')
.click();
});

Then('the event should be sent to the server successfully', () => {
cy.wait('@postData', { timeout: 30000 })
.then((result) => {
expect(result.status).to.equal(200);
expect(result.response.statusCode).to.equal(200);
// clean up
const id = result.response.body.bundleReport.typeReportMap.EVENT.objectReports[0].uid;
cy.buildApiUrl('events', id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ When('you click the enrollment widget toggle open close button', () => {

Then('the enrollment widget should be closed', () => {
cy.get('[data-test="widget-enrollment"]').within(() => {
cy.get('[data-test="widget-contents"]').children().should('not.exist');
cy.get('[data-test="widget-contents"]').should('not.exist');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Then('the widget profile should be closed', () => {
cy.get('[data-test="profile-widget"]')
.within(() => {
cy.get('[data-test="widget-contents"]')
.children()
.should('not.exist');
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
import '../../sharedSteps';

beforeEach(() => {
// Disable cache for chromium browsers to force the api to be called
if (Cypress.browser.family === 'chromium') {
Cypress.automation('remote:debugger:protocol', {
command: 'Network.enable',
params: {},
});
Cypress.automation('remote:debugger:protocol', {
command: 'Network.setCacheDisabled',
params: { cacheDisabled: true },
});
}
});

Given('you open the main page with Ngelehun and malaria case context', () => {
cy.server();
cy.route('GET', '**/tracker/events**').as('getDefaultEvents');
cy.intercept('GET', '**/tracker/events**').as('getDefaultEvents');

cy.visit('#/?programId=VBqh0ynB2wv&orgUnitId=DiszpKrYNg8');
});
Expand All @@ -12,15 +25,15 @@ Then('events should be retrieved from the api using the default query args', ()
cy.wait('@getDefaultEvents', { timeout: 40000 }).as('result');

cy.get('@result')
.its('status')
.its('response.statusCode')
.should('equal', 200);

cy.get('@result')
.its('url')
.its('response.url')
.should('include', 'pageSize=15');

cy.get('@result')
.its('url')
.its('response.url')
.should('include', 'page=1');

cy.get('@result').its('response.body.instances').as('events');
Expand Down Expand Up @@ -52,7 +65,7 @@ When('you select the working list called events assigned to anyone', () => {
.contains('Events assigned to anyone')
.should('exist');

cy.route('GET', '**/tracker/events**').as('getEventsAssignedToAnyone');
cy.intercept('GET', '**/tracker/events**').as('getEventsAssignedToAnyone');

cy.get('[data-test="workinglists-template-selector-chips-container"]')
.contains('Events assigned to anyone')
Expand All @@ -63,29 +76,29 @@ Then('events assigned to anyone should be retrieved from the api', () => {
cy.wait('@getEventsAssignedToAnyone', { timeout: 40000 }).as('result');

cy.get('@result')
.its('status')
.its('response.statusCode')
.should('equal', 200);

cy.get('@result')
.its('url')
.its('response.url')
.should('include', 'assignedUserMode=ANY');

cy.get('@result')
.its('url')
.its('response.url')
.should('include', 'page=1');

cy.get('@result').its('response.body.instances').as('events');
});

When('you apply the assignee filter', () => {
cy.route('GET', '**/tracker/events**').as('getEventsAssignedToAnyone');
cy.intercept('GET', '**/tracker/events**').as('getEventsAssignedToAnyone');

cy.get('[data-test="list-view-filter-apply-button"]')
.click();
});

When('you apply the status filter', () => {
cy.route('GET', '**/tracker/events**').as('getActiveEventsAssignedToAnyone');
cy.intercept('GET', '**/tracker/events**').as('getActiveEventsAssignedToAnyone');

cy.get('[data-test="list-view-filter-apply-button"]')
.click();
Expand All @@ -95,54 +108,48 @@ Then('active events that are assigned to anyone should be retrieved from the api
cy.wait('@getActiveEventsAssignedToAnyone', { timeout: 40000 }).as('result');

cy.get('@result')
.its('status')
.its('response.statusCode')
.should('equal', 200);

cy.get('@result')
.its('url')
.its('response.url')
.should('include', 'assignedUserMode=ANY');

cy.get('@result')
.its('url')
.its('response.url')
.should('include', 'status=ACTIVE');

cy.get('@result')
.its('url')
.its('response.url')
.should('include', 'page=1');

cy.get('@result').its('response.body.instances').as('events');
});

When('you apply the current filter on the event working list', () => {
cy.route('GET', '**/tracker/events**').as('getEvents');
cy.intercept('GET', '**/tracker/events**').as('getEvents');

cy.get('[data-test="list-view-filter-apply-button"]')
.click();
});

Then('the age filter button should show that the filter is in effect', () => {
cy.get('[data-test="event-working-lists"]')
.contains('Age (years): 10 to 20')
.should('exist');
});

Then('events where age is between 10 and 20 should be retrieved from the api', () => {
cy.wait('@getEvents', { timeout: 40000 }).as('result');

cy.get('@result')
.its('status')
.its('response.statusCode')
.should('equal', 200);

cy.get('@result')
.its('url')
.its('response.url')
.should('match', /filter=.*10/);

cy.get('@result')
.its('url')
.its('response.url')
.should('match', /filter=.*20/);

cy.get('@result')
.its('url')
.its('response.url')
.should('include', 'page=1');

cy.get('@result').its('response.body.instances').as('events');
Expand All @@ -152,7 +159,7 @@ When('you click the next page button on the event working list', () => {
cy.get('[data-test="search-pagination-next-page"]')
.should('exist');

cy.route('GET', '**/tracker/events**').as('getEvents');
cy.intercept('GET', '**/tracker/events**').as('getEvents');

cy.get('[data-test="search-pagination-next-page"]')
.click();
Expand All @@ -162,21 +169,21 @@ Then('new events should be retrieved from the api', () => {
cy.wait('@getEvents', { timeout: 40000 }).as('result');

cy.get('@result')
.its('status')
.its('response.statusCode')
.should('equal', 200);

cy.get('@result').its('response.body.instances').as('events');
});

When('you click the previous page button on the event working list', () => {
cy.route('GET', '**/tracker/events**').as('getEvents');
cy.intercept('GET', '**/tracker/events**').as('getEvents');

cy.get('[data-test="search-pagination-previous-page"]')
.click();
});

When('you click the first page button on the event working list', () => {
cy.route('GET', '**/tracker/events**').as('getEvents');
cy.intercept('GET', '**/tracker/events**').as('getEvents');

cy.get('[data-test="search-pagination-first-page"]')
.click();
Expand All @@ -186,7 +193,7 @@ When('you change rows per page to 50', () => {
cy.get('div[data-test="rows-per-page-selector"]')
.should('exist');

cy.route('GET', '**/tracker/events**').as('getEvents');
cy.intercept('GET', '**/tracker/events**').as('getEvents');

cy.get('div[data-test="rows-per-page-selector"]')
.click()
Expand All @@ -198,15 +205,15 @@ Then('an event batch capped at 50 records should be retrieved from the api', ()
cy.wait('@getEvents', { timeout: 40000 }).as('result');

cy.get('@result')
.its('status')
.its('response.statusCode')
.should('equal', 200);

cy.get('@result')
.its('url')
.its('response.url')
.should('include', 'pageSize=50');

cy.get('@result')
.its('url')
.its('response.url')
.should('include', 'page=1');

cy.get('@result').its('response.body.instances').as('events');
Expand All @@ -217,7 +224,7 @@ When('you click the report date column header', () => {
.contains('Report date')
.should('exist');

cy.route('GET', '**/tracker/events**').as('getEvents');
cy.intercept('GET', '**/tracker/events**').as('getEvents');

cy.get('[data-test="dhis2-uicore-tableheadercellaction"]')
.eq(0)
Expand All @@ -230,15 +237,15 @@ Then('events should be retrieved from the api ordered ascendingly by report date
cy.wait('@getEvents', { timeout: 40000 }).as('resultAsc');

cy.get('@resultAsc')
.its('status')
.its('response.statusCode')
.should('equal', 200);

cy.get('@resultAsc')
.its('url')
.its('response.url')
.should('match', /order=.*asc/);

cy.get('@resultAsc')
.its('url')
.its('response.url')
.should('include', 'page=1');

cy.get('@resultAsc').its('response.body.instances').as('events');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ Given you open the main page with Ngelehun and Inpatient morbidity and mortality
When you set the date of admission filter
And you save the view as toDeleteWorkingList
When you delete the name toDeleteWorkingList
Then the custom events working list is deleted
Then the custom events working list is deleted
Loading

0 comments on commit bc37417

Please sign in to comment.