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

QA New Test Balance after hiding and showing token #2062

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion packages/core-mobile/app/components/PortfolioListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ const PortfolioListItem: FC<Props> = ({
alignItems: 'flex-end',
marginLeft: 8
}}>
<Text variant="heading6" ellipsizeMode={'tail'}>
<Text
testID={`portfolio_list_item__${symbol}_balance`}
variant="heading6"
ellipsizeMode={'tail'}>
{currencyFormatter(tokenPriceInCurrency)}
</Text>
{priceChange !== undefined && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function PortfolioHeader(): JSX.Element {
<Space x={6} />
</>
)}
<Text variant="heading3">
<Text variant="heading3" testID="portfolio_balance__total">
{currencyBalance.replace(selectedCurrency, '')}
</Text>
<Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ const NetworkTokensHeader = (): JSX.Element => {
{isBalanceLoading ? (
<ActivityIndicator style={{ alignSelf: 'flex-start' }} size="small" />
) : (
<Text variant="heading4" ellipsizeMode={'tail'}>
<Text
testID={`network_tokens_header_balance__${chainName}`}
variant="heading4"
ellipsizeMode={'tail'}>
{formattedTotalBalance}
</Text>
)}
Expand Down
9 changes: 8 additions & 1 deletion packages/core-mobile/e2e/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ const dragTo = async (
)
}

const getAmount = (amount: string | undefined): number => {
if (amount) {
return parseFloat(amount.replace(/\$/g, '').replace(/,/g, ''))
} else return 0
}

const shuffleArray = <T>(array: T[]): T[] =>
array.sort(() => Math.random() - 0.5)

Expand Down Expand Up @@ -425,5 +431,6 @@ export default {
shuffleArray,
scrollToBottom,
scrollToTop,
hasText
hasText,
getAmount
}
31 changes: 31 additions & 0 deletions packages/core-mobile/e2e/pages/manageTokens.page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import manageTokens from '../locators/manageTokens.loc'
import Action from '../helpers/actions'
import commonElsPage from './commonEls.page'

