Skip to content

Commit

Permalink
Chore: fix e2e tests (safe-global#2118)
Browse files Browse the repository at this point in the history
* Chore: fix e2e tests

* Restore wallet check

* Use prod CGW

* Use prod CGW

* Pending actions

* Create tx
  • Loading branch information
katspaugh authored Jun 16, 2023
1 parent bd5200a commit 626442d
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 34 deletions.
34 changes: 15 additions & 19 deletions cypress/e2e/smoke/balances.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const balanceSingleRow = '[aria-labelledby="tableTitle"] > tbody tr'

const TEST_SAFE = 'gor:0x97d314157727D517A706B5D08507A1f9B44AaaE9'
const PAGINATION_TEST_SAFE = 'gor:0x850493a15914aAC05a821A3FAb973b4598889A7b'
const ASSETS_LENGTH = 7
const ASSETS_LENGTH = 8
const ASSET_NAME_COLUMN = 0
const TOKEN_AMOUNT_COLUMN = 1
const FIAT_AMOUNT_COLUMN = 2
Expand All @@ -13,28 +13,24 @@ describe('Assets > Coins', () => {
const fiatRegex = new RegExp(`([0-9]{1,3},)*[0-9]{1,3}.[0-9]{2}`)

before(() => {
cy.disableProdCGW()

// Open the Safe used for testing
cy.visit(`/balances?safe=${TEST_SAFE}`)
cy.contains('button', 'Accept selection').click()
// Table is loaded
cy.contains('Görli Ether')

cy.contains('button', 'Got it').click()

cy.get(balanceSingleRow).should('have.length.lessThan', ASSETS_LENGTH)
cy.contains('div', 'Default tokens').click()
cy.wait(100)
cy.contains('div', 'All tokens').click()
cy.get(balanceSingleRow).should('have.length', ASSETS_LENGTH)
})

describe('should have different tokens', () => {
it(`should have ${ASSETS_LENGTH} entries in the table`, () => {
// "Spam" tokens filtered
cy.get(balanceSingleRow).should('have.length', 3)

// Enable all tokens
cy.contains('div', 'Default tokens').click()
cy.wait(100)
cy.contains('div', 'All tokens').click()

cy.get(balanceSingleRow).should('have.length', ASSETS_LENGTH)
})

it('should have Dai', () => {
// Row should have an image with alt text "Dai"
cy.contains('Dai')
Expand Down Expand Up @@ -215,7 +211,7 @@ describe('Assets > Coins', () => {
it('should allow changing rows per page and navigate to next and previous page', () => {
// Table should have 25 rows inittially
cy.contains('Rows per page:').next().contains('25')
cy.contains('1–25 of 27')
cy.contains('1–25 of')
cy.get(balanceSingleRow).should('have.length', 25)

// Change to 10 rows per page
Expand All @@ -225,22 +221,22 @@ describe('Assets > Coins', () => {

// Table should have 10 rows
cy.contains('Rows per page:').next().contains('10')
cy.contains('1–10 of 27')
cy.contains('1–10 of')
cy.get(balanceSingleRow).should('have.length', 10)

// Click on the next page button
cy.get('button[aria-label="Go to next page"]').click({ force: true })
cy.get('button[aria-label="Go to next page"]').click({ force: true })

// Table should have 7 rows
cy.contains('21–27 of 27')
cy.get(balanceSingleRow).should('have.length', 7)
// Table should have N rows
cy.contains('21–28 of')
cy.get(balanceSingleRow).should('have.length', ASSETS_LENGTH)

// Click on the previous page button
cy.get('button[aria-label="Go to previous page"]').click({ force: true })

// Table should have 10 rows
cy.contains('11–20 of 27')
cy.contains('11–20 of')
cy.get(balanceSingleRow).should('have.length', 10)
})
})
Expand Down
3 changes: 2 additions & 1 deletion cypress/e2e/smoke/create_tx.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const currentNonce = 3
describe('Queue a transaction on 1/N', () => {
before(() => {
cy.connectE2EWallet()
cy.useProdCGW()

cy.visit(`/home?safe=${SAFE}`)

Expand Down Expand Up @@ -167,7 +168,7 @@ describe('Queue a transaction on 1/N', () => {
// Click on the notification
cy.contains('View transaction').click()

cy.contains('Queue').click()
//cy.contains('Queue').click()

// Single Tx page
cy.contains('h3', 'Transaction details').should('be.visible')
Expand Down
6 changes: 5 additions & 1 deletion cypress/e2e/smoke/dashboard.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ const SAFE = encodeURIComponent('gor:0xCD4FddB8FfA90012DFE11eD4bf258861204FeEAE'

describe('Dashboard', () => {
before(() => {
cy.useProdCGW()

// Go to the test Safe home page
cy.visit(`/home?safe=${SAFE}`)

cy.contains('button', 'Accept selection').click()

// Wait for dashboard to initialize
Expand All @@ -19,7 +22,8 @@ describe('Dashboard', () => {
cy.contains('0xCD4FddB8FfA90012DFE11eD4bf258861204FeEAE').should('exist')
cy.contains('2/3')
cy.get(`a[href="/balances?safe=${SAFE}"]`).contains('View assets')
cy.contains('p', 'Tokens').next().contains('1')
// Text next to Tokens contains a number greater than 0
cy.contains('p', 'Tokens').next().contains('3')
cy.contains('p', 'NFTs').next().contains('0')
})
})
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/smoke/pending_actions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const SAFE = 'gor:0xCD4FddB8FfA90012DFE11eD4bf258861204FeEAE'
describe('Pending actions', () => {
before(() => {
cy.connectE2EWallet()
cy.useProdCGW()

cy.visit(`/welcome`)
cy.contains('button', 'Accept selection').click()
cy.contains('E2E Wallet @ Görli')
})

beforeEach(() => {
Expand Down Expand Up @@ -42,8 +42,8 @@ describe('Pending actions', () => {
cy.get('li').within(() => {
cy.contains('0xCD4F...eEAE').should('exist')

cy.get('img[alt="E2E Wallet logo"]').next().contains('3').should('exist')
cy.get('[data-testid=CheckIcon]').next().contains('3').should('exist')
cy.get('img[alt="E2E Wallet logo"]').next().contains('2').should('exist')
cy.get('[data-testid=CheckIcon]').next().contains('2').should('exist')

// click on the pending actions
cy.get('[data-testid=CheckIcon]').next().click()
Expand All @@ -55,12 +55,12 @@ describe('Pending actions', () => {
cy.contains('h3', 'Transactions').should('be.visible')

// contains 3 queued transactions
cy.get('span:contains("1 out of 2")').should('have.length', 3)
cy.get('span:contains("1 out of 2")').should('have.length', 2)

// Ensure wallet is connected
cy.contains('E2E Wallet @ Görli')
cy.contains('E2E Wallet @ Goerli')

// contains 3 signable transactions
cy.get('span:contains("Needs your confirmation")').should('have.length', 3)
cy.get('span:contains("Needs your confirmation")').should('have.length', 2)
})
})
2 changes: 2 additions & 0 deletions cypress/e2e/smoke/tx_history.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const CONTRACT_INTERACTION = 'Contract interaction'

describe('Transaction history', () => {
before(() => {
cy.useProdCGW()

// Go to the test Safe transaction history
cy.visit(`/transactions/history?safe=${SAFE}`)
cy.contains('button', 'Accept selection').click()
Expand Down
12 changes: 12 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ Cypress.Commands.add('connectE2EWallet', () => {
})
})

Cypress.Commands.add('useProdCGW', () => {
cy.on('window:before:load', (window) => {
window.localStorage.setItem('SAFE_v2__debugProdCgw', JSON.stringify(true))
})
})

Cypress.Commands.add('disableProdCGW', () => {
cy.on('window:before:load', (window) => {
window.localStorage.setItem('SAFE_v2__debugProdCgw', JSON.stringify(false))
})
})

let LOCAL_STORAGE_MEMORY = {}

Cypress.Commands.add('saveLocalStorageCache', () => {
Expand Down
12 changes: 5 additions & 7 deletions src/hooks/wallets/useOnboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,10 @@ export const useInitOnboard = () => {
onboard.state.actions.setWalletModules(supportedWallets)
}

enableWallets()
}, [chain, onboard])
// Connect to the last connected wallet
enableWallets().then(() => {
if (onboard.state.get().wallets.length > 0) return

// Connect to the last connected wallet
useEffect(() => {
if (onboard && onboard.state.get().wallets.length === 0) {
const label = lastWalletStorage.get()
if (!label) return

Expand All @@ -212,8 +210,8 @@ export const useInitOnboard = () => {
autoSelect: { label, disableModals: true },
})
})
}
}, [onboard])
})
}, [chain, onboard])
}

export default useStore

0 comments on commit 626442d

Please sign in to comment.