2022-06-25 13:27:10 +00:00
|
|
|
use dioxus::prelude::*;
|
2022-09-13 23:22:27 +00:00
|
|
|
use dioxus_web::Config;
|
2022-01-07 05:33:09 +00:00
|
|
|
use wasm_bindgen_test::wasm_bindgen_test;
|
2022-03-17 14:51:23 +00:00
|
|
|
use web_sys::window;
|
2022-01-07 05:33:09 +00:00
|
|
|
|
|
|
|
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn makes_tree() {
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
2022-03-17 14:51:23 +00:00
|
|
|
div {
|
|
|
|
h1 {}
|
|
|
|
}
|
|
|
|
div {
|
|
|
|
h2 {}
|
|
|
|
}
|
2022-01-07 05:33:09 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut dom = VirtualDom::new(app);
|
|
|
|
let muts = dom.rebuild();
|
|
|
|
|
2022-12-01 05:46:15 +00:00
|
|
|
dbg!(muts.edits);
|
2022-01-07 05:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn rehydrates() {
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
2022-03-17 14:51:23 +00:00
|
|
|
div {
|
|
|
|
h1 { "h1" }
|
|
|
|
}
|
|
|
|
div {
|
|
|
|
h2 { "h2" }
|
|
|
|
}
|
|
|
|
button {
|
|
|
|
onclick: move |_| {
|
|
|
|
println!("clicked");
|
|
|
|
},
|
|
|
|
"listener test"
|
|
|
|
}
|
|
|
|
false.then(|| rsx!{ "hello" })
|
2022-01-07 05:33:09 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-17 14:51:23 +00:00
|
|
|
let mut dom = VirtualDom::new(app);
|
|
|
|
let _ = dom.rebuild();
|
2022-12-07 22:51:14 +00:00
|
|
|
let out = dioxus_ssr::render(&dom);
|
2022-03-17 14:51:23 +00:00
|
|
|
|
|
|
|
window()
|
|
|
|
.unwrap()
|
|
|
|
.document()
|
|
|
|
.unwrap()
|
|
|
|
.body()
|
|
|
|
.unwrap()
|
2023-01-28 02:35:46 +00:00
|
|
|
.set_inner_html(&format!("<div id='main'>{out}</div>"));
|
2022-03-17 14:51:23 +00:00
|
|
|
|
2022-09-13 23:22:27 +00:00
|
|
|
dioxus_web::launch_cfg(app, Config::new().hydrate(true));
|
2022-01-07 05:33:09 +00:00
|
|
|
}
|