Skip to content

Commit

Permalink
Update e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ltthienn committed Dec 6, 2023
1 parent 8beac44 commit 815f5b0
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 293 deletions.
22 changes: 22 additions & 0 deletions cypress/e2e/pages/cross-chain.po.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { NETWORK_LIST } from "../selectors/constants.cy"
import { CrossChainLocators, NetworkLocators } from "../selectors/selectors.cy"
import { TokenCatalog } from "./swap-page.po.cy"

export interface myCallbackType<T> {
(myArgument: T): void
}

export const CrossChain = {

Expand Down Expand Up @@ -27,6 +32,15 @@ export const CrossChain = {
return NETWORK_LIST[random]
},

selectTokenIn(): TokenCatalog {
cy.selectToken(CrossChainLocators.dropdownTokenIn)
return new TokenCatalog()
},
selectTokenOut(): TokenCatalog {
cy.selectToken(CrossChainLocators.dropdownTokenOut)
return new TokenCatalog()
},

checkLoadedPage() {
return cy.get(CrossChainLocators.rechartsSurface, { timeout: 20000 }).should('be.visible').then($obj => {
if ($obj.length > 0) {
Expand All @@ -47,4 +61,12 @@ export const CrossChain = {
return network
})
},

getCurrentTokenIn(text: myCallbackType<string>) {
cy.getContent(CrossChainLocators.dropdownTokenIn, text)
},

getCurrentTokenOut(text: myCallbackType<string>) {
cy.getContent(CrossChainLocators.dropdownTokenOut, text)
},
}
46 changes: 0 additions & 46 deletions cypress/e2e/pages/farm-page.po.cy.ts

This file was deleted.

1 change: 0 additions & 1 deletion cypress/e2e/pages/header.po.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
CrossChainLocators,
HeaderLocators,
LimitOrderLocators,
NetworkLocators,
SwapPageLocators,
Expand Down
51 changes: 0 additions & 51 deletions cypress/e2e/pages/pools-page.po.cy.ts

This file was deleted.

16 changes: 4 additions & 12 deletions cypress/e2e/pages/swap-page.po.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
CrossChainLocators,
HeaderLocators,
LimitOrderLocators,
NetworkLocators,
SwapPageLocators,
Expand Down Expand Up @@ -55,19 +54,12 @@ export const SwapPage = {
cy.get(CrossChainLocators.btnCrossChain).click()
},

goToFarmPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblFarms).click({ force: true })
getBalanceWallet(text: myCallbackType<string>) {
cy.getContent(WalletLocators.lblBalance, text)
},

goToPoolPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblPools).click({ force: true })
},

goToMyPoolsPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblMyPools).click({ force: true })
getCurrentBalanceIn(text: myCallbackType<string>) {
cy.getContent(SwapPageLocators.lblBalanceIn, text)
},
}

Expand Down
24 changes: 4 additions & 20 deletions cypress/e2e/selectors/selectors.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const SwapPageLocators = {
dropdownTokenIn: '[data-testid=swap-currency-input] [data-testid=token-symbol-container]',
dropdownTokenOut: '[data-testid=swap-currency-output] [data-testid=token-symbol-container]',
btnSkipTutorial: '[data-testid=button-skip-tutorial]',
lblBalanceIn: '[data-testid=swap-currency-input] [data-testid=balance]',
}

export const LimitOrderLocators = {
Expand All @@ -38,6 +39,8 @@ export const CrossChainLocators = {
btnCrossChain: '[data-testid=cross-chain-tab]',
btnNetworkIn: '[data-testid=swap-currency-input] [data-testid=network-button]',
btnNetworkOut: '[data-testid=swap-currency-output] [data-testid=network-button]',
dropdownTokenIn: '[data-testid=swap-currency-input] [data-testid=open-currency-select-button]',
dropdownTokenOut: '[data-testid=swap-currency-output] [data-testid=open-currency-select-button]',
btnUnderstand: '[data-testid=understand-button]',
rechartsSurface: '.recharts-surface', //it's in the library so don't use data-testid
}
Expand All @@ -47,29 +50,10 @@ export const WalletLocators = {
btnMetaMask: '[data-testid=connect-METAMASK]',
chkAcceptTerm: '[data-testid=accept-term]',
statusConnected: '[data-testid=web3-status-connected]',
lblBalance: '[data-testid=select-network] div div div'
}

export const NetworkLocators = {
btnSelectNetwork: '[data-testid=select-network]',
btnNetwork: '[data-testid=network-list]',
}

export const HeaderLocators = {
dropdownEarn: '[data-testid=earn-menu]',
lblPools: '[data-testid=pools-nav-link]',
lblMyPools: '[data-testid=my-pools-nav-link]',
lblFarms: '[data-testid=farms-nav-link]',
}

export const FarmLocators = {
lblApr: '[data-testid=apr-value]',
lblTvl: '[data-testid=tvl-value]',
}

export const PoolLocators = {
txtSearchPool: 'input[data-testid="search-pool"]',
txtPriceValue: 'input[data-testid="price-value"]',
txtAmountIn: '[data-testid="token-amount-input"]',
lblCurrentPrice: '[data-testid="current-price"]',
btnZapIn: '[data-testid="zap-in-btn"]',
}
12 changes: 11 additions & 1 deletion cypress/e2e/specs/connect-wallet.e2e.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Network, SwapPage } from '../pages/swap-page.po.cy'
import { DEFAULT_NETWORK, DEFAULT_URL, NETWORK, TAG } from '../selectors/constants.cy'
import { SwapPageLocators } from '../selectors/selectors.cy'

