-
-
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.
- Loading branch information
Showing
4 changed files
with
94 additions
and
20 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
test/src/features/albums/presentation/albums_list/albums_list_filter_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'); | ||
}); | ||
}); | ||
} |
39 changes: 39 additions & 0 deletions
39
test/src/features/albums/presentation/albums_list/albums_list_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,39 @@ | ||
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/data/album_repository.dart'; | ||
import 'package:vocadb_app/src/features/albums/presentation/album_tile/album_tile.dart'; | ||
import 'package:vocadb_app/src/features/albums/presentation/albums_list/albums_list_screen.dart'; | ||
import 'package:vocadb_app/src/features/settings/data/user_settings_repository.dart'; | ||
|
||
class AlbumsListScreenRobot { | ||
final WidgetTester tester; | ||
|
||
AlbumsListScreenRobot(this.tester); | ||
|
||
Future<void> pumpAlbumsListScreen( | ||
{AlbumRepository? albumRepository}) async { | ||
await tester.pumpWidget( | ||
ProviderScope( | ||
overrides: [ | ||
if (albumRepository != null) | ||
albumRepositoryProvider.overrideWithValue(albumRepository), | ||
userSettingsRepositoryProvider | ||
.overrideWithValue(UserSettingsRepository()) | ||
], | ||
child: const MaterialApp( | ||
home: AlbumsListScreen(), | ||
), | ||
), | ||
); | ||
|
||
await tester.pump(); | ||
await tester.pump(); | ||
await tester.pump(); | ||
} | ||
|
||
Future<void> expectAlbumsDisplayCountAtLeast(int count) async { | ||
final finder = find.byType(AlbumTile); | ||
expect(finder, findsAtLeastNWidgets(count)); | ||
} | ||
} |
41 changes: 21 additions & 20 deletions
41
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 |
---|---|---|
@@ -1,31 +1,32 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:vocadb_app/src/features/albums/data/constants/fake_albums_list.dart'; | ||
import 'package:vocadb_app/src/features/albums/domain/albums_list_params.dart'; | ||
|
||
import 'albums_list_filter_screen_robot.dart'; | ||
import '../../../../mocks.dart'; | ||
import 'albums_list_screen_robot.dart'; | ||
|
||
void main() { | ||
group('albums filter screen', () { | ||
testWidgets('change album type', (tester) async { | ||
String? selectedValue; | ||
final r = AlbumsListFilterScreenRobot(tester); | ||
testWidgets('albums list screen ...', (tester) async { | ||
registerFallbackValue(FakeAlbumsListParams()); | ||
|
||
await r.pumpAlbumsListFilterScreen( | ||
onAlbumsTypesChanged: (value) => selectedValue = value, | ||
); | ||
final r = AlbumsListScreenRobot(tester); | ||
final albumRepository = MockAlbumRepository(); | ||
|
||
await r.selectAlbumTypes('E.P.'); | ||
expect(selectedValue, 'EP'); | ||
}); | ||
when(() => albumRepository.fetchAlbums( | ||
params: any(named: 'params', that: isNotNull), | ||
)).thenAnswer((_) => Future.value(kFakeAlbumsList)); | ||
|
||
testWidgets('change album sort', (tester) async { | ||
String? selectedValue; | ||
final r = AlbumsListFilterScreenRobot(tester); | ||
await r.pumpAlbumsListScreen(albumRepository: albumRepository); | ||
|
||
await r.pumpAlbumsListFilterScreen( | ||
onAlbumsTypesChanged: (value) => selectedValue = value, | ||
); | ||
await r.expectAlbumsDisplayCountAtLeast(3); | ||
|
||
await r.selectSort('Addition date'); | ||
expect(selectedValue, 'AdditionDate'); | ||
}); | ||
expect( | ||
verify(() => | ||
albumRepository.fetchAlbums(params: captureAny(named: 'params'))) | ||
.captured, | ||
[ | ||
const AlbumsListParams(), | ||
]); | ||
}); | ||
} |
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