-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(amplify_authenticator): sign in with email and reset password te…
…sts (#1174)
- Loading branch information
1 parent
0d5afe0
commit 254eb16
Showing
11 changed files
with
491 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/amplify_authenticator/example/integration_test/pages/forgot_password_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/amplify_authenticator/example/integration_test/reset_password_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
} |
Oops, something went wrong.