Skip to content

Commit

Permalink
QA-60 | E2E | Cross-chain - Add e2e tests (#2336)
Browse files Browse the repository at this point in the history
  • Loading branch information
ltthienn authored Oct 27, 2023
1 parent 5722a81 commit 7075972
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
network: ['Ethereum', 'Arbitrum', 'Optimism', 'Avalanche', 'BNB']
network: ['Ethereum', 'Arbitrum', 'Optimism', 'Avalanche', 'BNB Chain']
steps:
- name: Trigger Code Checkout
uses: actions/checkout@v3
Expand Down
50 changes: 50 additions & 0 deletions cypress/e2e/pages/cross-chain.po.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { NETWORK_LIST } from "../selectors/constants.cy"
import { CrossChainLocators, NetworkLocators } from "../selectors/selectors.cy"

export const CrossChain = {

closeUnderstandPopup() {
cy.get(CrossChainLocators.btnUnderstand).click()
},

selectNetworkIn(networkName: string) {
cy.get(CrossChainLocators.btnNetworkIn).click()
cy.get(NetworkLocators.btnNetwork).contains(networkName).click({ force: true })

},

selectNetworkOut(networkName: string) {
cy.get(CrossChainLocators.btnNetworkOut).click()
cy.get(NetworkLocators.btnNetwork).contains(networkName).click({ force: true })
},

changeNetwork(oldNetwork: string[]) {
let random = 0
do {
random = Math.floor(Math.random() * NETWORK_LIST.length)
} while (oldNetwork.includes(NETWORK_LIST[random]) === true)

return NETWORK_LIST[random]
},

checkLoadedPage() {
return cy.get(CrossChainLocators.rechartsSurface, { timeout: 20000 }).should(() => { }).then($obj => {
if ($obj.length > 0) {
return true
}
return false
})
},

getCurrentNetworkIn() {
return cy.get(CrossChainLocators.btnNetworkIn).invoke('text').then(network => {
return network
})
},

getCurrentNetworkOut() {
return cy.get(CrossChainLocators.btnNetworkOut).invoke('text').then(network => {
return network
})
},
}
13 changes: 13 additions & 0 deletions cypress/e2e/pages/limit-order.po.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ export interface myCallbackType<T> {
}
export const LimitOder = {

checkGetStartedDisplay() {
return cy.get(LimitOrderLocators.btnGetStarted, { timeout: 10000 }).should(() => { }).then($obj => {
if ($obj.length > 0) {
return true
}
return false
})
},

clickGetStarted() {
cy.get(LimitOrderLocators.btnGetStarted, { timeout: 10000 }).click({ force: true })
},

selectTokenSell(): TokenCatalog {
cy.selectToken(LimitOrderLocators.dropdownTokenSell)
return new TokenCatalog()
Expand Down
6 changes: 5 additions & 1 deletion cypress/e2e/pages/swap-page.po.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HeaderLocators, LimitOrderLocators, NetworkLocators, SwapPageLocators, TokenCatalogLocators, WalletLocators } from "../selectors/selectors.cy"
import { CrossChainLocators, HeaderLocators, LimitOrderLocators, NetworkLocators, SwapPageLocators, TokenCatalogLocators, WalletLocators } from "../selectors/selectors.cy"

export interface myCallbackType<T> {
(myArgument: T): void
Expand Down Expand Up @@ -41,6 +41,10 @@ export const SwapPage = {
cy.get(LimitOrderLocators.btnLimit).click()
},

goToCrossChain() {
cy.get(CrossChainLocators.btnCrossChain).click()
},

goToFarmPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblFarms).click({ force: true })
Expand Down
2 changes: 2 additions & 0 deletions cypress/e2e/selectors/constants.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const TOKEN_SYMBOLS = {
'BNB': ['RICE', 'DAI', 'USDT', 'USDC', 'MAI']
}

export const NETWORK_LIST = ['Ethereum', 'Arbitrum', 'Optimism', 'Avalanche', 'BNB Chain', 'Polygon PoS', 'Fantom', 'Linea', 'Base']

export const UNWHITELIST_TOKENS = {
"Ethereum":
[
Expand Down
13 changes: 11 additions & 2 deletions cypress/e2e/selectors/selectors.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ export const LimitOrderLocators = {
btnLimit: '[data-testid=limit-button]',
txtSellingRate: '[data-testid=input-selling-rate]',
lblBalanceIn: '[data-testid=limit-order-input-tokena] [data-testid=balance]',
lblErrorMessage: '[data-testid=error-message]'
lblErrorMessage: '[data-testid=error-message]',
btnGetStarted: '[data-testid=get-started-button]'
}

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]',
btnUnderstand: '[data-testid=understand-button]',
rechartsSurface: '.recharts-surface' //it's in the library so don't use data-testid
}

export const WalletLocators = {
Expand All @@ -40,7 +49,7 @@ export const WalletLocators = {

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

export const HeaderLocators = {
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/specs/connect-wallet.e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ describe('Metamask Extension tests', { tags: TAG.regression }, () => {
SwapPage.connectWallet()
})

it.skip('Redirects to swap page when a user has already connected a wallet', () => {
it('Redirects to swap page when a user has already connected a wallet', () => {
cy.acceptMetamaskAccess()
SwapPage.getStatusConnectedWallet()
cy.url().should('include', '/swap')
})

it.skip('Should approve permission to switch network', () => {
it('Should approve permission to switch network', () => {
if (NETWORK !== DEFAULT_NETWORK) {
SwapPage.getStatusConnectedWallet()
wallet.selectNetwork(NETWORK)
Expand Down
37 changes: 37 additions & 0 deletions cypress/e2e/specs/cross-chain.e2e.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { CrossChain } from "../pages/cross-chain.po.cy"
import { SwapPage } from "../pages/swap-page.po.cy"
import { DEFAULT_URL, NETWORK, TAG } from "../selectors/constants.cy"


describe(`Cross-chain on ${NETWORK}`, { tags: TAG.regression }, () => {
beforeEach(() => {
SwapPage.open(DEFAULT_URL)
SwapPage.goToCrossChain()
CrossChain.checkLoadedPage().then((checked) => {
if (checked === true) {
CrossChain.closeUnderstandPopup()
}
})
})

describe('Select network', () => {
it('The network should be changed successfully', () => {
const networkIn = CrossChain.changeNetwork([NETWORK])
CrossChain.selectNetworkIn(networkIn)
CrossChain.getCurrentNetworkIn().then((currentNetworkIn) => {
expect(currentNetworkIn).to.equal(networkIn)
})

CrossChain.getCurrentNetworkOut().then((currentNetworkOut) => {
const networkOut = CrossChain.changeNetwork([networkIn, currentNetworkOut])
cy.wait(1000)
CrossChain.selectNetworkOut(networkOut)
CrossChain.getCurrentNetworkOut().then((currentNetworkOut) => {
expect(currentNetworkOut).to.equal(networkOut)
})

})
})

})
})
7 changes: 5 additions & 2 deletions cypress/e2e/specs/limit-order.e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { DEFAULT_URL, NETWORK, NORESULTS_TEXT, NOTOKENS_TEXT, TAG, TOKEN_SYMBOLS

const tokenSymbols = TOKEN_SYMBOLS[NETWORK]


const tokenCatalog = new TokenCatalog();


describe(`Limit Order on ${NETWORK}`, { tags: TAG.regression }, () => {
beforeEach(() => {
SwapPage.open(DEFAULT_URL)
SwapPage.goToLimitOrder()
LimitOder.checkGetStartedDisplay().then((checked) => {
if (checked === true) {
LimitOder.clickGetStarted()
}
})
})

describe('Add/remove/select token with favorite tokens list', () => {
Expand Down
3 changes: 2 additions & 1 deletion cypress/support/connectWalletCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare global {
}

Cypress.Commands.add('connectWallet', () => {
cy.get(WalletLocators.chkAcceptTerm).click()
// feature changed => temporary comment
// cy.get(WalletLocators.chkAcceptTerm).click()
cy.get(WalletLocators.btnMetaMask).click()
})
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface CurrencyInputPanelBridgeProps {
usdValue?: string
isCrossChain?: boolean
tooltipNotSupportChain?: string
dataTestId?: string
}

const noop = () => {
Expand Down Expand Up @@ -80,6 +81,7 @@ export default function CurrencyInputPanelBridge({
usdValue,
isCrossChain,
tooltipNotSupportChain,
dataTestId,
}: CurrencyInputPanelBridgeProps) {
const [modalOpen, setModalOpen] = useState(false)
const { account } = useActiveWeb3React()
Expand Down Expand Up @@ -111,7 +113,7 @@ export default function CurrencyInputPanelBridge({

return (
<div style={{ width: '100%' }}>
<InputPanel id={id}>
<InputPanel id={id} data-testid={dataTestId}>
<Container hideInput={false} selected={false} error={error}>
<Flex justifyContent="space-between" fontSize="12px" marginBottom="12px" alignItems="center">
<SelectNetwork
Expand Down
1 change: 1 addition & 0 deletions src/components/Header/web3/NetworkModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export default function NetworkModal({
}
}}
id={CHAINS_DROPZONE_ID}
data-testid="network-list"
style={{ position: 'relative', minHeight: '50px' }}
>
<DropzoneOverlay show={dropIdDraggingOver === CHAINS_DROPZONE_ID} text={t`Remove from favorite`} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/swapv2/LimitOrder/Tutorial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function Tutorial({ onClose }: { onClose: () => void }) {
Learn more about our limit orders <ExternalLink href={DOCS_LINKS.USER_GUIDE}>here</ExternalLink>.
</Trans>
</Text>
<ButtonPrimary height="40px" width={'100%'} onClick={onGetStart}>
<ButtonPrimary height="40px" width={'100%'} onClick={onGetStart} data-testid="get-started-button">
<Trans>Get Started</Trans>
</ButtonPrimary>
</Column>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Bridge/Disclaimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function DisclaimerCrossChain() {
liability for any losses incurred.
</Trans>
</TextWrapper>
<ButtonWarning style={{ marginTop: 20 }} onClick={handleClickUnderstand}>
<ButtonWarning style={{ marginTop: 20 }} onClick={handleClickUnderstand} data-testid="understand-button">
<Trans>I Understand</Trans>
</ButtonWarning>
</Container>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Bridge/SelectNetwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Web3Network({
const { name } = selectedChainId ? NETWORKS_INFO[selectedChainId] : { name: t`Select a network` }
return (
<>
<NetworkSwitchContainer onClick={() => chainIds.length && toggleNetworkModal()}>
<NetworkSwitchContainer data-testid="network-button" onClick={() => chainIds.length && toggleNetworkModal()}>
{selectedChainId && (
<NetworkLogo chainId={selectedChainId} style={{ width: 20, height: 20, marginRight: '8px' }} />
)}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/CrossChain/SwapForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export default function SwapForm() {
onMax={handleMaxInput}
onCurrencySelect={onCurrencySelect}
id="swap-currency-input"
dataTestId="swap-currency-input"
usdValue={amountUsdIn ?? ''}
/>
</Flex>
Expand Down Expand Up @@ -342,6 +343,7 @@ export default function SwapForm() {
}
onCurrencySelect={onCurrencySelectDest}
id="swap-currency-output"
dataTestId="swap-currency-output"
usdValue={amountUsdOut ?? ''}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/SwapV3/Tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const Tab = styled(ButtonEmpty)<{ isActive: boolean }>`
margin-right: 0;
}
${({ theme }) => theme.mediaWidth.upToSmall`
${({ theme }) => theme.mediaWidth.upToSmall`
padding: 0px 0.75rem;
`}
`
Expand Down Expand Up @@ -104,7 +104,7 @@ export default function Tabs({ activeTab }: Props) {
</Tab>
{isSupportLimitOrder(chainId) && <LimitTab onClick={() => onClickTab(TAB.LIMIT)} />}
{CHAINS_SUPPORT_CROSS_CHAIN.includes(chainId) && (
<Tab onClick={() => onClickTab(TAB.CROSS_CHAIN)} isActive={isCrossChainPage}>
<Tab onClick={() => onClickTab(TAB.CROSS_CHAIN)} isActive={isCrossChainPage} data-testid="cross-chain-tab">
<Text fontSize={20} fontWeight={500}>
<Trans>Cross-Chain</Trans>
</Text>
Expand Down

0 comments on commit 7075972

Please sign in to comment.