Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENV-1450: BeefQA: "cannot boost" screen #1422

Merged
merged 7 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions integration_test/boost_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// SPDX-FileCopyrightText: 2024 Foundation Devices Inc.
//
// SPDX-License-Identifier: GPL-3.0-or-later

import 'package:envoy/business/faucet.dart';
import 'package:envoy/main.dart';
import 'package:envoy/ui/home/cards/accounts/detail/coins/coin_balance_widget.dart';
import 'package:envoy/ui/home/cards/accounts/detail/coins/coins_switch.dart';
import 'package:envoy/ui/theme/envoy_icons.dart';
import 'package:envoy/util/console.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:screenshot/screenshot.dart';
import 'btc_sats.dart';
import 'check_fiat_in_app.dart';
import 'edit_account_name.dart';
import 'enable_testnet_test.dart';
import 'flow_to_map_and_p2p_test.dart';
import 'switch_fiat_currency.dart';

const hotSignetAddress = 'tb1qt0h7r2hhphnsctj3akmusquszxvtkkupgmwrpq';
const signetWalletAddress =
'tb1p7n5z27jfsef6552q560y5z4a69c7ry9u5d74u0s2qelwa4dt7p5qs4ujrm';

/// Also there should be at least 2 Coins inside the current Tag
/// Should wait a few minutes for another test

void main() {
testWidgets('Boost screen', (tester) async {
// Only test the app version and Open Source Licenses page.
// Unable to test Terms of Use and Privacy Policy as they open in an external application.

final FlutterExceptionHandler? originalOnError = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails details) {
kPrint('FlutterError caught: ${details.exceptionAsString()}');
if (originalOnError != null) {
originalOnError(details);
}
};
try {
// Uncomment the line below if you want to start from the beginning,
// but then you MUST call setAppFromStart or setUpWalletFromSeedViaMagicRecover.
// await resetEnvoyData();

await initSingletons();
ScreenshotController envoyScreenshotController = ScreenshotController();
await tester.pumpWidget(Screenshot(
controller: envoyScreenshotController, child: const EnvoyApp()));

// await setUpWalletFromSeedViaMagicRecover(tester, seed);

await fromHomeToAdvancedMenu(tester);

bool isSettingsSignetSwitchOn = await isSlideSwitchOn(tester, 'Signet');
if (!isSettingsSignetSwitchOn) {
// find And Toggle Signet Switch
await findAndToggleSettingsSwitch(tester, 'Signet');
}

// go back to accounts
await pressHamburgerMenu(tester);
await pressHamburgerMenu(tester);

// go to Signet account
await findAndPressTextButton(tester, 'Signet');

// go to tags
await findAndPressEnvoyIcon(tester, EnvoyIcons.tag);
await tester.pump(Durations.long2);

/// lock all tags in the Untagged
// Find all instances of the CoinTagSwitch
final Finder switchFinder = find.byType(CoinTagSwitch);

// Check if the tag is locked
if (switchFinder.evaluate().isNotEmpty) {
// If there's a CoinTagSwitch, lock all of the Coins by tapping the CoinLockButton
await findAndTapCoinLockButton(tester);
await findAndPressTextButton(tester, 'Lock');
}

// go to Untagged
await findAndPressTextButton(tester, 'Untagged');
await tester.pump(Durations.long2);

// unlock one Coin
await findAndTapCoinLockButton(tester);
await findAndPressTextButton(tester, 'Unlock');

// toggle that coin for Send
await findAndToggleCoinTagSwitch(tester);

await findAndPressTextButton(tester, 'Send Selected');

await enterTextInField(
tester, find.byType(TextFormField), signetWalletAddress);

await findAndPressTextButton(
tester, 'Send Selected'); // send the whole coin

// go to staging
await waitForTealTextAndTap(tester, 'Confirm');
await tester.pump(Durations.long2);

// now wait for it to go to staging
final textFinder = find.text("Fee");
await tester.pumpUntilFound(textFinder,
tries: 20, duration: Durations.long2);

await findAndPressTextButton(tester, 'Send Transaction');

await findAndPressTextButton(tester, 'No thanks');

await slowSearchAndToggleText(tester, 'Continue');

// go to activity
await findAndPressEnvoyIcon(tester, EnvoyIcons.tag);
await tester.pump();
await tester.pump(Durations.long2);

await findFirstTextButtonAndPress(tester, 'Sent');

// check if you are out of pop-up
await slowSearchAndToggleText(tester, 'Boost');

await tester.pump(const Duration(milliseconds: 1000));

//close via X button
final closeDialogButton = find.byIcon(Icons.close);
await tester.pumpUntilFound(closeDialogButton,
duration: Durations.long2, tries: 200);

await tester.pump(Durations.long2);

await findTextOnScreen(tester, 'Boost');

// pull some money on the end for the next test
await getSatsFromSignetFaucet(5000, hotSignetAddress);
await tester.pump(Durations.long2);
} finally {
// Restore the original FlutterError.onError handler after the test.
FlutterError.onError = originalOnError;
}
});
}

