Skip to content

Commit

Permalink
test: ensure NextEventPage loads next event data on page init
Browse files Browse the repository at this point in the history
  • Loading branch information
hmartiins committed Jan 4, 2025
1 parent 479eac9 commit 9baeea5
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/ui/pages/next_event_page_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

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

final class NextEventPage extends StatefulWidget {
final NextEventPresenter presenter;
final String groupId;

const NextEventPage({
super.key,
required this.presenter,
required this.groupId,
});

@override
State<NextEventPage> createState() => _NextEventPageState();
}

class _NextEventPageState extends State<NextEventPage> {
@override
void initState() {
widget.presenter.loadNextEvent(groupId: widget.groupId);
super.initState();
}

@override
Widget build(BuildContext context) {
return const Scaffold();
}
}

abstract class NextEventPresenter {
void loadNextEvent({required String groupId});
}

final class NextEventPresenterSpy implements NextEventPresenter {
int loadCallsCount = 0;
String? groupId;

@override
void loadNextEvent({required String groupId}) {
loadCallsCount++;
this.groupId = groupId;
}
}

void main() {
testWidgets('should load event data on page init', (tester) async {
final presenter = NextEventPresenterSpy();
final groupId = anyString();
final sut = MaterialApp(
home: NextEventPage(
presenter: presenter,
groupId: groupId,
),
);
await tester.pumpWidget(sut);
expect(presenter.loadCallsCount, 1);
expect(presenter.groupId, groupId);
});
}

0 comments on commit 9baeea5

Please sign in to comment.