Add tests with golden files

Let's see if this doesn't make too much work later on, when changing some detail
in a widget causes the test to fail
This commit is contained in:
Roland Geider
2021-04-23 19:42:08 +02:00
parent 3c21650003
commit a7b67631df
26 changed files with 57 additions and 0 deletions

BIN
test/gym_mode_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
test/gym_mode_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
test/gym_mode_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
test/gym_mode_4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
test/gym_mode_5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
test/gym_mode_6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
test/gym_mode_7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -80,6 +80,8 @@ void main() {
expect(find.byIcon(Icons.chevron_left), findsNothing);
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
expect(find.byIcon(Icons.chevron_right), findsOneWidget);
await expectLater(find.byType(MaterialApp), matchesGoldenFile('gym_mode_1.png'));
await tester.tap(find.byIcon(Icons.chevron_right));
await tester.pumpAndSettle();
@@ -89,6 +91,7 @@ void main() {
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
expect(find.byIcon(Icons.chevron_right), findsOneWidget);
await expectLater(find.byType(MaterialApp), matchesGoldenFile('gym_mode_2.png'));
await tester.drag(find.byType(ExerciseOverview), Offset(-500.0, 0.0));
await tester.pumpAndSettle();
@@ -102,6 +105,7 @@ void main() {
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
expect(find.byIcon(Icons.chevron_right), findsOneWidget);
await expectLater(find.byType(MaterialApp), matchesGoldenFile('gym_mode_3.png'));
await tester.drag(find.byType(LogPage), Offset(-500.0, 0.0));
await tester.pumpAndSettle();
@@ -111,6 +115,7 @@ void main() {
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
expect(find.byIcon(Icons.chevron_right), findsOneWidget);
await expectLater(find.byType(MaterialApp), matchesGoldenFile('gym_mode_4.png'));
await tester.tap(find.byIcon(Icons.chevron_right));
await tester.pumpAndSettle();
@@ -118,6 +123,7 @@ void main() {
expect(find.text('test exercise 1'), findsOneWidget);
expect(find.byType(LogPage), findsOneWidget);
expect(find.byType(Form), findsOneWidget);
await expectLater(find.byType(MaterialApp), matchesGoldenFile('gym_mode_5.png'));
await tester.drag(find.byType(LogPage), Offset(-500.0, 0.0));
await tester.pumpAndSettle();
@@ -127,6 +133,7 @@ void main() {
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
expect(find.byIcon(Icons.chevron_right), findsOneWidget);
await expectLater(find.byType(MaterialApp), matchesGoldenFile('gym_mode_6.png'));
await tester.tap(find.byIcon(Icons.chevron_right));
await tester.pumpAndSettle();
@@ -137,6 +144,7 @@ void main() {
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
expect(find.byIcon(Icons.chevron_right), findsNothing);
await expectLater(find.byType(MaterialApp), matchesGoldenFile('gym_mode_7.png'));
//
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -114,4 +114,9 @@ void main() {
// Detail page
// ...
});
testWidgets('Golden test', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(meal1));
await expectLater(find.byType(MaterialApp), matchesGoldenFile('nutritional_meal_form.png'));
});
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -118,4 +118,9 @@ void main() {
await tester.pumpAndSettle();
expect(find.text(('New cool plan')), findsOneWidget, reason: 'Nutritional plan detail page');
});
testWidgets('Golden test', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(plan1));
await expectLater(find.byType(MaterialApp), matchesGoldenFile('nutritional_plan_form.png'));
});
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -87,4 +87,9 @@ void main() {
expect(find.text('17:00'), findsOneWidget);
});
testWidgets('Golden test', (WidgetTester tester) async {
await tester.pumpWidget(createNutritionalPlan());
await expectLater(find.byType(MaterialApp), matchesGoldenFile('nutritional_plan_screen.png'));
});
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -106,4 +106,9 @@ void main() {
expect(find.text('1.1.2021'), findsOneWidget);
expect(find.text('10.1.2021'), findsOneWidget);
});
testWidgets('Golden test', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await expectLater(find.byType(MaterialApp), matchesGoldenFile('nutritional_plans_screen.png'));
});
}

BIN
test/weight_screen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -107,4 +107,9 @@ void main() {
expect(find.text('1.1.2021'), findsOneWidget);
expect(find.text('10.1.2021'), findsOneWidget);
});
testWidgets('Golden test', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await expectLater(find.byType(MaterialApp), matchesGoldenFile('weight_screen.png'));
});
}

BIN
test/workout_day_form.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -98,4 +98,9 @@ void main() {
expect(find.text('Dienstag'), findsOneWidget);
expect(find.text('Donnerstag'), findsOneWidget);
});
testWidgets('Golden test', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await expectLater(find.byType(MaterialApp), matchesGoldenFile('workout_day_form.png'));
});
}

BIN
test/workout_form.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -106,4 +106,10 @@ void main() {
await tester.pumpAndSettle();
expect(find.text(('New cool workout')), findsOneWidget, reason: 'Workout plan detail page');
});
testWidgets('Golden test', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(plan2));
await tester.pumpAndSettle();
await expectLater(find.byType(MaterialApp), matchesGoldenFile('workout_form.png'));
});
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

@@ -83,4 +83,12 @@ void main() {
expect(find.text('Montag, Dienstag'), findsOneWidget);
expect(find.text('Donnerstag'), findsOneWidget);
});
// flutter test --update-goldens
testWidgets('Golden test', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
await expectLater(find.byType(MaterialApp), matchesGoldenFile('workout_plan_screen.png'));
});
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -108,4 +108,9 @@ void main() {
expect(find.text('1.1.2021'), findsOneWidget);
expect(find.text('12.2.2021'), findsOneWidget);
});
testWidgets('Golden test', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await expectLater(find.byType(MaterialApp), matchesGoldenFile('workout_plan_screens.png'));
});
}