dioxus/packages/core/tests/kitchen_sink.rs

49 lines
1.3 KiB
Rust
Raw Normal View History

2022-12-09 22:18:37 +00:00
use bumpalo::Bump;
2022-11-27 05:56:49 +00:00
use dioxus::core::{ElementId, Mutation};
use dioxus::prelude::*;
fn basic_syntax_is_a_template(cx: Scope) -> Element {
let asd = 123;
let var = 123;
cx.render(rsx! {
div { key: "12345",
class: "asd",
class: "{asd}",
onclick: move |_| {},
div { "{var}" }
div {
h1 { "var" }
p { "you're great!" }
div { background_color: "red",
h1 { "var" }
div { b { "asd" } "not great" }
}
p { "you're great!" }
}
}
})
}
#[test]
fn dual_stream() {
let mut dom = VirtualDom::new(basic_syntax_is_a_template);
2022-12-09 22:18:37 +00:00
let bump = Bump::new();
2022-11-27 05:56:49 +00:00
let edits = dom.rebuild().santize();
use Mutation::*;
2022-12-09 22:18:37 +00:00
assert_eq!(edits.edits, {
2022-11-27 05:56:49 +00:00
[
LoadTemplate { name: "template", index: 0, id: ElementId(1) },
2022-12-09 22:18:37 +00:00
SetAttribute {
name: "class",
value: (&*bump.alloc("123".into_value(&bump))).into(),
2022-12-09 22:18:37 +00:00
id: ElementId(1),
ns: None,
},
2022-12-13 23:36:15 +00:00
NewEventListener { name: "click", id: ElementId(1) },
2022-11-27 05:56:49 +00:00
HydrateText { path: &[0, 0], value: "123", id: ElementId(2) },
2022-12-09 22:18:37 +00:00
AppendChildren { id: ElementId(0), m: 1 },
]
});
2022-11-27 05:56:49 +00:00
}