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

test(proposals): add e2e test to test proposal logbook fetch #1635

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Junjiequan
Copy link
Contributor

@Junjiequan Junjiequan commented Nov 1, 2024

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

  • Items added

Changes:

Please provide a list of the changes implemented by this PR

  • changes made

Tests included

  • Included for each change/fix?
  • Passing? (Merge will not be approved unless this is checked)

Documentation

  • swagger documentation updated [required]
  • official documentation updated [nice-to-have]

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

  • Does it require a specific version of the backend
  • which version of the backend is required:

Summary by Sourcery

Tests:

  • Add an end-to-end test for the proposal logbook fetch functionality, ensuring the 'Fetch Logbook Complete' action is triggered only once after navigation.

@Junjiequan Junjiequan marked this pull request as draft November 1, 2024 09:43
Copy link

@sourcery-ai sourcery-ai bot left a 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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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
Copy link

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) => {
Copy link

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", () => {
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant