mirror of
https://github.com/phfroidmont/scalive.git
synced 2025-12-25 21:46:59 +01:00
Add dynamic attributes
This commit is contained in:
parent
82c0922cfa
commit
62c1a8a9f4
4 changed files with 53 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ object LiveViewSpec extends TestSuite:
|
|||
title: String = "title value",
|
||||
bool: Boolean = false,
|
||||
nestedTitle: String = "nested title value",
|
||||
cls: String = "text-sm",
|
||||
items: List[NestedModel] = List.empty
|
||||
)
|
||||
final case class NestedModel(name: String, age: Int)
|
||||
|
|
@ -79,6 +80,43 @@ object LiveViewSpec extends TestSuite:
|
|||
}
|
||||
}
|
||||
|
||||
test("Dynamic attribute") {
|
||||
val lv =
|
||||
LiveView(
|
||||
new View[TestModel]:
|
||||
val root: HtmlElement[TestModel] =
|
||||
div(cls := model(_.cls))
|
||||
,
|
||||
TestModel()
|
||||
)
|
||||
test("init") {
|
||||
assertEqualsJson(
|
||||
lv.fullDiff,
|
||||
Json
|
||||
.Obj(
|
||||
"s" -> Json
|
||||
.Arr(Json.Str("<div class=\""), Json.Str("\"></div>")),
|
||||
"0" -> Json.Str("text-sm")
|
||||
)
|
||||
)
|
||||
}
|
||||
test("diff no update") {
|
||||
assertEqualsJson(lv.diff, emptyDiff)
|
||||
}
|
||||
test("diff with update") {
|
||||
lv.update(TestModel(cls = "text-md"))
|
||||
assertEqualsJson(
|
||||
lv.diff,
|
||||
Json.Obj("0" -> Json.Str("text-md"))
|
||||
)
|
||||
}
|
||||
test("diff with update and no change") {
|
||||
lv.update(TestModel(cls = "text-md"))
|
||||
lv.update(TestModel(cls = "text-md"))
|
||||
assertEqualsJson(lv.diff, emptyDiff)
|
||||
}
|
||||
}
|
||||
|
||||
test("when mod") {
|
||||
val lv =
|
||||
LiveView(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue