chore: tweak fragments and tests

This commit is contained in:
Jonathan Kelley committed 2022-11-22 19:59:56 -08:00
1 parent 0e5a59f9ed
commit 4bfd936e12
9 files changed
+638 -539

No files matched your search

+10
View File
@@ -18,3 +18,13 @@ fn root_node_isnt_null() {
// todo: there should also be a default error boundary
assert!(scope.has_context::<SuspenseContext>().is_some());
}
#[test]
fn elements() {
let mut dom = VirtualDom::new(|cx| {
//
cx.render(rsx!( div { "Hello world!" } ))
});
let muts = dom.rebuild();
}
+104
View File
@@ -0,0 +1,104 @@
//! 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!(
edits.edits,
[
CreatePlaceholder { id: ElementId(2) },
AppendChildren { m: 1 }
]
);
}
#[test]
fn root_fragments_work() {
let mut vdom = VirtualDom::new(|cx| {
cx.render(rsx!(
div { "hello" }
div { "goodbye" }
))
});
assert_eq!(
vdom.rebuild().edits.last().unwrap(),
&AppendChildren { m: 2 }
);
}
#[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!(
vdom.rebuild().edits.last().unwrap(),
&AppendChildren { m: 8 }
);
}
#[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!(
VirtualDom::new(app).rebuild().edits.last().unwrap(),
&AppendChildren { m: 8 }
);
}
#[test]
fn list_fragments() {
fn app(cx: Scope) -> Element {
cx.render(rsx!(
h1 {"hello"}
(0..6).map(|f| rsx!( span { "{f}" }))
))
}
assert_eq!(
VirtualDom::new(app).rebuild().edits.last().unwrap(),
&AppendChildren { m: 7 }
);
}