dioxus/packages/core/tests/kitchen_sink.rs

52 lines
1.4 KiB
Rust
Raw Normal View History

2024-01-16 01:14:11 +00:00
use dioxus::dioxus_core::{ElementId, Mutation};
2022-11-27 05:56:49 +00:00
use dioxus::prelude::*;
2024-01-11 17:11:44 +00:00
fn basic_syntax_is_a_template() -> Element {
2022-11-27 05:56:49 +00:00
let asd = 123;
let var = 123;
2024-01-11 01:21:15 +00:00
render! {
div { key: "12345", class: "asd", class: "{asd}", class: if true {
"{asd}"
}, class: if false {
"{asd}"
}, onclick: move |_| {},
2022-11-27 05:56:49 +00:00
div { "{var}" }
div {
h1 { "var" }
p { "you're great!" }
div { background_color: "red",
h1 { "var" }
2024-01-11 01:21:15 +00:00
div {
b { "asd" }
"not great"
}
2022-11-27 05:56:49 +00:00
}
p { "you're great!" }
}
}
2024-01-11 01:21:15 +00:00
}
2022-11-27 05:56:49 +00:00
}
2023-09-19 14:39:53 +00:00
2022-11-27 05:56:49 +00:00
#[test]
fn dual_stream() {
let mut dom = VirtualDom::new(basic_syntax_is_a_template);
2024-01-11 01:21:15 +00:00
let edits = dom.rebuild_to_vec().santize();
2022-11-27 05:56:49 +00:00
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",
2024-01-11 01:21:15 +00:00
value: "asd 123 123".into_value(),
2022-12-09 22:18:37 +00:00
id: ElementId(1),
ns: None,
},
2024-01-11 01:21:15 +00:00
NewEventListener { name: "click".to_string(), id: ElementId(1) },
HydrateText { path: &[0, 0], value: "123".to_string(), 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
}