class ManageTokensPage {
get addButton() {
Expand Down Expand Up @@ -37,6 +38,36 @@ class ManageTokensPage {
async inputCustomToken(address: string) {
await Action.setInputText(this.inputContractAddress, address, 0)
}

async hideToken(token: string) {
await commonElsPage.typeSearchBar(token)
// TryCatch Phrase is for test requirment
try {
await Action.waitForElement(by.id(`${token}_blocked`))
await Action.tap(by.id(`${token}_blocked`))
console.log("Display the token if it's already hidden")
} catch (e) {
console.log("It's already displayed on token list")
}
// Hide the token
await Action.tap(by.id(`${token}_displayed`))
await commonElsPage.goBack()
}

async showToken(token: string) {
await commonElsPage.typeSearchBar(token)
// TryCatch Phrase is for test requirment
try {
await Action.waitForElement(by.id(`${token}_display`))
await Action.tap(by.id(`${token}_blocked`))
console.log("Block the token if it's already displayed")
} catch (e) {
console.log("It's already blocked")
}
// Display the token
await Action.tap(by.id(`${token}_blocked`))
await commonElsPage.goBack()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These methods are almost the same and should be combined into one. Something like this?

async showToken(token: string, tokenStatus: "blocked") {
    await commonElsPage.typeSearchBar(token)
    // TryCatch Phrase is for test requirement
    try {
      await Action.waitForElement(by.id(`${token}_${tokenStatus}`))
      await Action.tap(by.id(`${token}_${tokenStatus}`))
      console.log("Block the token if it's already displayed")
    } catch (e) {
      console.log("It's already blocked")
    }
    // Display the token
    await Action.tap(by.id(`${token}_${tokenStatus}`))
    await commonElsPage.goBack()
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

}

export default new ManageTokensPage()
10 changes: 10 additions & 0 deletions packages/core-mobile/e2e/pages/networksManage.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Action from '../helpers/actions'
import Assert from '../helpers/assertions'
import networksManage from '../locators/networksManage.loc'
import { Platform } from '../helpers/constants'
import portfolioLoc from '../locators/portfolio.loc'
import PortfolioPage from './portfolio.page'

const platformIndex = Action.platform() === Platform.iOS ? 1 : 0
Expand Down Expand Up @@ -295,6 +296,15 @@ class NetworksPage {
)
}

async switchActiveNetwork(network = 'Avalanche (C-Chain)') {
await Action.scrollToTop(by.id(portfolioLoc.tokensTabListView))
if (
!(await Action.isVisible(by.id(portfolioLoc.activeNetwork + network), 0))
) {
await this.switchNetwork(network)
}
}

async switchToBitcoinTestNet() {
await PortfolioPage.tapNetworksDropdown()
await PortfolioPage.tapNetworksDropdownBTCTestNet()
Expand Down
36 changes: 36 additions & 0 deletions packages/core-mobile/e2e/pages/portfolio.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,42 @@ class PortfolioPage {
async verifyAccountName(name: string) {
await Assert.hasText(accountManagePage.accountDropdownTitle, name)
}

async getTotalBalance(): Promise<number> {
// The total balance on Portfolio header
const bal = await Action.getElementText(by.id('portfolio_balance__total'))
return Action.getAmount(bal)
}

async getActiveNetworkBalance(): Promise<number> {
// Balance of the active network on Portfolio tab
const bal = await Action.getElementText(this.activeNetworkBalance)
return Action.getAmount(bal)
}

async getNetworkTokensBalance(
network = 'Avalanche (C-Chain)'
): Promise<number> {
// The selected network tokens' balance (e.g. Avalanche (C-Chain) tokens' balance)
await Action.waitForElement(this.portfolioTokenList)
const bal = await Action.getElementText(
by.id(`network_tokens_header_balance__${network}`)
)
return Action.getAmount(bal)
}

async getTokenBalance(token: string): Promise<number> {
await Action.waitForElement(this.portfolioTokenList)
await Action.scrollListUntil(
by.id(`portfolio_list_item__${token}_balance`),
this.portfolioTokenList,
100
)
const bal = await Action.getElementText(
by.id(`portfolio_list_item__${token}_balance`)
)
return Action.getAmount(bal)
}
}

export default new PortfolioPage()
212 changes: 212 additions & 0 deletions packages/core-mobile/e2e/tests/balance/manageTokenBalance.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
import assert from 'assert'
import actions from '../../helpers/actions'
import { warmup } from '../../helpers/warmup'
import portfolioLoc from '../../locators/portfolio.loc'
import commonElsPage from '../../pages/commonEls.page'
import manageTokensPage from '../../pages/manageTokens.page'
import networksManagePage from '../../pages/networksManage.page'
import portfolioPage from '../../pages/portfolio.page'

describe('Balance After Managing Token', () => {
beforeAll(async () => {
await warmup()
})

it('should deduct balance after hiding token on C-Chain', async () => {
// Get balances before hiding token
const fullBal = await portfolioPage.getTotalBalance()
const activeNetworkBal = await portfolioPage.getActiveNetworkBalance()
await portfolioPage.tapActiveNetwork()
const networkTokensBal = await portfolioPage.getNetworkTokensBalance()
const btcBal = await portfolioPage.getTokenBalance('BTC.b')

// Hide token
await actions.scrollToTop(portfolioPage.portfolioTokenList)
await portfolioPage.tapManageTokens()
await manageTokensPage.hideToken('Bitcoin')

// Get balances after hiding token
const newNetworkTokensBal = await portfolioPage.getNetworkTokensBalance()
await commonElsPage.goBack()
const newFullBal = await portfolioPage.getTotalBalance()
const newActiveNetworkBal = await portfolioPage.getActiveNetworkBalance()
const tolerance = 1

// Log token balances before and after hiding token
console.log(
`Before: \nfullBal: ${fullBal}, \nbtcBal: ${btcBal}, \nactiveNetworkBal: ${activeNetworkBal} \nnetworkTotalBal: ${networkTokensBal}`
)
console.log(
`After: \nnewFullBal: ${newFullBal}, \nnewActiveNetworkBal: ${newActiveNetworkBal} \nnewNetworkTotalBal: ${newNetworkTokensBal}`
)

// Assert that the tolerance is within the expected range
const fullBalDiff = Math.abs(fullBal - btcBal - newFullBal)
const networkTokensBalDiff = Math.abs(
networkTokensBal - btcBal - newNetworkTokensBal
)
const activeNetworkBalDiff = Math.abs(
activeNetworkBal - btcBal - newActiveNetworkBal
)
assert(fullBalDiff < tolerance, `${fullBalDiff} !< ${tolerance}`)
assert(
networkTokensBalDiff < tolerance,
`${networkTokensBalDiff} !< ${tolerance}`
)
assert(
activeNetworkBalDiff < tolerance,
`${activeNetworkBalDiff} !< ${tolerance}`
)
})

it('should deduct balance after hiding token on Ethereum', async () => {
// Get balances before hiding token
await networksManagePage.switchActiveNetwork(portfolioLoc.ethNetwork)
const fullBal = await portfolioPage.getTotalBalance()
const activeNetworkBal = await portfolioPage.getActiveNetworkBalance()
await portfolioPage.tapActiveNetwork(portfolioLoc.ethNetwork)
const networkTokensBal = await portfolioPage.getNetworkTokensBalance(
portfolioLoc.ethNetwork
)
const wethBal = await portfolioPage.getTokenBalance('WETH')

// Hide token
await actions.scrollToTop(portfolioPage.portfolioTokenList)
await portfolioPage.tapManageTokens()
await manageTokensPage.hideToken('Wrapped Ether')

// Get balances after hiding token
const newNetworkTokensBal = await portfolioPage.getNetworkTokensBalance(
portfolioLoc.ethNetwork
)
await commonElsPage.goBack()
const newFullBal = await portfolioPage.getTotalBalance()
const newActiveNetworkBal = await portfolioPage.getActiveNetworkBalance()
const tolerance = 1

// Log token balances before and after hiding token
console.log(
`Before: \nfullBal: ${fullBal}, \nbtcBal: ${wethBal}, \nactiveNetworkBal: ${activeNetworkBal} \nnetworkTotalBal: ${networkTokensBal}`
)
console.log(
`After: \nnewFullBal: ${newFullBal}, \nnewActiveNetworkBal: ${newActiveNetworkBal} \nnewNetworkTotalBal: ${newNetworkTokensBal}`
)

// Assert that the tolerance is within the expected range
const fullBalDiff = Math.abs(fullBal - wethBal - newFullBal)
const networkTokensBalDiff = Math.abs(
networkTokensBal - wethBal - newNetworkTokensBal
)
const activeNetworkBalDiff = Math.abs(
activeNetworkBal - wethBal - newActiveNetworkBal
)
assert(fullBalDiff < tolerance, `${fullBalDiff} !< ${tolerance}`)
assert(
networkTokensBalDiff < tolerance,
`${networkTokensBalDiff} !< ${tolerance}`
)
assert(
activeNetworkBalDiff < tolerance,
`${activeNetworkBalDiff} !< ${tolerance}`
)
})

it('should update balance after showing token on Ethereum', async () => {
// Get balances before showing token
const fullBal = await portfolioPage.getTotalBalance()
const activeNetworkBal = await portfolioPage.getActiveNetworkBalance()
await portfolioPage.tapActiveNetwork(portfolioLoc.ethNetwork)
const networkTokensBal = await portfolioPage.getNetworkTokensBalance(
portfolioLoc.ethNetwork
)

// Show token
await actions.scrollToTop(portfolioPage.portfolioTokenList)
await portfolioPage.tapManageTokens()
await manageTokensPage.showToken('Wrapped Ether')

// Get balances after hiding token
const newNetworkTokensBal = await portfolioPage.getNetworkTokensBalance(
portfolioLoc.ethNetwork
)
const wethBal = await portfolioPage.getTokenBalance('WETH')
await commonElsPage.goBack()
const newFullBal = await portfolioPage.getTotalBalance()
const newActiveNetworkBal = await portfolioPage.getActiveNetworkBalance()
const tolerance = 1

// Log token balances before and after hiding token
console.log(
`Before: \nfullBal: ${fullBal}, \nactiveNetworkBal: ${activeNetworkBal} \nnetworkTotalBal: ${networkTokensBal}`
)
console.log(
`After: \nnewFullBal: ${newFullBal}, \nwethBal: ${wethBal}, \nnewActiveNetworkBal: ${newActiveNetworkBal} \nnewNetworkTotalBal: ${newNetworkTokensBal}`
)

// Assert that the tolerance is within the expected range
const fullBalDiff = Math.abs(fullBal + wethBal - newFullBal)
const networkTokensBalDiff = Math.abs(
networkTokensBal + wethBal - newNetworkTokensBal
)
const activeNetworkBalDiff = Math.abs(
activeNetworkBal + wethBal - newActiveNetworkBal
)
assert(fullBalDiff < tolerance, `${fullBalDiff} !< ${tolerance}`)
assert(
networkTokensBalDiff < tolerance,
`${networkTokensBalDiff} !< ${tolerance}`
)
assert(
activeNetworkBalDiff < tolerance,
`${activeNetworkBalDiff} !< ${tolerance}`
)
})

it('should update balance after showing token on C-Chain', async () => {
// Get balances before showing token
await networksManagePage.switchActiveNetwork()
const fullBal = await portfolioPage.getTotalBalance()
const activeNetworkBal = await portfolioPage.getActiveNetworkBalance()
await portfolioPage.tapActiveNetwork()
const networkTokensBal = await portfolioPage.getNetworkTokensBalance()

// Show token
await actions.scrollToTop(portfolioPage.portfolioTokenList)
await portfolioPage.tapManageTokens()
await manageTokensPage.showToken('Bitcoin')

// Get balances after hiding token
const newNetworkTokensBal = await portfolioPage.getNetworkTokensBalance()
const btcBal = await portfolioPage.getTokenBalance('BTC.b')
await commonElsPage.goBack()
const newFullBal = await portfolioPage.getTotalBalance()
const newActiveNetworkBal = await portfolioPage.getActiveNetworkBalance()
const tolerance = 1

// Log token balances before and after hiding token
console.log(
`Before: \nfullBal: ${fullBal}, \nbtcBal: ${btcBal}, \nactiveNetworkBal: ${activeNetworkBal} \nnetworkTotalBal: ${networkTokensBal}`
)
console.log(
`After: \nnewFullBal: ${newFullBal}, \nnewActiveNetworkBal: ${newActiveNetworkBal} \nnewNetworkTotalBal: ${newNetworkTokensBal}`
)

// Assert that the tolerance is within the expected range
const fullBalDiff = Math.abs(fullBal + btcBal - newFullBal)
const networkTokensBalDiff = Math.abs(
networkTokensBal + btcBal - newNetworkTokensBal
)
const activeNetworkBalDiff = Math.abs(
activeNetworkBal + btcBal - newActiveNetworkBal
)
assert(fullBalDiff < tolerance, `${fullBalDiff} !< ${tolerance}`)
assert(
networkTokensBalDiff < tolerance,
`${networkTokensBalDiff} !< ${tolerance}`
)
assert(
activeNetworkBalDiff < tolerance,
`${activeNetworkBalDiff} !< ${tolerance}`
)
})
})
Loading
Loading