-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathMarketInsightsView.view.test.tsx
More file actions
182 lines (163 loc) · 5.89 KB
/
MarketInsightsView.view.test.tsx
File metadata and controls
182 lines (163 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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();
}
});
});