const wallet = new Network()

Expand All @@ -11,7 +12,7 @@ describe('Metamask Extension tests', { tags: TAG.regression }, () => {
SwapPage.getStatusConnectedWallet()
})

it('Redirects to swap page when a user has already connected a wallet', { tags: TAG.smoke }, () => {
it('Redirects to swap page when a user has already connected a wallet', () => {
cy.url().should('include', '/swap')
})

Expand All @@ -22,6 +23,15 @@ describe('Metamask Extension tests', { tags: TAG.regression }, () => {
cy.allowMetamaskToAddAndSwitchNetwork().then(approved => {
expect(approved).to.be.true
})
cy.wait(2000)
SwapPage.getBalanceWallet(value => {
const balance = value.split(' ')[0]
if (balance !== '0') {
SwapPage.getCurrentBalanceIn(value => {
expect(Number(value)).to.be.greaterThan(0);
})
}
})
}
})
})
3 changes: 0 additions & 3 deletions cypress/e2e/specs/constants.ts

This file was deleted.

24 changes: 0 additions & 24 deletions cypress/e2e/specs/farm-page.e2e.cy.ts

This file was deleted.

56 changes: 0 additions & 56 deletions cypress/e2e/specs/intercept.e2e.cy.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,16 @@
import { FarmPage } from "../pages/farm-page.po.cy";
import { SwapPage, TokenCatalog } from "../pages/swap-page.po.cy"
import { DEFAULT_URL, TAG, } from "../selectors/constants.cy"
const tokenCatalog = new TokenCatalog()
const farm = new FarmPage()

describe('Intercept', { tags: TAG.regression }, () => {
beforeEach(() => {
SwapPage.open(DEFAULT_URL)
})

afterEach(() => {
cy.clearCookies();
cy.clearLocalStorage();
})

describe('Swap', () => {
it('Should get route successfully', () => {
cy.intercept('GET', '**/routes?**').as('get-route')
cy.wait('@get-route', { timeout: 20000 }).its('response.statusCode').should('be.oneOf', [200, 404, 408])
})
})

describe('Pools', () => {
it('Should get pool, farm list successfully', () => {
cy.intercept('GET', '**/farm-pools?**').as('get-farm-list')
cy.intercept('GET', '**/pools?**').as('get-pool-list')
SwapPage.goToPoolPage()
cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200)
cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200)
})

it('Should be displayed APR and TVL values', () => {
cy.intercept('GET', '**/pools?**').as('get-pools')
SwapPage.goToPoolPage()
cy.wait('@get-pools', { timeout: 20000 }).its('response.body.data').then(response => {
const totalPools = response.pools.length;
const count = response.pools.reduce((acc: number, pool: { totalValueLockedUsd: string; apr: string }) => {
if (pool.totalValueLockedUsd === '0' && pool.apr === '0') {
return acc + 1;
}
return acc;
}, 0);
expect(count).not.to.equal(totalPools);
})
})
})

describe('My Pools', () => {
it('Should get farm list successfully', () => {
cy.intercept('GET', '**/farm-pools?**').as('get-farm-list')
SwapPage.goToMyPoolsPage()
cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200)
})
})

describe('Farms', () => {
it('Should get pool, farm list successfully', () => {
cy.intercept('GET', '**/farm-pools?**').as('get-farm-list')
cy.intercept('GET', '**/pools?**').as('get-pool-list')
SwapPage.goToFarmPage()
cy.get('[data-testid=farm-block]')
.should(_ => { })
.then($list => {
if ($list.length) {
cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200)
}
cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200)
})
})
})
})
Loading

0 comments on commit 815f5b0

Please sign in to comment.