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

Use clock & tick instead of waituntil #398

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 2 additions & 5 deletions packages/ui/cypress/tests/login.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import { injectedAccounts } from '../fixtures/injectedAccounts'
import { landingPageUrl } from '../fixtures/landingData'
import { landingPage } from '../support/page-objects/landingPage'
import { topMenuItems } from '../support/page-objects/topMenuItems'
import { waitForAuthRequest } from '../utils/waitForAuthRequests'
import { clickOnConnect } from '../utils/clickOnConnect'

describe('Connect Account', () => {
beforeEach(() => {
cy.visit(landingPageUrl)
cy.initExtension(injectedAccounts)
topMenuItems.connectButton().click()
landingPage.accountsLoader().should('contain', 'Loading accounts')
clickOnConnect()
})

it('Reject connection', () => {
waitForAuthRequest()
cy.getAuthRequests().then((authRequests) => {
const requests = Object.values(authRequests)
// we should have 1 connection request to the extension
Expand All @@ -28,7 +26,6 @@ describe('Connect Account', () => {
})

it('Connects with Alice', () => {
waitForAuthRequest()
const AliceAddress = Object.values(injectedAccounts)[0].address
cy.getAuthRequests().then((authRequests) => {
const requests = Object.values(authRequests)
Expand Down
7 changes: 2 additions & 5 deletions packages/ui/cypress/tests/transactions.cy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { injectedAccounts } from '../fixtures/injectedAccounts'
import { knownMultisigs } from '../fixtures/knownMultisigs'
import { landingPageUrl } from '../fixtures/landingData'
import { landingPage } from '../support/page-objects/landingPage'
import { multisigPage } from '../support/page-objects/multisigPage'
import { notifications } from '../support/page-objects/notifications'
import { sendTxModal } from '../support/page-objects/sendTxModal'
import { topMenuItems } from '../support/page-objects/topMenuItems'
import { waitForAuthRequest } from '../utils/waitForAuthRequests'
import { clickOnConnect } from '../utils/clickOnConnect'
import { waitForTxRequest } from '../utils/waitForTxRequests'

const AliceAddress = Object.values(injectedAccounts)[0].address
Expand All @@ -21,9 +20,7 @@ describe('Perform transactions', () => {
beforeEach(() => {
cy.visit(landingPageUrl)
cy.initExtension(injectedAccounts)
topMenuItems.connectButton().click()
landingPage.accountsLoader().should('contain', 'Loading accounts')
waitForAuthRequest()
clickOnConnect()
cy.getAuthRequests().then((authRequests) => {
const requests = Object.values(authRequests)
// we should have 1 connection request to the extension
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/cypress/utils/clickOnConnect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { landingPage } from '../support/page-objects/landingPage'
import { topMenuItems } from '../support/page-objects/topMenuItems'

export const clickOnConnect = () => {
cy.clock()
topMenuItems.connectButton().click()
landingPage.accountsLoader().should('contain', 'Loading accounts')
cy.tick(500)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I understood from the documentation, it's a method to mock the time. I didn't find any setInterval in our implementation. Isn't it just pending Promise, or am I mistaken?

Copy link
Collaborator Author

@Tbaut Tbaut Oct 13, 2023

Choose a reason for hiding this comment

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

Nope there's a settimeout to go around a bug

// delay the request by 500ms
// race condition see https://github.com/polkadot-js/extension/issues/938
setTimeout(() => {
getaccountList(chainInfo.isEthereum)

So effectively, when the user clicks on the Connect button, the request is fired 500ms after. But because it's in useEffect etc. it may be a lil more. tick(600) or more failed sometimes for me still.

// restore the clock to prevent WS errors
cy.clock().invoke('restore')
}
2 changes: 0 additions & 2 deletions packages/ui/cypress/utils/waitForAuthRequests.ts

This file was deleted.

Loading