Closed rehlma closed 6 months ago
I tried it, here's an example test for a login form.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:f93_forming_forms/main.dart';
import 'package:spot/spot.dart';
final textFieldLabelText = widgetProp<TextField, String?>(
'labelText',
(textField) => textField.decoration?.labelText,
);
void main() {
group('Part 1', () {
testWidgets('enter username password', (tester) async {
await tester.pumpWidget(FormingFormsKata());
final email = spot<TextField>()
.whereWidgetProp(textFieldLabelText, (label) => label == 'Email')
..existsOnce();
await act.enterText(email, 'pascal@phntm.xyz');
final password = spot<TextField>()
.whereWidgetProp(textFieldLabelText, (label) => label == 'Password')
..existsOnce();
await act.enterText(password, 'asdfasdf');
await act.tap(spotText('Accept AGBs'));
await tester.pump();
// wait for async matchers and debounce
await tester.pump(Duration(milliseconds: 250));
await tester.pump(Duration(seconds: 2));
await act.tap(spotText('Sign in'));
await tester.pump();
await tester.pump(Duration(seconds: 1));
spotText('Success').existsOnce();
});
});
}
Add the
tester.enterText()
functionality to Spot