first commit
This commit is contained in:
commit
e630f2a3ec
80 changed files with 3889 additions and 0 deletions
72
test/receipt_parser_test.dart
Normal file
72
test/receipt_parser_test.dart
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fuel_tax_tracker/services/receipt_parser.dart';
|
||||
|
||||
void main() {
|
||||
group('ReceiptParser', () {
|
||||
test('parses a typical gas station receipt', () {
|
||||
const receipt = '''
|
||||
SHELL OIL 12345
|
||||
123 MAIN ST
|
||||
PUMP 04
|
||||
GALLONS 12.345
|
||||
PRICE/GAL \$3.599
|
||||
FUEL TOTAL \$44.44
|
||||
THANK YOU
|
||||
''';
|
||||
|
||||
final result = ReceiptParser.parse(receipt);
|
||||
|
||||
expect(result.gallons, 12.345);
|
||||
expect(result.pricePerGallon, 3.599);
|
||||
expect(result.totalCost, 44.44);
|
||||
});
|
||||
|
||||
test('does not confuse SUBTOTAL with TOTAL', () {
|
||||
const receipt = '''
|
||||
SUBTOTAL 10.00
|
||||
TAX 0.50
|
||||
TOTAL 10.50
|
||||
''';
|
||||
|
||||
final result = ReceiptParser.parse(receipt);
|
||||
|
||||
expect(result.totalCost, 10.50);
|
||||
});
|
||||
|
||||
test('derives total when gallons and price per gallon are known', () {
|
||||
const receipt = '''
|
||||
GALLONS 10.000
|
||||
PPG 3.500
|
||||
''';
|
||||
|
||||
final result = ReceiptParser.parse(receipt);
|
||||
|
||||
expect(result.gallons, 10.0);
|
||||
expect(result.pricePerGallon, 3.5);
|
||||
expect(result.totalCost, 35.0);
|
||||
});
|
||||
|
||||
test('derives gallons when total and price per gallon are known', () {
|
||||
const receipt = '''
|
||||
PRICE PER GALLON \$4.000
|
||||
TOTAL \$20.00
|
||||
''';
|
||||
|
||||
final result = ReceiptParser.parse(receipt);
|
||||
|
||||
expect(result.pricePerGallon, 4.0);
|
||||
expect(result.totalCost, 20.0);
|
||||
expect(result.gallons, 5.0);
|
||||
});
|
||||
|
||||
test('returns nulls when nothing recognizable is present', () {
|
||||
const receipt = 'THANK YOU FOR YOUR PURCHASE';
|
||||
|
||||
final result = ReceiptParser.parse(receipt);
|
||||
|
||||
expect(result.gallons, isNull);
|
||||
expect(result.pricePerGallon, isNull);
|
||||
expect(result.totalCost, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
24
test/widget_test.dart
Normal file
24
test/widget_test.dart
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:fuel_tax_tracker/screens/home_screen.dart';
|
||||
import 'package:fuel_tax_tracker/services/app_state.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Shows empty state and add-vehicle action when there are no vehicles',
|
||||
(WidgetTester tester) async {
|
||||
final appState = AppState()..isLoading = false;
|
||||
|
||||
await tester.pumpWidget(
|
||||
ChangeNotifierProvider.value(
|
||||
value: appState,
|
||||
child: const MaterialApp(home: HomeScreen()),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('My Vehicles'), findsOneWidget);
|
||||
expect(find.text('Add Vehicle'), findsOneWidget);
|
||||
expect(find.textContaining('No vehicles yet'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue