2021-10-22 01:16:39 -04:00
|
|
|
#![allow(unused, non_upper_case_globals)]
|
|
|
|
|
2021-07-30 16:07:42 -04:00
|
|
|
//! Rebuilding tests
|
|
|
|
//! ----------------
|
|
|
|
//!
|
|
|
|
//! This tests module ensures that the initial build of the virtualdom is correct.
|
|
|
|
//! This does not include dynamic tests or the diffing algorithm itself.
|
|
|
|
//!
|
|
|
|
//! It does prove that mounting works properly and the correct edit streams are generated.
|
|
|
|
//!
|
|
|
|
//! Don't have a good way to validate, everything is done manually ATM
|
|
|
|
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
use dioxus_core as dioxus;
|
2021-09-24 21:46:23 -04:00
|
|
|
use dioxus_core_macro::*;
|
2021-07-30 16:07:42 -04:00
|
|
|
use dioxus_html as dioxus_elements;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_runs() {
|
2021-11-07 20:59:09 -05:00
|
|
|
static App: FC<()> = |cx, props| {
|
2021-07-30 16:07:42 -04:00
|
|
|
//
|
2021-11-01 02:22:08 -04:00
|
|
|
cx.render(rsx!( div{"hello"} ))
|
2021-07-30 16:07:42 -04:00
|
|
|
};
|
|
|
|
let mut vdom = VirtualDom::new(App);
|
2021-08-24 15:12:20 -04:00
|
|
|
let edits = vdom.rebuild();
|
2021-07-30 16:07:42 -04:00
|
|
|
dbg!(edits);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fragments_work() {
|
2021-11-07 20:59:09 -05:00
|
|
|
static App: FC<()> = |cx, props| {
|
2021-11-01 02:22:08 -04:00
|
|
|
cx.render(rsx!(
|
2021-07-30 16:07:42 -04:00
|
|
|
div{"hello"}
|
|
|
|
div{"goodbye"}
|
2021-11-01 02:22:08 -04:00
|
|
|
))
|
2021-07-30 16:07:42 -04:00
|
|
|
};
|
|
|
|
let mut vdom = VirtualDom::new(App);
|
2021-08-24 15:12:20 -04:00
|
|
|
let edits = vdom.rebuild();
|
2021-07-30 16:07:42 -04:00
|
|
|
// should result in a final "appendchildren n=2"
|
|
|
|
dbg!(edits);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lists_work() {
|
2021-11-07 20:59:09 -05:00
|
|
|
static App: FC<()> = |cx, props| {
|
2021-11-01 02:22:08 -04:00
|
|
|
cx.render(rsx!(
|
2021-07-30 16:07:42 -04:00
|
|
|
h1 {"hello"}
|
|
|
|
{(0..6).map(|f| rsx!(span{ "{f}" }))}
|
2021-11-01 02:22:08 -04:00
|
|
|
))
|
2021-07-30 16:07:42 -04:00
|
|
|
};
|
|
|
|
let mut vdom = VirtualDom::new(App);
|
2021-08-24 15:12:20 -04:00
|
|
|
let edits = vdom.rebuild();
|
2021-07-30 16:07:42 -04:00
|
|
|
dbg!(edits);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn conditional_rendering() {
|
2021-11-07 20:59:09 -05:00
|
|
|
static App: FC<()> = |cx, props| {
|
2021-11-01 02:22:08 -04:00
|
|
|
cx.render(rsx!(
|
2021-07-30 16:07:42 -04:00
|
|
|
h1 {"hello"}
|
|
|
|
{true.then(|| rsx!(span{ "a" }))}
|
|
|
|
{false.then(|| rsx!(span{ "b" }))}
|
2021-11-01 02:22:08 -04:00
|
|
|
))
|
2021-07-30 16:07:42 -04:00
|
|
|
};
|
|
|
|
let mut vdom = VirtualDom::new(App);
|
|
|
|
|
2021-08-24 15:12:20 -04:00
|
|
|
let mutations = vdom.rebuild();
|
2021-08-15 10:13:03 -04:00
|
|
|
dbg!(&mutations);
|
2021-07-30 16:07:42 -04:00
|
|
|
// the "false" fragment should generate an empty placeholder to re-visit
|
2021-08-15 10:13:03 -04:00
|
|
|
assert!(mutations.edits[mutations.edits.len() - 2].is("CreatePlaceholder"));
|
2021-07-30 16:07:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn child_components() {
|
2021-11-07 20:59:09 -05:00
|
|
|
static App: FC<()> = |cx, props| {
|
2021-11-01 02:22:08 -04:00
|
|
|
cx.render(rsx!(
|
2021-07-30 16:07:42 -04:00
|
|
|
{true.then(|| rsx!(Child { }))}
|
|
|
|
{false.then(|| rsx!(Child { }))}
|
2021-11-01 02:22:08 -04:00
|
|
|
))
|
2021-07-30 16:07:42 -04:00
|
|
|
};
|
2021-11-07 20:59:09 -05:00
|
|
|
static Child: FC<()> = |cx, props| {
|
2021-11-01 02:22:08 -04:00
|
|
|
cx.render(rsx!(
|
2021-07-30 16:07:42 -04:00
|
|
|
h1 {"hello"}
|
|
|
|
h1 {"goodbye"}
|
2021-11-01 02:22:08 -04:00
|
|
|
))
|
2021-07-30 16:07:42 -04:00
|
|
|
};
|
|
|
|
let mut vdom = VirtualDom::new(App);
|
2021-08-24 15:12:20 -04:00
|
|
|
let edits = vdom.rebuild();
|
2021-07-30 16:07:42 -04:00
|
|
|
dbg!(edits);
|
|
|
|
}
|