test: create basic tests #24

Merged
hernik merged 4 commits from dev-tests into dev 2024-01-22 14:41:17 +01:00
6 changed files with 71 additions and 12 deletions
Showing only changes of commit d4ffc73099 - Show all commits

1
.gitignore vendored
View file

@ -42,3 +42,4 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release
reports

View file

@ -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'
}

View file

@ -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<int>).value ?? -1) == 0,
),
findsOne,
);
});
});
}

View file

@ -28,6 +28,21 @@ class WalletManager {
return wallets;
}
/// Deletes all [Wallet]s
static Future<void> 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<Wallet> loadWallet(String name) async {
final path =

View file

@ -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

View file

@ -297,7 +297,7 @@ class _SetupViewState extends State<SetupView> {
(await SharedPreferences.getInstance())
.getBool("useMaterialYou") ??
false;
if (!mounted) return;
if (!context.mounted) return;
await showDialog(
context: context,
builder: (c) => PlatformDialog(