Oleksandr Karpovich
2 years ago
committed by
GitHub
6 changed files with 181 additions and 0 deletions
@ -0,0 +1,27 @@ |
|||||||
|
plugins { |
||||||
|
kotlin("multiplatform") |
||||||
|
id("org.jetbrains.compose") |
||||||
|
} |
||||||
|
|
||||||
|
repositories { |
||||||
|
mavenLocal() |
||||||
|
mavenCentral() |
||||||
|
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") |
||||||
|
} |
||||||
|
|
||||||
|
kotlin { |
||||||
|
js(IR) { |
||||||
|
nodejs {} |
||||||
|
browser() {} |
||||||
|
} |
||||||
|
|
||||||
|
sourceSets { |
||||||
|
val commonMain by getting { |
||||||
|
dependencies { |
||||||
|
implementation(kotlin("stdlib-common")) |
||||||
|
implementation(compose.runtime) |
||||||
|
implementation(project(":web-core")) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
import androidx.compose.runtime.Composable |
||||||
|
import org.jetbrains.compose.web.dom.Div |
||||||
|
import org.jetbrains.compose.web.dom.Text |
||||||
|
|
||||||
|
interface ComposableCollection { |
||||||
|
val list: List<@Composable () -> Unit> |
||||||
|
fun add(c: @Composable () -> Unit) |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
interface ComposableContent { |
||||||
|
|
||||||
|
@Composable |
||||||
|
fun ComposableContent() |
||||||
|
} |
||||||
|
|
||||||
|
abstract class AbstrComposableContent : ComposableContent { |
||||||
|
|
||||||
|
@Composable |
||||||
|
override fun ComposableContent() { |
||||||
|
Div { Text("AbstrComposableContent") } |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,86 @@ |
|||||||
|
import kotlinx.browser.document |
||||||
|
import org.jetbrains.compose.web.dom.Div |
||||||
|
import org.jetbrains.compose.web.dom.Text |
||||||
|
import org.jetbrains.compose.web.renderComposable |
||||||
|
import kotlin.test.Test |
||||||
|
import kotlin.test.assertEquals |
||||||
|
|
||||||
|
class InheritanceTests { |
||||||
|
|
||||||
|
@Test |
||||||
|
// Issues: |
||||||
|
// https://github.com/JetBrains/compose-jb/issues/2291 |
||||||
|
// https://github.com/JetBrains/compose-jb/issues/2660 |
||||||
|
fun implementComposableCollection() { |
||||||
|
val collection = createComposableCollection().apply { |
||||||
|
add { |
||||||
|
Div { Text("Div1") } |
||||||
|
} |
||||||
|
add { |
||||||
|
Div { Text("Div2") } |
||||||
|
} |
||||||
|
add { |
||||||
|
Div { Text("Div3") } |
||||||
|
} |
||||||
|
} |
||||||
|
val root = document.createElement("div") |
||||||
|
|
||||||
|
renderComposable(root) { |
||||||
|
collection.list.forEach { it() } |
||||||
|
} |
||||||
|
|
||||||
|
assertEquals("<div>Div1</div><div>Div2</div><div>Div3</div>", root.innerHTML) |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
fun implementComposableContent() { |
||||||
|
val contentImpl = createComposableContent() |
||||||
|
|
||||||
|
val root = document.createElement("div") |
||||||
|
|
||||||
|
renderComposable(root) { |
||||||
|
contentImpl.ComposableContent() |
||||||
|
} |
||||||
|
|
||||||
|
assertEquals("<div>ComposableContent</div>", root.innerHTML) |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
fun implementComposableContentDelegation() { |
||||||
|
val contentImpl = ComposableContentDelegation(createComposableContent()) |
||||||
|
|
||||||
|
val root = document.createElement("div") |
||||||
|
|
||||||
|
renderComposable(root) { |
||||||
|
contentImpl.ComposableContent() |
||||||
|
} |
||||||
|
|
||||||
|
assertEquals("<div>ComposableContent</div>", root.innerHTML) |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
fun testAbstrComposableContentExtendImpl() { |
||||||
|
val contentImpl: ComposableContent = AbstrComposableContentExtendImpl() |
||||||
|
|
||||||
|
val root = document.createElement("div") |
||||||
|
|
||||||
|
renderComposable(root) { |
||||||
|
contentImpl.ComposableContent() |
||||||
|
} |
||||||
|
|
||||||
|
assertEquals("<div>AbstrComposableContent</div><div>AbstrComposableContentImpl</div>", root.innerHTML) |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
fun testAbstrComposableContentNoExtendImpl() { |
||||||
|
val contentImpl: ComposableContent = AbstrComposableContentNoExtendImpl() |
||||||
|
|
||||||
|
val root = document.createElement("div") |
||||||
|
|
||||||
|
renderComposable(root) { |
||||||
|
contentImpl.ComposableContent() |
||||||
|
} |
||||||
|
|
||||||
|
assertEquals("<div>AbstrComposableContent</div>", root.innerHTML) |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue