-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
test: add component view test coverage for network related bugs #26101
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
Open
cortisiko
wants to merge
3
commits into
main
Choose a base branch
from
MMQA-1399
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+301
−0
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
app/components/Views/AssetDetails/AssetDetails.view.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import '../../../util/test/component-view/mocks'; | ||
| import { renderAssetDetailsView } from '../../../util/test/component-view/renderers/assetDetails'; | ||
| import { describeForPlatforms } from '../../../util/test/platform'; | ||
|
|
||
| // addresses Regression: #25100 – Token Details page shows wrong network | ||
|
|
||
| describeForPlatforms('AssetDetails', () => { | ||
| it('displays network name from token chainId, not from selected network', () => { | ||
| const polygonTokenAddress = '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619'; | ||
|
|
||
| const { getAllByText, queryByText } = renderAssetDetailsView({ | ||
| deterministicFiat: true, | ||
| routeParams: { | ||
| address: polygonTokenAddress, | ||
| chainId: '0x89', | ||
| asset: { | ||
| address: polygonTokenAddress, | ||
| symbol: 'WETH', | ||
| decimals: 18, | ||
| name: 'Wrapped Ether', | ||
| image: '', | ||
| isNative: false, | ||
| isETH: false, | ||
| aggregators: [], | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // Network name should appear twice: header subtitle + "Network" section body | ||
| const polygonTexts = getAllByText('Polygon'); | ||
| expect(polygonTexts.length).toBeGreaterThanOrEqual(2); | ||
|
|
||
| // The globally selected network (Ethereum Main Network) should NOT appear | ||
| expect(queryByText('Ethereum Main Network')).toBeNull(); | ||
| }); | ||
| }); |
17 changes: 17 additions & 0 deletions
17
app/components/Views/WalletActions/WalletActions.view.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import '../../../util/test/component-view/mocks'; | ||
| import { renderWalletActionsView } from '../../../util/test/component-view/renderers/walletActions'; | ||
| import { WalletActionsBottomSheetSelectorsIDs } from './WalletActionsBottomSheet.testIds'; | ||
| import { describeForPlatforms } from '../../../util/test/platform'; | ||
|
|
||
| // Regression: #24972 – Perps missing from Trade menu when non-EVM network selected | ||
| describeForPlatforms('WalletActions', () => { | ||
| it('shows Perps button when non-EVM network is selected', () => { | ||
| const { getByTestId } = renderWalletActionsView({ | ||
| isEvmSelected: false, | ||
| }); | ||
|
|
||
| expect( | ||
| getByTestId(WalletActionsBottomSheetSelectorsIDs.PERPS_BUTTON), | ||
| ).toBeOnTheScreen(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { createStateFixture } from '../stateFixture'; | ||
| import type { DeepPartial } from '../../renderWithProvider'; | ||
| import type { RootState } from '../../../../reducers'; | ||
|
|
||
| interface InitialStateAssetDetailsOptions { | ||
| deterministicFiat?: boolean; | ||
| } | ||
|
|
||
| export const initialStateAssetDetails = ( | ||
| options?: InitialStateAssetDetailsOptions, | ||
| ) => { | ||
| const builder = createStateFixture() | ||
| .withMinimalAccounts() | ||
| .withMinimalMainnetNetwork() | ||
| .withMinimalMultichainNetwork(true) | ||
| .withMinimalKeyringController() | ||
| .withMinimalTokenRates() | ||
| .withMinimalMultichainAssetsRates() | ||
| .withMinimalAnalyticsController() | ||
| .withAccountTreeForSelectedAccount() | ||
| .withRemoteFeatureFlags({}) | ||
| .withOverrides({ | ||
| engine: { | ||
| backgroundState: { | ||
| // Add Polygon alongside Mainnet (deepMerge preserves 0x1) | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: { | ||
| '0x89': { | ||
| chainId: '0x89', | ||
| rpcEndpoints: [ | ||
| { | ||
| networkClientId: 'polygon-mainnet', | ||
| url: 'https://polygon-rpc.com', | ||
| type: 'custom', | ||
| }, | ||
| ], | ||
| defaultRpcEndpointIndex: 0, | ||
| blockExplorerUrls: ['https://polygonscan.com'], | ||
| defaultBlockExplorerUrlIndex: 0, | ||
| name: 'Polygon', | ||
| nativeCurrency: 'POL', | ||
| }, | ||
| }, | ||
| networksMetadata: { | ||
| 'polygon-mainnet': { | ||
| status: 'available', | ||
| EIPS: { 1559: true }, | ||
| }, | ||
| }, | ||
| }, | ||
| CurrencyRateController: { | ||
| currentCurrency: 'USD', | ||
| currencyRates: { | ||
| ETH: { conversionRate: 2000 }, | ||
| POL: { conversionRate: 0.5 }, | ||
| }, | ||
| }, | ||
| PreferencesController: { | ||
| isIpfsGatewayEnabled: false, | ||
| }, | ||
| TokenBalancesController: { tokenBalances: {} }, | ||
| TokensController: { | ||
| allTokens: {}, | ||
| allDetectedTokens: {}, | ||
| allIgnoredTokens: {}, | ||
| }, | ||
| }, | ||
| }, | ||
| settings: { primaryCurrency: 'ETH' }, | ||
| } as unknown as DeepPartial<RootState>); | ||
|
|
||
| if (options?.deterministicFiat) { | ||
| builder.withOverrides({ | ||
| engine: { | ||
| backgroundState: { | ||
| CurrencyRateController: { | ||
| currentCurrency: 'USD', | ||
| currencyRates: { | ||
| ETH: { conversionRate: 2000 }, | ||
| POL: { conversionRate: 0.5 }, | ||
| }, | ||
| }, | ||
| TokenRatesController: { marketData: {} }, | ||
| MultichainAssetsRatesController: { conversionRates: {} }, | ||
| }, | ||
| }, | ||
| } as unknown as DeepPartial<RootState>); | ||
| } | ||
|
|
||
| return builder; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { createStateFixture } from '../stateFixture'; | ||
| import type { DeepPartial } from '../../renderWithProvider'; | ||
| import type { RootState } from '../../../../reducers'; | ||
|
|
||
| interface InitialStateWalletActionsOptions { | ||
| isEvmSelected?: boolean; | ||
| } | ||
|
|
||
| export const initialStateWalletActions = ( | ||
| options?: InitialStateWalletActionsOptions, | ||
| ) => { | ||
| const isEvmSelected = options?.isEvmSelected ?? false; | ||
|
|
||
| const builder = createStateFixture() | ||
| .withMinimalAccounts() | ||
| .withMinimalMainnetNetwork() | ||
| .withMinimalMultichainNetwork(isEvmSelected) | ||
| .withOverrides({ | ||
| engine: { | ||
| backgroundState: { | ||
| MultichainNetworkController: { | ||
| selectedMultichainNetworkChainId: | ||
| 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', | ||
| }, | ||
| }, | ||
| }, | ||
| } as unknown as DeepPartial<RootState>) | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .withMinimalKeyringController() | ||
| .withMinimalTokenRates() | ||
| .withMinimalMultichainAssetsRates() | ||
| .withMinimalMultichainBalances() | ||
| .withMinimalMultichainAssets() | ||
| .withMinimalAnalyticsController() | ||
| .withAccountTreeForSelectedAccount() | ||
| .withRemoteFeatureFlags({ | ||
| perpsPerpTradingEnabled: { | ||
| enabled: true, | ||
| minimumVersion: '1.0.0', | ||
| }, | ||
| }) | ||
| .withOverrides({ | ||
| engine: { | ||
| backgroundState: { | ||
| PreferencesController: { | ||
| isIpfsGatewayEnabled: false, | ||
| }, | ||
| TokenBalancesController: { tokenBalances: {} }, | ||
| TokensController: { | ||
| allTokens: {}, | ||
| allDetectedTokens: {}, | ||
| allIgnoredTokens: {}, | ||
| }, | ||
| CurrencyRateController: { | ||
| currentCurrency: 'USD', | ||
| currencyRates: { | ||
| ETH: { conversionRate: 2000 }, | ||
| }, | ||
| }, | ||
| EarnController: { | ||
| pooled_staking: { | ||
| isEligible: true, | ||
| }, | ||
| lending: { | ||
| positions: [], | ||
| markets: [], | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| settings: { | ||
| basicFunctionalityEnabled: true, | ||
| primaryCurrency: 'ETH', | ||
| }, | ||
| swaps: { | ||
| '0x1': { isLive: true }, | ||
| hasOnboarded: false, | ||
| isLive: true, | ||
| }, | ||
| fiatOrders: { | ||
| networks: [ | ||
| { | ||
| active: true, | ||
| chainId: '1', | ||
| chainName: 'Ethereum Mainnet', | ||
| nativeTokenSupported: true, | ||
| }, | ||
| ], | ||
| }, | ||
| } as unknown as DeepPartial<RootState>); | ||
|
|
||
| return builder; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import '../mocks'; | ||
| import React from 'react'; | ||
| import type { DeepPartial } from '../../renderWithProvider'; | ||
| import type { RootState } from '../../../../reducers'; | ||
| import { renderComponentViewScreen } from '../render'; | ||
| import AssetDetailsContainer from '../../../../components/Views/AssetDetails'; | ||
| import { initialStateAssetDetails } from '../presets/assetDetails'; | ||
|
|
||
| interface RenderAssetDetailsViewOptions { | ||
| overrides?: DeepPartial<RootState>; | ||
| deterministicFiat?: boolean; | ||
| routeParams: { | ||
| address: string; | ||
| chainId: string; | ||
| asset: Record<string, unknown>; | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Renders AssetDetails view with a sensible default AssetDetails preset. | ||
| * Pass overrides to tweak the state for each specific test. | ||
| */ | ||
| export function renderAssetDetailsView( | ||
| options: RenderAssetDetailsViewOptions, | ||
| ): ReturnType<typeof renderComponentViewScreen> { | ||
| const { overrides, deterministicFiat, routeParams } = options; | ||
|
|
||
| const builder = initialStateAssetDetails({ deterministicFiat }); | ||
| if (overrides) { | ||
| builder.withOverrides(overrides); | ||
| } | ||
| const state = builder.build(); | ||
|
|
||
| return renderComponentViewScreen( | ||
| AssetDetailsContainer as unknown as React.ComponentType, | ||
| { name: 'AssetDetails' }, | ||
| { state }, | ||
| routeParams, | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import '../mocks'; | ||
| import React from 'react'; | ||
| import type { DeepPartial } from '../../renderWithProvider'; | ||
| import type { RootState } from '../../../../reducers'; | ||
| import { renderComponentViewScreen } from '../render'; | ||
| import Routes from '../../../../constants/navigation/Routes'; | ||
| import WalletActions from '../../../../components/Views/WalletActions'; | ||
| import { initialStateWalletActions } from '../presets/walletActions'; | ||
|
|
||
| interface RenderWalletActionsViewOptions { | ||
| overrides?: DeepPartial<RootState>; | ||
| isEvmSelected?: boolean; | ||
| } | ||
|
|
||
| export function renderWalletActionsView( | ||
| options: RenderWalletActionsViewOptions = {}, | ||
| ): ReturnType<typeof renderComponentViewScreen> { | ||
| const { overrides, isEvmSelected } = options; | ||
|
|
||
| const builder = initialStateWalletActions({ isEvmSelected }); | ||
| if (overrides) { | ||
| builder.withOverrides(overrides); | ||
| } | ||
| const state = builder.build(); | ||
|
|
||
| return renderComponentViewScreen( | ||
| WalletActions as unknown as React.ComponentType, | ||
| { name: Routes.MODAL.WALLET_ACTIONS }, | ||
| { state }, | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.