-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test album list filter screen
- Loading branch information
Showing
3 changed files
with
88 additions
and
1 deletion.
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
56 changes: 56 additions & 0 deletions
56
test/src/features/albums/presentation/albums_list/albums_list_filter_screen_robot.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,56 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:vocadb_app/src/features/albums/presentation/albums_list/albums_list_filter_screen.dart'; | ||
import 'package:vocadb_app/src/features/albums/presentation/widgets/dropdown_album_sort.dart'; | ||
import 'package:vocadb_app/src/features/albums/presentation/widgets/dropdown_album_type.dart'; | ||
|
||
class AlbumsListFilterScreenRobot { | ||
final WidgetTester tester; | ||
|
||
AlbumsListFilterScreenRobot(this.tester); | ||
|
||
Future<void> pumpAlbumsListFilterScreen({ | ||
Function(String?)? onAlbumsTypesChanged, | ||
Function(String?)? onSortChanged, | ||
}) async { | ||
await tester.pumpWidget( | ||
ProviderScope( | ||
child: MaterialApp( | ||
home: AlbumsFilterScreen( | ||
onAlbumTypesChanged: onAlbumsTypesChanged, | ||
onSortChanged: onSortChanged, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
Future<void> selectAlbumTypes(String value) async { | ||
final albumTypeDropdownBtnFinder = | ||
find.byKey(DropdownAlbumType.dropdownKey); | ||
expect(albumTypeDropdownBtnFinder, findsOneWidget); | ||
|
||
await tester.tap(albumTypeDropdownBtnFinder); | ||
await tester.pump(); | ||
|
||
final selectedFinder = find.text(value).last; | ||
expect(selectedFinder, findsOneWidget); | ||
await tester.tap(selectedFinder); | ||
await tester.pump(); | ||
} | ||
|
||
Future<void> selectSort(String value) async { | ||
final albumSortDropdownBtnFinder = | ||
find.byKey(DropdownAlbumSort.dropdownKey); | ||
expect(albumSortDropdownBtnFinder, findsOneWidget); | ||
|
||
await tester.tap(albumSortDropdownBtnFinder); | ||
await tester.pump(); | ||
|
||
final selectedFinder = find.text(value).last; | ||
expect(selectedFinder, findsOneWidget); | ||
await tester.tap(selectedFinder); | ||
await tester.pump(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
test/src/features/albums/presentation/albums_list/albums_list_screen_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,31 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'albums_list_filter_screen_robot.dart'; | ||
|
||
void main() { | ||
group('albums filter screen', () { | ||
testWidgets('change album type', (tester) async { | ||
String? selectedValue; | ||
final r = AlbumsListFilterScreenRobot(tester); | ||
|
||
await r.pumpAlbumsListFilterScreen( | ||
onAlbumsTypesChanged: (value) => selectedValue = value, | ||
); | ||
|
||
await r.selectAlbumTypes('E.P.'); | ||
expect(selectedValue, 'EP'); | ||
}); | ||
|
||
testWidgets('change album sort', (tester) async { | ||
String? selectedValue; | ||
final r = AlbumsListFilterScreenRobot(tester); | ||
|
||
await r.pumpAlbumsListFilterScreen( | ||
onAlbumsTypesChanged: (value) => selectedValue = value, | ||
); | ||
|
||
await r.selectSort('Addition date'); | ||
expect(selectedValue, 'AdditionDate'); | ||
}); | ||
}); | ||
} |