airbnb / mavericks

Mavericks: Android on Autopilot
https://airbnb.io/mavericks/
Apache License 2.0
5.85k stars 498 forks source link

[2.0.0-beta1] MavericksLauncher crashes when trying to create View with Arguments #459

Closed pwillmann closed 4 years ago

pwillmann commented 4 years ago

MvRx: 2.0.0-beta1 Kotlin: 1.4.10

I played around a bit with the new Mavericks/MvRx Version to test out the new Mockable and Launcher features, really cool stuff I am super excited for this to get out of beta! I found a few smaller issues and one blocker/crash.

  1. First of all the project I am testing this on is based on MvRx and RxJava which is why i am using the mvrx-rxjava2 artifact. Unfortunately the mvrx-mocking artifact only suppurts coroutines, but just copying over the MockableMvRxView and basing it on MockableMavericksView worked fine.
  2. https://airbnb.io/MvRx/#/setup tells us to use MavericksMocks.initialize(this) but it should be MockableMavericks.initialize(this)
  3. https://airbnb.io/MvRx/#/mocking?id=launching-mocked-screens never mentions that the mvrx-launcher artifact is needed to get access to the MavericksLauncherActivity

Now to the crash, as I am using Dagger Hilt and the jetpack navigation library for navigation I copied over the Launcher code from the sample app (https://github.com/airbnb/MvRx/blob/609a797954863ff7815cb697a8964f96db1d867e/sample/src/main/java/com/airbnb/mvrx/sample/LauncherActivity.kt). Fragments without arguments worked fine (only tested the default states so far) but fragments that use arguments with the help of the jetpack navigation arguments crash.

I get the following error message:

java.lang.ClassCastException: android.os.Bundle cannot be cast to java.lang.Void
        at com.airbnb.mvrx.mocking.ViewMockerKt$getMockVariants$3.invoke(Unknown Source:0)
        at com.airbnb.mvrx.mocking.ViewMockerKt$getMockVariants$$inlined$map$lambda$1$1.invoke(ViewMocker.kt:163)
        at com.airbnb.mvrx.mocking.ViewMockerKt$getMockVariants$$inlined$map$lambda$1$1.invoke(Unknown Source:0)
        at com.airbnb.mvrx.mocking.MockMavericksViewModelConfigFactory.withMockBehavior(MockableMavericksViewModelConfig.kt:183)
        at com.airbnb.mvrx.mocking.ViewMockerKt$getMockVariants$$inlined$map$lambda$1.invoke(ViewMocker.kt:162)
        at com.airbnb.mvrx.mocking.ViewMockerKt$getMockVariants$$inlined$map$lambda$1.invoke(Unknown Source:2)
        at com.airbnb.mvrx.launcher.MavericksLauncherMockActivity$Companion.showNextMockFromActivity(MavericksLauncherMockActivity.kt:139)

the mocks for the crashing fragment are provided like this:

  override fun provideMocks() = mockNoViewModels(
            defaultArgs = bundleOf("url" to "www.google.com")
    ) {

    }
elihart commented 4 years ago

Thanks for trying it out and reporting. I'll update the docs and try to fix this crash soon.

As far as interfaces go, you should be able to easily use rxjava by having your fragments implement both MvRxView, MockableMavericksView. They both extend MavericksView. I can also put this in the docs

elihart commented 4 years ago

I believe I've already fixed your crash in https://github.com/airbnb/MvRx/pull/461

elihart commented 4 years ago

Docs are fixed with https://github.com/airbnb/MvRx/pull/465

Really appreciate you trying it out and reporting issues :) Feel free to submit a PR for other doc improvements, it's very helpful to have fresh eyes on this stuff.

I'll try to push another beta version soon so you have the crash fix, we're just finalizing some more API changes for coroutine configuration now

pwillmann commented 4 years ago

Thanks a lot @elihart ! I will get back to it once the update is available :D.

elihart commented 4 years ago

Beta 2 is now out, let me know if you have any issues with it