Skip to content

Instantly share code, notes, and snippets.

@albertusdev
Created March 20, 2019 15:42
Show Gist options
  • Save albertusdev/4d022a84225c2422c91a78611d373c7c to your computer and use it in GitHub Desktop.
Save albertusdev/4d022a84225c2422c91a78611d373c7c to your computer and use it in GitHub Desktop.
group('User inputs valid form values', () {
const Duration delayedDuration = const Duration(milliseconds: 50);
setUp(() {
mockHttpClient = MockHttpClient();
when(mockHttpClient.post<Map<String, dynamic>>(any,
data: anyNamed('data')))
.thenAnswer((_) async {
await Future.delayed(delayedDuration);
return Future<Response<Map<String, dynamic>>>.value(
Response<Map<String, dynamic>>(data: <String, dynamic>{
'token': 'token',
'user': UserFactory.constructDefaultUserJson()
}));
});
});
Future<void> chooseImageThenFillInAllFormThenScrollThenTapSubmitButton(WidgetTester tester) async {
await chooseImageFromImagePicker(tester);
await fillInAllFormWithValidInput(tester);
await scrollUntilBottom(tester);
final Finder submit = find.widgetWithText(InkWell, 'Register');
await tester.tap(submit);
await tester.pump();
}
testWidgets('Test submit status code 200 should redirect to another page',
(WidgetTester tester) async {
await tester.pumpWidget(makeTestableWidget(child: page));
await chooseImageThenFillInAllFormThenScrollThenTapSubmitButton(tester);
await tester.pumpAndSettle(delayedDuration);
await tester.pumpAndSettle();
expect(find.byType(DashboardPage), findsOneWidget);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment