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

Add EmbeddedActivityLauncher #9919

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

tjclawson-stripe
Copy link
Collaborator

@tjclawson-stripe tjclawson-stripe commented Jan 15, 2025

Summary

Add EmbeddedActivityLauncher
Add FormActivity

Motivation

MOBILESDK-2940

Testing

  • Added tests
  • Modified tests
  • Manually verified

Changelog

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Diffuse output:

OLD: identity-example-release-base.apk (signature: V1, V2)
NEW: identity-example-release-pr.apk (signature: V1, V2)

          │          compressed          │         uncompressed         
          ├───────────┬───────────┬──────┼───────────┬───────────┬──────
 APK      │ old       │ new       │ diff │ old       │ new       │ diff 
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
      dex │     2 MiB │     2 MiB │  0 B │   4.1 MiB │   4.1 MiB │  0 B 
     arsc │     1 MiB │     1 MiB │  0 B │     1 MiB │     1 MiB │  0 B 
 manifest │   2.3 KiB │   2.3 KiB │  0 B │     8 KiB │     8 KiB │  0 B 
      res │ 302.6 KiB │ 302.6 KiB │  0 B │ 456.7 KiB │ 456.7 KiB │  0 B 
   native │   6.2 MiB │   6.2 MiB │  0 B │  15.8 MiB │  15.8 MiB │  0 B 
    asset │   7.2 KiB │   7.2 KiB │  0 B │   6.9 KiB │   6.9 KiB │  0 B 
    other │  90.4 KiB │  90.4 KiB │ -9 B │ 170.7 KiB │ 170.7 KiB │  0 B 
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
    total │   9.6 MiB │   9.6 MiB │ -9 B │  21.5 MiB │  21.5 MiB │  0 B 

 DEX     │ old   │ new   │ diff      
─────────┼───────┼───────┼───────────
   files │     1 │     1 │ 0         
 strings │ 19982 │ 19982 │ 0 (+0 -0) 
   types │  6194 │  6194 │ 0 (+0 -0) 
 classes │  4985 │  4985 │ 0 (+0 -0) 
 methods │ 29820 │ 29820 │ 0 (+0 -0) 
  fields │ 17539 │ 17539 │ 0 (+0 -0) 

 ARSC    │ old  │ new  │ diff 
─────────┼──────┼──────┼──────
 configs │  164 │  164 │  0   
 entries │ 3624 │ 3624 │  0
APK
    compressed    │   uncompressed   │                        
──────────┬───────┼───────────┬──────┤                        
 size     │ diff  │ size      │ diff │ path                   
──────────┼───────┼───────────┼──────┼────────────────────────
 28.5 KiB │ -11 B │  63.1 KiB │  0 B │ ∆ META-INF/CERT.SF     
 25.4 KiB │  +3 B │    63 KiB │  0 B │ ∆ META-INF/MANIFEST.MF 
  1.2 KiB │  -1 B │   1.2 KiB │  0 B │ ∆ META-INF/CERT.RSA    
──────────┼───────┼───────────┼──────┼────────────────────────
 55.1 KiB │  -9 B │ 127.3 KiB │  0 B │ (total)

@@ -161,6 +169,10 @@ internal class DefaultEmbeddedContentHelper @AssistedInject constructor(
transitionToManageScreen = {
},
transitionToFormScreen = {
embeddedActivityLauncher?.launchForm(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We will need some way to do this, but ideally we can just pass the method straight through, and the DefaultEmbeddedContentHelper doesn't need to know directly about FormContract.Args, or how to handle the result.

@tjclawson-stripe tjclawson-stripe force-pushed the tyler/mobilesdk-2940 branch 2 times, most recently from ce8663f to 93d0c5a Compare January 16, 2025 00:27
Copy link
Collaborator

@jaynewstrom-stripe jaynewstrom-stripe left a comment

Choose a reason for hiding this comment

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

Can you write some tests?

We should have an easy test for FormActivity. And there's likely a lot of other tests we can write.

@tjclawson-stripe tjclawson-stripe marked this pull request as ready for review January 17, 2025 00:31
@tjclawson-stripe tjclawson-stripe requested review from a team as code owners January 17, 2025 00:31
finish()
}
) {
Text(args?.selectedPaymentMethodCode ?: "Whoops")
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we return above, we don't need this "whoops" text.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wrapped in a ?.let

{ code, metadata ->
formActivityLauncher.launch(FormContract.Args(code, metadata))
}
private set
Copy link
Collaborator

Choose a reason for hiding this comment

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

This has no effect.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed and made override a val as well

@@ -119,6 +125,16 @@ internal class DefaultEmbeddedContentHelper @AssistedInject constructor(
)
}

override fun setFormLauncher(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have tests for this?

override fun setFormLauncher(
formLauncher: ((code: String, paymentMethodMetaData: PaymentMethodMetadata?) -> Unit)?
) {
// NO-OP
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should have these do something, and validate it below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added functionality to set class property. Do we want to add logic in the validation method since it's not set/clear aren't called during initialization?

finish()
}
) {
args?.selectedPaymentMethodCode?.let { Text(it) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should know it's not null here. Can we store a local val?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It has to either have null check or be cast to FormContract.Args as the compiler cannot smart cast


@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
Copy link
Collaborator

Choose a reason for hiding this comment

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

These mocks don't feel like the type of tests we should write. Is it possible to write this with fakes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created a task to refactor here

@RunWith(RobolectricTestRunner::class)
internal class EmbeddedActivityLauncherTest {

private lateinit var activityResultCaller: ActivityResultCaller
Copy link
Collaborator

Choose a reason for hiding this comment

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

We typically write these tests with a scenario (see

) rather than lateinit vars.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

@RunWith(RobolectricTestRunner::class)
internal class FormActivityTest {

private lateinit var scenario: ActivityScenario<FormActivity>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you rewrite this without lateinit vars?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove lateinit vars

@Test
fun `initEmbeddedActivityLauncher and clearEmbeddedActivityLauncher successfully init and clear formLauncher`() =
testScenario {
val launcher: ActivityResultLauncher<FormContract.Args> = mock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you rewrite these with fakes instead of mocks?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed mocks

lifecycleOwner.lifecycle.addObserver(
object : DefaultLifecycleObserver {
override fun onDestroy(owner: LifecycleOwner) {
formActivityLauncher.unregister()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you write a test to ensure this is happening?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added to EmbeddedActivityLauncherTest

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