Skip to content

Commit

Permalink
test: ensure NextEventPage presents goalkeepers section
Browse files Browse the repository at this point in the history
  • Loading branch information
hmartiins committed Jan 4, 2025
1 parent 3793572 commit a78e760
Showing 1 changed file with 56 additions and 8 deletions.
64 changes: 56 additions & 8 deletions test/ui/pages/next_event_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ import 'package:rxdart/subjects.dart';

import '../../helpers/fakes.dart';

final class NextEventViewModel {
final List<NextEventPlayerViewModel> 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;
Expand All @@ -28,38 +42,55 @@ class _NextEventPageState extends State<NextEventPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: StreamBuilder(
body: StreamBuilder<NextEventViewModel>(
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),
),
],
);
},
),
);
}
}

abstract class NextEventPresenter {
Stream get nextEventStream;
Stream<NextEventViewModel> get nextEventStream;
void loadNextEvent({required String groupId});
}

final class NextEventPresenterSpy implements NextEventPresenter {
int loadCallsCount = 0;
String? groupId;
var nextEventSubjet = BehaviorSubject();
var nextEventSubject = BehaviorSubject<NextEventViewModel>();

@override
Stream get nextEventStream => nextEventSubjet.stream;
Stream<NextEventViewModel> get nextEventStream => nextEventSubject.stream;

void emitNextEvent() {
nextEventSubjet.add('');
void emitNextEvent([NextEventViewModel? viewModel]) {
nextEventSubject.add(viewModel ?? const NextEventViewModel());
}

void emitNextEventWith({
List<NextEventPlayerViewModel> goalkeepers = const [],
}) {
nextEventSubject.add(NextEventViewModel(goalkeepers: goalkeepers));
}

void emitError() {
nextEventSubjet.addError(Error());
nextEventSubject.addError(Error());
}

@override
Expand Down Expand Up @@ -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);
});
}

0 comments on commit a78e760

Please sign in to comment.