use std::convert::TryFrom;
use mogwai::{
builder::{DecomposedViewBuilder, ViewBuilder},
channel::broadcast,
patch::HashPatch,
target::Streamable,
view::{Dom, View},
};
use mogwai_html_macro::{builder, view};
#[test]
fn expand_this_builder() {
let _ = builder! {
};
}
#[test]
fn node_self_closing() {
// not all nodes are void nodes
let div: String = view! {
}
.into();
assert_eq!(&div, r#""#);
let div: String = view! {
}
.into();
assert_eq!(&div, r#""#);
}
#[test]
fn node_self_closing_gt_1_att() {
let decomp: DecomposedViewBuilder =
builder! {}.into();
assert_eq!(
decomp.attribs[0],
HashPatch::Insert("href".to_string(), "http://zyghost.com".to_string())
);
// not all nodes are void nodes
let div: String = view! {}.into();
assert_eq!(&div, r#""#);
let div: String = view! {}.into();
assert_eq!(
&div,
r#""#
);
}
#[test]
fn by_hand() {
let builder: ViewBuilder = ViewBuilder::element("a")
.with_single_attrib_stream("href", "http://zyghost.com")
.with_single_attrib_stream("class", "a_link")
.with_child(ViewBuilder::text("a text node"));
assert_eq!(
r#"a text node"#,
String::from(View::try_from(builder).unwrap())
);
}
#[test]
fn node() {
let div: String = view! {
"a text node"
}
.into();
assert_eq!(
&div,
r#"a text node"#
);
}
#[test]
fn block_in_text() {
let x: u32 = 66;
let s: String = view! {
"just a string with the number" {format!("{}", x)} "<- blah blah"
}
.into();
assert_eq!(
s,
format!("just a string with the number 66 <- blah blah
")
);
}
#[test]
fn block_at_end_of_text() {
let x: u32 = 66;
let s: String = view! {
"just a string with the number" {format!("{}", x)}
}
.into();
assert_eq!(&s, "just a string with the number 66
");
}
#[test]
fn lt_in_text() {
let s: String = view! {
"this is text <- text"
}
.into();
assert_eq!(s, "this is text <- text
");
}
#[test]
fn allow_attributes_on_next_line() {
let _: String = view! {
"A string"
}
.into();
}
#[test]
fn rsx_cookbook() {
let (_tx, rx) = broadcast::bounded::(1);
let _ = signed_in_view_builder(
&User {
username: "oona".to_string(),
o_image: None,
},
rx.clone(),
rx.clone(),
rx.clone(),
rx,
);
}
struct User {
username: String,
o_image: Option,
}
fn signed_in_view_builder(
user: &User,
home_class: impl Streamable,
editor_class: impl Streamable,
settings_class: impl Streamable,
profile_class: impl Streamable,
) -> ViewBuilder {
let o_image: Option> = user
.o_image
.as_ref()
.map(|image| {
if image.is_empty() {
None
} else {
Some(builder! { })
}
})
.flatten();
builder! {
}
}
#[cfg(feature = "never")]
#[test]
pub fn struct_view_macro_source() {
struct_view! {
"Hello"
}
let (facade, builder): (Facade, _) = Facade::new();
let view = Component::from(builder).build().unwrap();
view.run().unwrap();
let mut remote_facade: Facade = facade.clone();
mogwai::spawn(async move {
remote_facade.set_bg_color("red").await.unwrap();
let _event: DomEvent = remote_facade.get_click().await.unwrap();
});
}