-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
test: add component view tests and skip duplicated smoke E2E #28911
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ba9b9dd
test: add component view coverage and skip duplicated smoke E2E
racitores b37ace9
fix: lint:tsc
racitores 4120a53
fix: test
racitores d11c204
fix: bugbot
racitores 59e03c8
test: alert system addition
racitores 4f79c47
test: included notification + fixes
racitores cd2fb57
test: add component view tests
racitores eb3dc3b
test: fix
racitores b8f655a
test: fix lint
racitores 9d74f1b
test: fix comments
racitores 6098045
Merge branch 'main' into qa/e2e-cleanup
racitores 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
139 changes: 139 additions & 0 deletions
139
app/components/UI/DeFiPositions/DeFiProtocolPositionDetails.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,139 @@ | ||
| import '../../../../tests/component-view/mocks'; | ||
| import React from 'react'; | ||
| import { FlatList } from 'react-native'; | ||
| import { act, fireEvent } from '@testing-library/react-native'; | ||
| import type { GroupedDeFiPositions } from '@metamask/assets-controllers'; | ||
|
|
||
| import DeFiProtocolPositionDetails, { | ||
| DEFI_PROTOCOL_POSITION_DETAILS_BALANCE_TEST_ID, | ||
| } from './DeFiProtocolPositionDetails'; | ||
| import { WalletViewSelectorsIDs } from '../../Views/Wallet/WalletView.testIds'; | ||
| import { renderComponentViewScreen } from '../../../../tests/component-view/render'; | ||
| import { describeForPlatforms } from '../../../../tests/component-view/platform'; | ||
| import { backgroundState } from '../../../util/test/initial-root-state'; | ||
|
|
||
| /** | ||
| * Mirrors smoke `view-defi-details`: tap Aave V3 → read-only position details with | ||
| * Supplied tokens and fiat balances (no transaction). | ||
| */ | ||
| const aaveV3PositionAggregate: GroupedDeFiPositions['protocols'][number] = { | ||
| protocolDetails: { | ||
| name: 'Aave V3', | ||
| iconUrl: '', | ||
| }, | ||
| aggregatedMarketValue: 14.74, | ||
| positionTypes: { | ||
| supply: { | ||
| aggregatedMarketValue: 14.74, | ||
| positions: [ | ||
| [ | ||
| { | ||
| address: '0x23878914efe38d27c4d67ab83ed1b93a74d4086a', | ||
| name: 'Aave Ethereum USDT', | ||
| symbol: 'aEthUSDT', | ||
| decimals: 6, | ||
| balance: 0.300112, | ||
| balanceRaw: '300112', | ||
| marketValue: 14.74, | ||
| type: 'protocol', | ||
| tokens: [ | ||
| { | ||
| address: '0xdac17f958d2ee523a2206206994597c13d831ec7', | ||
| name: 'Tether USD', | ||
| symbol: 'USDT', | ||
| decimals: 6, | ||
| balance: 0.300112, | ||
| balanceRaw: '300112', | ||
| marketValue: 14.74, | ||
| price: 0.99994, | ||
| type: 'underlying', | ||
| iconUrl: '', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| [ | ||
| { | ||
| address: '0xfa1fdbbd71b0aa16162d76914d69cd8cb3ef92da', | ||
| name: 'Aave Ethereum Lido WETH', | ||
| symbol: 'aEthLidoWETH', | ||
| decimals: 18, | ||
| balance: 1e-5, | ||
| balanceRaw: '9030902767263172', | ||
| marketValue: 0.3, | ||
| type: 'protocol', | ||
| tokens: [ | ||
| { | ||
| address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', | ||
| name: 'Wrapped Ether', | ||
| symbol: 'WETH', | ||
| decimals: 18, | ||
| balance: 1e-5, | ||
| balanceRaw: '10000000000000', | ||
| marketValue: 0.3, | ||
| price: 1599.45, | ||
| type: 'underlying', | ||
| iconUrl: '', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| ], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const defiDetailsState = { | ||
| engine: { | ||
| backgroundState: { | ||
| ...backgroundState, | ||
| PreferencesController: { | ||
| ...backgroundState.PreferencesController, | ||
| privacyMode: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| describeForPlatforms('DeFi position details (read-only)', () => { | ||
| it('shows Aave V3 supplied assets with token symbols and fiat amounts', () => { | ||
| const { getByTestId, getByText, getAllByText, UNSAFE_getByType } = | ||
| renderComponentViewScreen( | ||
| DeFiProtocolPositionDetails, | ||
| { name: 'DeFiProtocolPositionDetails' }, | ||
| { state: defiDetailsState }, | ||
| { | ||
| protocolAggregate: aaveV3PositionAggregate, | ||
| networkIconAvatar: undefined, | ||
| }, | ||
| ); | ||
|
|
||
| expect( | ||
| getByTestId(WalletViewSelectorsIDs.DEFI_POSITIONS_DETAILS_CONTAINER), | ||
| ).toBeOnTheScreen(); | ||
|
|
||
| expect(getByText('Aave V3')).toBeOnTheScreen(); | ||
| expect( | ||
| getByTestId(DEFI_PROTOCOL_POSITION_DETAILS_BALANCE_TEST_ID), | ||
| ).toHaveTextContent('$14.74'); | ||
|
|
||
| // Smoke parity for details checks: Supplied + USDT + WETH + $14.74 + $0.30. | ||
| expect(getAllByText('Supplied')).toHaveLength(2); | ||
| expect(getAllByText('USDT')).toHaveLength(1); | ||
| expect(getAllByText('$14.74').length).toBeGreaterThanOrEqual(2); | ||
|
|
||
| const list = UNSAFE_getByType(FlatList); | ||
| act(() => { | ||
| fireEvent.scroll(list, { | ||
| nativeEvent: { | ||
| contentOffset: { y: 150 }, | ||
| contentSize: { height: 500, width: 400 }, | ||
| layoutMeasurement: { height: 400, width: 400 }, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| expect(getByText('WETH')).toBeOnTheScreen(); | ||
| expect(getByText('$0.30')).toBeOnTheScreen(); | ||
| }); | ||
| }); | ||
182 changes: 182 additions & 0 deletions
182
app/components/UI/MarketInsights/Views/MarketInsightsView/MarketInsightsView.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,182 @@ | ||
| /** | ||
| * Component view tests for token (non-Perps) MarketInsightsView: content, | ||
| * swap/buy navigation, trend sources sheet, thumbs up. | ||
| * Mirrors smoke: tests/smoke/assets/market-insights/view-market-insights.spec.ts | ||
| * (cases 7, 10, 11, 12). Entry card visibility cases (8, 9) are covered by | ||
| * AssetOverviewContent.view.test.tsx. | ||
| * Run: yarn test:view:one MarketInsightsView.view.test.tsx | ||
| */ | ||
| import '../../../../../../tests/component-view/mocks'; | ||
| import { fireEvent, screen, waitFor } from '@testing-library/react-native'; | ||
| import { CHAIN_IDS } from '@metamask/transaction-controller'; | ||
| import { | ||
| MOCK_PERPS_MARKET_INSIGHTS_REPORT, | ||
| setupMarketInsightsEngineMock, | ||
| } from '../../../../../../tests/component-view/fixtures/perpsMarketInsights'; | ||
| import { renderMarketInsightsViewWithNavigation } from '../../../../../../tests/component-view/renderers/marketInsights'; | ||
| import { describeForPlatforms } from '../../../../../../tests/component-view/platform'; | ||
| import { BuildQuoteSelectors } from '../../../Ramp/Aggregator/Views/BuildQuote/BuildQuote.testIds'; | ||
| import { MarketInsightsSelectorsIDs } from '../../MarketInsights.testIds'; | ||
| import { analytics } from '../../../../../util/analytics/analytics'; | ||
| import { resetFeedbackCache } from './MarketInsightsView'; | ||
|
|
||
| const ETH_MAINNET_ROUTE_PARAMS = { | ||
| assetSymbol: 'ETH', | ||
| assetIdentifier: 'eip155:1/slip44:60', | ||
| tokenAddress: '0x0000000000000000000000000000000000000000', | ||
| tokenDecimals: 18, | ||
| tokenName: 'Ethereum', | ||
| tokenChainId: CHAIN_IDS.MAINNET, | ||
| token: { | ||
| address: '0x123', | ||
| symbol: 'ETH', | ||
| decimals: 18, | ||
| name: 'Ethereum', | ||
| chainId: '0x1', | ||
| image: 'https://example.com/eth.png', | ||
| balance: '0', | ||
| logo: undefined, | ||
| }, | ||
| }; | ||
|
|
||
| describeForPlatforms('MarketInsightsView (token flow)', () => { | ||
| beforeEach(() => { | ||
| setupMarketInsightsEngineMock(MOCK_PERPS_MARKET_INSIGHTS_REPORT); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| resetFeedbackCache(); | ||
| }); | ||
|
|
||
| it('displays market insights content and navigates to swap', async () => { | ||
| renderMarketInsightsViewWithNavigation({ | ||
| initialParams: ETH_MAINNET_ROUTE_PARAMS, | ||
| overrides: { | ||
| engine: { | ||
| backgroundState: { | ||
| TokensController: { | ||
| allTokens: { | ||
| '0x1': { | ||
| '0x0000000000000000000000000000000000000001': [ | ||
| { | ||
| address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', | ||
| decimals: 6, | ||
| symbol: 'USDC', | ||
| name: 'USD Coin', | ||
| image: '', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| allIgnoredTokens: {}, | ||
| }, | ||
| TokenBalancesController: { | ||
| tokenBalances: { | ||
| '0x0000000000000000000000000000000000000001': { | ||
| '0x1': { | ||
| '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': '0x3b9aca00', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| TokenRatesController: { | ||
| marketData: { | ||
| '0x1': { | ||
| '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': { | ||
| tokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', | ||
| currency: 'ETH', | ||
| price: 0.0005, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| expect( | ||
| await screen.findByTestId(MarketInsightsSelectorsIDs.VIEW_CONTAINER), | ||
| ).toBeOnTheScreen(); | ||
| expect( | ||
| await screen.findByText( | ||
| 'Ethereum shows strong momentum amid institutional demand', | ||
| ), | ||
| ).toBeOnTheScreen(); | ||
| expect( | ||
| await screen.findByText( | ||
| 'Ethereum continues to attract institutional interest with increasing on-chain activity and a healthy DeFi ecosystem.', | ||
| ), | ||
| ).toBeOnTheScreen(); | ||
| expect(await screen.findByText('Institutional Adoption')).toBeOnTheScreen(); | ||
| expect(await screen.findByText('DeFi Activity Surge')).toBeOnTheScreen(); | ||
|
|
||
| fireEvent.press( | ||
| await screen.findByTestId(MarketInsightsSelectorsIDs.SWAP_BUTTON), | ||
| ); | ||
|
|
||
| expect(await screen.findByTestId('route-BridgeView')).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('navigates to buy flow when tapping Buy button', async () => { | ||
| renderMarketInsightsViewWithNavigation({ | ||
| initialParams: ETH_MAINNET_ROUTE_PARAMS, | ||
| }); | ||
|
|
||
| await screen.findByTestId(MarketInsightsSelectorsIDs.VIEW_CONTAINER); | ||
|
|
||
| fireEvent.press( | ||
| await screen.findByTestId(MarketInsightsSelectorsIDs.BUY_BUTTON), | ||
| ); | ||
|
|
||
| expect( | ||
| await screen.findByTestId(BuildQuoteSelectors.CONTINUE_BUTTON), | ||
| ).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('shows sources bottom sheet when tapping a trend item', async () => { | ||
| renderMarketInsightsViewWithNavigation({ | ||
| initialParams: ETH_MAINNET_ROUTE_PARAMS, | ||
| }); | ||
|
|
||
| await screen.findByTestId(MarketInsightsSelectorsIDs.VIEW_CONTAINER); | ||
|
|
||
| fireEvent.press( | ||
| await screen.findByTestId(`${MarketInsightsSelectorsIDs.TREND_ITEM}-0`), | ||
| ); | ||
|
|
||
| expect( | ||
| await screen.findByText('Spot Ethereum ETFs See Record Weekly Inflows'), | ||
| ).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('can tap thumbs up feedback button', async () => { | ||
| const trackEventSpy = jest.spyOn(analytics, 'trackEvent'); | ||
| try { | ||
| renderMarketInsightsViewWithNavigation({ | ||
| initialParams: ETH_MAINNET_ROUTE_PARAMS, | ||
| }); | ||
|
|
||
| await screen.findByTestId(MarketInsightsSelectorsIDs.VIEW_CONTAINER); | ||
|
|
||
| const thumbsUp = await screen.findByTestId( | ||
| MarketInsightsSelectorsIDs.THUMBS_UP_BUTTON, | ||
| ); | ||
| trackEventSpy.mockClear(); | ||
| fireEvent.press(thumbsUp); | ||
|
|
||
| await waitFor(() => { | ||
| expect(trackEventSpy).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| name: 'Market Insights Interaction', | ||
| properties: expect.objectContaining({ | ||
| interaction_type: 'thumbs_up', | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
| } finally { | ||
| trackEventSpy.mockRestore(); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
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.