test: create basic tests #24
6 changed files with 71 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -42,3 +42,4 @@ app.*.map.json
|
||||||
/android/app/debug
|
/android/app/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
reports
|
|
@ -51,7 +51,7 @@ android {
|
||||||
applicationId "cafe.caras.prasule"
|
applicationId "cafe.caras.prasule"
|
||||||
// You can update the following values to match your application needs.
|
// 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.
|
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||||
minSdkVersion flutter.minSdkVersion
|
minSdkVersion 21
|
||||||
targetSdkVersion 33
|
targetSdkVersion 33
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
|
@ -76,4 +76,6 @@ flutter {
|
||||||
source '../..'
|
source '../..'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {}
|
dependencies {
|
||||||
|
implementation 'com.android.support:multidex:1.0.3'
|
||||||
|
}
|
||||||
|
|
|
@ -1,24 +1,61 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:integration_test/integration_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/main.dart';
|
||||||
|
import 'package:prasule/pw/platformfield.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
final logger = Logger();
|
||||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||||
group("Test Setup screen:", () {
|
group("Test Setup screen:", () {
|
||||||
testWidgets('First-time setup', (WidgetTester tester) async {
|
testWidgets('First-time setup', (WidgetTester tester) async {
|
||||||
|
// delete all data
|
||||||
|
await WalletManager.deleteAllData();
|
||||||
// Build our app and trigger a frame.
|
// 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);
|
expect(find.text('Welcome!'), findsOneWidget);
|
||||||
|
|
||||||
// // Tap the '+' icon and trigger a frame.
|
// Tap "Next" button
|
||||||
// await tester.tap(find.byIcon(Icons.add));
|
await tester.tap(find.text("Next"));
|
||||||
// await tester.pump();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
// // Verify that our counter has incremented.
|
logger.i("Next view, looking for name+balance fields");
|
||||||
// expect(find.text('0'), findsNothing);
|
|
||||||
// expect(find.text('1'), findsOneWidget);
|
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,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,21 @@ class WalletManager {
|
||||||
return wallets;
|
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
|
/// Loads and returns a single [Wallet] by name
|
||||||
static Future<Wallet> loadWallet(String name) async {
|
static Future<Wallet> loadWallet(String name) async {
|
||||||
final path =
|
final path =
|
||||||
|
|
|
@ -29,12 +29,15 @@ final logger = Logger();
|
||||||
/// The application itself
|
/// The application itself
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
/// The application itself
|
/// The application itself
|
||||||
const MyApp({super.key});
|
const MyApp({super.key, this.locale});
|
||||||
|
|
||||||
/// If Material You was applied
|
/// If Material You was applied
|
||||||
///
|
///
|
||||||
/// Used to check if it is supported
|
/// Used to check if it is supported
|
||||||
static bool appliedYou = false;
|
static bool appliedYou = false;
|
||||||
|
|
||||||
|
/// Override locale, used for testing
|
||||||
|
final Locale? locale;
|
||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -50,6 +53,7 @@ class MyApp extends StatelessWidget {
|
||||||
...GlobalCupertinoLocalizations.delegates,
|
...GlobalCupertinoLocalizations.delegates,
|
||||||
],
|
],
|
||||||
supportedLocales: AppLocalizations.supportedLocales,
|
supportedLocales: AppLocalizations.supportedLocales,
|
||||||
|
locale: locale,
|
||||||
title: 'Prašule',
|
title: 'Prašule',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: _materialYou
|
colorScheme: _materialYou
|
||||||
|
|
|
@ -297,7 +297,7 @@ class _SetupViewState extends State<SetupView> {
|
||||||
(await SharedPreferences.getInstance())
|
(await SharedPreferences.getInstance())
|
||||||
.getBool("useMaterialYou") ??
|
.getBool("useMaterialYou") ??
|
||||||
false;
|
false;
|
||||||
if (!mounted) return;
|
if (!context.mounted) return;
|
||||||
await showDialog(
|
await showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (c) => PlatformDialog(
|
builder: (c) => PlatformDialog(
|
||||||
|
|
Loading…
Reference in a new issue