-
-
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
8 changed files
with
169 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
18 changes: 18 additions & 0 deletions
18
...leaseEvents/presentation/release_events_list_screen/release_events_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,18 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:vocadb_app/src/features/releaseEvents/domain/release_events_list_params.dart'; | ||
import 'package:vocadb_app/src/features/settings/data/user_settings_repository.dart'; | ||
|
||
class ReleaseEventsListParamsState extends StateNotifier<ReleaseEventsListParams> { | ||
ReleaseEventsListParamsState({String lang = 'Default'}) | ||
: super(ReleaseEventsListParams(lang: lang)); | ||
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 releaseEventsListParamsStateProvider = StateNotifierProvider.autoDispose< | ||
ReleaseEventsListParamsState, ReleaseEventsListParams>((ref) { | ||
final preferredLang = ref.watch(userSettingsRepositoryProvider | ||
.select((value) => value.currentPreferredLang)); | ||
return ReleaseEventsListParamsState(lang: preferredLang); | ||
}); |
55 changes: 55 additions & 0 deletions
55
...res/releaseEvents/presentation/release_events_list_screen/release_events_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,55 @@ | ||
|
||
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/artists/data/artist_repository.dart'; | ||
import 'package:vocadb_app/src/features/artists/domain/artist.dart'; | ||
import 'package:vocadb_app/src/features/artists/presentation/artists_list/artist_list_view.dart'; | ||
import 'package:vocadb_app/src/features/artists/presentation/artists_list_screen/artists_list_params_state.dart'; | ||
import 'package:vocadb_app/src/features/releaseEvents/data/release_event_repository.dart'; | ||
import 'package:vocadb_app/src/features/releaseEvents/domain/release_event.dart'; | ||
import 'package:vocadb_app/src/features/releaseEvents/presentation/release_events_list/release_events_list_view.dart'; | ||
import 'package:vocadb_app/src/features/releaseEvents/presentation/release_events_list_screen/release_events_list_params_state.dart'; | ||
import 'package:vocadb_app/src/routing/app_route_context.dart'; | ||
|
||
class ReleaseEventsListScreen extends ConsumerWidget { | ||
const ReleaseEventsListScreen({super.key, this.onSelectEvent}); | ||
|
||
static const filterKey = Key('icon-filter-key'); | ||
|
||
final Function(ReleaseEvent)? onSelectEvent; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Scaffold( | ||
appBar: SearchAppBar( | ||
titleText: 'Events', | ||
onSubmitted: (value) { | ||
ref.read(releaseEventsListParamsStateProvider.notifier).updateQuery(value); | ||
}, | ||
onCleared: () { | ||
ref.read(releaseEventsListParamsStateProvider.notifier).clearQuery(); | ||
}, | ||
), | ||
body: Consumer(builder: ((context, ref, child) { | ||
final value = ref.watch(releaseEventsListProvider); | ||
return AsyncValueWidget( | ||
value: value, | ||
data: (data) { | ||
return ReleaseEventsListView( | ||
events: data, | ||
onSelect: (event) => onSelectEvent?.call(event), | ||
); | ||
}); | ||
})), | ||
); | ||
} | ||
} | ||
|
||
// State | ||
final releaseEventsListProvider = FutureProvider.autoDispose<List<ReleaseEvent>>((ref) { | ||
final params = ref.watch(releaseEventsListParamsStateProvider); | ||
final releaseEventRepository = ref.watch(releaseEventRepositoryProvider); | ||
return releaseEventRepository.fetchReleaseEventsList(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
39 changes: 39 additions & 0 deletions
39
...leaseEvents/presentation/release_events_list_screen/release_events_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/releaseEvents/data/release_event_repository.dart'; | ||
import 'package:vocadb_app/src/features/releaseEvents/presentation/release_event_tile/release_event_tile.dart'; | ||
import 'package:vocadb_app/src/features/releaseEvents/presentation/release_events_list_screen/release_events_list_screen.dart'; | ||
import 'package:vocadb_app/src/features/settings/data/user_settings_repository.dart'; | ||
|
||
class ReleaseEventsListScreenRobot { | ||
final WidgetTester tester; | ||
|
||
ReleaseEventsListScreenRobot(this.tester); | ||
|
||
Future<void> pumpReleaseEventsListScreen( | ||
{ReleaseEventRepository? releaseEventRepository}) async { | ||
await tester.pumpWidget( | ||
ProviderScope( | ||
overrides: [ | ||
if (releaseEventRepository != null) | ||
releaseEventRepositoryProvider.overrideWithValue(releaseEventRepository), | ||
userSettingsRepositoryProvider | ||
.overrideWithValue(UserSettingsRepository()) | ||
], | ||
child: const MaterialApp( | ||
home: ReleaseEventsListScreen(), | ||
), | ||
), | ||
); | ||
|
||
await tester.pump(); | ||
await tester.pump(); | ||
await tester.pump(); | ||
} | ||
|
||
Future<void> expectReleaseEventsDisplayCountAtLeast(int count) async { | ||
final finder = find.byType(ReleaseEventTile); | ||
expect(finder, findsAtLeastNWidgets(count)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...eleaseEvents/presentation/release_events_list_screen/release_events_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,32 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:vocadb_app/src/features/releaseEvents/data/constants/fake_release_events_list.dart'; | ||
import 'package:vocadb_app/src/features/releaseEvents/domain/release_events_list_params.dart'; | ||
|
||
import '../../../../mocks.dart'; | ||
import 'release_events_list_screen_robot.dart'; | ||
|
||
void main() { | ||
testWidgets('Release events list screen ...', (tester) async { | ||
registerFallbackValue(FakeReleaseEventsListParams()); | ||
|
||
final r = ReleaseEventsListScreenRobot(tester); | ||
final releaseEventRepository = MockReleaseEventRepository(); | ||
|
||
when(() => releaseEventRepository.fetchReleaseEventsList( | ||
params: any(named: 'params', that: isNotNull), | ||
)).thenAnswer((_) => Future.value(kFakeReleaseEventsList)); | ||
|
||
await r.pumpReleaseEventsListScreen(releaseEventRepository: releaseEventRepository); | ||
|
||
await r.expectReleaseEventsDisplayCountAtLeast(3); | ||
|
||
expect( | ||
verify(() => | ||
releaseEventRepository.fetchReleaseEventsList(params: captureAny(named: 'params'))) | ||
.captured, | ||
[ | ||
const ReleaseEventsListParams(), | ||
]); | ||
}); | ||
} |
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