Skip to content

Commit

Permalink
Merge pull request #75 from globalfund/feat/DE-991
Browse files Browse the repository at this point in the history
Feat/de 991
  • Loading branch information
stephanoshadjipetrou authored Aug 28, 2024
2 parents 9211a5c + 4f420fc commit 482f06d
Show file tree
Hide file tree
Showing 57 changed files with 2,010 additions and 31 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,42 @@ Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

## Tests - Cypress

Cypress is used for end-to-end testing to ensure that the application functions as expected in the browser. To run the Cypress tests, follow these steps:

In addition to the env variables above the following is also needed for cypress tests to run successfully:

```
REACT_APP_BASE_URL
```

`REACT_APP_BASE_URL`: This is the url your application runs on locally it's usually `http://localhost:3000`

### Install Cypress dependencies

If you haven't already installed Cypress, ensure all dependencies are installed by running:

#### `yarn install`

### Start the Application

Ensure your application is running before starting the Cypress tests. You can do this by running:

#### `yarn start`

### Open Cypress Test Runner

Open the Cypress Test Runner by running:

#### `yarn cypress open`

### Run Cypress Tests in Headless Mode

Alternatively, you can run all Cypress tests in headless mode (without the GUI) directly from the command line using:

#### `yarn cypress run`

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
Expand Down
15 changes: 15 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from "cypress";

require("dotenv").config();

export default defineConfig({
projectId: 'ioki3q',
viewportHeight: 820,
viewportWidth: 1440,
e2e: {
env: {
api_url: process.env.REACT_APP_API,
},
baseUrl: process.env.REACT_APP_BASE_URL,
},
});
150 changes: 150 additions & 0 deletions cypress/e2e/datasets/access-to-funding.page.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/// <reference types="cypress" />

// @ts-ignore
const interceptAllRequests = () => {
const apiUrl = Cypress.env("api_url");
cy.intercept(`${apiUrl}/**`).as("apiData");
};

// @ts-ignore
const waitData = (requestCount: number) => {
for (let i = 0; i < requestCount; i++) {
cy.wait("@apiData");
}
};

describe(
"Testing The Datasets/Access to Funding Page",
{ scrollBehavior: false },
() => {
beforeEach(() => {
interceptAllRequests();

cy.visit("/");
waitData(22);
cy.contains("[data-cy=header-menu-button]", "Datasets").click();
cy.contains("[data-cy=header-menu-button]", "Access to Funding").click();
waitData(8);
});

it("displays the header", { scrollBehavior: "nearest" }, () => {
cy.get("h1").should("have.text", "Access to Funding");
cy.contains("Eligible Countries by Numbers").should("be.visible");
cy.contains("Segmented by Components.").should("be.visible");
cy.contains("Countries Eligible for HIV/AIDS").should("be.visible");
cy.contains("Countries Eligible for Malaria").should("be.visible");
cy.contains("Countries Eligible for Tuberculosis").should("be.visible");
});

it("Can switch eligibility year", { scrollBehavior: "nearest" }, () => {
cy.contains('[data-cy="category-dropdown-button"]', "2023").click();

cy.get('[data-cy="category-dropdown-menu"]')
.filter((_index, parent) => {
return Cypress.$(parent).css("visibility") !== "hidden";
})
.within(() => {
cy.contains('[data-cy="category-dropdown-item"]', "2022").click();
});

waitData(1);

cy.contains('[data-cy="category-dropdown-button"]', "2022").should(
"be.visible"
);
});

it("shows the eligibility block", { scrollBehavior: "nearest" }, () => {
cy.contains('[data-cy="dataset-chart-block"]', "Eligibility")
.first()
.within(() => {
cy.contains("Country eligibility for funding over time.").should(
"be.visible"
);
cy.get('[data-cy="table"]').should("be.visible");
});
});

it(
"Shows the allocation block and can switch chart type",
{ scrollBehavior: "nearest" },
() => {
cy.contains('[data-cy="dataset-chart-block"]', "Allocation")
.first()
.within(() => {
cy.contains("Allocations amounts for countries.").should(
"be.visible"
);
cy.get('[data-cy="sunburst-chart"]').should("be.visible");

cy.contains(
'[data-cy="category-dropdown-button"]',
"Sunburst Chart"
).click();
});

cy.get('[data-cy="category-dropdown-menu"]')
.filter((_index, parent) => {
return Cypress.$(parent).css("visibility") !== "hidden";
})
.within(() => {
cy.contains(
'[data-cy="category-dropdown-item"]',
"Treemap"
).click();
});

cy.contains("[data-cy=dataset-chart-block]", "Allocation").within(
() => {
cy.get('[data-cy="treemap-chart"]').should("be.visible");
cy.contains(
'[data-cy="category-dropdown-button"]',
"Treemap"
).click();
}
);

cy.get('[data-cy="category-dropdown-menu"]')
.filter((_index, parent) => {
return Cypress.$(parent).css("visibility") !== "hidden";
})
.within(() => {
cy.contains(
'[data-cy="category-dropdown-item"]',
"Table View"
).click();
});

cy.contains("[data-cy=dataset-chart-block]", "Allocation").within(
() => {
cy.get('[data-cy="table"]').should("be.visible");
}
);

cy.get('[data-cy="allocation-block-2"]').within(() => {
cy.contains("Cumulative Allocation by Cycles").should("be.visible");
cy.contains("Accompanied by the Component Breakdown.").should(
"be.visible"
);

cy.get('[data-cy="bar-series-chart"]').should("be.visible");
});
}
);

it(
"shows the funding requests block",
{ scrollBehavior: "nearest" },
() => {
cy.contains('[data-cy="dataset-chart-block"]', "Funding Requests")
.first()
.within(() => {
cy.contains("Funding request applications by countries.").should(
"be.visible"
);
cy.get('[data-cy="table"]').should("be.visible");
});
}
);
}
);
132 changes: 132 additions & 0 deletions cypress/e2e/datasets/annual-results.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/// <reference types="cypress" />

