feat: more tests working

This commit is contained in:
Jonathan Kelley committed 2022-11-24 06:47:14 -05:00
1 parent 4dd9a616a5
commit 0cfbfc88e2
16 files changed
+568 -248

No files matched your search

-24
View File
@@ -1,24 +0,0 @@
fn component(cx: Scope) -> Element {
cx.render(rsx! {
div { hidden: false }
})
}
use dioxus::prelude::*;
#[test]
fn bool_test() {
let mut app = VirtualDom::new(component);
let edits = app.rebuild();
use dioxus_core::{ElementId, Mutation::*};
assert_eq!(
edits.edits,
vec![
LoadTemplate { name: "packages/dioxus/tests/boolattrs.rs:2:15:66", index: 0 },
AssignId { path: &[], id: ElementId(2,) },
SetBoolAttribute { name: "hidden", value: false, id: ElementId(2,) },
AppendChildren { m: 1 },
]
)
}
-46
View File
@@ -1,46 +0,0 @@
#![allow(non_snake_case)]
use dioxus::prelude::*;
#[test]
fn test_borrowed_state() {
let _ = VirtualDom::new(Parent);
}
fn Parent(cx: Scope) -> Element {
let value = cx.use_hook(String::new);
cx.render(rsx! {
div {
Child { name: value }
Child { name: value }
Child { name: value }
Child { name: value }
}
})
}
#[derive(Props)]
struct ChildProps<'a> {
name: &'a str,
}
fn Child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
cx.render(rsx! {
div {
h1 { "it's nested" }
Child2 { name: cx.props.name }
}
})
}
#[derive(Props)]
struct Grandchild<'a> {
name: &'a str,
}
fn Child2<'a>(cx: Scope<'a, Grandchild<'a>>) -> Element {
cx.render(rsx! {
div { "Hello {cx.props.name}!" }
})
}
-100
View File
@@ -1,100 +0,0 @@
#![allow(unused, non_upper_case_globals)]
#![allow(non_snake_case)]
//! Diffing Tests
//!
//! These tests only verify that the diffing algorithm works properly for single components.
//!
//! It does not validated that component lifecycles work properly. This is done in another test file.
use dioxus::prelude::*;
fn new_dom() -> VirtualDom {
VirtualDom::new(|cx| render!("hi"))
}
use dioxus_core::DomEdit::*;
/// Should push the text node onto the stack and modify it
#[test]
fn nested_passthru_creates() {
fn app(cx: Scope) -> Element {
cx.render(rsx! {
Child {
Child {
Child {
div {
"hi"
}
}
}
}
})
};
#[inline_props]
fn Child<'a>(cx: Scope, children: Element<'a>) -> Element {
cx.render(rsx! { children })
};
let mut dom = VirtualDom::new(app);
let mut channel = dom.get_scheduler_channel();
assert!(dom.has_work());
let edits = dom.rebuild();
assert_eq!(
edits.edits,
[
CreateElement { tag: "div", root: Some(1), children: 0 },
CreateTextNode { text: "hi", root: Some(2) },
AppendChildren { root: Some(1), children: vec![2] },
AppendChildren { root: Some(0), children: vec![1] },
]
)
}
/// Should push the text node onto the stack and modify it
#[test]
fn nested_passthru_creates_add() {
fn app(cx: Scope) -> Element {
cx.render(rsx! {
Child {
"1"
Child {
"2"
Child {
"3"
div {
"hi"
}
}
}
}
})
};
#[inline_props]
fn Child<'a>(cx: Scope, children: Element<'a>) -> Element {
cx.render(rsx! {
children
})
};
let mut dom = VirtualDom::new(app);
let mut channel = dom.get_scheduler_channel();
assert!(dom.has_work());
let edits = dom.rebuild();
assert_eq!(
edits.edits,
[
CreateTextNode { text: "1", root: Some(1) },
CreateTextNode { text: "2", root: Some(2) },
CreateTextNode { text: "3", root: Some(3) },
CreateElement { tag: "div", root: Some(4), children: 0 },
CreateTextNode { text: "hi", root: Some(5) },
AppendChildren { root: Some(4), children: vec![5] },
AppendChildren { root: Some(0), children: vec![1, 2, 3, 4] },
]
)
}
-6
View File
@@ -1,6 +0,0 @@
//! Tests for the scheduler.
//!
//! TODO
//! - priority lanes
//! - periodic checking
//!
+25 -29
View File
@@ -1,18 +1,37 @@
use std::future::IntoFuture;
use std::{future::IntoFuture, rc::Rc};
use dioxus::prelude::*;
use dioxus_core::SuspenseBoundary;
#[tokio::test]
async fn basic_prints() {
let mut dom = VirtualDom::new(|cx| {
cx.render(rsx! {
div {
h1 { "var" }
suspense_boundary {
basic_child { }
async_child { }
}
}
})
});
dbg!(dom.rebuild());
dom.wait_for_work().await;
dbg!(dom.rebuild());
}
#[inline_props]
fn suspense_boundary<'a>(cx: Scope<'a>, children: Element<'a>) -> Element {
cx.use_hook(|| cx.provide_context(SuspenseBoundary::new(cx.scope_id())));
cx.use_hook(|| cx.provide_context(Rc::new(SuspenseBoundary::new(cx.scope_id()))));
cx.render(rsx! { children })
}
fn basic_child(cx: Scope) -> Element {
cx.render(rsx! {
div { "basic child 1" }
})
cx.render(rsx!( div { "basic child 1" } ))
}
async fn async_child(cx: Scope<'_>) -> Element {
@@ -38,28 +57,5 @@ async fn async_child(cx: Scope<'_>) -> Element {
let (username, age) = tokio::join!(username.into_future(), age.into_future());
cx.render(rsx!(
div { "Hello! {username}, you are {age}, {_user} {_age}" }
))
}
#[tokio::test]
async fn basic_prints() {
let mut dom = VirtualDom::new(|cx| {
cx.render(rsx! {
div {
h1 { "var" }
suspense_boundary {
basic_child { }
async_child { }
}
}
})
});
dbg!(dom.rebuild());
dom.wait_for_work().await;
dbg!(dom.rebuild());
cx.render(rsx!( div { "Hello! {username}, you are {age}, {_user} {_age}" } ))
}