dev
dart 122 lines 3.96 KB
Raw
1 import 'package:cake_wallet/generated/i18n.dart';
2 import 'package:cake_wallet/src/screens/dashboard/dashboard_page.dart';
3 import 'package:cake_wallet/src/screens/dashboard/pages/balance/crypto_balance_widget.dart';
4 import 'package:cw_core/wallet_type.dart';
5 import 'package:flutter_test/flutter_test.dart';
6
7 import '../components/common_test_cases.dart';
8 import 'dashboard_menu_widget_robot.dart';
9
10 class DashboardPageRobot {
11 DashboardPageRobot(this.tester)
12 : commonTestCases = CommonTestCases(tester),
13 dashboardMenuWidgetRobot = DashboardMenuWidgetRobot(tester);
14
15 final WidgetTester tester;
16 final DashboardMenuWidgetRobot dashboardMenuWidgetRobot;
17 late CommonTestCases commonTestCases;
18
19 Future<void> isDashboardPage() async {
20 await commonTestCases.isSpecificPage<DashboardPage>();
21 await commonTestCases.takeScreenshots('dashboard_page');
22 }
23
24 Future<void> confirmWalletTypeIsDisplayedCorrectly(
25 WalletType type, {
26 bool isHaven = false,
27 }) async {
28 final cryptoBalanceWidget =
29 tester.widget<CryptoBalanceWidget>(find.byType(CryptoBalanceWidget));
30 final hasAccounts = cryptoBalanceWidget.dashboardViewModel.balanceViewModel.hasAccounts;
31
32 if (hasAccounts) {
33 final walletName = cryptoBalanceWidget.dashboardViewModel.name;
34 commonTestCases.hasText(walletName);
35 } else {
36 final walletName = walletTypeToString(type);
37 final assetName = isHaven ? '$walletName Assets' : walletName;
38 commonTestCases.hasText(assetName);
39 }
40 await commonTestCases.defaultSleepTime(seconds: 5);
41 }
42
43 void confirmServiceUpdateButtonDisplays() {
44 commonTestCases.hasValueKey('dashboard_page_services_update_button_key');
45 }
46
47 void confirmSyncIndicatorButtonDisplays() {
48 commonTestCases.hasValueKey('dashboard_page_sync_indicator_button_key');
49 }
50
51 void confirmMenuButtonDisplays() {
52 commonTestCases.hasValueKey('dashboard_page_wallet_menu_button_key');
53 }
54
55 Future<void> confirmRightCryptoAssetTitleDisplaysPerPageView(
56 WalletType type, {
57 bool isHaven = false,
58 }) async {
59 //Balance Page
60 await confirmWalletTypeIsDisplayedCorrectly(type, isHaven: isHaven);
61
62 // Swipe to Cake features Page
63 await swipeDashboardTab(false);
64 commonTestCases.hasText('Cake ${S.current.features}');
65
66 // Swipe back to balance
67 await swipeDashboardTab(true);
68
69 // Swipe to Transactions Page
70 await swipeDashboardTab(true);
71 commonTestCases.hasText(S.current.transactions);
72
73 // Swipe back to balance
74 await swipeDashboardTab(false);
75 await commonTestCases.defaultSleepTime(seconds: 3);
76 }
77
78 Future<void> swipeDashboardTab(bool swipeRight) async {
79 await commonTestCases.swipeByPageKey(
80 key: 'dashboard_page_view_key',
81 swipeRight: swipeRight,
82 );
83 await commonTestCases.defaultSleepTime();
84 }
85
86 Future<void> openDrawerMenu() async {
87 await commonTestCases.tapItemByKey('dashboard_page_wallet_menu_button_key');
88 await commonTestCases.defaultSleepTime();
89 }
90
91 Future<void> navigateToBuyPage() async {
92 await commonTestCases.tapItemByKey('dashboard_page_buy_action_button_key');
93 }
94
95 Future<void> navigateToWalletsListPage({bool isDrawer = false}) async {
96 await tester.pumpAndSettle(Duration(milliseconds: 1000));
97
98 await commonTestCases.tapItemByKey(
99 isDrawer
100 ? 'dashboard_page_menu_widget_wallet_menu_button_key'
101 : 'dashboard_page__wallet_list_button_key',
102 );
103
104 await tester.pumpAndSettle(Duration(milliseconds: 2000));
105 }
106
107 Future<void> navigateToSendPage() async {
108 await commonTestCases.tapItemByKey('dashboard_page_send_action_button_key');
109 }
110
111 Future<void> navigateToSellPage() async {
112 await commonTestCases.tapItemByKey('dashboard_page_sell_action_button_key');
113 }
114
115 Future<void> navigateToReceivePage() async {
116 await commonTestCases.tapItemByKey('dashboard_page_receive_action_button_key');
117 }
118
119 Future<void> navigateToExchangePage() async {
120 await commonTestCases.tapItemByKey('dashboard_page_swap_action_button_key');
121 }
122 }