From d4ffc730995361e64db52f7d6c9c4c46d1d4a965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Fri, 19 Jan 2024 20:23:16 +0100 Subject: [PATCH] test: create test for setup view --- .gitignore | 1 + android/app/build.gradle | 6 ++-- integration_test/setup_test.dart | 53 +++++++++++++++++++++++++++----- lib/api/wallet_manager.dart | 15 +++++++++ lib/main.dart | 6 +++- lib/views/setup.dart | 2 +- 6 files changed, 71 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 24476c5..1a1da39 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release +reports \ No newline at end of file diff --git a/android/app/build.gradle b/android/app/build.gradle index 7551c3f..b3e80a0 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -51,7 +51,7 @@ android { applicationId "cafe.caras.prasule" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdkVersion flutter.minSdkVersion + minSdkVersion 21 targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName @@ -76,4 +76,6 @@ flutter { source '../..' } -dependencies {} +dependencies { + implementation 'com.android.support:multidex:1.0.3' +} diff --git a/integration_test/setup_test.dart b/integration_test/setup_test.dart index db9ca13..4a9294f 100644 --- a/integration_test/setup_test.dart +++ b/integration_test/setup_test.dart @@ -1,24 +1,61 @@ +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; +import 'package:logger/logger.dart'; +import 'package:prasule/api/wallet_manager.dart'; import 'package:prasule/main.dart'; +import 'package:prasule/pw/platformfield.dart'; void main() { + final logger = Logger(); IntegrationTestWidgetsFlutterBinding.ensureInitialized(); group("Test Setup screen:", () { testWidgets('First-time setup', (WidgetTester tester) async { + // delete all data + await WalletManager.deleteAllData(); // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - + await tester.pumpWidget( + const MyApp( + locale: Locale('en', 'US'), + ), + ); + await tester.pumpAndSettle(); + logger.i("Looking for welcome header"); expect(find.text('Welcome!'), findsOneWidget); - // // Tap the '+' icon and trigger a frame. - // await tester.tap(find.byIcon(Icons.add)); - // await tester.pump(); + // Tap "Next" button + await tester.tap(find.text("Next")); + await tester.pumpAndSettle(); - // // Verify that our counter has incremented. - // expect(find.text('0'), findsNothing); - // expect(find.text('1'), findsOneWidget); + logger.i("Next view, looking for name+balance fields"); + + final firstFields = find.byType(PlatformField); + + expect(firstFields, findsExactly(2)); + + logger.i("Entering text"); + await tester.enterText(find.byType(PlatformField).first, "Debugging"); + await tester.pumpAndSettle(); + await tester.enterText(find.byType(PlatformField).last, "100"); + await tester.pumpAndSettle(); + + // Tap "Next" button + await tester.tap(find.text("Next")); + await tester.pumpAndSettle(); + + // Tap "Finish" button + await tester.tap(find.text("Finish")); + await tester.pumpAndSettle(); + + expect( + find.byWidgetPredicate( + (widget) => + widget is DropdownButton && + ((widget as DropdownButton).value ?? -1) == 0, + ), + findsOne, + ); }); }); } diff --git a/lib/api/wallet_manager.dart b/lib/api/wallet_manager.dart index e2c66ab..de1a3f6 100644 --- a/lib/api/wallet_manager.dart +++ b/lib/api/wallet_manager.dart @@ -28,6 +28,21 @@ class WalletManager { return wallets; } + /// Deletes all [Wallet]s + static Future deleteAllData() async { + final path = + Directory("${(await getApplicationDocumentsDirectory()).path}/wallets"); + if (!path.existsSync()) { + return; + } + + for (final entry in path.listSync()) { + if (!entry.path.endsWith(".json")) return; // only delete wallet files + logger.d("Deleting ${entry.path}"); + entry.deleteSync(); + } + } + /// Loads and returns a single [Wallet] by name static Future loadWallet(String name) async { final path = diff --git a/lib/main.dart b/lib/main.dart index 9a86716..d6791ea 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -29,12 +29,15 @@ final logger = Logger(); /// The application itself class MyApp extends StatelessWidget { /// The application itself - const MyApp({super.key}); + const MyApp({super.key, this.locale}); /// If Material You was applied /// /// Used to check if it is supported static bool appliedYou = false; + + /// Override locale, used for testing + final Locale? locale; // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -50,6 +53,7 @@ class MyApp extends StatelessWidget { ...GlobalCupertinoLocalizations.delegates, ], supportedLocales: AppLocalizations.supportedLocales, + locale: locale, title: 'PraĊĦule', theme: ThemeData( colorScheme: _materialYou diff --git a/lib/views/setup.dart b/lib/views/setup.dart index e8749e3..cde8424 100644 --- a/lib/views/setup.dart +++ b/lib/views/setup.dart @@ -297,7 +297,7 @@ class _SetupViewState extends State { (await SharedPreferences.getInstance()) .getBool("useMaterialYou") ?? false; - if (!mounted) return; + if (!context.mounted) return; await showDialog( context: context, builder: (c) => PlatformDialog(