2022-11-29 21:31:04 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_drops() {
|
2024-01-11 16:48:04 +00:00
|
|
|
fn App() -> Element {
|
2024-01-11 01:21:15 +00:00
|
|
|
render! { div {} }
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-11 18:40:36 +00:00
|
|
|
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2024-01-11 01:21:15 +00:00
|
|
|
_ = dom.render_immediate_to_vec();
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hooks_drop() {
|
2024-01-11 16:48:04 +00:00
|
|
|
fn App() -> Element {
|
2024-01-11 21:18:11 +00:00
|
|
|
once(|| String::from("asd"));
|
|
|
|
once(|| String::from("asd"));
|
|
|
|
once(|| String::from("asd"));
|
|
|
|
once(|| String::from("asd"));
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-11 01:21:15 +00:00
|
|
|
render! { div {} }
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-11 18:40:36 +00:00
|
|
|
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2024-01-11 01:21:15 +00:00
|
|
|
_ = dom.render_immediate_to_vec();
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn contexts_drop() {
|
2024-01-11 16:48:04 +00:00
|
|
|
fn App() -> Element {
|
2024-01-11 21:18:11 +00:00
|
|
|
provide_context(String::from("asd"));
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-11 01:21:15 +00:00
|
|
|
render! {
|
|
|
|
div { ChildComp {} }
|
|
|
|
}
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2024-01-11 17:11:44 +00:00
|
|
|
fn ChildComp() -> Element {
|
2024-01-11 21:18:11 +00:00
|
|
|
let el = consume_context::<String>().unwrap();
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-11 01:21:15 +00:00
|
|
|
render! { div { "hello {el}" } }
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-11 18:40:36 +00:00
|
|
|
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2024-01-11 01:21:15 +00:00
|
|
|
_ = dom.render_immediate_to_vec();
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 04:26:04 +00:00
|
|
|
#[test]
|
|
|
|
fn tasks_drop() {
|
2024-01-11 16:48:04 +00:00
|
|
|
fn App() -> Element {
|
2024-01-11 21:18:11 +00:00
|
|
|
spawn(async {
|
2022-12-17 04:26:04 +00:00
|
|
|
// tokio::time::sleep(std::time::Duration::from_millis(100000)).await;
|
2022-11-29 21:31:04 +00:00
|
|
|
});
|
|
|
|
|
2024-01-11 01:21:15 +00:00
|
|
|
render! { div {} }
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-11 18:40:36 +00:00
|
|
|
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2024-01-11 01:21:15 +00:00
|
|
|
_ = dom.render_immediate_to_vec();
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn root_props_drop() {
|
2024-01-11 18:40:36 +00:00
|
|
|
#[derive(Clone)]
|
2022-11-29 21:31:04 +00:00
|
|
|
struct RootProps(String);
|
|
|
|
|
|
|
|
let mut dom = VirtualDom::new_with_props(
|
2024-01-11 17:11:44 +00:00
|
|
|
|cx| render!( div { "{cx.0}" } ),
|
2022-11-29 21:31:04 +00:00
|
|
|
RootProps("asdasd".to_string()),
|
|
|
|
);
|
|
|
|
|
2024-01-11 18:40:36 +00:00
|
|
|
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2024-01-11 01:21:15 +00:00
|
|
|
_ = dom.render_immediate_to_vec();
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn diffing_drops_old() {
|
2024-01-11 16:48:04 +00:00
|
|
|
fn App() -> Element {
|
2024-01-11 01:21:15 +00:00
|
|
|
render! {
|
2022-11-29 21:31:04 +00:00
|
|
|
div {
|
2024-01-11 01:21:15 +00:00
|
|
|
match generation() % 2 {
|
|
|
|
0 => render!( ChildComp1 { name: "asdasd".to_string() }),
|
|
|
|
1 => render!( ChildComp2 { name: "asdasd".to_string() }),
|
2022-11-29 21:31:04 +00:00
|
|
|
_ => todo!()
|
|
|
|
}
|
|
|
|
}
|
2024-01-11 01:21:15 +00:00
|
|
|
}
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
2024-01-11 17:11:44 +00:00
|
|
|
fn ChildComp1(name: String) -> Element {
|
2024-01-11 01:21:15 +00:00
|
|
|
render! {"Hello {name}"}
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
2024-01-11 17:11:44 +00:00
|
|
|
fn ChildComp2(name: String) -> Element {
|
2024-01-11 01:21:15 +00:00
|
|
|
render! {"Goodbye {name}"}
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2024-01-11 18:40:36 +00:00
|
|
|
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-11 01:21:15 +00:00
|
|
|
_ = dom.render_immediate_to_vec();
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|