Files
ingtrakapp/test/widget_test.dart
T

90 lines
2.8 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:myapp/main.dart';
import 'package:myapp/models/bank.dart';
import 'package:myapp/models/transaction_meta.dart';
import 'package:myapp/services/storage_service.dart';
import 'package:myapp/utils/constants.dart';
import 'package:myapp/utils/helpers.dart';
import 'package:myapp/utils/look_ahead.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Future<void> pumpApp(WidgetTester tester) async {
SharedPreferences.setMockInitialValues({});
final storage = StorageService();
await storage.init();
await tester.pumpWidget(MyApp(storage: storage));
}
testWidgets('splash shows the app name then opens Home', (tester) async {
await pumpApp(tester);
expect(find.text(kAppName), findsWidgets);
await tester.pump(kSplashDuration);
await tester.pump(const Duration(milliseconds: 450));
await tester.pump(const Duration(milliseconds: 350));
expect(find.text('Home'), findsWidgets);
expect(find.text('Overview'), findsOneWidget);
expect(find.byTooltip('Settings'), findsOneWidget);
});
test('ConnectStart.fromJson maps authUrl and state', () {
final start = ConnectStart.fromJson({
'authUrl': 'https://example.test/auth',
'state': 'abc',
});
expect(start.authUrl, 'https://example.test/auth');
expect(start.state, 'abc');
});
test('BankTransaction match keys support auto-label and notes', () {
final tx = BankTransaction.fromJson({
'date': '2026-09-01',
'description':
'BCK*AH CAMPUS DIEMEN ZUID NLD Pasvolgnr: 001 Transactie: C00338123',
'amount': -3.5,
'currency': 'EUR',
'pending': false,
});
expect(tx.descriptionKey, contains('pasvolgnr'));
expect(tx.merchantKey, contains('ah campus diemen'));
expect(tx.merchantKey.contains('pasvolgnr'), isFalse);
expect(tx.exactKey, contains('-3.5'));
expect(formatMoney(tx.amount, tx.currency), contains('EUR'));
expect(kBuiltinLabels.first.name, 'Groceries');
});
test('look-ahead applies monthly recurring amounts', () {
final items = [
const RecurringItem(
description: 'Salary',
amount: 2000,
currency: 'EUR',
dayOfMonth: 25,
labelIds: ['salary'],
),
const RecurringItem(
description: 'Rent',
amount: -900,
currency: 'EUR',
dayOfMonth: 1,
labelIds: ['mortgage'],
),
];
final from = DateTime(2026, 9, 6);
final through = DateTime(2026, 10, 31);
final predicted = predictBalance(
currentBalance: 1000,
from: from,
throughDate: through,
items: items,
);
// Sep 25 salary + Oct 1 rent + Oct 25 salary = 1000+2000-900+2000
expect(predicted, 4100);
});
}