Coder Social home page Coder Social logo

Comments (6)

m-sasha avatar m-sasha commented on May 30, 2024

Does it work without Koin? Without resources?

from compose-multiplatform.

igorescodro avatar igorescodro commented on May 30, 2024

That's a very good question... No, it also fails with the exact same error. However, in Android it crashes because at some point the Koin Graph is needed to get the injections. Which leads me to think that something else is happening and my iOS' MainViewController is not being rendered.

$ gradle shared:connectedAndroidTest

java.lang.IllegalStateException: KoinApplication has not been started
at org.koin.core.context.GlobalContext.get(GlobalContext.kt:36)
at org.koin.compose.KoinApplicationKt.getKoinContext(KoinApplication.kt:52)
at org.koin.compose.KoinApplicationKt.access$getKoinContext(KoinApplication.kt:1)

The sample code runs fine even with Koin and resources, though:

@BeforeTest
fun setup() {
    initKoin(appModule = module)
}

@AfterTest
fun tearDown() {
    stopKoin()
}

@Test
fun test_titleChangesWhenBottomIconIsSelected() = uiTest {
    val title = resourcesProvider.getString(HomeSection.Tasks.title.desc())
    setContent {
        var text by remember { mutableStateOf(title) }
        Text(
            text = text,
            modifier = Modifier.testTag("text")
        )
        Button(
            onClick = { text = "Compose" },
            modifier = Modifier.testTag("button")
        ) {
            Text("Click me")
        }
    }

    onNodeWithTag("text").assertTextEquals(title)
    onNodeWithTag("button").performClick()
    onNodeWithTag("text").assertTextEquals("Compose")
}

from compose-multiplatform.

m-sasha avatar m-sasha commented on May 30, 2024

Wait, the testing framework only works with Compose UI. It won't work with native elements such as UIViewController.

from compose-multiplatform.

igorescodro avatar igorescodro commented on May 30, 2024

But if I update the coding to directly call the AlkaaMultiplatformApp() directly in iOS, I face the following issue:

kotlin.IllegalStateException: CompositionLocal UIViewController not provided

That's my iOS's MainViewController:

@OptIn(ExperimentalComposeApi::class)
@Suppress("Unused", "FunctionName")
fun MainViewController(): UIViewController = ComposeUIViewController(
    configure = {
        accessibilitySyncOptions = AccessibilitySyncOptions.Always(AccessibilityDebugLoggerImpl())
    },
) {
    AlkaaMultiplatformApp()
}

Is there a way to use it directly and provide this custom CompositionLocal?

from compose-multiplatform.

m-sasha avatar m-sasha commented on May 30, 2024

You need to remove the direct dependency on UIViewController from the code you're trying to test.

from compose-multiplatform.

igorescodro avatar igorescodro commented on May 30, 2024

Got it. The reason was the WindowSizeClass inside my AppState class. Removing caused another problems with UNUserNotificationCenter.currentNotificationCenter() but definitely not related to ComposeUIViewController as I reported. Thank you for the help!

from compose-multiplatform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.