-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathonramp.spec.ts
More file actions
194 lines (170 loc) · 6.5 KB
/
onramp.spec.ts
File metadata and controls
194 lines (170 loc) · 6.5 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
183
184
185
186
187
188
189
190
191
192
193
194
import { test, type BrowserContext } from '@playwright/test';
import { ModalPage } from './shared/pages/ModalPage';
import { OnRampPage } from './shared/pages/OnRampPage';
import { OnRampValidator } from './shared/validators/OnRampValidator';
import { WalletPage } from './shared/pages/WalletPage';
import { ModalValidator } from './shared/validators/ModalValidator';
let modalPage: ModalPage;
let modalValidator: ModalValidator;
let onRampPage: OnRampPage;
let onRampValidator: OnRampValidator;
let walletPage: WalletPage;
let context: BrowserContext;
// -- Setup --------------------------------------------------------------------
const onrampTest = test.extend<{ library: string }>({
library: ['wagmi', { option: true }]
});
onrampTest.describe.configure({ mode: 'serial' });
onrampTest.beforeAll(async ({ browser }) => {
context = await browser.newContext();
const browserPage = await context.newPage();
modalPage = new ModalPage(browserPage);
modalValidator = new ModalValidator(browserPage);
onRampPage = new OnRampPage(browserPage);
onRampValidator = new OnRampValidator(browserPage);
walletPage = new WalletPage(await context.newPage());
await modalPage.load();
// Connect to wallet first
await modalPage.qrCodeFlow(modalPage, walletPage);
await modalValidator.expectConnected();
});
onrampTest.afterAll(async () => {
await modalPage.page.close();
await walletPage.page.close();
});
// -- Tests --------------------------------------------------------------------
/**
* OnRamp Tests
* Tests the OnRamp functionality including:
* - Opening the OnRamp modal
* - Loading states
* - Currency selection
* - Amount input and quotes
* - Payment method selection
* - Checkout flow
*/
onrampTest('Should be able to open buy crypto modal', async () => {
await onRampPage.openBuyCryptoModal();
try {
// Wait for loading to complete
await onRampValidator.expectOnRampLoadingView();
} catch (error) {
// Loading view might be quick and disappear before we can check
// eslint-disable-next-line no-console
console.log('Loading view not visible, might have already loaded');
}
await onRampValidator.expectOnRampInitialScreen();
await modalPage.goBack();
await modalPage.closeModal();
});
onrampTest('Should display loading view when initializing', async () => {
await onRampPage.openBuyCryptoModal();
await onRampValidator.expectOnRampInitialScreen();
await modalPage.goBack();
await modalPage.closeModal();
});
onrampTest('Should be able to select a purchase currency', async () => {
await onRampPage.openBuyCryptoModal();
await onRampValidator.expectOnRampInitialScreen();
await onRampPage.clickSelectCurrency();
await onRampValidator.expectCurrencySelectionModal();
await onRampPage.selectCurrency('ZRX');
await onRampValidator.expectSelectedCurrency('ZRX');
await modalPage.goBack();
await modalPage.closeModal();
});
onrampTest('Should be able to select a payment method', async () => {
await onRampPage.openBuyCryptoModal();
await onRampValidator.expectOnRampInitialScreen();
await onRampPage.enterAmount(100);
await onRampValidator.expectQuotesLoaded();
try {
await onRampPage.clickPaymentMethod();
await onRampValidator.expectPaymentMethodModal();
await onRampPage.selectPaymentMethod('Apple Pay');
await onRampPage.selectPaymentMethod('Credit & Debit Card');
} catch (error) {
// eslint-disable-next-line no-console
console.log('Payment method selection failed');
}
await onRampPage.closePaymentModal();
await modalPage.goBack();
await modalPage.closeModal();
});
onrampTest('Should show suggested values and be able to select them', async () => {
await onRampPage.openBuyCryptoModal();
await onRampValidator.expectOnRampInitialScreen();
try {
await onRampValidator.expectSuggestedValues();
await onRampPage.selectSuggestedValue();
// Wait for quotes to load
await onRampValidator.expectQuotesLoaded();
} catch (error) {
// eslint-disable-next-line no-console
console.log('Suggested values not available or quotes not loading, continuing test');
}
await modalPage.goBack();
await modalPage.closeModal();
});
onrampTest('Should proceed to checkout when continue button is clicked', async () => {
test.setTimeout(60000); // Extend timeout for this test
await onRampPage.openBuyCryptoModal();
await onRampValidator.expectOnRampInitialScreen();
await onRampPage.enterAmount(100);
try {
// Wait for quotes to load
await onRampValidator.expectQuotesLoaded();
await onRampPage.clickContinue();
await onRampValidator.expectCheckoutScreen();
} catch (error) {
// If checkout fails, it's likely due to API issues - skip this step
// eslint-disable-next-line no-console
console.log('Checkout process failed, likely API issue');
}
await modalPage.closeModal();
});
onrampTest('Should be able to navigate to onramp settings', async () => {
await onRampPage.openBuyCryptoModal();
await onRampValidator.expectOnRampInitialScreen();
try {
await onRampPage.openSettings();
await onRampValidator.expectSettingsScreen();
// Go back to main screen
await modalPage.goBack();
await onRampValidator.expectOnRampInitialScreen();
} catch (error) {
// If settings navigation fails, skip this step
// eslint-disable-next-line no-console
console.log('Settings navigation failed');
}
await modalPage.goBack();
await modalPage.closeModal();
});
onrampTest('Should display appropriate error messages for invalid amounts', async () => {
await onRampPage.openBuyCryptoModal();
await onRampValidator.expectOnRampInitialScreen();
try {
// Test too low amount
await onRampPage.enterAmount(0.1);
await onRampValidator.expectAmountError();
// Test too high amount
await onRampPage.enterAmount(50000);
await onRampValidator.expectAmountError();
} catch (error) {
// If error messages don't appear, it might be that the API accepts these values
// eslint-disable-next-line no-console
console.log('Amount error testing failed, API might accept these values');
}
await modalPage.goBack();
await modalPage.closeModal();
});
onrampTest('Should navigate to a loading view after checkout', async () => {
await onRampPage.openBuyCryptoModal();
await onRampValidator.expectOnRampInitialScreen();
await onRampPage.enterAmount(100);
await onRampValidator.expectQuotesLoaded();
await onRampPage.clickContinue();
await onRampValidator.expectCheckoutScreen();
await onRampPage.clickConfirmCheckout();
await onRampValidator.expectLoadingWidgetView();
});