Skip to content

Commit

Permalink
rx-html: Add tests for attribute updates #1341 (#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial committed Apr 2, 2021
1 parent 6fa6468 commit fe26b2b
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,52 @@ object RxRenderingTest extends AirSpec {
b shouldBe true
b1 shouldBe true
}

test("rendering attributes with Rx") {
val a = Rx.variable("primary")
val e = new RxElement {
override def render: RxElement = div(
cls -> a
)
}
val (n, c) = render(e)
n.outerHTML shouldBe """<div class="primary"></div>"""

a := "secondary"
n.outerHTML shouldBe """<div class="secondary"></div>"""
c.cancel
}

test("rendering whole attributes with Rx") {
val a = Rx.variable("primary")
val e = new RxElement {
override def render: RxElement = div(
a.map { x => cls -> x }
)
}
val (n, c) = render(e)
n.outerHTML shouldBe """<div class="primary"></div>"""

a := "secondary"
n.outerHTML shouldBe """<div class="secondary"></div>"""
c.cancel
}

test("rendering attribute value with Rx") {
val color = Rx.variable("white")

val e = new RxElement {
override def render: RxElement = div(
// This needs to be updated when color variable is changed
style -> color.map { x => s"color: ${x};" },
"message"
)
}

val (n, c) = render(e)
n.outerHTML shouldBe """<div style="color: white;">message</div>"""
color := "black"
n.outerHTML shouldBe """<div style="color: black;">message</div>"""
c.cancel
}
}

0 comments on commit fe26b2b

Please sign in to comment.