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: spy and wait for slow network requests #1107

Merged
merged 3 commits into from
Nov 10, 2022
Merged
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions cypress/e2e/smoke/create_tx.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ describe('Queue a transaction on 1/N', () => {
})

it('should create a queued transaction', () => {
// Spy the /estimations request
cy.intercept('POST', '/**/multisig-transactions/estimations').as('estimations')

// Alias for New transaction modal
cy.contains('h2', 'Review transaction').parents('div').as('modal')

// Wait for /estimations response
cy.wait('@estimations')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of waiting for the real request, I've also considered stubbing the first request by using Date.now() for the recommended nonce. This way we wouldn't have to hit the server with any /estimations request at all and we'd guarantee the nonce is never repeated.

It would make the test more robust but it felt like an overkill. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO e2e tests should not stub anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it. Only spy on the request now


// Estimation is loaded
cy.get('button[type="submit"]').should('not.be.disabled')

Expand Down Expand Up @@ -91,7 +97,19 @@ describe('Queue a transaction on 1/N', () => {
cy.get('input[type="checkbox"]').should('not.exist')
})

// Stub the second /estimations request
cy.intercept('POST', '/**/multisig-transactions/estimations', {
statusCode: 200,
body: { currentNonce: 3, recommendedNonce: recommendedNonce, safeTxGas: '45006' },
})

cy.contains('Submit').click()

// Spy the /propose request and give it an alias
cy.intercept('POST', '/**/propose').as('propose')

// Wait for the /propose request
cy.wait('@propose')
})

it('should click the notification and see the transaction queued', () => {
Expand Down