Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDS-5505] e2e test major projects refactor #2780

Merged
merged 5 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/core-web.unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: yarn workspace @mds/core-web run http-server-spa build /index.html 3000 &

- name: Run cypress tests
run: yarn workspace @mds/core-web cypress run --spec "**/*.cy.ts,!**/majorprojects.cy.ts"
run: yarn workspace @mds/core-web cypress run
env:
CYPRESS_TEST_USER: ${{ secrets.CYPRESS_CORE_USER }}
CYPRESS_TEST_PASSWORD: ${{ secrets.CYPRESS_CORE_PASSWORD }}
Expand Down
99 changes: 37 additions & 62 deletions services/core-web/cypress/e2e/majorprojects.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,72 @@ describe("Major Projects", () => {
beforeEach(() => {
cy.login();

cy.get('[data-cy="home-link-button-major-projects"]', { timeout: 5000 }).click({ force: true });
cy.get('[data-cy="home-link-button-major-projects"]', { timeout: 10000 }).click({
force: true,
});

// .eq(1) selects the second row (0-based index).
cy.get("[data-cy=major-projects-table-open-button]", { timeout: 5000 })
cy.get("[data-cy=major-projects-table-open-button]", { timeout: 10000 })
.eq(1)
.find("button")
.click({ force: true });

cy.get('a[data-cy="project-description-view-link"]', { timeout: 5000 }).click();
});

it("should upload and download a document successfully", () => {
const fileName = "dummy.pdf";

// Wait for the edit button to be visible and click it
cy.get("#project-summary-submit").then(($button) => {
$button[0].click();
});
});

it("should upload a document successfully", () => {
const fileName = "dummy.pdf";

cy.fixture(fileName).then((fileContent) => {
cy.get('input[type="file"]').attachFile({
fileContent: fileContent,
fileName: fileName,
mimeType: "application/pdf",
});

// Mock the API call with a regular expression in the URL pattern
// Intercept the POST request and stub the response
cy.intercept(
"POST",
/.*\/(api\/)?projects\/.*\/project-summaries\/.*\/documents\?mine_guid=.*$/,
(req) => {
req.reply((res) => {
res.send({
statusCode: 200,
delay: 1000,
});
});
{
statusCode: 200,
body: { message: "file uploaded successfully" }, // Stubbed response
}
).as("uploadComplete");

// Wait for the mocked PATCH request to complete
cy.wait("@uploadComplete");
).as("uploadRequest");

// Make the PATCH request
cy.intercept("PATCH", /(?:\/document-manager)?\/documents\/.*$/, (req) => {
req.reply((res) => {
res.send({
statusCode: 200,
delay: 1000,
});
});
}).as("patchComplete");

// Wait for the mocked PATCH request to complete
cy.wait("@patchComplete");

// Make the GET request
cy.intercept("GET", /(?:\/api)?\/mines\/documents\/upload\/.*$/, (req) => {
req.reply((res) => {
res.send({
statusCode: 200,
delay: 1000,
});
});
}).as("getComplete");

// Wait for the mocked GET request to complete
cy.wait("@getComplete");
cy.get('input[type="file"]').attachFile({
fileContent: fileContent,
fileName: fileName,
mimeType: "application/pdf",
});

// Wait for the "Upload complete" text to appear within a maximum of 25 seconds.
cy.contains(".filepond--file-status-main", "Upload complete", { timeout: 25000 });
// Wait for the upload request to complete (simulated)
cy.wait("@uploadRequest").then((interception) => {
// Assert that the response body contains the expected message
expect(interception.response.body.message).to.equal("file uploaded successfully");
});
});
});

it("should download a document successfully", () => {
// Intercept the GET request and stub the response
cy.intercept("GET", "**/documents**", (req) => {
// Set the desired response properties
req.reply({
statusCode: 301,
body: "Mocked response data",
});
}).as("downloadRequest");

cy.get("[data-cy=menu-actions-button]")
.first()
.click({ force: true });

// Click the Download file button in the dropdown
cy.contains("button", "Download file", { timeout: 1000 })
cy.contains("button", "Download file", { timeout: 3000 })
.find("div")
.click({ force: true });

// Wait for the file to download
cy.url().then((url) => {
// Make an HTTP request to the URL
cy.request(url).then((response) => {
// Check the response status code
expect(response.status).to.eq(301);
});
// Wait for the network request to complete
cy.wait("@downloadRequest").then((interception) => {
// Check that the download request was made successfully
expect(interception.response.statusCode).to.equal(301);
});
});
});
Loading