cpd_2022_energy/test/widget_test.dart

143 lines
5.2 KiB
Dart
Raw Permalink Normal View History

2022-11-08 22:35:54 +01:00
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:energy/main.dart';
void main() {
group('Widgets Test', () {
testWidgets('Test title', (tester) async {
// execute the actual test
await tester.pumpWidget(MaterialApp(home: Scaffold(appBar: AppBar(title: const Text('Energy App')))));
await tester.pump();
// Expect to find the item on screen.
expect(find.text('Energy App'), findsOneWidget);
});
testWidgets('Test find ChangeNotifierProvider with a specific key', (tester) async {
// find widget
final altitudeChange = find.byKey(const ValueKey("ChangeNotifierProvider"));
// execute the actual test
await tester.pumpWidget(MaterialApp(home: EnergyHomePage()));
await tester.pump(); //rebuild your widget
// Expect to find the item on screen.
expect(find.byKey(const ValueKey("ChangeNotifierProvider")), findsOneWidget);
});
testWidgets('Test find a widget with a specific key', (tester) async {
// find widget
final altitudeChange = find.byKey(const ValueKey("AltitudeChange"));
// execute the actual test
await tester.pumpWidget(MaterialApp(home: EnergyHomePage()));
await tester.enterText(altitudeChange, "600");
await tester.pump(); //rebuild your widget
// Expect to find the item on screen.
expect(find.text("600"), findsOneWidget);
});
testWidgets('Test find a widget with a specific key', (tester) async {
// find widget
final velocityChange = find.byKey(const ValueKey("VelocityChange"));
// execute the actual test
await tester.pumpWidget(MaterialApp(home: EnergyHomePage()));
await tester.enterText(velocityChange, "900");
await tester.pump(); //rebuild your widget
// Expect to find the item on screen.
expect(find.text("900"), findsOneWidget);
});
testWidgets('Test find a widget with a specific key', (tester) async {
// find widget
final weightValue = find.byKey(const ValueKey("WeightValue"));
// execute the actual test
await tester.pumpWidget(MaterialApp(home: EnergyHomePage()));
await tester.enterText(weightValue, "1000");
await tester.pump(); //rebuild your widget
// Expect to find the item on screen.
expect(find.text("1000"), findsOneWidget);
});
testWidgets('Test find a widget with a specific key', (tester) async {
// find widget
final buttonEnergyInJoule = find.byKey(const ValueKey("ButtonEnergyInJoule"));
// execute the actual test
await tester.pumpWidget(MaterialApp(home: EnergyHomePage()));
await tester.press(buttonEnergyInJoule);
await tester.pump(); //rebuild your widget
// Expect to find the item on screen.
expect(find.byKey(const ValueKey("ButtonEnergyInJoule")), findsOneWidget);
});
testWidgets('Test find a widget with a specific key', (tester) async {
// find widget
final buttonPotentialEnergy = find.byKey(const ValueKey("ButtonPotentialEnergy"));
// execute the actual test
await tester.pumpWidget(MaterialApp(home: EnergyHomePage()));
await tester.press(buttonPotentialEnergy);
await tester.pump(); //rebuild your widget
// Expect to find the item on screen.
expect(find.byKey(const ValueKey("ButtonPotentialEnergy")), findsOneWidget);
});
testWidgets('Test find a widget with a specific key', (tester) async {
// find widget
final buttonKineticEnergy = find.byKey(const ValueKey("ButtonKineticEnergy"));
// execute the actual test
await tester.pumpWidget(MaterialApp(home: EnergyHomePage()));
await tester.press(buttonKineticEnergy);
await tester.pump(); //rebuild your widget
// Expect to find the item on screen.
expect(find.byKey(const ValueKey("ButtonKineticEnergy")), findsOneWidget);
});
testWidgets('Test find a widget with a specific key', (tester) async {
// find widget
final buttonLiterWater = find.byKey(const ValueKey("ButtonLiterWater"));
// execute the actual test
await tester.pumpWidget(MaterialApp(home: EnergyHomePage()));
await tester.press(buttonLiterWater);
await tester.pump(); //rebuild your widget
// Expect to find the item on screen.
expect(find.byKey(const ValueKey("ButtonLiterWater")), findsOneWidget);
});
testWidgets('Test find a widget with a specific key', (tester) async {
// find widget
final buttonKilogrammWater = find.byKey(const ValueKey("ButtonKilogrammIron"));
// execute the actual test
await tester.pumpWidget(MaterialApp(home: EnergyHomePage()));
await tester.press(buttonKilogrammWater);
await tester.pump(); //rebuild your widget
// Expect to find the item on screen.
expect(find.byKey(const ValueKey("ButtonKilogrammIron")), findsOneWidget);
});
});
}