// @ts-ignore
const interceptAllRequests = () => {
const apiUrl = Cypress.env("api_url");
cy.intercept(`${apiUrl}/**`).as("apiData");
};

// @ts-ignore
const waitData = (requestCount: number) => {
for (let i = 0; i < requestCount; i++) {
cy.wait("@apiData");
}
};

describe("Testing The Location page", () => {
describe("Testing The Datasets/Annual Results Page", () => {
beforeEach(() => {
interceptAllRequests();

cy.visit("/");
waitData(22);
cy.contains("[data-cy=header-menu-button]", "Datasets").click();
cy.contains("[data-cy=header-menu-button]", "Annual Results").click();
waitData(4);
});

it("displays the header", () => {
cy.get("h1").should("have.text", "Annual Results");
cy.contains(
"Indicator results reported as part of annual Results Report."
).should("be.visible");
cy.contains("People on antiretroviral therapy for HIV in 2022").should(
"be.visible"
);
cy.contains("People with TB treated in 2022").should("be.visible");
cy.contains("Mosquito nets distributed in 2022").should("be.visible");
});

it("Can filter page data", { scrollBehavior: false }, () => {
cy.get('[data-cy="datasets-filter-btn"]').click();
cy.get('[data-cy="filter-panel"]').should("be.visible");

cy.contains('[data-cy="filter-list-accordion"]', "Geography").within(
() => {
cy.get('[data-cy="filter-list-accordion-summary"]').click();
cy.get('[data-cy="filter-panel-search-input"]')
.first()
.type("Europe");
cy.contains(
'[data-cy="filter-list-content-accordion-summary"]',
"Europe"
).within(() => {
cy.get('[data-cy="filter-list-content-checkbox"]').click();
waitData(4);
});
}
);

cy.get('[data-cy="filter-panel"]').within(() => {
cy.contains('[data-cy="applied-filter"]', "Europe").should(
"be.visible"
);
});
});

it("Can switch the data view", { scrollBehavior: false }, () => {
cy.get('[data-cy="toolbar-right-content"]').within(() => {
cy.contains('[data-cy="category-dropdown-button"]', "2022").click();
});

cy.get('[data-cy="category-dropdown-menu"]')
.filter((_index, parent) => {
return Cypress.$(parent).css("visibility") !== "hidden";
})
.within(() => {
cy.contains('[data-cy="category-dropdown-item"]', "2021").click();
});

waitData(4);

cy.contains('[data-cy="category-dropdown-button"]', "2021").should(
"be.visible"
);

cy.contains("People on antiretroviral therapy for HIV in 2021").should(
"be.visible"
);
});

it(
"Shows the Annual Results block and can switch chart type",
{ scrollBehavior: "nearest" },
() => {
cy.contains('[data-cy="dataset-chart-block"]', "Annual Results")
.first()
.within(() => {
cy.get('[data-cy="polyline-tree"]').should("be.visible");

cy.contains(
'[data-cy="category-dropdown-button"]',
"Polyline Tree"
).click();
});

cy.get('[data-cy="category-dropdown-menu"]')
.filter((_index, parent) => {
return Cypress.$(parent).css("visibility") !== "hidden";
})
.within(() => {
cy.contains(
'[data-cy="category-dropdown-item"]',
"Table View"
).click();
});

cy.contains("[data-cy=dataset-chart-block]", "Annual Results").within(
() => {
cy.get('[data-cy="table"]').should("be.visible");
}
);
}
);

it("Shows the Documents block ", { scrollBehavior: "nearest" }, () => {
cy.get('[data-cy="documents-block"]').within(() => {
cy.contains("Documents").should("be.visible");
cy.get('[data-cy="table"]').should("be.visible");
});
});
});
});
Loading

0 comments on commit 482f06d

Please sign in to comment.