Skip to content

Commit

Permalink
chore: address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Nelson committed Jun 22, 2022
1 parent 7a59686 commit 72261b1
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,118 +48,120 @@ void main() {
),
);

group('confirm-sign-up', () {
// Given I'm running the example with an "Email or Phone" config
setUpAll(() async {
await loadConfiguration(
'email-or-phone',
additionalConfigs: isMobile ? [AmplifyAPI()] : null,
);
});
group(
'confirm-sign-up',
() {
// Given I'm running the example with an "Email or Phone" config
setUpAll(() async {
await loadConfiguration(
'email-or-phone',
additionalConfigs: isMobile ? [AmplifyAPI()] : null,
);
});

setUp(signOut);
setUp(signOut);

tearDown(Amplify.Auth.deleteUser);
tearDown(Amplify.Auth.deleteUser);

// Scenario: Sign up & confirm account with email as username
testWidgets(
'Sign up & confirm account with email as username',
(tester) async {
SignUpPage signUpPage = SignUpPage(tester: tester);
ConfirmSignUpPage confirmSignUpPage = ConfirmSignUpPage(tester: tester);
SignInPage signInPage = SignInPage(tester: tester);
// Scenario: Sign up & confirm account with email as username
testWidgets(
'Sign up & confirm account with email as username',
(tester) async {
final signUpPage = SignUpPage(tester: tester);
final confirmSignUpPage = ConfirmSignUpPage(tester: tester);
final signInPage = SignInPage(tester: tester);

await loadAuthenticator(tester: tester, authenticator: authenticator);
await loadAuthenticator(tester: tester, authenticator: authenticator);

final email = generateEmail();
final phoneNumber = generateUSPhoneNumber();
final password = generatePassword();
final email = generateEmail();
final phoneNumber = generateUSPhoneNumber();
final password = generatePassword();

final code = getOtpCode(email);
final code = getOtpCode(email);

await signInPage.navigateToSignUp();
await signInPage.navigateToSignUp();

// When I select email as a username
await signUpPage.selectEmail();
// When I select email as a username
await signUpPage.selectEmail();

// And I type my email address as a username
await signUpPage.enterUsername(email);
// And I type my email address as a username
await signUpPage.enterUsername(email);

// And I type my password
await signUpPage.enterPassword(password);
// And I type my password
await signUpPage.enterPassword(password);

// And I confirm my password
await signUpPage.enterPasswordConfirmation(password);
// And I confirm my password
await signUpPage.enterPasswordConfirmation(password);

// And I enter my phone number
await signUpPage.enterPhoneNumber(phoneNumber.withOutCountryCode());
// And I enter my phone number
await signUpPage.enterPhoneNumber(phoneNumber.withOutCountryCode());

// And I click the "Create Account" button
await signUpPage.submitSignUp();
// And I click the "Create Account" button
await signUpPage.submitSignUp();

// And I see "Confirmation Code"
confirmSignUpPage.expectConfirmationCodeIsPresent();
// And I see "Confirmation Code"
confirmSignUpPage.expectConfirmationCodeIsPresent();

// And I type a valid confirmation code
await confirmSignUpPage.enterCode(await code);
// And I type a valid confirmation code
await confirmSignUpPage.enterCode(await code);

// And I click the "Confirm" button
await confirmSignUpPage.submitConfirmSignUp();
// And I click the "Confirm" button
await confirmSignUpPage.submitConfirmSignUp();

// Then I see "Sign out"
await signInPage.expectAuthenticated();
},
skip: !isMobile,
);
// Then I see "Sign out"
await signInPage.expectAuthenticated();
},
);

testWidgets(
'Sign up & confirm account with phone number as username',
(tester) async {
SignUpPage signUpPage = SignUpPage(tester: tester);
ConfirmSignUpPage confirmSignUpPage = ConfirmSignUpPage(tester: tester);
SignInPage signInPage = SignInPage(tester: tester);
testWidgets(
'Sign up & confirm account with phone number as username',
(tester) async {
final signUpPage = SignUpPage(tester: tester);
final confirmSignUpPage = ConfirmSignUpPage(tester: tester);
final signInPage = SignInPage(tester: tester);

await loadAuthenticator(tester: tester, authenticator: authenticator);
await loadAuthenticator(tester: tester, authenticator: authenticator);

final email = generateEmail();
final phoneNumber = generateUSPhoneNumber();
final password = generatePassword();
final email = generateEmail();
final phoneNumber = generateUSPhoneNumber();
final password = generatePassword();

final code = getOtpCode(email);
final code = getOtpCode(email);

await signInPage.navigateToSignUp();
await signInPage.navigateToSignUp();

// When I select phone number as a username
await signUpPage.selectPhone();
// When I select phone number as a username
await signUpPage.selectPhone();

// And I type my phone number as a username
await signUpPage.enterUsername(phoneNumber.withOutCountryCode());
// And I type my phone number as a username
await signUpPage.enterUsername(phoneNumber.withOutCountryCode());

// And I type my password
await signUpPage.enterPassword(password);
// And I type my password
await signUpPage.enterPassword(password);

// And I confirm my password
await signUpPage.enterPasswordConfirmation(password);
// And I confirm my password
await signUpPage.enterPasswordConfirmation(password);

// And I enter my email address
await signUpPage.enterEmail(email);
// And I enter my email address
await signUpPage.enterEmail(email);

// And I click the "Create Account" button
await signUpPage.submitSignUp();
// And I click the "Create Account" button
await signUpPage.submitSignUp();

// And I see "Confirmation Code"
confirmSignUpPage.expectConfirmationCodeIsPresent();
// And I see "Confirmation Code"
confirmSignUpPage.expectConfirmationCodeIsPresent();

// And I type a valid confirmation code
await confirmSignUpPage.enterCode(await code);
// And I type a valid confirmation code
await confirmSignUpPage.enterCode(await code);

// And I click the "Confirm" button
await confirmSignUpPage.submitConfirmSignUp();
// And I click the "Confirm" button
await confirmSignUpPage.submitConfirmSignUp();

// Then I see "Sign out"
await signInPage.expectAuthenticated();
},
skip: !isMobile,
);
});
// Then I see "Sign out"
await signInPage.expectAuthenticated();
},
);
},
skip: !isMobile,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_authenticator/src/keys.dart';
import 'package:amplify_authenticator/src/l10n/auth_strings_resolver.dart';
import 'package:amplify_authenticator/src/models/username_input.dart';
import 'package:amplify_authenticator/src/state/authenticator_state.dart';
import 'package:amplify_authenticator/src/utils/country_code.dart';
import 'package:amplify_authenticator/src/utils/validators.dart';
import 'package:amplify_authenticator/src/widgets/component.dart';
import 'package:amplify_authenticator/src/widgets/form.dart';
Expand Down Expand Up @@ -140,20 +140,27 @@ mixin AuthenticatorUsernameField<FieldType,
? UsernameSelection.email
: UsernameSelection.phoneNumber;
final oldUsernameSelection = state.usernameSelection;
// Return if username selection has not changed
if (oldUsernameSelection == newUsernameSelection) {
return;
}
state.usernameSelection = newUsernameSelection;
// Reset current username value to align with the current switch state.
String newUsername = newUsernameSelection ==
// Determine the new username value based off the new username selection
// and the current user attributes
final newUsername = newUsernameSelection ==
UsernameSelection.email
? state.getAttribute(CognitoUserAttributeKey.email) ?? ''
: state.getAttribute(
CognitoUserAttributeKey.phoneNumber) ??
'';
state.username = newUsername;
// Clear attributes on switch
// Clear user attributes
state.authAttributes.clear();
// Reset country code if phone is not being used as a username
if (newUsernameSelection != UsernameSelection.phoneNumber) {
state.country = countryCodes.first;
}
// Update the username & username selection
state.username = newUsername;
state.usernameSelection = newUsernameSelection;
},
children: [
Text(emailTitle, key: keyEmailUsernameToggleButton),
Expand Down

0 comments on commit 72261b1

Please sign in to comment.