2021-10-22 05:16:39 +00:00
|
|
|
#![allow(unused, non_upper_case_globals)]
|
|
|
|
|
2021-11-09 17:10:11 +00:00
|
|
|
use dioxus::{prelude::*, DomEdit, Mutations};
|
2021-09-16 17:20:04 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn shared_state_test() {
|
|
|
|
struct MySharedState(&'static str);
|
|
|
|
|
2021-12-29 04:48:25 +00:00
|
|
|
static App: Component = |cx| {
|
2021-12-29 04:20:01 +00:00
|
|
|
cx.provide_context(MySharedState("world!"));
|
2021-11-01 06:22:08 +00:00
|
|
|
cx.render(rsx!(Child {}))
|
2021-09-16 17:20:04 +00:00
|
|
|
};
|
|
|
|
|
2021-12-29 04:48:25 +00:00
|
|
|
static Child: Component = |cx| {
|
2021-12-29 04:20:01 +00:00
|
|
|
let shared = cx.consume_context::<MySharedState>()?;
|
2021-11-01 06:22:08 +00:00
|
|
|
cx.render(rsx!("Hello, {shared.0}"))
|
2021-09-16 17:20:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut dom = VirtualDom::new(App);
|
|
|
|
let Mutations { edits, .. } = dom.rebuild();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
edits,
|
|
|
|
[
|
|
|
|
CreateTextNode {
|
2021-11-12 02:50:08 +00:00
|
|
|
root: 1,
|
2021-09-16 17:20:04 +00:00
|
|
|
text: "Hello, world!"
|
|
|
|
},
|
|
|
|
AppendChildren { many: 1 },
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|