diff --git a/test/ui/pages/next_event_page_test.dart b/test/ui/pages/next_event_page_test.dart index 431a900..fed60a9 100644 --- a/test/ui/pages/next_event_page_test.dart +++ b/test/ui/pages/next_event_page_test.dart @@ -4,6 +4,20 @@ import 'package:rxdart/subjects.dart'; import '../../helpers/fakes.dart'; +final class NextEventViewModel { + final List goalkeepers; + + const NextEventViewModel({ + this.goalkeepers = const [], + }); +} + +final class NextEventPlayerViewModel { + final String name; + + const NextEventPlayerViewModel({required this.name}); +} + final class NextEventPage extends StatefulWidget { final NextEventPresenter presenter; final String groupId; @@ -28,13 +42,24 @@ class _NextEventPageState extends State { @override Widget build(BuildContext context) { return Scaffold( - body: StreamBuilder( + body: StreamBuilder( stream: widget.presenter.nextEventStream, builder: (context, snapshot) { if (snapshot.connectionState != ConnectionState.active) { return const CircularProgressIndicator(); } - return Text('Next Event'); + if (snapshot.hasError) { + return const Text('Erro'); + } + return ListView( + children: [ + const Text('DENTRO - GOLEIROS'), + Text(snapshot.data!.goalkeepers.length.toString()), + ...snapshot.data!.goalkeepers.map( + (player) => Text(player.name), + ), + ], + ); }, ), ); @@ -42,24 +67,30 @@ class _NextEventPageState extends State { } abstract class NextEventPresenter { - Stream get nextEventStream; + Stream get nextEventStream; void loadNextEvent({required String groupId}); } final class NextEventPresenterSpy implements NextEventPresenter { int loadCallsCount = 0; String? groupId; - var nextEventSubjet = BehaviorSubject(); + var nextEventSubject = BehaviorSubject(); @override - Stream get nextEventStream => nextEventSubjet.stream; + Stream get nextEventStream => nextEventSubject.stream; - void emitNextEvent() { - nextEventSubjet.add(''); + void emitNextEvent([NextEventViewModel? viewModel]) { + nextEventSubject.add(viewModel ?? const NextEventViewModel()); + } + + void emitNextEventWith({ + List goalkeepers = const [], + }) { + nextEventSubject.add(NextEventViewModel(goalkeepers: goalkeepers)); } void emitError() { - nextEventSubjet.addError(Error()); + nextEventSubject.addError(Error()); } @override @@ -108,4 +139,21 @@ void main() { await tester.pump(); expect(find.byType(CircularProgressIndicator), findsNothing); }); + + testWidgets('should present goalkeepers section', (tester) async { + await tester.pumpWidget(sut); + presenter.emitNextEventWith( + goalkeepers: const [ + NextEventPlayerViewModel(name: 'Henrique'), + NextEventPlayerViewModel(name: 'Rafael'), + NextEventPlayerViewModel(name: 'Isaac'), + ], + ); + await tester.pump(); + expect(find.text('DENTRO - GOLEIROS'), findsOne); + expect(find.text('3'), findsOne); + expect(find.text('Henrique'), findsOne); + expect(find.text('Rafael'), findsOne); + expect(find.text('Isaac'), findsOne); + }); }