Marco
2509c1721c
1. Make EnterFoodWidget animated 2. Fix exception when reading quantity for a food. Introduce first integration test
60 lines
1.9 KiB
Dart
60 lines
1.9 KiB
Dart
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
/* Copyright (C) 2024 Marco Groß <mgross@sw-gross.de> */
|
|
|
|
import 'package:calorimeter/main.dart';
|
|
import 'package:calorimeter/storage/storage.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
void main() {
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
setUp(() {});
|
|
|
|
group('end-to-end test', () {
|
|
testWidgets('add food manually', (tester) async {
|
|
var foodStorage = await FoodStorage.create();
|
|
|
|
await tester.pumpWidget(MainApp(storage: foodStorage));
|
|
await tester.pumpAndSettle();
|
|
|
|
final addButtonFinder = find.byIcon(Icons.add);
|
|
expect(addButtonFinder, findsOneWidget);
|
|
|
|
await tester.tap(addButtonFinder);
|
|
await tester.pumpAndSettle();
|
|
|
|
final nameAutocompleteFinder =
|
|
find.widgetWithText(Autocomplete<String>, "Name");
|
|
final amountFinder = find.widgetWithText(TextField, "Amount");
|
|
final kcalFinder = find.widgetWithText(TextField, "kcal");
|
|
final addButton = find.widgetWithIcon(ElevatedButton, Icons.check);
|
|
|
|
expect(nameAutocompleteFinder, findsOneWidget);
|
|
expect(amountFinder, findsOneWidget);
|
|
expect(kcalFinder, findsOneWidget);
|
|
expect(addButton, findsOneWidget);
|
|
|
|
await tester.enterText(nameAutocompleteFinder, "Bread");
|
|
await tester.enterText(amountFinder, "150");
|
|
await tester.enterText(kcalFinder, "250");
|
|
|
|
await tester.tap(addButton);
|
|
await tester.pumpAndSettle();
|
|
|
|
// EnterFoodWidget collapses
|
|
expect(nameAutocompleteFinder, findsNothing);
|
|
|
|
var enteredFood = find.text("Bread");
|
|
var enteredAmount = find.text("150");
|
|
var enteredKcal = find.text("250");
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(enteredFood, findsOneWidget);
|
|
expect(enteredAmount, findsOneWidget);
|
|
expect(enteredKcal, findsOneWidget);
|
|
});
|
|
});
|
|
}
|