-
Notifications
You must be signed in to change notification settings - Fork 38
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,74 @@ | ||
describe("Major Projects", () => { | ||
beforeEach(() => { | ||
cy.login(); | ||
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 }) | ||
.eq(1) | ||
.find("button") | ||
.click({ force: true }); | ||
// .eq(1) selects the second row (0-based index). | ||
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(); | ||
|
||
// Wait for the edit button to be visible and click it | ||
cy.get("#project-summary-submit").then(($button) => { | ||
$button[0].click(); | ||
cy.get('a[data-cy="project-description-view-link"]', { timeout: 5000 }).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 | ||
cy.intercept( | ||
"POST", | ||
/.*\/(api\/)?projects\/.*\/project-summaries\/.*\/documents\?mine_guid=.*$/, | ||
(req) => { | ||
req.reply((res) => { | ||
res.send({ | ||
statusCode: 200, | ||
delay: 1000, | ||
}); | ||
}); | ||
} | ||
).as("uploadComplete"); | ||
|
||
// Wait for the mocked PATCH request to complete | ||
cy.wait("@uploadComplete"); | ||
|
||
// 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, | ||
}); | ||
|
||
it("should upload a document successfully", () => { | ||
|
||
const fileName = 'dummy.pdf'; | ||
|
||
cy.get("#project-summary-submit").then(($button) => { | ||
$button[0].click(); | ||
}); | ||
}).as("getComplete"); | ||
|
||
// Wait for the mocked GET request to complete | ||
cy.wait("@getComplete"); | ||
cy.fixture(fileName).then((fileContent) => { | ||
const apiUrlRegex = /.*\/(api\/)?projects\/.*\/project-summaries\/.*\/documents\?mine_guid=.*$/; | ||
|
||
// Intercept the POST request and stub the response | ||
cy.intercept('POST', apiUrlRegex, { | ||
statusCode: 200, | ||
body: { message: "file uploaded successfully" }, // Stubbed response | ||
}).as('uploadRequest'); | ||
|
||
cy.get('input[type="file"]').attachFile({ | ||
fileContent: fileContent, | ||
fileName: fileName, | ||
mimeType: 'application/pdf', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did eslint not catch this file for formatting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to allow eslint to reformat. My frontend git tool had no verify checked all the while. |
||
}); | ||
|
||
// 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"); | ||
}); | ||
}); | ||
|
||
// Wait for the "Upload complete" text to appear within a maximum of 25 seconds. | ||
cy.contains(".filepond--file-status-main", "Upload complete", { timeout: 25000 }); | ||
}); | ||
}); | ||
|
||
it("should download a document successfully", () => { | ||
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 }) | ||
.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); | ||
}); | ||
|
||
it("should download a document successfully", () => { | ||
|
||
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: 3000 }) | ||
.find("div") | ||
.click({ force: true }); | ||
|
||
// Wait for the network request to complete | ||
cy.wait("@downloadRequest").then((interception) => { | ||
// Check that the request was made successfully | ||
expect(interception.response.statusCode).to.equal(301); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one thing- is this running 2 separate tests, the first which uploads the file and the second which downloads? If so, would it be faster to run it as one test that uploads and then downloads, taking out the login and navigation in the middle? I know that unit-test thinking promotes making tests smaller and independent, but cypress recommends combining pieces of the process into a longer one to enhance performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combined the 2 tests into one to enhance performance.