From f3f4f3754673e0e85c110f41d9c77e27e30caa68 Mon Sep 17 00:00:00 2001 From: ignaciosantise <25931366+ignaciosantise@users.noreply.github.com> Date: Thu, 20 Feb 2025 15:41:41 -0300 Subject: [PATCH 1/3] fix: load transactions only when needed --- .changeset/empty-mangos-push.md | 18 ++++++++++++++++++ .../scaffold/src/modal/w3m-modal/index.tsx | 1 - .../partials/w3m-account-activity/index.tsx | 8 +++++++- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 .changeset/empty-mangos-push.md diff --git a/.changeset/empty-mangos-push.md b/.changeset/empty-mangos-push.md new file mode 100644 index 00000000..7f70026a --- /dev/null +++ b/.changeset/empty-mangos-push.md @@ -0,0 +1,18 @@ +--- +'@reown/appkit-coinbase-ethers-react-native': patch +'@reown/appkit-coinbase-wagmi-react-native': patch +'@reown/appkit-scaffold-utils-react-native': patch +'@reown/appkit-auth-ethers-react-native': patch +'@reown/appkit-auth-wagmi-react-native': patch +'@reown/appkit-scaffold-react-native': patch +'@reown/appkit-ethers5-react-native': patch +'@reown/appkit-common-react-native': patch +'@reown/appkit-ethers-react-native': patch +'@reown/appkit-wagmi-react-native': patch +'@reown/appkit-core-react-native': patch +'@reown/appkit-siwe-react-native': patch +'@reown/appkit-ui-react-native': patch +'@reown/appkit-wallet-react-native': patch +--- + +fix: load transactions when needed diff --git a/packages/scaffold/src/modal/w3m-modal/index.tsx b/packages/scaffold/src/modal/w3m-modal/index.tsx index fe2db865..678942ec 100644 --- a/packages/scaffold/src/modal/w3m-modal/index.tsx +++ b/packages/scaffold/src/modal/w3m-modal/index.tsx @@ -71,7 +71,6 @@ export function AppKit() { const newAddress = CoreHelperUtil.getPlainAddress(address); TransactionsController.resetTransactions(); - TransactionsController.fetchTransactions(newAddress, true); if (OptionsController.state.isSiweEnabled) { const newNetworkId = CoreHelperUtil.getNetworkId(address); diff --git a/packages/scaffold/src/partials/w3m-account-activity/index.tsx b/packages/scaffold/src/partials/w3m-account-activity/index.tsx index b08ff265..5d75547a 100644 --- a/packages/scaffold/src/partials/w3m-account-activity/index.tsx +++ b/packages/scaffold/src/partials/w3m-account-activity/index.tsx @@ -1,4 +1,4 @@ -import { useCallback, useMemo, useState } from 'react'; +import { useCallback, useEffect, useMemo, useState } from 'react'; import { useSnapshot } from 'valtio'; import { ScrollView, View, type StyleProp, type ViewStyle, RefreshControl } from 'react-native'; import { @@ -58,6 +58,12 @@ export function AccountActivity({ style }: Props) { return TransactionsController.getTransactionsByYearAndMonth(transactions as Transaction[]); }, [transactions]); + useEffect(() => { + if (!TransactionsController.state.transactions.length) { + TransactionsController.fetchTransactions(AccountController.state.address, true); + } + }, []); + if (loading && !transactions.length) { return ( From 54f37b62df7fc7954f40f21cc4a33e2a4545406f Mon Sep 17 00:00:00 2001 From: ignaciosantise <25931366+ignaciosantise@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:22:17 -0300 Subject: [PATCH 2/3] chore: added tests --- .maestro/w3m-connect-flow.yaml | 4 +- apps/native/tests/shared/pages/ModalPage.ts | 91 +++---------------- apps/native/tests/shared/pages/WalletPage.ts | 22 ++++- .../tests/shared/validators/ModalValidator.ts | 17 +--- apps/native/tests/wallet.spec.ts | 49 +++++++++- .../views/w3m-account-default-view/index.tsx | 8 +- .../components/wui-loading-spinner/index.tsx | 10 +- 7 files changed, 96 insertions(+), 105 deletions(-) diff --git a/.maestro/w3m-connect-flow.yaml b/.maestro/w3m-connect-flow.yaml index 155431e5..ac7a4d80 100644 --- a/.maestro/w3m-connect-flow.yaml +++ b/.maestro/w3m-connect-flow.yaml @@ -57,7 +57,7 @@ appId: com.walletconnect.web3modal.rnclisdk id: 'account-button' - tapOn: - id: 'w3m-account-select-network' + id: 'button-network' - tapOn: text: 'Polygon' @@ -68,7 +68,7 @@ appId: com.walletconnect.web3modal.rnclisdk text: 'Polygon' - tapOn: - id: 'disconnect-button' + id: 'button-disconnect' - assertVisible: id: 'connect-button' diff --git a/apps/native/tests/shared/pages/ModalPage.ts b/apps/native/tests/shared/pages/ModalPage.ts index a8840f21..7781c80c 100644 --- a/apps/native/tests/shared/pages/ModalPage.ts +++ b/apps/native/tests/shared/pages/ModalPage.ts @@ -92,7 +92,7 @@ export class ModalPage { await expect(accountBtn, 'Account button should be visible').toBeVisible(); await expect(accountBtn, 'Account button should be enabled').toBeEnabled(); await accountBtn.click(); - const disconnectBtn = this.page.getByTestId('disconnect-button'); + const disconnectBtn = this.page.getByTestId('button-disconnect'); await expect(disconnectBtn, 'Disconnect button should be visible').toBeVisible(); await expect(disconnectBtn, 'Disconnect button should be enabled').toBeEnabled(); await disconnectBtn.click(); @@ -126,19 +126,11 @@ export class ModalPage { // } async switchNetwork(network: string) { - await this.openAccountModal(); - await this.page.getByTestId('w3m-account-select-network').click(); await this.page.getByTestId(`w3m-network-switch-${network}`).click(); // The state is chaing too fast and test runner doesn't wait the loading page. It's fastly checking the network selection button and detect that it's switched already. await this.page.waitForTimeout(300); } - // async clickWalletDeeplink() { - // await this.connectButton.click(); - // await this.page.getByTestId('wallet-selector-react-wallet-v2').click(); - // await this.page.getByTestId('tab-desktop').click(); - // } - async openAccountModal() { await this.page.getByTestId('account-button').click(); } @@ -157,14 +149,6 @@ export class ModalPage { await this.page.waitForTimeout(300); } - // async switchNetworkWithNetworkButton(networkName: string) { - // const networkButton = this.page.getByTestId('wui-network-button'); - // await networkButton.click(); - - // const networkToSwitchButton = this.page.getByTestId(`w3m-network-switch-${networkName}`); - // await networkToSwitchButton.click(); - // } - async openAllWallets() { const allWallets = this.page.getByTestId('all-wallets'); await expect(allWallets, 'All wallets should be visible').toBeVisible(); @@ -177,18 +161,6 @@ export class ModalPage { await qrCodeButton.click(); } - // async clickAllWalletsListSearchItem(id: string) { - // const allWalletsListSearchItem = this.page.getByTestId(`wallet-search-item-${id}`); - // await expect(allWalletsListSearchItem).toBeVisible(); - // await allWalletsListSearchItem.click(); - // } - - // async clickTabWebApp() { - // const tabWebApp = this.page.getByTestId('tab-webapp'); - // await expect(tabWebApp).toBeVisible(); - // await tabWebApp.click(); - // } - async clickHookDisconnectButton() { const disconnectHookButton = this.page.getByTestId('disconnect-hook-button'); await expect(disconnectHookButton).toBeVisible(); @@ -216,33 +188,6 @@ export class ModalPage { return this.page.evaluate(() => navigator.clipboard.readText()); } - // async clickOpenWebApp() { - // let url = ''; - - // const openButton = this.page.getByTestId('w3m-connecting-widget-secondary-button'); - // await expect(openButton).toBeVisible(); - // await expect(openButton).toHaveText('Open'); - - // while (!url) { - // await openButton.click(); - // await this.page.waitForTimeout(500); - - // const pages = this.page.context().pages(); - - // // Check if more than 1 tab is open - // if (pages.length > 1) { - // const lastTab = pages[pages.length - 1]; - - // if (lastTab) { - // url = lastTab.url(); - // break; - // } - // } - // } - - // return url; - // } - async search(value: string) { const searchInput = this.page.getByTestId('wui-input-text'); await expect(searchInput, 'Search input should be visible').toBeVisible(); @@ -250,30 +195,24 @@ export class ModalPage { await searchInput.fill(value); } - async openNetworks() { - await this.page.getByTestId('w3m-account-select-network').click(); + async goToNetworks() { + await this.page.getByTestId('button-network').click(); await expect(this.page.getByText('Select network')).toBeVisible(); } - // async openProfileView() { - // await this.page.getByTestId('wui-profile-button').click(); - // } - - // async getAddress(): Promise<`0x${string}`> { - // const address = await this.page.getByTestId('w3m-address').textContent(); - // expect(address, 'Address should be present').toBeTruthy(); - - // return address as `0x${string}`; - // } + async goToActivity() { + await this.page.getByTestId('button-activity').click(); + } - // async getChainId(): Promise { - // const chainId = await this.page.getByTestId('w3m-chain-id').textContent(); - // expect(chainId, 'Chain ID should be present').toBeTruthy(); + async goBack() { + await this.page.getByTestId('button-back').click(); + } - // return Number(chainId); - // } + async expectLoaderVisible() { + await expect(this.page.getByTestId('loading-spinner')).toBeVisible(); + } - // async switchNetworkWithHook() { - // await this.page.getByTestId('switch-network-hook-button').click(); - // } + async expectLoaderHidden() { + await expect(this.page.getByTestId('loading-spinner')).toBeHidden(); + } } diff --git a/apps/native/tests/shared/pages/WalletPage.ts b/apps/native/tests/shared/pages/WalletPage.ts index 49f5a203..44a48135 100644 --- a/apps/native/tests/shared/pages/WalletPage.ts +++ b/apps/native/tests/shared/pages/WalletPage.ts @@ -117,9 +117,23 @@ export class WalletPage { await this.page.waitForLoadState(); const sessionsButton = this.page.getByTestId('sessions'); await sessionsButton.click(); - const sessionCard = this.page.getByTestId(`session-card`); - await sessionCard.click(); - const disconnectButton = this.page.getByText('Delete'); - await disconnectButton.click(); + + // Try to disconnect all visible session cards + while (true) { + const sessionCards = this.page.getByTestId('session-card'); + const count = await sessionCards.count(); + + if (count === 0) { + break; + } + + // Click the first card and disconnect it + await sessionCards.first().click(); + const disconnectButton = this.page.getByText('Delete'); + await disconnectButton.click(); + + // Wait a bit for the disconnection to complete + await this.page.waitForTimeout(500); + } } } diff --git a/apps/native/tests/shared/validators/ModalValidator.ts b/apps/native/tests/shared/validators/ModalValidator.ts index d27de8fb..113c0c1f 100644 --- a/apps/native/tests/shared/validators/ModalValidator.ts +++ b/apps/native/tests/shared/validators/ModalValidator.ts @@ -82,16 +82,6 @@ export class ModalValidator { await expect(address, 'Correct address should be present').toHaveText(expectedAddress); } - // async expectNetwork(network: string) { - // const networkButton = this.page.getByTestId('w3m-account-select-network'); - // await expect(networkButton, `Network button should contain text ${network}`).toHaveText( - // network, - // { - // timeout: 5000 - // } - // ); - // } - async expectAcceptedSign() { await expect(this.page.getByText('Signature successful')).toBeVisible({ timeout: 30 * 1000 @@ -103,7 +93,7 @@ export class ModalValidator { } async expectSwitchedNetwork(network: string) { - const switchNetworkButton = this.page.getByTestId(`w3m-account-select-network-text`); + const switchNetworkButton = this.page.getByTestId(`account-select-network-text`); await expect(switchNetworkButton).toContainText(network); } @@ -132,11 +122,6 @@ export class ModalValidator { await expect(getAWalletView).toBeVisible(); } - // async expectHeaderText(text: string) { - // const headerText = this.page.getByTestId('header-text'); - // await expect(headerText).toHaveText(text); - // } - async expectNetworksDisabled(name: string) { const disabledNetworkButton = this.page.getByTestId(`w3m-network-switch-${name}`); disabledNetworkButton.click(); diff --git a/apps/native/tests/wallet.spec.ts b/apps/native/tests/wallet.spec.ts index 6f5eb68c..75fe6e4f 100644 --- a/apps/native/tests/wallet.spec.ts +++ b/apps/native/tests/wallet.spec.ts @@ -45,7 +45,7 @@ sampleWalletTest('it should be connected instantly after page refresh', async () sampleWalletTest('it should show disabled networks', async () => { const disabledNetworks = 'Gnosis'; await modalPage.openAccountModal(); - await modalPage.openNetworks(); + await modalPage.goToNetworks(); await modalValidator.expectNetworksDisabled(disabledNetworks); await modalPage.closeModal(); }); @@ -62,6 +62,8 @@ sampleWalletTest('it should switch networks and sign', async () => { // -- Switch network -------------------------------------------------------- const chainNameOnWalletPage = chainName; + await modalPage.openAccountModal(); + await modalPage.goToNetworks(); await modalPage.switchNetwork(chainName); await modalValidator.expectSwitchedNetwork(chainName); await modalPage.closeModal(); @@ -82,6 +84,8 @@ sampleWalletTest('it should switch networks and sign', async () => { sampleWalletTest('it should show last connected network after refreshing', async () => { const chainName = 'Polygon'; + await modalPage.openAccountModal(); + await modalPage.goToNetworks(); await modalPage.switchNetwork(chainName); await modalValidator.expectSwitchedNetwork(chainName); await modalPage.closeModal(); @@ -124,3 +128,46 @@ sampleWalletTest('it should disconnect as expected', async () => { await modalPage.disconnect(); await modalValidator.expectDisconnected(); }); + +sampleWalletTest('shows loader behavior on first visit to Activity screen', async () => { + // Connect to wallet + await modalPage.qrCodeFlow(modalPage, walletPage); + await modalValidator.expectConnected(); + + // First visit to Activity screen + await modalPage.openAccountModal(); + await modalPage.goToActivity(); + await modalPage.expectLoaderVisible(); + await modalPage.expectLoaderHidden(); + + // Second visit to Activity screen + await modalPage.goBack(); + await modalPage.goToActivity(); + await modalPage.expectLoaderHidden(); + + // Third visit after closing the modal + await modalPage.closeModal(); + await modalPage.openAccountModal(); + await modalPage.goToActivity(); + await modalPage.expectLoaderHidden(); + await modalPage.closeModal(); +}); + +sampleWalletTest('shows loader behavior after network change in Activity screen', async () => { + await modalPage.openAccountModal(); + + // Change network + await modalPage.goToNetworks(); + await modalPage.switchNetwork('Polygon'); + await modalValidator.expectSwitchedNetwork('Polygon'); + + // Visit Activity screen after network change + await modalPage.goToActivity(); + await modalPage.expectLoaderVisible(); + await modalPage.expectLoaderHidden(); + + // Second visit after network change + await modalPage.goBack(); + await modalPage.goToActivity(); + await modalPage.expectLoaderHidden(); +}); diff --git a/packages/scaffold/src/views/w3m-account-default-view/index.tsx b/packages/scaffold/src/views/w3m-account-default-view/index.tsx index dba1584a..f3982ed9 100644 --- a/packages/scaffold/src/views/w3m-account-default-view/index.tsx +++ b/packages/scaffold/src/views/w3m-account-default-view/index.tsx @@ -244,10 +244,10 @@ export function AccountDefaultView() { imageSrc={networkImage} imageHeaders={ApiController._getApiHeaders()} onPress={onNetworkPress} - testID="w3m-account-select-network" + testID="button-network" style={styles.actionButton} > - + {caipNetwork?.name} @@ -259,7 +259,7 @@ export function AccountDefaultView() { iconColor="accent-100" iconBackgroundColor="accent-glass-015" onPress={onSwapPress} - testID="button-activity" + testID="button-swap" style={styles.actionButton} > Swap @@ -299,7 +299,7 @@ export function AccountDefaultView() { onPress={onDisconnect} loading={disconnecting} iconBackgroundColor="gray-glass-010" - testID="disconnect-button" + testID="button-disconnect" > Disconnect diff --git a/packages/ui/src/components/wui-loading-spinner/index.tsx b/packages/ui/src/components/wui-loading-spinner/index.tsx index 4270f571..0fff6586 100644 --- a/packages/ui/src/components/wui-loading-spinner/index.tsx +++ b/packages/ui/src/components/wui-loading-spinner/index.tsx @@ -12,9 +12,15 @@ export interface LoadingSpinnerProps { size?: Exclude; color?: Exclude; style?: StyleProp; + testID?: string; } -export function LoadingSpinner({ color, style, size = 'lg' }: LoadingSpinnerProps) { +export function LoadingSpinner({ + color, + style, + size = 'lg', + testID = 'loading-spinner' +}: LoadingSpinnerProps) { const Theme = useTheme(); const spinValue = useRef(new Animated.Value(0)); const stroke = color ? Theme[color] : Theme['accent-100']; @@ -41,7 +47,7 @@ export function LoadingSpinner({ color, style, size = 'lg' }: LoadingSpinnerProp }); return ( - + Date: Fri, 21 Feb 2025 14:24:59 -0300 Subject: [PATCH 3/3] chore: test code improvements --- apps/native/tests/shared/constants/index.ts | 18 +++++- .../native/tests/shared/constants/timeouts.ts | 1 - apps/native/tests/shared/pages/ModalPage.ts | 22 ++++--- apps/native/tests/shared/types/index.ts | 4 ++ apps/native/tests/shared/utils/timeouts.ts | 6 +- apps/native/tests/wallet.spec.ts | 62 ++++++++++++++----- 6 files changed, 86 insertions(+), 27 deletions(-) delete mode 100644 apps/native/tests/shared/constants/timeouts.ts diff --git a/apps/native/tests/shared/constants/index.ts b/apps/native/tests/shared/constants/index.ts index dc2550fe..77f3b75c 100644 --- a/apps/native/tests/shared/constants/index.ts +++ b/apps/native/tests/shared/constants/index.ts @@ -8,4 +8,20 @@ export const DEFAULT_SESSION_PARAMS: SessionParams = { optAccounts: ['1', '2'], accept: true }; -export const DEFAULT_CHAIN_NAME = process.env.DEFAULT_CHAIN_NAME || 'Ethereum'; + +export const TEST_CHAINS = { + POLYGON: 'Polygon', + ETHEREUM: 'Ethereum', + GNOSIS: 'Gnosis' +} as const; + +export type SupportedChain = (typeof TEST_CHAINS)[keyof typeof TEST_CHAINS]; + +export const TIMEOUTS = { + ANIMATION: 300, + NETWORK_SWITCH: 500, + CONNECTION: 5000, + SESSION_PROPOSAL: 30000 +} as const; + +export const DEFAULT_CHAIN_NAME = process.env.DEFAULT_CHAIN_NAME || TEST_CHAINS.ETHEREUM; diff --git a/apps/native/tests/shared/constants/timeouts.ts b/apps/native/tests/shared/constants/timeouts.ts deleted file mode 100644 index 03ff123c..00000000 --- a/apps/native/tests/shared/constants/timeouts.ts +++ /dev/null @@ -1 +0,0 @@ -export const MAXIMUM_WAIT_CONNECTIONS = 30 * 1000; diff --git a/apps/native/tests/shared/pages/ModalPage.ts b/apps/native/tests/shared/pages/ModalPage.ts index 7781c80c..b7e6f1e7 100644 --- a/apps/native/tests/shared/pages/ModalPage.ts +++ b/apps/native/tests/shared/pages/ModalPage.ts @@ -1,9 +1,9 @@ import type { Locator, Page } from '@playwright/test'; import { expect } from '@playwright/test'; -import { BASE_URL, DEFAULT_SESSION_PARAMS } from '../constants'; +import { BASE_URL, DEFAULT_SESSION_PARAMS, TIMEOUTS } from '../constants'; import { WalletValidator } from '../validators/WalletValidator'; import { WalletPage } from './WalletPage'; -import { TimingRecords } from '../types'; +import { SupportedChain, TimingRecords } from '../types'; import { ModalValidator } from '../validators/ModalValidator'; export class ModalPage { @@ -125,10 +125,10 @@ export class ModalPage { // await this.page.getByTestId('w3m-connecting-siwe-cancel').click(); // } - async switchNetwork(network: string) { + async switchNetwork(network: SupportedChain) { await this.page.getByTestId(`w3m-network-switch-${network}`).click(); - // The state is chaing too fast and test runner doesn't wait the loading page. It's fastly checking the network selection button and detect that it's switched already. - await this.page.waitForTimeout(300); + // The state is changing too fast and test runner doesn't wait for the loading page + await this.page.waitForTimeout(TIMEOUTS.NETWORK_SWITCH); } async openAccountModal() { @@ -146,7 +146,7 @@ export class ModalPage { async closeModal() { await this.page.getByTestId('header-close')?.click?.(); // Wait for the modal fade out animation - await this.page.waitForTimeout(300); + await this.page.waitForTimeout(TIMEOUTS.ANIMATION); } async openAllWallets() { @@ -209,10 +209,16 @@ export class ModalPage { } async expectLoaderVisible() { - await expect(this.page.getByTestId('loading-spinner')).toBeVisible(); + await expect( + this.page.getByTestId('loading-spinner'), + 'Loading spinner should be visible' + ).toBeVisible(); } async expectLoaderHidden() { - await expect(this.page.getByTestId('loading-spinner')).toBeHidden(); + await expect( + this.page.getByTestId('loading-spinner'), + 'Loading spinner should be hidden' + ).toBeHidden(); } } diff --git a/apps/native/tests/shared/types/index.ts b/apps/native/tests/shared/types/index.ts index abf6bc54..05d6a4a0 100644 --- a/apps/native/tests/shared/types/index.ts +++ b/apps/native/tests/shared/types/index.ts @@ -1,3 +1,5 @@ +import { TEST_CHAINS } from '../constants'; + export interface SessionParams { reqAccounts: string[]; optAccounts: string[]; @@ -7,3 +9,5 @@ export interface SessionParams { export type TimingRecords = { item: string; timeMs: number }[]; export type CaipNetworkId = `${string}:${string}`; + +export type SupportedChain = (typeof TEST_CHAINS)[keyof typeof TEST_CHAINS]; diff --git a/apps/native/tests/shared/utils/timeouts.ts b/apps/native/tests/shared/utils/timeouts.ts index a74e5eee..d1d154cb 100644 --- a/apps/native/tests/shared/utils/timeouts.ts +++ b/apps/native/tests/shared/utils/timeouts.ts @@ -1,9 +1,9 @@ -import { MAXIMUM_WAIT_CONNECTIONS } from '../constants/timeouts'; +import { TIMEOUTS } from '../constants'; export function getMaximumWaitConnections(): number { if (process.env.CI) { - return MAXIMUM_WAIT_CONNECTIONS; + return TIMEOUTS.SESSION_PROPOSAL; } - return MAXIMUM_WAIT_CONNECTIONS * 2; + return TIMEOUTS.SESSION_PROPOSAL * 2; } diff --git a/apps/native/tests/wallet.spec.ts b/apps/native/tests/wallet.spec.ts index 75fe6e4f..c1bc69de 100644 --- a/apps/native/tests/wallet.spec.ts +++ b/apps/native/tests/wallet.spec.ts @@ -3,7 +3,7 @@ import { WalletPage } from './shared/pages/WalletPage'; import { WalletValidator } from './shared/validators/WalletValidator'; import { ModalPage } from './shared/pages/ModalPage'; import { ModalValidator } from './shared/validators/ModalValidator'; -import { DEFAULT_CHAIN_NAME } from './shared/constants'; +import { DEFAULT_CHAIN_NAME, TEST_CHAINS } from './shared/constants'; let modalPage: ModalPage; let modalValidator: ModalValidator; @@ -37,21 +37,36 @@ sampleWalletTest.afterAll(async () => { }); // -- Tests -------------------------------------------------------------------- +/** + * Connection Tests + * Tests the basic connection functionality including: + * - Page refresh behavior + * - Network switching + * - Disconnection flows + */ + sampleWalletTest('it should be connected instantly after page refresh', async () => { await modalPage.page.reload(); await modalValidator.expectToBeConnectedInstantly(); }); +/** + * Network Tests + * Tests network-related functionality including: + * - Disabled networks visibility + * - Network switching + * - Network persistence after refresh + */ + sampleWalletTest('it should show disabled networks', async () => { - const disabledNetworks = 'Gnosis'; await modalPage.openAccountModal(); await modalPage.goToNetworks(); - await modalValidator.expectNetworksDisabled(disabledNetworks); + await modalValidator.expectNetworksDisabled(TEST_CHAINS.GNOSIS); await modalPage.closeModal(); }); sampleWalletTest('it should switch networks and sign', async () => { - const chains = ['Polygon', 'Ethereum']; + const chains = [TEST_CHAINS.POLYGON, TEST_CHAINS.ETHEREUM]; async function processChain(index: number) { if (index >= chains.length) { @@ -77,34 +92,45 @@ sampleWalletTest('it should switch networks and sign', async () => { await processChain(index + 1); } - // Start processing from the first chain await processChain(0); }); sampleWalletTest('it should show last connected network after refreshing', async () => { - const chainName = 'Polygon'; - await modalPage.openAccountModal(); await modalPage.goToNetworks(); - await modalPage.switchNetwork(chainName); - await modalValidator.expectSwitchedNetwork(chainName); + await modalPage.switchNetwork(TEST_CHAINS.POLYGON); + await modalValidator.expectSwitchedNetwork(TEST_CHAINS.POLYGON); await modalPage.closeModal(); await modalPage.page.reload(); await modalPage.openAccountModal(); - await modalValidator.expectSwitchedNetwork(chainName); + await modalValidator.expectSwitchedNetwork(TEST_CHAINS.POLYGON); await modalPage.closeModal(); }); +/** + * Signing Tests + * Tests message signing functionality including: + * - Successful signing flow + * - Rejection flow + */ + sampleWalletTest('it should reject sign', async () => { - const chainName = 'Polygon'; await modalPage.sign(); - await walletValidator.expectReceivedSign({ chainName }); + await walletValidator.expectReceivedSign({ chainName: TEST_CHAINS.POLYGON }); await walletPage.handleRequest({ accept: false }); await modalValidator.expectRejectedSign(); }); +/** + * Disconnection Tests + * Tests various disconnection scenarios including: + * - Hook-based disconnection + * - Wallet-initiated disconnection + * - Manual disconnection + */ + sampleWalletTest('it should disconnect using hook', async () => { await modalValidator.expectConnected(); await modalPage.clickHookDisconnectButton(); @@ -129,6 +155,14 @@ sampleWalletTest('it should disconnect as expected', async () => { await modalValidator.expectDisconnected(); }); +/** + * Activity Screen Tests + * Tests the Activity screen behavior including: + * - Loader visibility on first visit + * - Loader behavior on subsequent visits + * - Loader behavior after network changes + */ + sampleWalletTest('shows loader behavior on first visit to Activity screen', async () => { // Connect to wallet await modalPage.qrCodeFlow(modalPage, walletPage); @@ -158,8 +192,8 @@ sampleWalletTest('shows loader behavior after network change in Activity screen' // Change network await modalPage.goToNetworks(); - await modalPage.switchNetwork('Polygon'); - await modalValidator.expectSwitchedNetwork('Polygon'); + await modalPage.switchNetwork(TEST_CHAINS.POLYGON); + await modalValidator.expectSwitchedNetwork(TEST_CHAINS.POLYGON); // Visit Activity screen after network change await modalPage.goToActivity();