Bump version to 1.2.8, add TestStyleUpdate for verifying style attribute updates and removals, and simplify style attribute handling in HtmlBuilder.
Some checks failed
Gradle CI / build (push) Has been cancelled
Some checks failed
Gradle CI / build (push) Has been cancelled
This commit is contained in:
@@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "nl.astraeus"
|
||||
version = "1.2.7"
|
||||
version = "1.2.8"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@@ -233,10 +233,7 @@ class HtmlBuilder(
|
||||
if (attribute?.name != null) {
|
||||
val attr = attribute.name
|
||||
|
||||
if (
|
||||
!setAttrs.contains(attr) &&
|
||||
attr != "style"
|
||||
) {
|
||||
if (!setAttrs.contains(attr)) {
|
||||
element.setKompAttribute(attr, null)
|
||||
}
|
||||
}
|
||||
|
||||
68
src/jsTest/kotlin/nl/astraeus/komp/TestStyleUpdate.kt
Normal file
68
src/jsTest/kotlin/nl/astraeus/komp/TestStyleUpdate.kt
Normal file
@@ -0,0 +1,68 @@
|
||||
package nl.astraeus.komp
|
||||
|
||||
import kotlinx.browser.document
|
||||
import kotlinx.html.div
|
||||
import kotlinx.html.style
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
|
||||
/**
|
||||
* Test class for verifying style attribute updates and removals
|
||||
*/
|
||||
class StyleKomponent : Komponent() {
|
||||
var includeStyle = true
|
||||
var styleValue = "color: red;"
|
||||
|
||||
override fun HtmlBuilder.render() {
|
||||
div {
|
||||
if (includeStyle) {
|
||||
style = styleValue
|
||||
}
|
||||
+"Content"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TestStyleUpdate {
|
||||
|
||||
@Test
|
||||
fun testStyleRemoval() {
|
||||
// Create a test component
|
||||
val styleComponent = StyleKomponent()
|
||||
val div = document.createElement("div") as HTMLDivElement
|
||||
|
||||
// Render it
|
||||
Komponent.create(div, styleComponent)
|
||||
|
||||
// Verify initial state - should have the style
|
||||
val contentDiv = div.querySelector("div")
|
||||
println("[DEBUG_LOG] Initial DOM: ${div.printTree()}")
|
||||
assertEquals("color: red;", contentDiv?.getAttribute("style"), "Div should have the style initially")
|
||||
|
||||
// Update to remove the style
|
||||
styleComponent.includeStyle = false
|
||||
styleComponent.requestImmediateUpdate()
|
||||
|
||||
// Verify the style was removed
|
||||
println("[DEBUG_LOG] After style removal: ${div.printTree()}")
|
||||
assertNull(contentDiv?.getAttribute("style"), "Style should be removed after update")
|
||||
|
||||
// Add the style back
|
||||
styleComponent.includeStyle = true
|
||||
styleComponent.requestImmediateUpdate()
|
||||
|
||||
// Verify the style was added back
|
||||
println("[DEBUG_LOG] After style added back: ${div.printTree()}")
|
||||
assertEquals("color: red;", contentDiv?.getAttribute("style"), "Style should be added back")
|
||||
|
||||
// Change the style value
|
||||
styleComponent.styleValue = "color: blue;"
|
||||
styleComponent.requestImmediateUpdate()
|
||||
|
||||
// Verify the style was changed
|
||||
println("[DEBUG_LOG] After style value change: ${div.printTree()}")
|
||||
assertEquals("color: blue;", contentDiv?.getAttribute("style"), "Style should be updated to new value")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user