Fiz as modificações conforme a orientação da atividade 07 Refatoração de teste. dá o seguinte erro:
Testing started at 08:15 ...
EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK
The following StateError was thrown running a test:
Bad state: No element
When the exception was thrown, this was the stack:
#0 Iterable.single (dart:core/iterable.dart:558:25)
#1 WidgetController.state (package:flutter_test/src/controller.dart:155:42)
#2 WidgetTester.showKeyboard.<anonymous closure> (package:flutter_test/src/widget_tester.dart:1066:42)
#5 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#6 WidgetTester.showKeyboard (package:flutter_test/src/widget_tester.dart:1065:27)
#7 WidgetTester.enterText.<anonymous closure> (package:flutter_test/src/widget_tester.dart:1089:13)
#10 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#11 WidgetTester.enterText
...
meu código sem os imports transfer_flow.dart
void main() {
MockContactDao mockContactDao;
MockTransactionWebClient mockTransactionWebClient;
setUp(() async {
mockContactDao = MockContactDao();
mockTransactionWebClient = MockTransactionWebClient();
});
testWidgets('Should transfer to a contact', (tester) async {
await tester.pumpWidget(BytebankApp(
transactionWebClient: mockTransactionWebClient,
contactDao: mockContactDao,
));
final dashboard = find.byType(Dashboard);
expect(dashboard, findsOneWidget);
var alex = Contact(0, 'Alex', 1000);
when(mockContactDao.findAll()).thenAnswer((invocation) async => [alex]);
await clickOnTheTransferFeatureItem(tester);
await tester.pumpAndSettle();
final contactsList = find.byType(ContactsList);
expect(contactsList, findsOneWidget);
verify(mockContactDao.findAll()).called(1);
final contactItem = find.byWidgetPredicate((widget) {
if (widget is ContactItem) {
return widget.contact.name == 'Alex' &&
widget.contact.accountNumber == 1000;
}
return false;
});
expect(contactItem, findsOneWidget);
await tester.tap(contactItem);
await tester.pumpAndSettle();
final transactionForm = find.byType(TransactionForm);
expect(transactionForm, findsOneWidget);
await fillTextFieldWithLabel(tester, 'Alex');
await tester.pumpAndSettle();
await fillTextFieldWithLabel(tester, '1000');
await tester.pumpAndSettle();
final textFieldValue = find.byWidgetPredicate((widget) {
return textFieldByLabelTextMatcher(widget, 'Value');
});
expect(textFieldValue, findsOneWidget);
await tester.enterText(textFieldValue, '200');
await clickOntheRaisedButtonWithText(tester, 'Transfer');
await tester.pumpAndSettle();
final transactionAuthDialog = find.byType(TransactionAuthDialog);
expect(transactionAuthDialog, findsOneWidget);
final textFieldPassword =
find.byKey(transactionAuthDialogTextFieldPasswordKey);
expect(textFieldPassword, findsOneWidget);
await tester.enterText(textFieldPassword, '1000');
await clickOntheFlatButtonWithText(tester, 'Cancel');
await tester.pumpAndSettle();
await clickOntheFlatButtonWithText(tester, 'Confirm');
await tester.pumpAndSettle();
when(mockTransactionWebClient.save(Transaction(null, 200, alex), '1000'))
.thenAnswer((_) async => Transaction(null, 200, alex));
await tester.pumpAndSettle();
final successDialog = find.byType(SuccessDialog);
expect(successDialog, findsOneWidget);
await clickOntheFlatButtonWithText(tester, 'Ok');
await tester.pumpAndSettle();
final contactsListBack = find.byType(ContactsList);
expect(contactsListBack, findsOneWidget);
// verify(mockContactDao.findAll());
});
}
Future<void> clickOntheFlatButtonWithText(WidgetTester tester, String text) async {
final botao = find.widgetWithText(FlatButton, text);
expect(botao, findsOneWidget);
return tester.tap(botao);
}
Future<void> clickOntheRaisedButtonWithText(WidgetTester tester, String text) async {
final botao = find.widgetWithText(RaisedButton, text);
expect(botao, findsOneWidget);
return tester.tap(botao);
}
Future<void> fillTextFieldWithLabel(WidgetTester tester, String labelText) async {
final contactName = find.text(labelText);
expect(contactName, findsOneWidget);
return tester.enterText(contactName, labelText);
}
Podem me ajudar?