-
Notifications
You must be signed in to change notification settings - Fork 249
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
chore(authenticator_test): Updated Golden tests to run on any screen #3655
Conversation
f10f0ce
to
9bc8dae
Compare
|
||
aft: | ||
github: | ||
custom: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is the best way to handle this. It means taking responsibility for updating the authenticator workflow file for any changes in the future. And the goldens thing may pop up in other packages if we add UI components. Can we handle this in generate_workflows
instead? Basically, add a check for the existence of goldens and make flutter_vm.yaml
take a boolean flag for whether there are goldens or not?
@@ -437,6 +438,9 @@ class Authenticator extends StatefulWidget { | |||
/// {@macro amplify_authenticator_dial_code_options} | |||
final DialCodeOptions dialCodeOptions; | |||
|
|||
@visibleForTesting | |||
final AuthenticatorState? mockAuthenticatorState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this and setState
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were added to populate the state with required properties depending on the desired authenticator step during testing. For example, some screens such as the TOTP setup screen expect TotpDetails to be non-null.
Perhaps naming it authenticatorStateOverride
would make its purpose more explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need setState as well though? Did setting the initial state via the mocked AuthenticatorState and state machine not work, or is there a need to change the state inside a test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need setState as well though? is there a need to change the state inside a test?
Yes -- setState
is required. The step continueSignInWithMfaSelection
requires the actual state to be typed as ContinueSignInWithMfaSelection
in order to retrieve it's required values.
Additionally, having one state for all tests was brittle. Any changes to the business logic of state inputs would need to be duplicated in tests and the bloc, ie transforming the Cognito provided TotpSetupDetails
into a setupURI
string. Instead, we only need to supply the required inputs for a given state. Then we are able to reuse the business logic in the bloc and discretely represent the proper state of each screen of the application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather make stateMachineBloc
visible for testing and call setState
on it than expose a parameter like this
@@ -437,6 +438,9 @@ class Authenticator extends StatefulWidget { | |||
/// {@macro amplify_authenticator_dial_code_options} | |||
final DialCodeOptions dialCodeOptions; | |||
|
|||
@visibleForTesting | |||
final AuthenticatorState? mockAuthenticatorState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need setState as well though? Did setting the initial state via the mocked AuthenticatorState and state machine not work, or is there a need to change the state inside a test?
${hasGoldens ? 'runner-os: macos-latest' : ''} | ||
${hasGoldens ? 'has-goldens: true' : ''} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates empty lines in other generated workflows when running the generate command.
Couldn't find a simple way to trim the extra lines when not needed...
@dnys1 would it be better to have them always defined?
@@ -9,46 +9,10 @@ on: | |||
paths: | |||
- '.github/workflows/amplify_authenticator.yaml' | |||
- '.github/workflows/flutter_vm.yaml' | |||
- 'packages/amplify/amplify_flutter/lib/**/*.dart' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running the generate workflows command removes several paths in all the workflow files. I only included this one though.
@@ -244,6 +246,8 @@ jobs: | |||
with: | |||
package-name: ${package.name} | |||
working-directory: $repoRelativePath | |||
${hasGoldens ? 'runner-os: macos-latest' : ''} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove, it's not a parameter you can pass anyway. But only has-goldens
is needed to know which runner to use.
fix: trimmed tests
9733d28
to
db69ffc
Compare
@@ -437,6 +438,9 @@ class Authenticator extends StatefulWidget { | |||
/// {@macro amplify_authenticator_dial_code_options} | |||
final DialCodeOptions dialCodeOptions; | |||
|
|||
@visibleForTesting | |||
final AuthenticatorState? mockAuthenticatorState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather make stateMachineBloc
visible for testing and call setState
on it than expose a parameter like this
@@ -214,6 +214,8 @@ $groupPubPackages | |||
// TODO(dnys1): Enable E2E runs for Dart packages | |||
final needsE2ETest = package.flavor == PackageFlavor.flutter && | |||
package.integrationTestDirectory != null; | |||
final hasGoldens = package.flavor == PackageFlavor.flutter && | |||
package.goldensTestDirectory != null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative to checking for a directory would be to look for a dev dep of golden_toolkit
. It isn't required to run golden tests, but I think we would be likely to use it in any future packages that have golden tests. Looking for a ui directory is fine too. If this is still in place when future UI components are built, we will just have to confirm to that dir.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, this for sure could be different. Since we don't have any other UI packages or other established conventions, we can readdress this down the road.
import 'package:amplify_flutter/amplify_flutter.dart'; | ||
import 'package:amplify_integration_test/amplify_integration_test.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
/// Use for testing the [MockAuthenticatorApp] widget locally. | ||
void main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you would like to commit this, can you move it to an /example dir and add all the platforms (not just iOS)
f8281ce
to
46a25b5
Compare
Description of changes:
AuthenticatorStep.loading
.amplify_authenticator.ymal
workflow uses a MacOS runner to ensure more consistent testingBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.