Fix cargo test and a number of little cleanup bugs
This commit is contained in:
49 files changed
+307
-309
No files matched your search
@@ -79,7 +79,7 @@ default-features = false
|
||||
features = ["tokio_runtime", "hot-reload"]
|
||||
|
||||
[dev-dependencies]
|
||||
dioxus = { workspace = true }
|
||||
dioxus = { workspace = true, features = ["desktop"] }
|
||||
exitcode = "1.1.2"
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
@@ -3,6 +3,10 @@ use dioxus::prelude::*;
|
||||
use dioxus_core::prelude::consume_context;
|
||||
use dioxus_desktop::DesktopContext;
|
||||
|
||||
pub fn main() {
|
||||
check_app_exits(app);
|
||||
}
|
||||
|
||||
pub(crate) fn check_app_exits(app: fn() -> Element) {
|
||||
use dioxus_desktop::tao::window::WindowBuilder;
|
||||
use dioxus_desktop::Config;
|
||||
@@ -10,7 +14,7 @@ pub(crate) fn check_app_exits(app: fn() -> Element) {
|
||||
let should_panic = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(true));
|
||||
let should_panic_clone = should_panic.clone();
|
||||
std::thread::spawn(move || {
|
||||
std::thread::sleep(std::time::Duration::from_secs(100));
|
||||
std::thread::sleep(std::time::Duration::from_secs(5));
|
||||
if should_panic_clone.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
std::process::exit(exitcode::SOFTWARE);
|
||||
}
|
||||
@@ -24,14 +28,10 @@ pub(crate) fn check_app_exits(app: fn() -> Element) {
|
||||
should_panic.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
check_app_exits(app);
|
||||
}
|
||||
|
||||
fn mock_event(id: &'static str, value: &'static str) {
|
||||
use_effect(move || {
|
||||
use_hook(move || {
|
||||
spawn(async move {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(2000)).await;
|
||||
|
||||
let js = format!(
|
||||
r#"
|
||||
@@ -45,7 +45,7 @@ fn mock_event(id: &'static str, value: &'static str) {
|
||||
value, id
|
||||
);
|
||||
|
||||
dioxus::eval(js);
|
||||
eval(&js).unwrap().await.unwrap();
|
||||
});
|
||||
})
|
||||
}
|
||||
@@ -205,7 +205,7 @@ fn app() -> Element {
|
||||
r#"new FocusEvent("focusout",{bubbles: true})"#,
|
||||
);
|
||||
|
||||
if received_events() == 13 {
|
||||
if received_events() == 12 {
|
||||
println!("all events recieved");
|
||||
desktop_context.close();
|
||||
}
|
||||
@@ -216,12 +216,11 @@ fn app() -> Element {
|
||||
width: "100px",
|
||||
height: "100px",
|
||||
onmounted: move |evt| async move {
|
||||
todo!();
|
||||
// let rect = evt.get_client_rect().await.unwrap();
|
||||
// println!("rect: {:?}", rect);
|
||||
// assert_eq!(rect.width(), 100.0);
|
||||
// assert_eq!(rect.height(), 100.0);
|
||||
// received_events.with_mut(|x| *x + 1)
|
||||
let rect = evt.get_client_rect().await.unwrap();
|
||||
println!("rect: {:?}", rect);
|
||||
assert_eq!(rect.width(), 100.0);
|
||||
assert_eq!(rect.height(), 100.0);
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
button {
|
||||
@@ -234,7 +233,7 @@ fn app() -> Element {
|
||||
event.data.trigger_button(),
|
||||
Some(dioxus_html::input_data::MouseButton::Primary),
|
||||
);
|
||||
received_events.with_mut(|x| *x + 1);
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
div {
|
||||
@@ -248,7 +247,7 @@ fn app() -> Element {
|
||||
.held_buttons()
|
||||
.contains(dioxus_html::input_data::MouseButton::Secondary),
|
||||
);
|
||||
received_events.with_mut(|x| *x + 1);
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
div {
|
||||
@@ -266,7 +265,7 @@ fn app() -> Element {
|
||||
event.data.trigger_button(),
|
||||
Some(dioxus_html::input_data::MouseButton::Secondary),
|
||||
);
|
||||
received_events.with_mut(|x| *x + 1);
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
div {
|
||||
@@ -287,7 +286,7 @@ fn app() -> Element {
|
||||
event.data.trigger_button(),
|
||||
Some(dioxus_html::input_data::MouseButton::Secondary),
|
||||
);
|
||||
received_events.with_mut(|x| *x + 1);
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
div {
|
||||
@@ -305,7 +304,7 @@ fn app() -> Element {
|
||||
event.data.trigger_button(),
|
||||
Some(dioxus_html::input_data::MouseButton::Secondary),
|
||||
);
|
||||
received_events.with_mut(|x| *x + 1);
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
div {
|
||||
@@ -318,7 +317,7 @@ fn app() -> Element {
|
||||
event.data.trigger_button(),
|
||||
Some(dioxus_html::input_data::MouseButton::Primary),
|
||||
);
|
||||
received_events.with_mut(|x| *x + 1);
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
div {
|
||||
@@ -331,7 +330,7 @@ fn app() -> Element {
|
||||
let dioxus_html::geometry::WheelDelta::Pixels(delta) = event.data.delta() else {
|
||||
panic!("Expected delta to be in pixels") };
|
||||
assert_eq!(delta, Vector3D::new(1.0, 2.0, 3.0));
|
||||
received_events.with_mut(|x| *x + 1);
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
input {
|
||||
@@ -344,7 +343,7 @@ fn app() -> Element {
|
||||
assert_eq!(event.data.location(), Location::Standard);
|
||||
assert!(event.data.is_auto_repeating());
|
||||
assert!(event.data.is_composing());
|
||||
received_events.with_mut(|x| *x + 1)
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
input {
|
||||
@@ -357,7 +356,7 @@ fn app() -> Element {
|
||||
assert_eq!(event.data.location(), Location::Standard);
|
||||
assert!(!event.data.is_auto_repeating());
|
||||
assert!(!event.data.is_composing());
|
||||
received_events.with_mut(|x| *x + 1)
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
input {
|
||||
@@ -370,21 +369,21 @@ fn app() -> Element {
|
||||
assert_eq!(event.data.location(), Location::Standard);
|
||||
assert!(!event.data.is_auto_repeating());
|
||||
assert!(!event.data.is_composing());
|
||||
received_events.with_mut(|x| *x + 1)
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
input {
|
||||
id: "focus_in_div",
|
||||
onfocusin: move |event| {
|
||||
println!("{:?}", event.data);
|
||||
received_events.with_mut(|x| *x + 1);
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
input {
|
||||
id: "focus_out_div",
|
||||
onfocusout: move |event| {
|
||||
println!("{:?}", event.data);
|
||||
received_events.with_mut(|x| *x + 1);
|
||||
received_events.with_mut(|x| *x += 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ pub(crate) fn check_app_exits(app: fn() -> Element) {
|
||||
let should_panic = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(true));
|
||||
let should_panic_clone = should_panic.clone();
|
||||
std::thread::spawn(move || {
|
||||
std::thread::sleep(std::time::Duration::from_secs(100));
|
||||
std::thread::sleep(std::time::Duration::from_secs(5));
|
||||
if should_panic_clone.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
std::process::exit(exitcode::SOFTWARE);
|
||||
}
|
||||
@@ -31,19 +31,21 @@ fn use_inner_html(id: &'static str) -> Option<String> {
|
||||
|
||||
use_effect(move || {
|
||||
spawn(async move {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(2000)).await;
|
||||
|
||||
let res = dioxus::eval(format!(
|
||||
let res = eval(&format!(
|
||||
r#"let element = document.getElementById('{}');
|
||||
return element.innerHTML"#,
|
||||
id
|
||||
))
|
||||
.await;
|
||||
.unwrap()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if let Ok(html) = res {
|
||||
if let Some(html) = res.as_str() {
|
||||
// serde_json::Value::String(html)
|
||||
println!("html: {}", html);
|
||||
value.set(Some(html));
|
||||
value.set(Some(html.to_string()));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -51,7 +53,7 @@ fn use_inner_html(id: &'static str) -> Option<String> {
|
||||
value.read().clone()
|
||||
}
|
||||
|
||||
const EXPECTED_HTML: &str = r#"<div id="5" style="width: 100px; height: 100px; color: rgb(0, 0, 0);"><input type="checkbox"><h1>text</h1><div><p>hello world</p></div></div>"#;
|
||||
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");
|
||||
@@ -62,10 +64,6 @@ fn check_html_renders() -> Element {
|
||||
println!("{}", raw_html);
|
||||
let fragment = &raw_html;
|
||||
let expected = EXPECTED_HTML;
|
||||
// let fragment = scraper::Html::parse_fragment(&raw_html);
|
||||
// println!("fragment: {}", fragment.html());
|
||||
// let expected = scraper::Html::parse_fragment(EXPECTED_HTML);
|
||||
// println!("expected: {}", expected.html());
|
||||
assert_eq!(raw_html, EXPECTED_HTML);
|
||||
if fragment == expected {
|
||||
println!("html matches");
|
||||
|
||||
Reference in new issue
Block a user