Browse Source

Add the tests for k/js compose compilation of an anonymous object with @Composable functions

release/1.3.0
Oleksandr Karpovich 2 years ago
parent
commit
ef14c563de
  1. 2
      web/buildSrc/src/main/kotlin/SeleniumDriverPlugin.kt
  2. 95
      web/compose-compiler-integration/src/jsTest/kotlin/AnonymousObjectsInComposable.kt
  3. 1
      web/gradle.properties

2
web/buildSrc/src/main/kotlin/SeleniumDriverPlugin.kt

@ -4,7 +4,7 @@ import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import java.io.File
import java.net.URL
private val CHROME_DRIVER_VERSION = "104.0.5112.79"
private val CHROME_DRIVER_VERSION = "108.0.5359.71"
private val GECKO_DRIVER_VERSION = "0.31.0"
private fun download(url: String, file: File) {

95
web/compose-compiler-integration/src/jsTest/kotlin/AnonymousObjectsInComposable.kt

@ -0,0 +1,95 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import kotlinx.browser.document
import org.jetbrains.compose.web.dom.Div
import org.jetbrains.compose.web.dom.Text
import org.jetbrains.compose.web.renderComposableInBody
import kotlin.test.Test
import kotlin.test.assertEquals
class AnonymousObjectsInComposable {
@Test
// Issue: content.Abc$composable_z540rc_k$ is not a function
// https://github.com/JetBrains/compose-jb/issues/2549
fun testComposableInAnonymousObject() {
renderComposableInBody {
val content: HasComposable2 = createHasComposable()
content.Abc()
}
assertEquals("<div>Abc</div>", document.body!!.firstElementChild!!.outerHTML)
}
@Test
// Issue:
// java.lang.IllegalArgumentException: Could not find local implementation for Abc$composable
// at androidx.compose.compiler.plugins.kotlin.lower.decoys.DecoyTransformBase$DefaultImpls.getComposableForDecoy(DecoyTransformBase.kt:110)
fun testLocalClassWithComposable() {
renderComposableInBody {
HasLocalClassWithComposable()
}
assertEquals("<div>Abc2</div>", document.body!!.firstElementChild!!.outerHTML)
}
@Test
// Issue:
// abc3.Abc$composable_z540rc_k$ is not a function
fun testConstructorWithComposable() {
renderComposableInBody {
TestConstructor { return@TestConstructor 111 }.otherComposable!!.invoke()
}
assertEquals("<div>Abc223-111</div>", document.body!!.firstElementChild!!.outerHTML)
}
}
@Composable
internal fun HasLocalClassWithComposable() {
class Abc : HasComposable2 {
@Composable
override fun Abc() {
Div { Text("Abc2") }
}
}
val abc = remember { Abc() }
abc.Abc()
}
@Composable
internal fun createHasComposable(): HasComposable2 {
return object : HasComposable2 {
@Composable
override fun Abc() {
Div {
Text("Abc")
}
}
}
}
internal interface HasComposable2 {
@Composable
fun Abc()
}
class TestConstructor constructor() {
var otherComposable: (@Composable () -> Unit)? = null
constructor(retInt: @Composable () -> Int): this() {
otherComposable = {
val abc3: HasComposable2 = object : HasComposable2 {
@Composable
override fun Abc() {
Div {
val i = retInt()
Text("Abc223-$i")
}
}
}
abc3.Abc()
}
}
}

1
web/gradle.properties

@ -2,3 +2,4 @@ compose.version=1.3.0-rc05
compose.web.buildSamples=false
compose.web.tests.integration.withFirefox
compose.web.tests.skip.benchmarks=false
org.gradle.jvmargs=-Xmx8g
Loading…
Cancel
Save