2022-11-23 03:59:56 +00:00
|
|
|
//! Do we create fragments properly across complex boundaries?
|
|
|
|
|
|
|
|
use dioxus::core::Mutation::*;
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
use dioxus_core::ElementId;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn empty_fragment_creates_nothing() {
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
cx.render(rsx!(()))
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut vdom = VirtualDom::new(app);
|
|
|
|
let edits = vdom.rebuild();
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-01 05:46:15 +00:00
|
|
|
edits.edits,
|
2022-11-23 03:59:56 +00:00
|
|
|
[
|
2022-11-24 14:11:27 +00:00
|
|
|
CreatePlaceholder { id: ElementId(1) },
|
2022-12-03 00:24:49 +00:00
|
|
|
AppendChildren { id: ElementId(0), m: 1 }
|
2022-11-23 03:59:56 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn root_fragments_work() {
|
|
|
|
let mut vdom = VirtualDom::new(|cx| {
|
|
|
|
cx.render(rsx!(
|
|
|
|
div { "hello" }
|
|
|
|
div { "goodbye" }
|
|
|
|
))
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-01 05:46:15 +00:00
|
|
|
vdom.rebuild().edits.last().unwrap(),
|
2022-12-03 00:24:49 +00:00
|
|
|
&AppendChildren { id: ElementId(0), m: 2 }
|
2022-11-23 03:59:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fragments_nested() {
|
|
|
|
let mut vdom = VirtualDom::new(|cx| {
|
|
|
|
cx.render(rsx!(
|
|
|
|
div { "hello" }
|
|
|
|
div { "goodbye" }
|
|
|
|
rsx! {
|
|
|
|
div { "hello" }
|
|
|
|
div { "goodbye" }
|
|
|
|
rsx! {
|
|
|
|
div { "hello" }
|
|
|
|
div { "goodbye" }
|
|
|
|
rsx! {
|
|
|
|
div { "hello" }
|
|
|
|
div { "goodbye" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
))
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-01 05:46:15 +00:00
|
|
|
vdom.rebuild().edits.last().unwrap(),
|
2022-12-03 00:24:49 +00:00
|
|
|
&AppendChildren { id: ElementId(0), m: 8 }
|
2022-11-23 03:59:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fragments_across_components() {
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
cx.render(rsx! {
|
|
|
|
demo_child {}
|
|
|
|
demo_child {}
|
|
|
|
demo_child {}
|
|
|
|
demo_child {}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn demo_child(cx: Scope) -> Element {
|
|
|
|
let world = "world";
|
|
|
|
cx.render(rsx! {
|
|
|
|
"hellO!"
|
|
|
|
world
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-01 05:46:15 +00:00
|
|
|
VirtualDom::new(app).rebuild().edits.last().unwrap(),
|
2022-12-03 00:24:49 +00:00
|
|
|
&AppendChildren { id: ElementId(0), m: 8 }
|
2022-11-23 03:59:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn list_fragments() {
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
cx.render(rsx!(
|
|
|
|
h1 {"hello"}
|
|
|
|
(0..6).map(|f| rsx!( span { "{f}" }))
|
|
|
|
))
|
|
|
|
}
|
|
|
|
assert_eq!(
|
2022-12-01 05:46:15 +00:00
|
|
|
VirtualDom::new(app).rebuild().edits.last().unwrap(),
|
2022-12-03 00:24:49 +00:00
|
|
|
&AppendChildren { id: ElementId(0), m: 7 }
|
2022-11-23 03:59:56 +00:00
|
|
|
);
|
|
|
|
}
|