Browse Source

Add test that basically check that scope is remembered

Thanks to Oleksandr - I would have never come up with a solution this
quick
pull/1112/head
Shagen Ogandzhanian 3 years ago
parent
commit
ce9fbcc8dd
  1. 38
      web/core/src/jsTest/kotlin/elements/AttributesTests.kt

38
web/core/src/jsTest/kotlin/elements/AttributesTests.kt

@ -3,6 +3,8 @@ package org.jetbrains.compose.web.core.tests
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import kotlinx.browser.document
import kotlinx.dom.clear
import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.attributes.disabled
import org.jetbrains.compose.web.attributes.forId
@ -334,6 +336,42 @@ class AttributesTests {
assertEquals(0, refDisposeCounter)
}
@Test
fun disposableRefEffectWithChangingKey() = runTest {
var key by mutableStateOf(0)
composition {
val readKey = key // read key here to recompose an entire scope
Div(
attrs = {
id("id$readKey")
}
) {
DisposableRefEffect(readKey) {
val p = document.createElement("p").also { it.innerHTML = "Key=$readKey" }
it.appendChild(p)
onDispose {
it.clear()
}
}
}
}
assertEquals(
expected = "<div><div id=\"id0\"><p>Key=0</p></div></div>",
actual = root.outerHTML
)
key = 1
waitForRecompositionComplete()
assertEquals(
expected = "<div><div id=\"id1\"><p>Key=1</p></div></div>",
actual = root.outerHTML
)
}
@Test // issue: https://github.com/JetBrains/compose-jb/issues/981
fun attributesUpdateShouldNotCauseInlineStylesCleanUp() = runTest {
var hasValue by mutableStateOf(false)

Loading…
Cancel
Save