-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ensure NextEventPage loads next event data on page init
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
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
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); | ||
}); | ||
} |