Skip to content

Commit

Permalink
More email & password sign in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bizz84 committed Nov 16, 2023
1 parent e5cb985 commit cb295c2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
12 changes: 12 additions & 0 deletions ecommerce_app/test/src/features/authentication/auth_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ class AuthRobot {
await tester.pump();
}

Future<void> enterEmail(String email) async {
final emailField = find.byKey(EmailPasswordSignInScreen.emailKey);
expect(emailField, findsOneWidget);
await tester.enterText(emailField, email);
}

Future<void> enterPassword(String password) async {
final passwordField = find.byKey(EmailPasswordSignInScreen.passwordKey);
expect(passwordField, findsOneWidget);
await tester.enterText(passwordField, password);
}

Future<void> pumpAccountScreen({FakeAuthRepository? authRepository}) async {
await tester.pumpWidget(
ProviderScope(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void main() {
controller.updateFormType(EmailPasswordSignInFormType.register);
// verify
expect(
controller.debugState,
controller.state,
EmailPasswordSignInState(
formType: EmailPasswordSignInFormType.register,
value: const AsyncData<void>(null),
Expand All @@ -196,7 +196,7 @@ void main() {
controller.updateFormType(EmailPasswordSignInFormType.signIn);
// verify
expect(
controller.debugState,
controller.state,
EmailPasswordSignInState(
formType: EmailPasswordSignInFormType.signIn,
value: const AsyncData<void>(null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}

0 comments on commit cb295c2

Please sign in to comment.