-
-
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
9 changed files
with
213 additions
and
18 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
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
20 changes: 20 additions & 0 deletions
20
lib/src/features/songs/presentation/songs_list_screen/songs_list_params_state.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,20 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:vocadb_app/src/features/settings/data/user_settings_repository.dart'; | ||
import 'package:vocadb_app/src/features/songs/domain/songs_list_params.dart'; | ||
|
||
class SongsListParamsState extends StateNotifier<SongsListParams> { | ||
SongsListParamsState({String lang = 'Default'}) | ||
: super(SongsListParams(lang: lang)); | ||
void updateSongTypes(String? value) => | ||
state = state.copyWith(songTypes: value); | ||
void updateQuery(String value) => state = state.copyWith(query: value); | ||
void updateSort(String value) => state = state.copyWith(sort: value); | ||
void clearQuery() => state = state.copyWith(query: null); | ||
} | ||
|
||
final songsListParamsStateProvider = StateNotifierProvider.autoDispose< | ||
SongsListParamsState, SongsListParams>((ref) { | ||
final preferredLang = ref.watch(userSettingsRepositoryProvider | ||
.select((value) => value.currentPreferredLang)); | ||
return SongsListParamsState(lang: preferredLang); | ||
}); |
57 changes: 57 additions & 0 deletions
57
lib/src/features/songs/presentation/songs_list_screen/songs_list_screen.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,57 @@ | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:vocadb_app/src/common_widgets/async_value_widget.dart'; | ||
import 'package:vocadb_app/src/common_widgets/search_appbar.dart'; | ||
import 'package:vocadb_app/src/features/songs/data/song_repository.dart'; | ||
import 'package:vocadb_app/src/features/songs/domain/song.dart'; | ||
import 'package:vocadb_app/src/features/songs/presentation/songs_list/songs_list_view.dart'; | ||
import 'package:vocadb_app/src/features/songs/presentation/songs_list_screen/songs_list_params_state.dart'; | ||
|
||
class SongsListScreen extends ConsumerWidget { | ||
const SongsListScreen({super.key, this.onSelectSong}); | ||
|
||
static const filterKey = Key('icon-filter-key'); | ||
|
||
final Function(Song)? onSelectSong; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Scaffold( | ||
appBar: SearchAppBar( | ||
titleText: 'Songs', | ||
actions: [ | ||
IconButton( | ||
key: filterKey, | ||
icon: const Icon(Icons.tune), | ||
onPressed: () => {} | ||
), | ||
], | ||
onSubmitted: (value) { | ||
ref.read(songsListParamsStateProvider.notifier).updateQuery(value); | ||
}, | ||
onCleared: () { | ||
ref.read(songsListParamsStateProvider.notifier).clearQuery(); | ||
}, | ||
), | ||
body: Consumer(builder: ((context, ref, child) { | ||
final value = ref.watch(songsListProvider); | ||
return AsyncValueWidget( | ||
value: value, | ||
data: (data) { | ||
return SongListView( | ||
songs: data, | ||
onSelect: (song) => {} | ||
); | ||
}); | ||
})), | ||
); | ||
} | ||
} | ||
|
||
// State | ||
final songsListProvider = FutureProvider.autoDispose<List<Song>>((ref) { | ||
final params = ref.watch(songsListParamsStateProvider); | ||
final songRepository = ref.watch(songRepositoryProvider); | ||
return songRepository.fetchSongsList(params: params); | ||
}); |
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
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
62 changes: 62 additions & 0 deletions
62
test/src/features/songs/presentation/songs_list_screen/songs_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,62 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
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_screen.dart'; | ||
|
||
class SongsListScreenRobot { | ||
final WidgetTester tester; | ||
|
||
SongsListScreenRobot(this.tester); | ||
|
||
Future<void> pumpSongsListScreen( | ||
{SongRepository? songRepository}) async { | ||
await tester.pumpWidget( | ||
ProviderScope( | ||
overrides: [ | ||
if (songRepository != null) | ||
songRepositoryProvider.overrideWithValue(songRepository), | ||
userSettingsRepositoryProvider | ||
.overrideWithValue(UserSettingsRepository()) | ||
], | ||
child: const MaterialApp( | ||
home: SongsListScreen(), | ||
), | ||
), | ||
); | ||
|
||
await tester.pump(); | ||
await tester.pump(); | ||
await tester.pump(); | ||
} | ||
|
||
Future<void> expectSongsDisplayCountAtLeast(int count) async { | ||
final finder = find.byType(SongTile); | ||
expect(finder, findsAtLeastNWidgets(count)); | ||
} | ||
|
||
Future<void> expectSongsDisplayCount(int count) async { | ||
final finder = find.byType(SongTile); | ||
expect(finder, findsNWidgets(count)); | ||
} | ||
|
||
Future<void> tapSearchIcon() async { | ||
final finder = find.byKey(SearchAppBar.iconSearchKey); | ||
expect(finder, findsOneWidget); | ||
await tester.tap(finder); | ||
await tester.pump(); | ||
} | ||
|
||
Future<void> typingSearchText(String text) async { | ||
final finder = find.byKey(SearchAppBar.searchInputKey); | ||
expect(finder, findsOneWidget); | ||
await tester.enterText(finder, text); | ||
await tester.pump(); | ||
await tester.sendKeyEvent(LogicalKeyboardKey.enter); | ||
await tester.pump(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
test/src/features/songs/presentation/songs_list_screen/songs_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,33 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:vocadb_app/src/features/songs/data/constants/fake_songs_list.dart'; | ||
import 'package:vocadb_app/src/features/songs/domain/songs_list_params.dart'; | ||
|
||
import '../../../../mocks.dart'; | ||
import 'songs_list_screen_robot.dart'; | ||
|
||
void main() { | ||
testWidgets('song list screen test', (tester) async { | ||
registerFallbackValue(FakeSongsListParams()); | ||
|
||
final r = SongsListScreenRobot(tester); | ||
final songRepository = MockSongRepository(); | ||
|
||
when(() => songRepository.fetchSongsList( | ||
params: any(named: 'params', that: isNotNull), | ||
)).thenAnswer((_) => Future.value(kFakeSongsList)); | ||
|
||
await r.pumpSongsListScreen(songRepository: songRepository); | ||
|
||
await r.expectSongsDisplayCountAtLeast(3); | ||
|
||
expect( | ||
verify(() => | ||
songRepository.fetchSongsList(params: captureAny(named: 'params'))) | ||
.captured, | ||
[ | ||
const SongsListParams(), | ||
]); | ||
}); | ||
|
||
} |
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