I have this screen with 2 TextFormField that receive the name and lastname, and a button, that comes disabled it there is no changes or if there is any wrong value, and it is enabled case there is any update in the fields and when tapped close the screen and return to EditProfileScreen. I was able to test the enable/disable state, but I'm not been able to test the pop navigation, it show that should receive a true, but returns a false, I tried every way, let the formFields with the names, but didn't work. If the code that is comment is in the code there's error on it, if I comment there's error here: expect(btn.enabled, true); I aldo tried call the EditProfileScreen in the expect, put their keys, but nothing Here is my code
testWidgets('Test pop navigation', (WidgetTester tester) async {
final loginBloc = LoginBlocMock();
final state = getLoggedState();
whenListen(
loginBloc,
Stream.fromIterable(
[state],
),
initialState: state,
);
await tester.pumpWidget(
UIWrapper.wrapTranslated(
UIWrapper.blocWrap(
UIWrapper.themeWrap(
EditNameScreen(),
),
[
BlocProvider<LoginBloc>.value(value: loginBloc),
],
),
),
);
final nameFormField = find.byKey(Key('FirstName'));
await tester.enterText(nameFormField, 'John');
final lastNameFormField = find.byKey(Key('LastName'));
await tester.enterText(lastNameFormField, 'Doe');
expect(find.byKey(Key('FirstName')), findsOneWidget);
expect(find.byKey(Key('LastName')), findsOneWidget);
/* expect(
tester
.widget<ElevatedButton>(find.byKey(Key('UpdateButton')))
.enabled,
isTrue); */
var btn =
tester.firstWidget<ElevatedButton>(find.byKey(Key('UpdateButton')));
expect(btn.enabled, true);
verify(navigationService.pop()).called(1);
await tester.tap(find.byWidget(btn));
await tester.pumpAndSettle();
});