-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathpredict-open-position.spec.ts
More file actions
118 lines (105 loc) · 4.79 KB
/
predict-open-position.spec.ts
File metadata and controls
118 lines (105 loc) · 4.79 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
import { withFixtures } from '../../framework/fixtures/FixtureHelper';
import FixtureBuilder from '../../framework/fixtures/FixtureBuilder';
import { SmokePredictions } from '../../tags';
import { loginToApp } from '../../flows/wallet.flow';
import TabBarComponent from '../../page-objects/wallet/TabBarComponent';
import WalletActionsBottomSheet from '../../page-objects/wallet/WalletActionsBottomSheet';
import PredictMarketList from '../../page-objects/Predict/PredictMarketList';
import PredictDetailsPage from '../../page-objects/Predict/PredictDetailsPage';
import Assertions from '../../framework/Assertions';
import {
remoteFeatureFlagHomepageSectionsV1Enabled,
remoteFeatureFlagPredictEnabled,
} from '../../api-mocking/mock-responses/feature-flags-mocks';
import { Mockttp } from 'mockttp';
import { setupRemoteFeatureFlagsMock } from '../../api-mocking/helpers/remoteFeatureFlagsHelper';
import {
POLYMARKET_COMPLETE_MOCKS,
POLYMARKET_POSITIONS_WITH_WINNINGS_MOCKS,
POLYMARKET_POST_OPEN_POSITION_MOCKS,
POLYMARKET_UPDATE_USDC_BALANCE_MOCKS,
} from '../../api-mocking/mock-responses/polymarket/polymarket-mocks';
import WalletView from '../../page-objects/wallet/WalletView';
import { predictOpenPositionAnalyticsExpectations } from '../../helpers/analytics/expectations/predict-open-position.analytics';
/*
Test Scenario: Open position on Celtics vs. Nets market
Verifies the open position flow for a predictions market:
1. Navigate to Predictions tab and open market list
2. Select Celtics vs. Nets market from sports category
3. Open a position with $10 investment
4. Verify position appears in Positions tab
5. Verify balance updates to $17.76
6. Verify position appears in Activities tab
*/
const positionDetails = {
name: 'Celtics vs. Nets',
positionAmount: '10',
newBalance: '$17.76',
category: 'sports' as const,
marketIndex: 1,
};
const PredictionMarketFeature = async (mockServer: Mockttp) => {
await setupRemoteFeatureFlagsMock(mockServer, {
...remoteFeatureFlagPredictEnabled(true),
...remoteFeatureFlagHomepageSectionsV1Enabled(),
carouselBanners: false,
});
await POLYMARKET_COMPLETE_MOCKS(mockServer);
await POLYMARKET_POSITIONS_WITH_WINNINGS_MOCKS(mockServer, false); // do not include winnings. Claim Button is animated and problematic for e2e
};
describe(SmokePredictions('Predictions'), () => {
it('opens position on Celtics vs. Nets market', async () => {
await withFixtures(
{
fixture: new FixtureBuilder()
.withPolygon()
.withMetaMetricsOptIn()
.build(),
restartDevice: true,
testSpecificMock: PredictionMarketFeature,
analyticsExpectations: predictOpenPositionAnalyticsExpectations,
},
async ({ mockServer }) => {
await loginToApp();
await TabBarComponent.tapActions();
await WalletActionsBottomSheet.tapPredictButton();
await device.disableSynchronization();
await Assertions.expectElementToBeVisible(PredictMarketList.container, {
description: 'Predict market list container should be visible',
});
await PredictMarketList.tapCategoryTab(positionDetails.category);
await PredictMarketList.tapMarketCard(
positionDetails.category,
positionDetails.marketIndex,
);
await PredictDetailsPage.tapGameBetYesButton();
await POLYMARKET_POST_OPEN_POSITION_MOCKS(mockServer);
await PredictDetailsPage.tapPositionAmount(
positionDetails.positionAmount,
);
await PredictDetailsPage.tapDoneButton();
await PredictDetailsPage.tapOpenPosition();
await PredictDetailsPage.tapBackButton();
await Assertions.expectTextDisplayed(positionDetails.newBalance, {
description: `USDC balance should display ${positionDetails.newBalance} after opening position`,
});
await PredictMarketList.tapBackButton();
await device.enableSynchronization();
await WalletView.scrollAndTapPredictionsPosition(positionDetails.name);
/*
When opening a position, the balance is optimistically updated in PredictController
with a cache valid for 5 seconds. When getBalance() is called after cache expiration
it invalidates the NetworkController's block cache and
makes a fresh RPC balance request. The mock is placed here to
verify that when the cache expires and a balance refresh request
is made, it successfully returns the updated balance.
*/
await POLYMARKET_UPDATE_USDC_BALANCE_MOCKS(mockServer, 'open-position');
await PredictDetailsPage.tapBackButton();
await TabBarComponent.tapActions();
await WalletActionsBottomSheet.tapPredictButton();
await Assertions.expectTextDisplayed(positionDetails.newBalance);
},
);
});
});