2022-11-16 00:05:22 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple() {
|
2024-01-15 17:12:24 +00:00
|
|
|
fn App() -> Element {
|
2022-11-16 00:05:22 +00:00
|
|
|
render! { div { "hello!" } }
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2024-01-10 23:57:15 +00:00
|
|
|
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2022-12-07 01:41:47 +00:00
|
|
|
|
|
|
|
assert_eq!(dioxus_ssr::render(&dom), "<div>hello!</div>");
|
2022-11-16 00:05:22 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
2024-01-10 23:57:15 +00:00
|
|
|
dioxus_ssr::render_element(render!( div {"hello!"} )),
|
2022-11-16 00:05:22 +00:00
|
|
|
"<div>hello!</div>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lists() {
|
2022-12-07 01:41:47 +00:00
|
|
|
assert_eq!(
|
2024-01-10 23:57:15 +00:00
|
|
|
dioxus_ssr::render_element(render! {
|
2022-11-16 00:05:22 +00:00
|
|
|
ul {
|
2024-01-15 17:12:24 +00:00
|
|
|
{
|
|
|
|
(0..5).map(|i| render! {
|
|
|
|
li { "item {i}" }
|
|
|
|
})
|
2024-01-11 03:33:34 +00:00
|
|
|
}
|
2022-11-16 00:05:22 +00:00
|
|
|
}
|
2022-12-07 01:41:47 +00:00
|
|
|
}),
|
2022-11-16 00:05:22 +00:00
|
|
|
"<ul><li>item 0</li><li>item 1</li><li>item 2</li><li>item 3</li><li>item 4</li></ul>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dynamic() {
|
2022-12-07 01:41:47 +00:00
|
|
|
let dynamic = 123;
|
2022-11-16 00:05:22 +00:00
|
|
|
assert_eq!(
|
2024-01-10 23:57:15 +00:00
|
|
|
dioxus_ssr::render_element(render! {
|
2022-12-07 01:41:47 +00:00
|
|
|
div { "Hello world 1 -->" "{dynamic}" "<-- Hello world 2" }
|
|
|
|
}),
|
2023-02-14 15:06:59 +00:00
|
|
|
"<div>Hello world 1 -->123<-- Hello world 2</div>"
|
2022-11-16 00:05:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn components() {
|
2024-01-10 23:57:15 +00:00
|
|
|
#[derive(Props, Clone, PartialEq)]
|
|
|
|
struct MyComponentProps {
|
|
|
|
name: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn MyComponent(MyComponentProps { name }: MyComponentProps) -> Element {
|
2023-12-27 16:17:18 +00:00
|
|
|
render! { div { "component {name}" } }
|
2022-11-16 00:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-01-10 23:57:15 +00:00
|
|
|
dioxus_ssr::render_element(render! {
|
2022-12-07 01:41:47 +00:00
|
|
|
div {
|
2024-01-15 17:12:24 +00:00
|
|
|
{
|
|
|
|
(0..5).map(|name| render! {
|
|
|
|
MyComponent { name: name }
|
|
|
|
})
|
2024-01-11 03:33:34 +00:00
|
|
|
}
|
2022-12-07 01:41:47 +00:00
|
|
|
}
|
|
|
|
}),
|
2022-11-16 00:05:22 +00:00
|
|
|
"<div><div>component 0</div><div>component 1</div><div>component 2</div><div>component 3</div><div>component 4</div></div>"
|
|
|
|
);
|
|
|
|
}
|
2022-12-07 01:41:47 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fragments() {
|
|
|
|
assert_eq!(
|
2024-01-10 23:57:15 +00:00
|
|
|
dioxus_ssr::render_element(render! {
|
2022-12-07 01:41:47 +00:00
|
|
|
div {
|
2024-01-15 17:12:24 +00:00
|
|
|
{
|
|
|
|
(0..5).map(|_| render! ({}))
|
|
|
|
}
|
2022-12-07 01:41:47 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
"<div></div>"
|
|
|
|
);
|
|
|
|
}
|