Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
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();
});
Comment thread
cursor[bot] marked this conversation as resolved.
});
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();
}
});
});
Loading
Loading