-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathpredict-cash-out.spec.ts
More file actions
112 lines (102 loc) · 4.91 KB
/
predict-cash-out.spec.ts
File metadata and controls
112 lines (102 loc) · 4.91 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
import { withFixtures } from '../../framework/fixtures/FixtureHelper';
import FixtureBuilder from '../../framework/fixtures/FixtureBuilder';
import { SmokePredictions } from '../../tags';
import { loginToApp } from '../../flows/wallet.flow';
import PredictDetailsPage from '../../page-objects/Predict/PredictDetailsPage';
import PredictMarketList from '../../page-objects/Predict/PredictMarketList';
import Assertions from '../../framework/Assertions';
import WalletView from '../../page-objects/wallet/WalletView';
import {
remoteFeatureFlagHomepageSectionsV1Enabled,
remoteFeatureFlagPredictEnabled,
} from '../../api-mocking/mock-responses/feature-flags-mocks';
import {
POLYMARKET_COMPLETE_MOCKS,
POLYMARKET_POSITIONS_WITH_WINNINGS_MOCKS,
POLYMARKET_POST_CASH_OUT_MOCKS,
POLYMARKET_REMOVE_CASHED_OUT_POSITION_MOCKS,
POLYMARKET_UPDATE_USDC_BALANCE_MOCKS,
} from '../../api-mocking/mock-responses/polymarket/polymarket-mocks';
import { Mockttp } from 'mockttp';
import { setupRemoteFeatureFlagsMock } from '../../api-mocking/helpers/remoteFeatureFlagsHelper';
import PredictCashOutPage from '../../page-objects/Predict/PredictCashOutPage';
import TabBarComponent from '../../page-objects/wallet/TabBarComponent';
import ActivitiesView from '../../page-objects/Transactions/ActivitiesView';
import PredictActivityDetails from '../../page-objects/Transactions/predictionsActivityDetails';
import { predictCashOutFlowAnalyticsExpectations } from '../../helpers/analytics/expectations/predict-cash-out.analytics';
import { SPURS_PELICANS_POSITION_ID } from '../../api-mocking/mock-responses/polymarket/polymarket-constants';
/*
Test Scenario: Cash out on open position - Spurs vs. Pelicans
Verifies the cash out flow for a predictions position (homepage sections v1 — no wallet tabs):
1. From wallet homepage Predictions section, open Spurs vs. Pelicans position details
2. Cash out the position with updated mocks
3. Verify balance and cash out in Activities tab
*/
const positionDetails = {
name: 'Spurs vs. Pelicans',
cashOutValue: '$30.75',
initialBalance: '$28.16',
newBalance: '$58.66',
};
const PredictionMarketFeature = async (mockServer: Mockttp) => {
await setupRemoteFeatureFlagsMock(mockServer, {
...remoteFeatureFlagHomepageSectionsV1Enabled(),
...remoteFeatureFlagPredictEnabled(true),
carouselBanners: false,
exploreSectionsOrder: {},
});
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('cashes out on open position: Spurs vs. Pelicans', async () => {
await withFixtures(
{
fixture: new FixtureBuilder()
.withPolygon()
.withMetaMetricsOptIn()
.build(),
restartDevice: true,
testSpecificMock: PredictionMarketFeature,
analyticsExpectations: predictCashOutFlowAnalyticsExpectations,
},
async ({ mockServer }) => {
await loginToApp();
await device.disableSynchronization();
await WalletView.scrollAndTapPredictionsPosition(positionDetails.name);
await Assertions.expectElementToBeVisible(PredictDetailsPage.container);
await POLYMARKET_POST_CASH_OUT_MOCKS(mockServer);
await PredictDetailsPage.tapGameCashOutButton(
SPURS_PELICANS_POSITION_ID,
);
await Assertions.expectElementToBeVisible(PredictCashOutPage.container);
await Assertions.expectElementToBeVisible(
PredictCashOutPage.cashOutButton,
);
await PredictCashOutPage.tapCashOutButton();
// Register position-removal and balance-update mocks only AFTER the
// cash-out confirmation tap. Registering them earlier causes a race
// condition: a background refetch can pick up the "position removed"
// response while the Cash Out button is still needed, making it vanish.
await POLYMARKET_REMOVE_CASHED_OUT_POSITION_MOCKS(mockServer);
await POLYMARKET_UPDATE_USDC_BALANCE_MOCKS(mockServer, 'cash-out');
await PredictDetailsPage.tapBackButton();
await device.enableSynchronization();
await WalletView.scrollAndTapPredictionsSection();
await WalletView.tapOnAvailableBalance();
await Assertions.expectTextDisplayed(positionDetails.newBalance, {
description: 'Predictions balance should be updated to $58.66',
});
await PredictMarketList.tapBackButton();
await TabBarComponent.tapActivity();
await ActivitiesView.tapOnPredictionsTab();
await Assertions.expectTextDisplayed('Cashed out');
await ActivitiesView.tapPredictPosition(positionDetails.name);
await Assertions.expectElementToBeVisible(
PredictActivityDetails.container,
);
await Assertions.expectTextDisplayed(positionDetails.cashOutValue);
},
);
});
});