2021-09-16 17:20:04 +00:00
|
|
|
use dioxus::{nodes::VSuspended, prelude::*, DomEdit, TestDom};
|
|
|
|
use dioxus_core as dioxus;
|
2021-09-25 01:46:23 +00:00
|
|
|
use dioxus_core_macro::*;
|
2021-09-16 17:20:04 +00:00
|
|
|
use dioxus_html as dioxus_elements;
|
2021-09-25 01:46:23 +00:00
|
|
|
|
2021-09-16 17:20:04 +00:00
|
|
|
use DomEdit::*;
|
|
|
|
|
|
|
|
mod test_logging;
|
|
|
|
|
|
|
|
fn new_dom() -> TestDom {
|
|
|
|
const IS_LOGGING_ENABLED: bool = false;
|
|
|
|
test_logging::set_up_logging(IS_LOGGING_ENABLED);
|
|
|
|
TestDom::new()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn shared_state_test() {
|
|
|
|
struct MySharedState(&'static str);
|
|
|
|
|
2021-10-16 21:37:28 +00:00
|
|
|
static App: FC<()> = |(cx, props)| {
|
2021-10-11 19:35:20 +00:00
|
|
|
cx.provide_state(MySharedState("world!"));
|
2021-09-16 17:20:04 +00:00
|
|
|
rsx!(cx, Child {})
|
|
|
|
};
|
|
|
|
|
2021-10-16 21:37:28 +00:00
|
|
|
static Child: FC<()> = |(cx, props)| {
|
2021-10-11 19:35:20 +00:00
|
|
|
let shared = cx.consume_state::<MySharedState>()?;
|
2021-09-16 17:20:04 +00:00
|
|
|
rsx!(cx, "Hello, {shared.0}")
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut dom = VirtualDom::new(App);
|
|
|
|
let Mutations { edits, .. } = dom.rebuild();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
edits,
|
|
|
|
[
|
|
|
|
CreateTextNode {
|
2021-10-05 07:37:15 +00:00
|
|
|
root: 0,
|
2021-09-16 17:20:04 +00:00
|
|
|
text: "Hello, world!"
|
|
|
|
},
|
|
|
|
AppendChildren { many: 1 },
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|