Use asHtmlElement helper only in TestUtils

TestUtils is a perfect classic name!
This commit is contained in:
Shagen Ogandzhanian
2021-08-30 22:28:53 +02:00
parent d8de109ba1
commit 4c252b8196
3 changed files with 11 additions and 28 deletions

View File

@@ -12,12 +12,8 @@ import kotlin.test.assertEquals
class DomSideEffectTests {
@Test
fun canCreateElementsInDomSideEffect() {
val root = "div".asHtmlElement()
renderComposable(
root = root
) {
fun canCreateElementsInDomSideEffect() = runTest {
composition {
Div {
DomSideEffect {
it.appendChild(
@@ -28,6 +24,7 @@ class DomSideEffectTests {
}
}
}
assertEquals(
expected = "<div><div><p>Hello World!</p></div></div>",
actual = root.outerHTML

View File

@@ -505,10 +505,8 @@ class InputsGenerateCorrectHtmlTests {
}
@Test
fun textAreaWithDefaultValueAndWithoutIt() {
val root = "div".asHtmlElement()
renderComposable(root = root) {
fun textAreaWithDefaultValueAndWithoutIt() = runTest {
composition {
TextArea()
TextArea {
defaultValue("not-empty-default-value")

View File

@@ -12,36 +12,24 @@ import kotlin.test.assertTrue
class ModifierTests {
@Test
fun backgroundModifier() {
val root = "div".asHtmlElement()
renderComposable(
root = root
) {
fun backgroundModifier() = runTest {
{
Box(
Modifier.background(Color(255, 0, 0))
) { }
}
val el = root.firstChild
assertTrue(el is HTMLElement, "element not found")
assertEquals("background-color: rgb(255, 0, 0);", el.style.cssText)
assertEquals("background-color: rgb(255, 0, 0);", nextChild().style.cssText)
}
@Test
fun size() {
val root = "div".asHtmlElement()
renderComposable(
root = root
) {
fun size() = runTest {
composition {
Box(
Modifier.size(40.dp)
) { }
}
val el = root.firstChild
assertTrue(el is HTMLElement, "element not found")
assertEquals("width: 40px; height: 40px;", el.style.cssText)
assertEquals("width: 40px; height: 40px;", nextChild().style.cssText)
}
}