Skip to content

Commit c2e77c0

Browse files
committed
feat: Modify Exchange and send tests to fit new flow
1 parent 9faec1c commit c2e77c0

12 files changed

+108
-66
lines changed

integration_test/components/common_test_cases.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class CommonTestCases {
7171
}
7272

7373
Future<void> startGesture(String key, Offset gestureOffset) async {
74+
await tester.pumpAndSettle();
75+
76+
final hasKey = isKeyPresent(key);
77+
78+
tester.printToConsole("Has gestureKey: $hasKey");
79+
80+
if (!hasKey) return;
81+
7482
final gesture = await tester.startGesture(tester.getCenter(find.byKey(ValueKey(key))));
7583

7684
// Drag to the left
@@ -176,6 +184,31 @@ class CommonTestCases {
176184
}
177185
}
178186

187+
Future<void> scrollItemIntoView(
188+
String itemKeyId,
189+
double scrollPixels,
190+
String scrollableFinderKey,
191+
) async {
192+
final Finder itemFinder = find.byKey(ValueKey(itemKeyId));
193+
194+
final scrollableFinder = find.descendant(
195+
of: find.byKey(ValueKey(scrollableFinderKey)),
196+
matching: find.byType(Scrollable),
197+
);
198+
199+
try {
200+
await tester.scrollUntilVisible(
201+
itemFinder,
202+
scrollPixels,
203+
scrollable: scrollableFinder,
204+
);
205+
} catch (e) {
206+
tester.printToConsole('Could not find $itemKeyId');
207+
}
208+
209+
await tester.pumpAndSettle();
210+
}
211+
179212
Future<void> enterText(String text, String editableTextKey) async {
180213
final editableTextWidget = find.byKey(ValueKey((editableTextKey)));
181214

integration_test/components/common_test_flows.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import 'package:flutter_test/flutter_test.dart';
1010
import 'package:cake_wallet/main.dart' as app;
1111

1212
import '../robots/create_pin_welcome_page_robot.dart';
13-
import '../robots/dashboard_page_robot.dart';
14-
import '../robots/disclaimer_page_robot.dart';
1513
import '../robots/new_wallet_page_robot.dart';
1614
import '../robots/new_wallet_type_page_robot.dart';
1715
import '../robots/pre_seed_page_robot.dart';
@@ -34,9 +32,7 @@ class CommonTestFlows {
3432
_welcomePageRobot = WelcomePageRobot(_tester),
3533
_preSeedPageRobot = PreSeedPageRobot(_tester),
3634
_setupPinCodeRobot = SetupPinCodeRobot(_tester),
37-
_dashboardPageRobot = DashboardPageRobot(_tester),
3835
_newWalletPageRobot = NewWalletPageRobot(_tester),
39-
_disclaimerPageRobot = DisclaimerPageRobot(_tester),
4036
_walletSeedPageRobot = WalletSeedPageRobot(_tester),
4137
_walletListPageRobot = WalletListPageRobot(_tester),
4238
_newWalletTypePageRobot = NewWalletTypePageRobot(_tester),
@@ -53,8 +49,6 @@ class CommonTestFlows {
5349
final PreSeedPageRobot _preSeedPageRobot;
5450
final SetupPinCodeRobot _setupPinCodeRobot;
5551
final NewWalletPageRobot _newWalletPageRobot;
56-
final DashboardPageRobot _dashboardPageRobot;
57-
final DisclaimerPageRobot _disclaimerPageRobot;
5852
final WalletSeedPageRobot _walletSeedPageRobot;
5953
final WalletListPageRobot _walletListPageRobot;
6054
final NewWalletTypePageRobot _newWalletTypePageRobot;
@@ -113,13 +107,6 @@ class CommonTestFlows {
113107
await _restoreFromKeys();
114108
}
115109

116-
//* ========== Handles switching to wallet list or menu from dashboard ===============
117-
Future<void> switchToWalletMenuFromDashboardPage() async {
118-
_tester.printToConsole('Switching to Wallet Menu');
119-
120-
await _dashboardPageRobot.dashboardMenuWidgetRobot.navigateToWalletMenu();
121-
}
122-
123110
void confirmAllAvailableWalletTypeIconsDisplayCorrectly() {
124111
for (var walletType in availableWalletTypes) {
125112
final imageUrl = walletTypeToCryptoCurrency(walletType).iconPath;

integration_test/robots/dashboard_menu_widget_robot.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DashboardMenuWidgetRobot {
2727
}
2828

2929
Future<void> navigateToWalletMenu() async {
30-
await commonTestCases.tapItemByKey('dashboard_page_Wallets_action_button_key');
30+
await commonTestCases.tapItemByKey('dashboard_page_menu_widget_wallet_menu_button_key');
3131
await commonTestCases.defaultSleepTime();
3232
}
3333

integration_test/robots/dashboard_page_robot.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ class DashboardPageRobot {
9292
await commonTestCases.tapItemByKey('dashboard_page_${S.current.buy}_action_button_key');
9393
}
9494

95+
Future<void> navigateToWalletsListPage() async {
96+
await commonTestCases.tapItemByKey('dashboard_page_${S.current.wallets}_action_button_key');
97+
}
98+
9599
Future<void> navigateToSendPage() async {
96100
await commonTestCases.tapItemByKey('dashboard_page_${S.current.send}_action_button_key');
97101
}

integration_test/robots/send_page_robot.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:async';
33
import 'package:cake_wallet/core/execution_state.dart';
44
import 'package:cake_wallet/generated/i18n.dart';
55
import 'package:cake_wallet/src/screens/send/send_page.dart';
6+
import 'package:cake_wallet/src/widgets/standard_slide_button_widget.dart';
67
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
78
import 'package:cw_core/crypto_currency.dart';
89
import 'package:cw_core/transaction_priority.dart';
@@ -299,37 +300,36 @@ class SendPageRobot {
299300

300301
//* ------ On Sending Success ------------
301302
Future<void> onSendSliderOnConfirmSendingBottomSheetDragged() async {
302-
tester.printToConsole('Inside confirm sending dialog: For sending');
303303
await commonTestCases.defaultSleepTime();
304304
await tester.pumpAndSettle();
305305

306-
bool hasConfirmSendBottomSheet =
307-
commonTestCases.isKeyPresent('send_page_confirm_sending_bottom_sheet_key');
306+
if (commonTestCases.isKeyPresent('send_page_confirm_sending_bottom_sheet_key')) {
307+
final state = tester.state<StandardSlideButtonState>(find.byType(StandardSlideButton));
308+
final double effectiveMaxWidth = state.effectiveMaxWidth;
309+
final double sliderWidth = state.sliderWidth;
310+
final double threshold = effectiveMaxWidth - sliderWidth - 10;
308311

309-
tester.printToConsole('Has Confirm Send BottomSheet: $hasConfirmSendBottomSheet');
312+
final sliderFinder =
313+
find.byKey(const ValueKey('standard_slide_button_widget_slider_container_key'));
314+
expect(sliderFinder, findsOneWidget);
310315

311-
if (hasConfirmSendBottomSheet) {
312-
await commonTestCases.startGesture(
313-
'standard_slide_button_widget_slider_key',
314-
Offset(200, 0),
315-
);
316+
// Using the center of the container as the drag start.
317+
final Offset dragStart = tester.getCenter(sliderFinder);
316318

317-
tester.printToConsole('Slider moved');
318-
319+
// Dragging by an offset sufficient to exceed the threshold.
320+
await tester.dragFrom(dragStart, Offset(threshold + 20, 0));
319321
await tester.pumpAndSettle();
320322

321-
tester.printToConsole('Slider pump done');
323+
tester.printToConsole('Final slider dragPosition: ${state.dragPosition}');
322324

323325
// Loop to wait for the operation to commit transaction
324326
await _waitForCommitTransactionCompletion();
325327

326-
await tester.pump();
327-
328328
await commonTestCases.defaultSleepTime(seconds: 4);
329329
} else {
330330
await commonTestCases.defaultSleepTime();
331331
await tester.pump();
332-
onSendSliderOnConfirmSendingBottomSheetDragged();
332+
await onSendSliderOnConfirmSendingBottomSheetDragged();
333333
}
334334
}
335335

integration_test/robots/transactions_page_robot.dart

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ class TransactionsPageRobot {
5252
// Define a timeout to prevent infinite loops
5353
// Putting at one hour for cases like monero that takes time to sync
5454
final timeout = Duration(hours: 1);
55-
final pollingInterval = Duration(seconds: 2);
5655
final endTime = DateTime.now().add(timeout);
5756

5857
while (DateTime.now().isBefore(endTime)) {
58+
await tester.pump(Duration(seconds: 5));
5959
final isSynced = dashboardViewModel.status is SyncedSyncStatus;
6060
final itemsLoaded = dashboardViewModel.items.isNotEmpty;
6161

@@ -64,21 +64,29 @@ class TransactionsPageRobot {
6464
await _performItemChecks(dashboardViewModel);
6565
} else {
6666
// Verify placeholder when items are not loaded
67+
await tester.pump(Duration(seconds: 5));
6768
_verifyPlaceholder();
69+
tester.printToConsole('No item to check for');
6870
}
6971

7072
// Determine if we should exit the loop
71-
if (_shouldExitLoop(hasTxHistoryWhileSyncing, isSynced, itemsLoaded)) {
73+
bool shouldExit = _shouldExitLoop(hasTxHistoryWhileSyncing, isSynced, itemsLoaded);
74+
await tester.pump(Duration(seconds: 2));
75+
76+
if (shouldExit) {
77+
await tester.pump(Duration(seconds: 2));
7278
break;
7379
}
7480

7581
// Pump the UI and wait for the next polling interval
76-
await tester.pumpAndSettle(pollingInterval);
82+
await commonTestCases.defaultSleepTime();
83+
await tester.pump(Duration(seconds: 2));
84+
await tester.pumpAndSettle();
7785
}
7886

7987
// After the loop, verify that both status is synced and items are loaded
8088
if (!_isFinalStateValid(dashboardViewModel)) {
81-
throw TimeoutException('Dashboard did not sync and load items within the allotted time.');
89+
tester.printToConsole('Dashboard did not sync and load items within the allotted time.');
8290
}
8391
}
8492

@@ -119,17 +127,22 @@ class TransactionsPageRobot {
119127
await tester.pumpAndSettle();
120128

121129
// Scroll the item into view
122-
await commonTestCases.dragUntilVisible(keyId, 'transactions_page_list_view_builder_key');
130+
await commonTestCases.scrollItemIntoView(
131+
keyId,
132+
20,
133+
'transactions_page_list_view_builder_key',
134+
);
123135
await tester.pumpAndSettle();
124136

125-
// Check if the widget is visible
137+
// Verify the widget is visible; if not, skip to the next one.
126138
if (!tester.any(find.byKey(ValueKey(keyId)))) {
127139
tester.printToConsole('Item not visible: $keyId. Moving to the next.');
128140
continue;
129141
}
130142

131143
await tester.pumpAndSettle();
132144

145+
// Execute the proper check depending on item type.
133146
switch (item.runtimeType) {
134147
case TransactionListItem:
135148
final transactionItem = item as TransactionListItem;

integration_test/robots/wallet_keys_robot.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,5 @@ class WalletKeysAndSeedPageRobot {
183183
tester.printToConsole('Going back to dashboard from credentials page');
184184
await commonTestCases.goBack();
185185
await commonTestCases.goBack();
186-
await commonTestCases.goBack();
187186
}
188187
}

integration_test/test_suites/confirm_seeds_flow_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import 'package:cake_wallet/wallet_types.g.dart';
32
import 'package:cw_core/wallet_type.dart';
43
import 'package:flutter/foundation.dart';
@@ -58,7 +57,7 @@ void main() {
5857
continue;
5958
}
6059

61-
await commonTestFlows.switchToWalletMenuFromDashboardPage();
60+
await dashboardPageRobot.navigateToWalletsListPage();
6261

6362
await commonTestFlows.createNewWalletFromWalletMenu(walletType);
6463

integration_test/test_suites/create_wallet_flow_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ void main() {
3939
continue;
4040
}
4141

42-
await commonTestFlows.switchToWalletMenuFromDashboardPage();
42+
await dashboardPageRobot.navigateToWalletsListPage();
4343

4444
await commonTestFlows.createNewWalletFromWalletMenu(walletType);
4545

4646
await dashboardPageRobot.confirmWalletTypeIsDisplayedCorrectly(walletType);
4747
}
4848

4949
// Goes to the wallet menu and provides a confirmation that all the wallets were correctly restored
50-
await commonTestFlows.switchToWalletMenuFromDashboardPage();
50+
await dashboardPageRobot.navigateToWalletsListPage();
5151

5252
commonTestFlows.confirmAllAvailableWalletTypeIconsDisplayCorrectly();
5353

integration_test/test_suites/restore_wallet_through_seeds_flow_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import 'package:cake_wallet/wallet_types.g.dart';
32
import 'package:cw_core/wallet_type.dart';
43
import 'package:flutter/material.dart';
@@ -51,7 +50,7 @@ void main() {
5150
continue;
5251
}
5352

54-
await commonTestFlows.switchToWalletMenuFromDashboardPage();
53+
await dashboardPageRobot.navigateToWalletsListPage();
5554

5655
await commonTestFlows.restoreWalletFromWalletMenu(
5756
walletType,
@@ -62,7 +61,7 @@ void main() {
6261
}
6362

6463
// Goes to the wallet menu and provides a visual confirmation that all the wallets were correctly restored
65-
await commonTestFlows.switchToWalletMenuFromDashboardPage();
64+
await dashboardPageRobot.navigateToWalletsListPage();
6665

6766
commonTestFlows.confirmAllAvailableWalletTypeIconsDisplayCorrectly();
6867

0 commit comments

Comments
 (0)