-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add golden test: "renders empty create homework dialog as expected"
- Loading branch information
1 parent
8b6b9a0
commit 6cbf3a2
Showing
13 changed files
with
1,387 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+35.8 KB
...ns/homework/homework_dialog/goldens/homework_dialog_add_empty_dark.iphone11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34.5 KB
...ldens/homework/homework_dialog/goldens/homework_dialog_add_empty_dark.phone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.2 KB
...work/homework_dialog/goldens/homework_dialog_add_empty_dark.phone_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.2 KB
...ork/homework_dialog/goldens/homework_dialog_add_empty_dark.tablet_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.4 KB
...work/homework_dialog/goldens/homework_dialog_add_empty_dark.tablet_portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36.6 KB
...s/homework/homework_dialog/goldens/homework_dialog_add_empty_light.iphone11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.1 KB
...dens/homework/homework_dialog/goldens/homework_dialog_add_empty_light.phone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.5 KB
...ork/homework_dialog/goldens/homework_dialog_add_empty_light.phone_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.8 KB
...rk/homework_dialog/goldens/homework_dialog_add_empty_light.tablet_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.9 KB
...ork/homework_dialog/goldens/homework_dialog_add_empty_light.tablet_portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 90 additions & 0 deletions
90
app/test_goldens/homework/homework_dialog/homework_dialog_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) 2023 Sharezone UG (haftungsbeschränkt) | ||
// Licensed under the EUPL-1.2-or-later. | ||
// | ||
// You may obtain a copy of the Licence at: | ||
// https://joinup.ec.europa.eu/software/page/eupl | ||
// | ||
// SPDX-License-Identifier: EUPL-1.2 | ||
|
||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart' as bloc_lib; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:golden_toolkit/golden_toolkit.dart'; | ||
import 'package:sharezone/blocs/homework/homework_dialog_bloc.dart'; | ||
import 'package:sharezone/pages/homework/homework_dialog.dart'; | ||
import 'package:sharezone_widgets/sharezone_widgets.dart'; | ||
|
||
// ignore_for_file: invalid_use_of_visible_for_testing_member | ||
|
||
class MockHomeworkDialogBloc | ||
extends MockBloc<HomeworkDialogEvent, HomeworkDialogState> | ||
implements HomeworkDialogBloc {} | ||
|
||
void main() { | ||
group('HomeworkDialog', () { | ||
late MockHomeworkDialogBloc homeworkDialogBloc; | ||
|
||
setUp(() { | ||
homeworkDialogBloc = MockHomeworkDialogBloc(); | ||
}); | ||
|
||
Future<void> pumpAndSettleHomeworkDialog(WidgetTester tester, | ||
{required ThemeData theme, required bool isEditing}) async { | ||
await tester.pumpWidgetBuilder( | ||
bloc_lib.BlocProvider<HomeworkDialogBloc>( | ||
create: (context) => homeworkDialogBloc, | ||
child: Scaffold( | ||
body: HomeworkDialogMain( | ||
isEditing: isEditing, | ||
bloc: homeworkDialogBloc, | ||
), | ||
), | ||
), | ||
wrapper: materialAppWrapper(theme: theme), | ||
); | ||
|
||
// We have a delay for displaying the keyboard (using a Timer). | ||
// We have to wait until the timer is finished, otherwise this happens: | ||
// The following assertion was thrown running a test: | ||
// A Timer is still pending even after the widget tree was disposed. | ||
// We use a very long timer to show that it doesn't actually | ||
// make the test slower. | ||
await tester.pumpAndSettle(const Duration(seconds: 25)); | ||
} | ||
|
||
testGoldens('renders empty create homework dialog as expected', | ||
(tester) async { | ||
whenListen( | ||
homeworkDialogBloc, | ||
Stream.value(emptyCreateHomeworkDialogState), | ||
initialState: emptyCreateHomeworkDialogState, | ||
); | ||
|
||
await pumpAndSettleHomeworkDialog(tester, | ||
isEditing: false, theme: lightTheme); | ||
|
||
await multiScreenGolden( | ||
tester, | ||
'homework_dialog_add_empty_light', | ||
); | ||
|
||
await pumpAndSettleHomeworkDialog(tester, | ||
isEditing: false, theme: darkTheme); | ||
|
||
await multiScreenGolden( | ||
tester, | ||
'homework_dialog_add_empty_dark', | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
// Used temporarily when testing so one can see what happens "on the screen" in | ||
// a widget test without having to use a real device / simulator to run these | ||
// tests. | ||
// --update-goldens | ||
Future<void> generateGolden(String name) async { | ||
await expectLater( | ||
find.byType(MaterialApp), matchesGoldenFile('goldens/golden_$name.png')); | ||
} |
Oops, something went wrong.