Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(examples,e2e): Add examples and tests for #1580 #1578

Merged

Conversation

wlee221
Copy link
Contributor

@wlee221 wlee221 commented Mar 24, 2022

Description of changes

This updates the useAuthenticator examples and their e2e test to match #1580.

Details

Our current useAuthenticator examples are really SPA and do not sufficiently test router use cases.

There are many useAuthenticator bugs, especially with refresh, so we plan to update examples and tests incrementally as we add more router support. For now, this PR adds additional route useAuthenticator/home.

This PR adds:

  1. Test starts at /useAuthenticater route. This has the authenticator for user to sign in.
  2. User signs in with Authenticator.
  3. Once user signs in, they'll see a "Navigate to Home" button. (This can be something like "Manage your account" irl)
  4. Clicking that button redirects user to /useAuthenticator/home`. This will have basic greetings with a sign out button.
  5. Refreshing sustains auth contexts.

Future Goals
This example needs to be extended to better resemble customer use cases:

  • Have a separate /sign-in route
  • Automatically redirect users without buttons
  • Add current user check in /home and make it actually protected.

Issue #, if available

Related to #1332, #1497, accompanies #1580

Description of how you validated changes

Checklist

  • PR description included
  • yarn test passes
  • Tests are updated
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@changeset-bot
Copy link

changeset-bot bot commented Mar 24, 2022

⚠️ No Changeset found

Latest commit: 16aefaf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@lgtm-com
Copy link

lgtm-com bot commented Mar 24, 2022

This pull request introduces 3 alerts when merging 7aee0cf into eedae23 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Mar 24, 2022

This pull request introduces 3 alerts when merging 81492e1 into eedae23 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@wlee221 wlee221 changed the base branch from get-user-on-refresh/main to get-user-on-refresh/state-machine March 24, 2022 11:17
@lgtm-com
Copy link

lgtm-com bot commented Mar 24, 2022

This pull request introduces 3 alerts when merging a6e26ea into 7e00926 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Mar 24, 2022

This pull request introduces 3 alerts when merging 5a090b8 into 7e00926 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Mar 24, 2022

This pull request introduces 3 alerts when merging 3e3527f into 7e00926 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Mar 24, 2022

This pull request introduces 3 alerts when merging 4ab0271 into 7e00926 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Mar 24, 2022

This pull request introduces 3 alerts when merging 5a62d1d into 7e00926 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Mar 24, 2022

This pull request introduces 3 alerts when merging c9cf401 into fc71b28 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@wlee221 wlee221 changed the title Update examples and e2e test for useAuthenticator fix(examples,e2e): Update examples and tests for #1580 Mar 24, 2022
Comment on lines +22 to +23
<!-- TODO: this authenticator shouldn't be needed -->
<authenticator></authenticator>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vue still needed this hidden authenticator, because authenticator was needed to interpret and start the machine in the first place. This seemed like a much bigger refactor, so left this as-is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 I can look at this in a different PR. Maybe we need to add an initialization via provide/inject somewhere. A user could also hide this with CSS when the user is not logged in, I suppose

@wlee221 wlee221 changed the title fix(examples,e2e): Update examples and tests for #1580 fix(examples,e2e): Add examples and tests for #1580 Mar 24, 2022
@lgtm-com
Copy link

lgtm-com bot commented Mar 24, 2022

This pull request introduces 3 alerts when merging bae13aa into e777730 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class


Then('I see a valid greetings message', () => {
cy.findByRole('document')
.contains(new RegExp('^Hello, .+!$', 'i'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks if the message has "Hello, {username}" structure. Kept it generic to not expose the test username 😈

@@ -101,6 +102,10 @@ const routes: Routes = [
path: 'ui/components/authenticator/useAuthenticator',
component: UseAuthenticatorComponent,
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

export default function MyApp(props) {
return (
<AmplifyProvider>
<Authenticator.Provider>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing this in the other PR and I had to add this. Glad it's there now.

Copy link
Contributor

@ErikCH ErikCH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lgtm-com
Copy link

lgtm-com bot commented Mar 24, 2022

This pull request introduces 3 alerts when merging 16aefaf into 7857497 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@wlee221 wlee221 merged commit 43119e4 into get-user-on-refresh/state-machine Mar 24, 2022
@wlee221 wlee221 deleted the get-user-on-refresh/examples branch March 24, 2022 23:33
wlee221 added a commit that referenced this pull request Mar 25, 2022
…1580)

* [Revert] use devTools

* Check for current user first before init

* Revert "[Revert] use devTools"

This reverts commit df53b24.

* react: send INIT event on 'setup' state

* vue: send INIT event on 'setup' state

* angular: send INIT event on 'setup' state

* Remove unused var

* Move comment

* Create five-crabs-help.md

* Update packages/ui/src/machines/authenticator/index.ts

Co-authored-by: Caleb Pollman <cpollman@amazon.com>

* Combine if statements

* Unsubscribe on vue

* Unsubscribe on angular

* fix(examples,e2e): Add examples and tests for #1580 (#1578)

* Angular Example

* React example

* Vue examples

* Add missing !

* Update useAuthenticator test

* Use slots on parent route

* Configure Amplify on `/home`

* Add react sign out button

* Update wording on react example

* Add sign out test

* Add angular sign out buttons

* Sign Out button in Vue

* destructure signOut ref

* Add hidden Authenticator on Vue

* Fix copy paste typo

* fix(e2e): AutoSignIn directly after signUp is done

* Trigger CI

Co-authored-by: Caleb Pollman <cpollman@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants