2023-05-18 23:32:35 +03:00
|
|
|
import { getTestSelector } from '../../utils'
|
|
|
|
|
|
|
|
describe('Mini Portfolio account drawer', () => {
|
|
|
|
beforeEach(() => {
|
2023-09-19 17:59:21 +03:00
|
|
|
const portfolioSpy = cy.spy().as('portfolioSpy')
|
|
|
|
cy.intercept(/api.uniswap.org\/v1\/graphql/, (req) => {
|
|
|
|
if (req.body.operationName === 'PortfolioBalances') {
|
|
|
|
portfolioSpy(req)
|
|
|
|
}
|
|
|
|
})
|
2023-08-02 08:13:19 +03:00
|
|
|
cy.visit('/swap')
|
2023-05-18 23:32:35 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('fetches balances when account button is first hovered', () => {
|
|
|
|
// The balances should not be fetched before the account button is hovered
|
2023-09-19 17:59:21 +03:00
|
|
|
cy.get('@portfolioSpy').should('not.have.been.called')
|
2023-05-18 23:32:35 +03:00
|
|
|
|
|
|
|
// Balances should have been fetched once after hover
|
|
|
|
cy.get(getTestSelector('web3-status-connected')).trigger('mouseover')
|
2023-09-19 17:59:21 +03:00
|
|
|
cy.get('@portfolioSpy').should('have.been.calledOnce')
|
2023-08-23 00:34:29 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not re-fetch balances on second hover', () => {
|
|
|
|
// The balances should not be fetched before the account button is hovered
|
2023-09-19 17:59:21 +03:00
|
|
|
cy.get('@portfolioSpy').should('not.have.been.called')
|
2023-08-23 00:34:29 +03:00
|
|
|
|
|
|
|
// Balances should have been fetched once after hover
|
|
|
|
cy.get(getTestSelector('web3-status-connected')).trigger('mouseover')
|
2023-09-19 17:59:21 +03:00
|
|
|
cy.get('@portfolioSpy').should('have.been.calledOnce')
|
2023-05-18 23:32:35 +03:00
|
|
|
|
|
|
|
// Balances should not be refetched upon second hover
|
|
|
|
cy.get(getTestSelector('web3-status-connected')).trigger('mouseover')
|
2023-09-19 17:59:21 +03:00
|
|
|
cy.get('@portfolioSpy').should('have.been.calledOnce')
|
2023-08-23 00:34:29 +03:00
|
|
|
})
|
2023-05-18 23:32:35 +03:00
|
|
|
|
2023-08-23 00:34:29 +03:00
|
|
|
it('should not re-fetch balances when the account drawer is opened', () => {
|
|
|
|
// The balances should not be fetched before the account button is hovered
|
2023-09-19 17:59:21 +03:00
|
|
|
cy.get('@portfolioSpy').should('not.have.been.called')
|
2023-08-23 00:34:29 +03:00
|
|
|
|
|
|
|
// Balances should have been fetched once after hover
|
|
|
|
cy.get(getTestSelector('web3-status-connected')).trigger('mouseover')
|
2023-09-19 17:59:21 +03:00
|
|
|
cy.get('@portfolioSpy').should('have.been.calledOnce')
|
2023-05-18 23:32:35 +03:00
|
|
|
|
2023-08-23 00:34:29 +03:00
|
|
|
// Balances should not be refetched upon opening drawer
|
2023-05-18 23:32:35 +03:00
|
|
|
cy.get(getTestSelector('web3-status-connected')).click()
|
2023-09-19 17:59:21 +03:00
|
|
|
cy.get('@portfolioSpy').should('have.been.calledOnce')
|
2023-05-18 23:32:35 +03:00
|
|
|
})
|
|
|
|
|
2023-06-06 18:57:04 +03:00
|
|
|
it('fetches account information', () => {
|
|
|
|
// Open the mini portfolio
|
|
|
|
cy.intercept(/graphql/, { fixture: 'mini-portfolio/tokens.json' })
|
|
|
|
cy.get(getTestSelector('web3-status-connected')).click()
|
|
|
|
|
|
|
|
// Verify that wallet state loads correctly
|
|
|
|
cy.get(getTestSelector('mini-portfolio-navbar')).contains('Tokens')
|
2023-10-06 19:11:44 +03:00
|
|
|
cy.get(getTestSelector('mini-portfolio-page')).contains('Hidden (197)')
|
2023-06-06 18:57:04 +03:00
|
|
|
|
|
|
|
cy.intercept(/graphql/, { fixture: 'mini-portfolio/nfts.json' })
|
|
|
|
cy.get(getTestSelector('mini-portfolio-navbar')).contains('NFTs').click()
|
|
|
|
cy.get(getTestSelector('mini-portfolio-page')).contains('I Got Plenty')
|
|
|
|
|
2023-11-10 03:57:01 +03:00
|
|
|
// Skip this for now, someone sent test account an NFT on block 17445713 that causes this test to fail
|
|
|
|
// cy.intercept(/graphql/, { fixture: 'mini-portfolio/pools.json' })
|
|
|
|
// cy.get(getTestSelector('mini-portfolio-navbar')).contains('Pools').click()
|
|
|
|
// cy.get(getTestSelector('mini-portfolio-page')).contains('No pools yet')
|
2023-06-06 18:57:04 +03:00
|
|
|
|
2023-08-15 22:02:24 +03:00
|
|
|
cy.intercept(/graphql/, { fixture: 'mini-portfolio/full_activity.json' })
|
2023-06-06 18:57:04 +03:00
|
|
|
cy.get(getTestSelector('mini-portfolio-navbar')).contains('Activity').click()
|
|
|
|
cy.get(getTestSelector('mini-portfolio-page')).contains('Contract Interaction')
|
|
|
|
})
|
|
|
|
|
2023-05-18 23:32:35 +03:00
|
|
|
it('refetches balances when account changes', () => {
|
|
|
|
cy.hardhat().then((hardhat) => {
|
|
|
|
const accountA = hardhat.wallets[0].address
|
|
|
|
const accountB = hardhat.wallets[1].address
|
|
|
|
|
|
|
|
// Opens the account drawer
|
|
|
|
cy.get(getTestSelector('web3-status-connected')).click()
|
|
|
|
|
|
|
|
// A shortened version of the first account's address should be shown
|
|
|
|
cy.contains(accountA.slice(0, 6)).should('exist')
|
|
|
|
|
|
|
|
// Stores the current portfolio balance to later compare to next account's balance
|
|
|
|
cy.get(getTestSelector('portfolio-total-balance'))
|
|
|
|
.invoke('text')
|
|
|
|
.then((originalBalance) => {
|
|
|
|
// TODO(INFRA-3) Replace window.ethereum access below with cypress-hardhat utility
|
|
|
|
// Simulates the wallet changing accounts via eip-1193 event
|
|
|
|
cy.window().then((win) => win.ethereum.emit('accountsChanged', [accountB]))
|
|
|
|
|
|
|
|
// The second account's address should now be shown
|
|
|
|
cy.contains(accountB.slice(0, 6)).should('exist')
|
|
|
|
|
|
|
|
// The second account's portfolio balance should differ from the original balance
|
|
|
|
cy.get(getTestSelector('portfolio-total-balance')).should('not.have.text', originalBalance)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2023-07-27 20:34:26 +03:00
|
|
|
|
|
|
|
it('fetches ENS name', () => {
|
|
|
|
cy.hardhat().then(() => {
|
|
|
|
const haydenAccount = '0x50EC05ADe8280758E2077fcBC08D878D4aef79C3'
|
|
|
|
const haydenENS = 'hayden.eth'
|
|
|
|
|
|
|
|
// Opens the account drawer
|
|
|
|
cy.get(getTestSelector('web3-status-connected')).click()
|
|
|
|
|
|
|
|
// Simulate wallet changing to Hayden's account
|
|
|
|
cy.window().then((win) => win.ethereum.emit('accountsChanged', [haydenAccount]))
|
|
|
|
|
|
|
|
// Hayden's ENS name should be shown
|
|
|
|
cy.contains(haydenENS).should('exist')
|
|
|
|
|
|
|
|
// Close account drawer
|
|
|
|
cy.get(getTestSelector('close-account-drawer')).click()
|
|
|
|
|
|
|
|
// Switch chain to Polygon
|
|
|
|
cy.get(getTestSelector('chain-selector')).eq(1).click()
|
|
|
|
cy.contains('Polygon').click()
|
|
|
|
|
|
|
|
//Reopen account drawer
|
|
|
|
cy.get(getTestSelector('web3-status-connected')).click()
|
|
|
|
|
|
|
|
// Simulate wallet changing to Hayden's account
|
|
|
|
cy.window().then((win) => win.ethereum.emit('accountsChanged', [haydenAccount]))
|
|
|
|
|
|
|
|
// Hayden's ENS name should be shown
|
|
|
|
cy.contains(haydenENS).should('exist')
|
|
|
|
})
|
|
|
|
})
|
2023-05-18 23:32:35 +03:00
|
|
|
})
|