Skip to content

Commit

Permalink
Add unit test song list filter screen
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed May 2, 2024
1 parent bfbbb69 commit 150a218
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -34,6 +35,27 @@ class SongsListScreenRobot {
await tester.pump();
}

Future<void> 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<void> expectSongsDisplayCountAtLeast(int count) async {
final finder = find.byType(SongTile);
expect(finder, findsAtLeastNWidgets(count));
Expand Down

0 comments on commit 150a218

Please sign in to comment.