From 150a21804a78078f0fbb759d43bbc5396b8a4254 Mon Sep 17 00:00:00 2001 From: Augsorn Chanklad Date: Thu, 2 May 2024 21:59:45 +0700 Subject: [PATCH] Add unit test song list filter screen --- .../songs_list_filter_screen_test.dart | 19 ++++++++++++++++ .../songs_list_screen_robot.dart | 22 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/src/features/songs/presentation/songs_list_screen/songs_list_filter_screen_test.dart diff --git a/test/src/features/songs/presentation/songs_list_screen/songs_list_filter_screen_test.dart b/test/src/features/songs/presentation/songs_list_screen/songs_list_filter_screen_test.dart new file mode 100644 index 00000000..9f3e97a3 --- /dev/null +++ b/test/src/features/songs/presentation/songs_list_screen/songs_list_filter_screen_test.dart @@ -0,0 +1,19 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:vocadb_app/src/features/songs/presentation/widgets/dropdown_song_sort.dart'; +import 'package:vocadb_app/src/features/songs/presentation/widgets/dropdown_song_types.dart'; + +import '../../../../mocks.dart'; +import 'songs_list_screen_robot.dart'; + +void main() { + testWidgets('Render song list filter screen without error', (tester) async { + final r = SongsListScreenRobot(tester); + + final songRepository = MockSongRepository(); + + await r.pumpSongsListFilterScreen(songRepository: songRepository); + + expect(find.byType(DropdownSongTypes), findsOneWidget); + expect(find.byType(DropdownSongSort), findsOneWidget); + }); +} \ No newline at end of file diff --git a/test/src/features/songs/presentation/songs_list_screen/songs_list_screen_robot.dart b/test/src/features/songs/presentation/songs_list_screen/songs_list_screen_robot.dart index 0b337648..f936ccef 100644 --- a/test/src/features/songs/presentation/songs_list_screen/songs_list_screen_robot.dart +++ b/test/src/features/songs/presentation/songs_list_screen/songs_list_screen_robot.dart @@ -6,6 +6,7 @@ import 'package:vocadb_app/src/common_widgets/search_appbar.dart'; import 'package:vocadb_app/src/features/settings/data/user_settings_repository.dart'; import 'package:vocadb_app/src/features/songs/data/song_repository.dart'; import 'package:vocadb_app/src/features/songs/presentation/song_tile/song_tile.dart'; +import 'package:vocadb_app/src/features/songs/presentation/songs_list_screen/songs_list_filter_screen.dart'; import 'package:vocadb_app/src/features/songs/presentation/songs_list_screen/songs_list_screen.dart'; class SongsListScreenRobot { @@ -34,6 +35,27 @@ class SongsListScreenRobot { await tester.pump(); } + Future pumpSongsListFilterScreen( + {SongRepository? songRepository}) async { + await tester.pumpWidget( + ProviderScope( + overrides: [ + if (songRepository != null) + songRepositoryProvider.overrideWithValue(songRepository), + userSettingsRepositoryProvider + .overrideWithValue(UserSettingsRepository()) + ], + child: const MaterialApp( + home: SongsFilterScreen(), + ), + ), + ); + + await tester.pump(); + await tester.pump(); + await tester.pump(); + } + Future expectSongsDisplayCountAtLeast(int count) async { final finder = find.byType(SongTile); expect(finder, findsAtLeastNWidgets(count));