Future<void> findAndTapCoinLockButton(WidgetTester tester) async {
// Find all instances of the CoinLockButton
final Finder lockButtonFinder = find.byType(CoinLockButton);

// Ensure that at least one CoinLockButton is found
expect(lockButtonFinder, findsWidgets,
reason: "No CoinLockButton found on the screen");

// Select the last CoinLockButton
final Finder specificButtonFinder = lockButtonFinder.last;

// Tap the selected button
await tester.tap(specificButtonFinder);
await tester.pump(); // Reflect the UI changes
await tester.pump(Durations.long2);
}

Future<void> findAndToggleCoinTagSwitch(WidgetTester tester) async {
// Find all instances of the CoinTagSwitch
final Finder switchFinder = find.byType(CoinTagSwitch);

// Ensure that at least one CoinTagSwitch is found
expect(switchFinder, findsWidgets,
reason: "No CoinTagSwitch found on the screen");

// Select the last CoinTagSwitch
final Finder specificSwitchFinder = switchFinder.last;

// Tap the selected switch to toggle it
await tester.tap(specificSwitchFinder);
await tester.pump(); // Reflect the UI changes
await tester.pump(Durations.long2);
}

Future<void> slowSearchAndToggleText(
WidgetTester tester, String buttonText) async {
final text = find.text(buttonText);
await tester.pumpUntilFound(text, duration: Durations.long2, tries: 200);
expect(text, findsOneWidget);
await tester.tap(text);
await tester.pump(Durations.long2);
}
25 changes: 9 additions & 16 deletions integration_test/btc_sats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ void main() {
}
};
try {
// Uncomment the line below if testing on local machine.
// Uncomment the line below if you want to start from the beginning,
// but then you MUST call setAppFromStart or setUpWalletFromSeedViaMagicRecover.
// await resetEnvoyData();

await initSingletons();
ScreenshotController envoyScreenshotController = ScreenshotController();
await tester.pumpWidget(Screenshot(
controller: envoyScreenshotController, child: const EnvoyApp()));

await setUpWalletFromSeedViaMagicRecover(tester, seed);
// await setUpWalletFromSeedViaMagicRecover(tester, seed);

/// Go to setting and enable fiat, we will need this later
await pressHamburgerMenu(tester);
Expand Down Expand Up @@ -70,10 +71,7 @@ void main() {

// Go to Activity and check for BTC
await findAndPressTextButton(tester, 'Activity');
await checkForEnvoyIcon(
tester,
EnvoyIcons
.btc); // TODO: why does it pass if there is no icon on the screen
await checkForEnvoyIcon(tester, EnvoyIcons.btc);
//back to accounts
await findAndPressTextButton(tester, 'Accounts');

Expand Down Expand Up @@ -152,10 +150,6 @@ void main() {
await findAndToggleSettingsSwitch(tester, 'View Amount in Sats');
}

// 10) Close the app, reopen the app // TODO: Can't do this
//
// 11) Go to settings, check that killing the app didn't disable the Sats toggle

/// Repeat steps 2-8, but instead of BTC you should be seeing Sats in every step
// return to home
await pressHamburgerMenu(tester);
Expand All @@ -167,10 +161,7 @@ void main() {

// Go to Activity and check for sats
await findAndPressTextButton(tester, 'Activity');
await checkForEnvoyIcon(
tester,
EnvoyIcons
.sats); // TODO: why does it pass if there is no icon on the screen
await checkForEnvoyIcon(tester, EnvoyIcons.sats);
//back to accounts
await findAndPressTextButton(tester, 'Accounts');

Expand Down Expand Up @@ -240,13 +231,15 @@ Future<void> waitForTealTextAndTap(
// Finder for the text widget
final Finder textFinder = find.text(textToFind);

// Wait until the text is found
// Wait until the text is found initially
await tester.pumpUntilFound(textFinder, tries: 20, duration: Durations.long2);

// Set the maximum number of retries to wait for the text to turn Teal
const int maxRetries = 10;
int retryCount = 0;

// Wait the text button to settle
await tester.pump(const Duration(milliseconds: 3000));
// Loop until the text's color is Teal or the maximum retries are reached
bool isTeal = false;
while (!isTeal && retryCount < maxRetries) {
Expand Down Expand Up @@ -319,7 +312,7 @@ Future<void> findFirstTextButtonAndPress(
}

Future<void> findAndPressWidget<T extends Widget>(WidgetTester tester) async {
await tester.pump(Durations.long2); // Initial pump to settle the widget tree
await tester.pump(Durations.long2);

// Find the widget of type T
final widgetFinder = find.byType(T);
Expand Down
51 changes: 40 additions & 11 deletions integration_test/check_fiat_in_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,11 @@ void main() {
}

/// in Activity
// await findAndPressTextButton(tester, 'Activity'); // TODO: uncomment when transaction is made
//
// if (currentSettingsFiatCode != null) {
// await tester.pump(Durations.long2);
// bool fiatCheckResult =
// await checkFiatOnCurrentScreen(tester, currentSettingsFiatCode);
// expect(fiatCheckResult, isTrue);
// }
await findAndPressTextButton(tester, 'Activity');

if (currentSettingsFiatCode != null) {
await scrollActivityAndCheckFiat(tester, currentSettingsFiatCode);
}

/// in Mainet Account
await findAndPressTextButton(tester, 'Accounts');
Expand Down Expand Up @@ -174,9 +171,6 @@ void main() {
expect(fiatCheckResult, isTrue);
}

// 5) Close the app, reopen it // TODO: unable to do this
// 6) Check that the toggle remains switched on

// Note: The "ramp" widget is only supported on Android and iOS platforms,
// so there is no reliable way to verify its functionality in this test.
} finally {
Expand Down Expand Up @@ -305,3 +299,38 @@ Future<void> fromSettingsToFiatDropdown(WidgetTester tester) async {
await tester.tap(dropdownButton);
await tester.pump(Durations.long2);
}

Future<void> scrollActivityAndCheckFiat(
WidgetTester tester,
String currentSettingsFiatCode,
) async {
bool fiatCheckResult;

// Loop until the check passes or until you cannot scroll anymore
while (true) {
// Check the result on the current screen
fiatCheckResult =
await checkFiatOnCurrentScreen(tester, currentSettingsFiatCode);

// If the check is successful, exit the loop
if (fiatCheckResult) {
break;
}

// Perform the drag operation on the CustomScrollView by the specified number of pixels
await tester.drag(find.byType(CustomScrollView), const Offset(0, -100));
await tester.pump(Durations.long2);

// If it reaches the bottom and cannot scroll further, it will return
final Finder scrollable = find.byType(CustomScrollView);
final ScrollableState scrollableState =
tester.state<ScrollableState>(scrollable);
if (scrollableState.position.pixels >=
scrollableState.position.maxScrollExtent) {
break;
}
}

// Assert that the fiatCheckResult is true at the end of the scroll
expect(fiatCheckResult, isTrue);
}
2 changes: 1 addition & 1 deletion integration_test/edit_account_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ Future<void> saveName(WidgetTester tester) async {

Future<void> checkName(WidgetTester tester, String name) async {
await tester.pump();
final nameText = find.text(name);
final nameText = find.text(name).first;
expect(nameText, findsOneWidget);
}
1 change: 1 addition & 0 deletions integration_test_order
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ integration_test/enable_testnet_test.dart
integration_test/enable_taproot.dart
integration_test/signet.dart
integration_test/enable_tor.dart
integration_test/boost_screen.dart
# Below this is test that use app without any account
integration_test/buy_button_test.dart
Loading