mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-12-04 01:49:11 +00:00
cbeda0af76
* wip * pull out eval into the interpreter * fix web eval * fix DioxusChannel name * properly drop dioxus channel * use typescript dioxus chanel in desktop * add more comments to native eval * add desktop headless eval tests * expand web playwright eval tests * fix web headless tests * fix default hasher path * run eval tests on windows * restore desktop query drop code * remove data from drop desktop query message * catch syntax errors in desktop eval * catch js runtime errors in desktop * fix typo interprerter -> interpreter --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
71 lines
1.9 KiB
Rust
71 lines
1.9 KiB
Rust
use dioxus::prelude::*;
|
|
use dioxus_desktop::DesktopContext;
|
|
|
|
#[path = "./utils.rs"]
|
|
mod utils;
|
|
|
|
fn main() {
|
|
#[cfg(not(windows))]
|
|
utils::check_app_exits(check_html_renders);
|
|
}
|
|
|
|
fn use_inner_html(id: &'static str) -> Option<String> {
|
|
let mut value = use_signal(|| None as Option<String>);
|
|
|
|
use_effect(move || {
|
|
spawn(async move {
|
|
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
|
|
|
let res = eval(&format!(
|
|
r#"let element = document.getElementById('{}');
|
|
return element.innerHTML"#,
|
|
id
|
|
))
|
|
.await
|
|
.unwrap();
|
|
|
|
if let Some(html) = res.as_str() {
|
|
println!("html: {}", html);
|
|
value.set(Some(html.to_string()));
|
|
}
|
|
});
|
|
});
|
|
|
|
value()
|
|
}
|
|
|
|
const EXPECTED_HTML: &str = r#"<div style="width: 100px; height: 100px; color: rgb(0, 0, 0);" id="5"><input type="checkbox"><h1>text</h1><div><p>hello world</p></div></div>"#;
|
|
|
|
fn check_html_renders() -> Element {
|
|
let inner_html = use_inner_html("main_div");
|
|
|
|
let desktop_context: DesktopContext = consume_context();
|
|
|
|
if let Some(raw_html) = inner_html {
|
|
println!("{}", raw_html);
|
|
let fragment = &raw_html;
|
|
let expected = EXPECTED_HTML;
|
|
assert_eq!(raw_html, EXPECTED_HTML);
|
|
if fragment == expected {
|
|
println!("html matches");
|
|
desktop_context.close();
|
|
}
|
|
}
|
|
|
|
let dyn_value = 0;
|
|
let dyn_element = rsx! { div { dangerous_inner_html: "<p>hello world</p>" } };
|
|
|
|
rsx! {
|
|
div { id: "main_div",
|
|
div {
|
|
width: "100px",
|
|
height: "100px",
|
|
color: "rgb({dyn_value}, {dyn_value}, {dyn_value})",
|
|
id: 5,
|
|
input { "type": "checkbox" }
|
|
h1 { "text" }
|
|
{dyn_element}
|
|
}
|
|
}
|
|
}
|
|
}
|