Skip to content

Commit

Permalink
test(amplify_authenticator): sign in with email and reset password te…
Browse files Browse the repository at this point in the history
…sts (#1174)
  • Loading branch information
haverchuck authored Dec 3, 2021
1 parent 0d5afe0 commit 254eb16
Show file tree
Hide file tree
Showing 11 changed files with 491 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ const environmentsByConfiguration = {
'ui/components/authenticator/sign-up-with-email': 'auth-with-email',
'ui/components/authenticator/sign-up-with-phone': 'auth-with-phone',
'ui/components/authenticator/sign-up-with-username': 'auth-with-username',
'ui/components/authenticator/sign-in-with-email': 'auth-with-email',
'ui/components/authenticator/sign-in-with-username': 'auth-with-username',
'ui/components/authenticator/sign-in-with-phone': 'auth-with-phone',
'ui/components/authenticator/sign-in-sms-mfa': 'auth-with-phone',
'ui/components/authenticator/sign-in-with-email-lambda':
'auth-with-email-lambda-signup-trigger',
'ui/components/authenticator/reset-password': 'auth-with-username',
};

const environments = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ abstract class AuthenticatorPage {
expectError('Invalid code or auth state for the user');
}

/// Then I see Username/client id combination not found banner.
Future<void> expectCombinationNotFound() async {
expect(bannerFinder, findsOneWidget);
Finder expectCombinationNotFound = find.descendant(
of: find.byKey(keyAuthenticatorBanner),
matching: find.textContaining('Username/client id combination not found'),
);
expect(expectCombinationNotFound, findsOneWidget);
}

Future<void> selectCountryCode() async {
expect(countrySelectField, findsOneWidget);
await tester.tap(countrySelectField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ import 'package:amplify_authenticator/src/screens/authenticator_screen.dart';

import 'package:flutter_test/flutter_test.dart';

import 'authenticator_page.dart';
import 'test_utils.dart';

/// Confirm Sign Up Page Object
class ConfirmSignUpPage {
ConfirmSignUpPage({required this.tester});

final WidgetTester tester;
class ConfirmSignUpPage extends AuthenticatorPage {
ConfirmSignUpPage({required WidgetTester tester}) : super(tester: tester);

@override
Finder get usernameField => find.byKey(keyUsernameConfirmSignUpFormField);
Finder get confirmationCodeField => find.byKey(keyCodeConfirmSignUpFormField);
Finder get confirmSignUpButton => find.byKey(keyConfirmSignUpButton);

/// Then I see "Confirm Sign Up"
Future<void> expectConfirmSignUpIsPresent() async {
Expand All @@ -42,4 +44,18 @@ class ConfirmSignUpPage {
void expectConfirmationCodeIsPresent() {
expect(confirmationCodeField, findsOneWidget);
}

/// When I type my code
Future<void> enterCode(String code) async {
await tester.ensureVisible(confirmationCodeField);
await tester.tap(confirmationCodeField);
await tester.enterText(confirmationCodeField, code);
}

/// When I click the "Confirm" button
Future<void> submitConfirmSignUp() async {
await tester.ensureVisible(confirmSignUpButton);
await tester.tap(confirmSignUpButton);
await tester.pumpAndSettle();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import 'authenticator_page.dart';
class ConfirmVerifyUserPage extends AuthenticatorPage {
ConfirmVerifyUserPage({required WidgetTester tester}) : super(tester: tester);

@override
Finder get usernameField =>
throw UnimplementedError('Username does not exist on this page');

Finder get confirmationCodeField => find.byKey(keyVerifyUserConfirmationCode);

/// Then I see "Code"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_authenticator/src/keys.dart';
import 'package:amplify_authenticator/src/screens/authenticator_screen.dart';
import 'package:flutter_test/flutter_test.dart';
import 'authenticator_page.dart';

/// Forgot Password Page Object
class ForgotPasswordPage extends AuthenticatorPage {
ForgotPasswordPage({required WidgetTester tester}) : super(tester: tester);

@override
Finder get usernameField => find.byKey(keyUsernameSignInFormField);
Finder get sendCodeButton => find.byKey(keySendCodeButton);

/// Then I see "Forgot Password"
Future<void> expectForgotPassword() async {
final currentScreen = tester.widget<AuthenticatorScreen>(
find.byType(AuthenticatorScreen),
);
expect(currentScreen.screen, equals(AuthScreen.resetPassword));
}

/// When I type a new "username"
Future<void> enterUsername(String username) async {
await tester.enterText(usernameField, username);
}

/// When I click 'Send Code'
Future<void> submitSendCode() async {
await tester.tap(sendCodeButton);
await tester.pumpAndSettle();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SignInPage extends AuthenticatorPage {
Finder get usernameField => find.byKey(keyUsernameSignInFormField);
Finder get passwordField => find.byKey(keyPasswordSignInFormField);
Finder get signInButton => find.byKey(keySignInButton);
Finder get forgotPasswordButton => find.byKey(keyForgotPasswordButton);
Finder get confirmSignInField => find.byKey(keyCodeConfirmSignInFormField);
Finder get signUpTabBar => find.descendant(
of: find.byType(TabBar),
Expand All @@ -52,6 +53,18 @@ class SignInPage extends AuthenticatorPage {
await tester.enterText(passwordField, password);
}

/// Then I see "Username" as an input field
void expectUserNameIsPresent({String usernameLabel = 'Username'}) {
// username field is present
expect(usernameField, findsOneWidget);
// login type is "username"
Finder usernameFieldHint = find.descendant(
of: find.byKey(keyUsernameSignInFormField),
matching: find.text(usernameLabel),
);
expect(usernameFieldHint, findsOneWidget);
}

/// When I click the "Sign In" button
Future<void> submitSignIn() async {
await tester.ensureVisible(signInButton);
Expand All @@ -64,4 +77,10 @@ class SignInPage extends AuthenticatorPage {
await tester.tap(signUpTabBar);
await tester.pumpAndSettle();
}

/// When I tap the "Forgot Password" button.
Future<void> submitForgotPassword() async {
await tester.tap(forgotPasswordButton);
await tester.pumpAndSettle();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import 'authenticator_page.dart';
class VerifyUserPage extends AuthenticatorPage {
VerifyUserPage({required WidgetTester tester}) : super(tester: tester);

@override
Finder get usernameField =>
throw UnimplementedError('Username does not exist on this page');
Finder get skipButton => find.byKey(keySkipVerifyUserButton);
Finder get verifyButton => find.byKey(keySubmitVerifyUserButton);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// This test follows the Amplify UI feature "reset-password"
// https://github.com/aws-amplify/amplify-ui/blob/main/packages/e2e/features/ui/components/authenticator/reset-password.feature
import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'config.dart';
import 'pages/forgot_password_page.dart';
import 'pages/sign_in_page.dart';
import 'pages/test_utils.dart';
import 'utils/data_utils.dart';
import 'utils/mock_data.dart';

void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized()
as IntegrationTestWidgetsFlutterBinding;
// resolves issue on iOS. See: https://github.com/flutter/flutter/issues/89651
binding.deferFirstFrame();

final authenticator = MaterialApp(
home: Authenticator(
child: const SignOutButton(
key: Key('keySignOutButton'),
)),
);

group('reset-password', () {
// Given I'm running the example "ui/components/authenticator/reset-password.feature"
setUpAll(() async {
await loadConfiguration('ui/components/authenticator/reset-password',
additionalConfigs: [AmplifyAPI()]);
});

tearDownAll(() async {
await Amplify.Auth.signOut();
});

// Scenario: Reset Password with valid username
testWidgets('Reset Password with valid username', (tester) async {
final username = generateUsername();
final password = generatePassword();
await adminCreateUser(username, password,
autoConfirm: true, verifyAttributes: true);
await loadAuthenticator(tester: tester, authenticator: authenticator);
SignInPage signInPage = SignInPage(tester: tester);
ForgotPasswordPage forgotPasswordPage =
ForgotPasswordPage(tester: tester);
signInPage.expectUserNameIsPresent();

// When I type my "username" with status "CONFIRMED"
await signInPage.enterUsername(username);

// And I click the "Forgot Password" button
await signInPage.submitForgotPassword();

// Then I will be redirected to the confirm forgot password page
await forgotPasswordPage.expectForgotPassword();
});

// Scenario: Reset Password with invalid username
testWidgets('Reset Password with invalid username', (tester) async {
final username = generateUsername();
await loadAuthenticator(tester: tester, authenticator: authenticator);
SignInPage signInPage = SignInPage(tester: tester);
ForgotPasswordPage forgotPasswordPage =
ForgotPasswordPage(tester: tester);
signInPage.expectUserNameIsPresent();

// When I type my "username" with status "UNKNOWN"
await signInPage.enterUsername(username);

// And I click the "Forgot Password" button
await signInPage.submitForgotPassword();
await forgotPasswordPage.expectForgotPassword();
await forgotPasswordPage.enterUsername(username);
await forgotPasswordPage.submitSendCode();

// Then I see "Username/client id combination not found."
await forgotPasswordPage.expectCombinationNotFound();
});

// Scenario: Reset Password with valid placeholder
// TODO: Confirm Requirements
});
}
Loading

0 comments on commit 254eb16

Please sign in to comment.