diff --git a/test/ui/pages/next_event_page_test.dart b/test/ui/pages/next_event_page_test.dart new file mode 100644 index 0000000..a7d31fc --- /dev/null +++ b/test/ui/pages/next_event_page_test.dart @@ -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 createState() => _NextEventPageState(); +} + +class _NextEventPageState extends State { + @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); + }); +}