-
Notifications
You must be signed in to change notification settings - Fork 29
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
test(proposals): add e2e test to test proposal logbook fetch #1635
base: master
Are you sure you want to change the base?
Conversation
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.
Hey @Junjiequan - I've reviewed your changes - here's some feedback:
Overall Comments:
- Please fill out the PR description with proper motivation and details about what problem this test is solving.
- The 50-second wait in the test is excessive and could lead to flaky tests. Consider using Cypress's built-in waiting mechanisms or network request interception instead.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟡 Testing: 1 issue found
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
cy.finishedLoading(); | ||
cy.visit("/datasets"); | ||
|
||
cy.wait(50000); // Test |
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.
issue (testing): The 50-second wait is excessive and could make tests unreliable and slow
Consider using Cypress's built-in waiting mechanisms like cy.wait('@APIrequest') or cy.should() with assertions instead of a fixed timeout.
|
||
it("should trigger 'Fetch Logbook Complete' action only once after navigation", () => { | ||
// Capture console logs matching logBookAction | ||
Cypress.on("window:before:load", (win) => { |
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.
suggestion: Console.log interception could be simplified using Cypress's built-in spying capabilities
Consider using cy.spy(console, 'log') instead of manually intercepting console.log. This would make the test more maintainable and clearer.
logbookLogs = []; | ||
}); | ||
|
||
it("should trigger 'Fetch Logbook Complete' action only once after navigation", () => { |
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.
issue (complexity): Consider using network interception to verify API behavior instead of console log monitoring
The test can be simplified by using Cypress's network interception instead of console log capturing. This removes the need for global state and long waits while maintaining the same verification:
it("should trigger logbook fetch only once after navigation", () => {
const proposalId = Math.floor(100000 + Math.random() * 900000).toString();
// Intercept logbook API calls
cy.intercept('GET', '**/logbook*').as('logbookFetch');
cy.createProposal(proposalId);
cy.visit("/proposals");
cy.contains("A minimal test proposal").click();
cy.finishedLoading();
cy.visit("/datasets");
// Verify exactly one logbook fetch occurred
cy.get('@logbookFetch.all').should('have.length', 1);
cy.login(
Cypress.env("secondaryUsername"),
Cypress.env("secondaryPassword")
);
cy.deleteProposal(proposalId);
});
This approach:
- Removes global state management
- Eliminates the 50-second wait
- Directly verifies the API call instead of checking console logs
- Is more reliable and faster to execute
Description
Short description of the pull request
Motivation
Background on use case, changes needed
Fixes:
Please provide a list of the fixes implemented in this PR
Changes:
Please provide a list of the changes implemented by this PR
Tests included
Documentation
official documentation info
If you have updated the official documentation, please provide PR # and URL of the pages where the updates are included
Backend version
Summary by Sourcery
Tests: