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
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 cypress/e2e/smoke/balances.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('Assets > Coins', () => {
cy.get('[id="currency"]').click()

// Select EUR
cy.get('ul[role="listbox"]').findByText('EUR').click()
cy.get('ul[role="listbox"]').findByText('EUR').click({ force: true })

// First row Fiat balance should not contain USD
cy.get(balanceSingleRow).first().find('td').eq(FIAT_AMOUNT_COLUMN).should('not.contain', 'USD')
Expand Down
15 changes: 14 additions & 1 deletion 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 All @@ -53,7 +59,7 @@ describe('Queue a transaction on 1/N', () => {
cy.get('label').contains('Safe transaction nonce').next().clear().type('3')
cy.contains('Confirm').click()

// Asserts the execute checkbox exists and is checkable
// Asserts the execute checkbox exists
cy.get('@modal').within(() => {
cy.get('input[type="checkbox"]')
.parent('span')
Expand All @@ -66,6 +72,7 @@ describe('Queue a transaction on 1/N', () => {
})
cy.contains('Estimated fee').should('exist')

// Asserts the execute checkbox is uncheckable
cy.contains('Execute transaction').click()
cy.get('@modal').within(() => {
cy.get('input[type="checkbox"]')
Expand All @@ -92,6 +99,12 @@ describe('Queue a transaction on 1/N', () => {
})

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