diff --git a/ecommerce_app/test/src/features/authentication/auth_robot.dart b/ecommerce_app/test/src/features/authentication/auth_robot.dart index 230fcaa5..70af72e9 100644 --- a/ecommerce_app/test/src/features/authentication/auth_robot.dart +++ b/ecommerce_app/test/src/features/authentication/auth_robot.dart @@ -41,6 +41,18 @@ class AuthRobot { await tester.pump(); } + Future enterEmail(String email) async { + final emailField = find.byKey(EmailPasswordSignInScreen.emailKey); + expect(emailField, findsOneWidget); + await tester.enterText(emailField, email); + } + + Future enterPassword(String password) async { + final passwordField = find.byKey(EmailPasswordSignInScreen.passwordKey); + expect(passwordField, findsOneWidget); + await tester.enterText(passwordField, password); + } + Future pumpAccountScreen({FakeAuthRepository? authRepository}) async { await tester.pumpWidget( ProviderScope( diff --git a/ecommerce_app/test/src/features/authentication/presentation/sign_in/email_password_sign_in_controller_test.dart b/ecommerce_app/test/src/features/authentication/presentation/sign_in/email_password_sign_in_controller_test.dart index a94c742b..54dd51fd 100644 --- a/ecommerce_app/test/src/features/authentication/presentation/sign_in/email_password_sign_in_controller_test.dart +++ b/ecommerce_app/test/src/features/authentication/presentation/sign_in/email_password_sign_in_controller_test.dart @@ -173,7 +173,7 @@ void main() { controller.updateFormType(EmailPasswordSignInFormType.register); // verify expect( - controller.debugState, + controller.state, EmailPasswordSignInState( formType: EmailPasswordSignInFormType.register, value: const AsyncData(null), @@ -196,7 +196,7 @@ void main() { controller.updateFormType(EmailPasswordSignInFormType.signIn); // verify expect( - controller.debugState, + controller.state, EmailPasswordSignInState( formType: EmailPasswordSignInFormType.signIn, value: const AsyncData(null), diff --git a/ecommerce_app/test/src/features/authentication/presentation/sign_in/email_password_sign_in_screen_test.dart b/ecommerce_app/test/src/features/authentication/presentation/sign_in/email_password_sign_in_screen_test.dart index 0db62855..098cd593 100644 --- a/ecommerce_app/test/src/features/authentication/presentation/sign_in/email_password_sign_in_screen_test.dart +++ b/ecommerce_app/test/src/features/authentication/presentation/sign_in/email_password_sign_in_screen_test.dart @@ -29,5 +29,34 @@ void main() { any(), )); }); + testWidgets(''' + Given formType is signIn + When enter valid email and password + And tap on the sign-in button + Then signInWithEmailAndPassword is called + And onSignedIn callback is called + And error alert is not shown + ''', (tester) async { + var didSignIn = false; + final r = AuthRobot(tester); + when(() => authRepository.signInWithEmailAndPassword( + testEmail, + testPassword, + )).thenAnswer((_) => Future.value()); + await r.pumpEmailPasswordSignInContents( + authRepository: authRepository, + formType: EmailPasswordSignInFormType.signIn, + onSignedIn: () => didSignIn = true, + ); + await r.enterEmail(testEmail); + await r.enterPassword(testPassword); + await r.tapEmailAndPasswordSubmitButton(); + verify(() => authRepository.signInWithEmailAndPassword( + testEmail, + testPassword, + )).called(1); + r.expectErrorAlertNotFound(); + expect(didSignIn, true); + }); }); }