Skip to content

Commit

Permalink
QA fix staking and rpc call testing (#2142)
Browse files Browse the repository at this point in the history
  • Loading branch information
eunjisong authored Dec 5, 2024
1 parent a68977a commit 0a044e4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 59 deletions.
12 changes: 11 additions & 1 deletion packages/core-mobile/e2e/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ const waitForElementNoSync = async (
throw new Error('Element not visible within timeout')
}

const getRandomEle = (items: any[]): any => {
return items[Math.floor(Math.random() * items.length)]
}

const getRandomIndex = (itemsLength: number): number => {
return Math.floor(Math.random() * itemsLength)
}

const getElementTextNoSync = async (
item: Detox.NativeMatcher,
timeout = 2000,
Expand Down Expand Up @@ -436,5 +444,7 @@ export default {
scrollToBottom,
scrollToTop,
hasText,
getAmount
getAmount,
getRandomEle,
getRandomIndex
}
9 changes: 8 additions & 1 deletion packages/core-mobile/e2e/pages/Stake/stake.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,13 @@ class StakePage {
await Actions.tap(this.customRadio)
await Actions.tap(commonElsPage.calendarSVG)
const datePicker = element(commonElsPage.datePicker)
duration = new Date(
new Date().setFullYear(new Date().getFullYear() + 2)
).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
await datePicker.setDatePickerDate(duration, 'MMMM dd, yyyy')
if (Actions.platform() === Platform.Android) {
await Actions.tap(commonElsPage.okBtn)
Expand All @@ -539,7 +546,7 @@ class StakePage {
this.instantBaseFee,
this.customBaseFee
]
const randomIndex = Math.floor(Math.random() * feeOptions.length)
const randomIndex = Actions.getRandomIndex(feeOptions.length)
const selectedFeeOption = feeOptions[randomIndex] as Detox.NativeMatcher

await Actions.tap(selectedFeeOption)
Expand Down
1 change: 1 addition & 0 deletions packages/core-mobile/e2e/pages/popUpModal.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class PopUpModalPage {
}

async tapApproveBtn() {
await actions.waitForElement(this.popUpModalScrollView, 10000)
await actions.tapElementAtIndex(this.approveBtn, 0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe('Dapp - Core Playground', () => {
it('should handle eth_sendTransaction', async () => {
await bottomTabsPage.tapBrowserTab()
await browserPage.sendRpcCall('eth_sendTransaction')
await popUpModalPage.verifyApproveTransactionItems()
await popUpModalPage.tapApproveBtn()
await sendPage.verifySuccessToast()
})
Expand Down
2 changes: 1 addition & 1 deletion packages/core-mobile/e2e/tests/portfolioTab/subTabs.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Sub tabs on Portfolio', () => {

it('should navigate sub tabs fine', async () => {
for (let i = 0; i < 5; i++) {
const randomIndex = Math.floor(Math.random() * subTabs.length)
const randomIndex = Actions.getRandomIndex(subTabs.length)
if (subTabs[randomIndex]) {
await Actions.tapElementAtIndex(by.text(subTabs[randomIndex]), 0)
await portfolioPage.verifySubTab(subTabs[randomIndex])
Expand Down
68 changes: 13 additions & 55 deletions packages/core-mobile/e2e/tests/stake/stakingTestnet.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { expect as jestExpect } from 'expect'
import Actions from '../../helpers/actions'
import Assert from '../../helpers/assertions'
import AccountManagePage from '../../pages/accountManage.page'
import AdvancedPage from '../../pages/burgerMenu/advanced.page'
import BottomTabsPage from '../../pages/bottomTabs.page'
import { warmup } from '../../helpers/warmup'
Expand All @@ -18,47 +15,20 @@ describe('Stake on Testnet', () => {
afterAll(async () => {
await cleanup()
})
const duration = Actions.getRandomEle([
'1 Day',
'1 Month',
'3 Months',
'6 Months',
'1 Year',
'Custom'
])

it('should stake one day', async () => {
it(`should stake with random ${duration} duration`, async () => {
const isCustom = duration === 'Custom' ? true : false
console.log('duration: ', duration)
await BottomTabsPage.tapStakeTab()
await StakePage.stake('1', '1 Day')
await StakePage.verifyStakeSuccessToast()
})

it('should stake one month', async () => {
await BottomTabsPage.tapStakeTab()
await StakePage.stake('1', '1 Month')
await StakePage.verifyStakeSuccessToast()
})

it('should stake three months', async () => {
await BottomTabsPage.tapStakeTab()
await StakePage.stake('1', '3 Months')
await StakePage.verifyStakeSuccessToast()
})

it('should stake six months', async () => {
await BottomTabsPage.tapStakeTab()
await StakePage.stake('1', '6 Months')
await StakePage.verifyStakeSuccessToast()
})

it('should stake one year', async () => {
await BottomTabsPage.tapStakeTab()
await StakePage.stake('1', '1 Year')
await StakePage.verifyStakeSuccessToast()
})

it('should stake custom duration', async () => {
await BottomTabsPage.tapStakeTab()
const maximumDuration = new Date(
new Date().setFullYear(new Date().getFullYear() + 2)
).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
await StakePage.stake('1', maximumDuration, true)
await StakePage.stake('1', duration, isCustom)
await StakePage.verifyStakeSuccessToast()
})

Expand All @@ -70,19 +40,7 @@ describe('Stake on Testnet', () => {
await Actions.tap(StakePage.stakeClaimButton)
await ClaimPage.verifyClaimRewardsScreenItems(claimableBalance)
await ClaimPage.tapClaimNowButton()
await Actions.waitForElement(StakePage.stakePrimaryButton, 25000, 0)
await Assert.isVisible(StakePage.stakePrimaryButton)
if (Actions.platform() === 'android') {
const newClaimableBalance = await StakePage.getTopBalance('claimable')
jestExpect(newClaimableBalance).toBe(0)
}
await Actions.waitForElementNotVisible(ClaimPage.claimButton, 10000)
}
})

it('should test a staking flow for a new account on testnet', async () => {
await BottomTabsPage.tapPortfolioTab()
await AccountManagePage.createNthAccountAndSwitchToNth(3)
await BottomTabsPage.tapStakeTab()
await StakePage.verifyNoActiveStakesScreenItems()
})
})

0 comments on commit 0a044e4

Please sign in to comment.