fix event tests in core
This commit is contained in:
1 parent
0388a5c1f4
commit
7ffb204eac
3 files changed
+10
-12
No files matched your search
+1
-1
@@ -26,7 +26,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
button {
|
button {
|
||||||
onclick: move |_| {
|
onclick: move |_| {
|
||||||
let dom = VirtualDom::new_with_props(compose, ComposeProps { app_tx: tx.clone() });
|
let dom = VirtualDom::new_with_props(compose, ComposeProps { app_tx: tx.clone() });
|
||||||
window.new_window(dom, Default::default());
|
dioxus_desktop::window().new_window(dom, Default::default());
|
||||||
},
|
},
|
||||||
"Click to compose a new email"
|
"Click to compose a new email"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ static CLICKS: Mutex<usize> = Mutex::new(0);
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn events_propagate() {
|
fn events_propagate() {
|
||||||
|
set_event_converter(Box::new(dioxus_html::SerializedHtmlEventConverter));
|
||||||
|
|
||||||
let mut dom = VirtualDom::new(app);
|
let mut dom = VirtualDom::new(app);
|
||||||
_ = dom.rebuild();
|
_ = dom.rebuild();
|
||||||
|
|
||||||
// Top-level click is registered
|
// Top-level click is registered
|
||||||
dom.handle_event("click", Rc::new(MouseData::default()), ElementId(1), true);
|
dom.handle_event("click", Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())), ElementId(1), true);
|
||||||
assert_eq!(*CLICKS.lock().unwrap(), 1);
|
assert_eq!(*CLICKS.lock().unwrap(), 1);
|
||||||
|
|
||||||
// break reference....
|
// break reference....
|
||||||
@@ -20,7 +22,7 @@ fn events_propagate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lower click is registered
|
// Lower click is registered
|
||||||
dom.handle_event("click", Rc::new(MouseData::default()), ElementId(2), true);
|
dom.handle_event("click", Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())), ElementId(2), true);
|
||||||
assert_eq!(*CLICKS.lock().unwrap(), 3);
|
assert_eq!(*CLICKS.lock().unwrap(), 3);
|
||||||
|
|
||||||
// break reference....
|
// break reference....
|
||||||
@@ -30,14 +32,13 @@ fn events_propagate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stop propagation occurs
|
// Stop propagation occurs
|
||||||
dom.handle_event("click", Rc::new(MouseData::default()), ElementId(2), true);
|
dom.handle_event("click", Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())), ElementId(2), true);
|
||||||
assert_eq!(*CLICKS.lock().unwrap(), 3);
|
assert_eq!(*CLICKS.lock().unwrap(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
render! {
|
render! {
|
||||||
div {
|
div { onclick: move |_| {
|
||||||
onclick: move |_| {
|
|
||||||
println!("top clicked");
|
println!("top clicked");
|
||||||
*CLICKS.lock().unwrap() += 1;
|
*CLICKS.lock().unwrap() += 1;
|
||||||
},
|
},
|
||||||
@@ -53,17 +54,14 @@ fn app(cx: Scope) -> Element {
|
|||||||
|
|
||||||
fn problematic_child(cx: Scope) -> Element {
|
fn problematic_child(cx: Scope) -> Element {
|
||||||
render! {
|
render! {
|
||||||
button {
|
button { onclick: move |evt| {
|
||||||
onclick: move |evt| {
|
|
||||||
println!("bottom clicked");
|
println!("bottom clicked");
|
||||||
let mut clicks = CLICKS.lock().unwrap();
|
let mut clicks = CLICKS.lock().unwrap();
|
||||||
|
|
||||||
if *clicks == 3 {
|
if *clicks == 3 {
|
||||||
evt.stop_propagation();
|
evt.stop_propagation();
|
||||||
} else {
|
} else {
|
||||||
*clicks += 1;
|
*clicks += 1;
|
||||||
}
|
}
|
||||||
}
|
} }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ keywords = ["dom", "ui", "gui", "react", "ssr"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dioxus-core = { workspace = true, features = ["serialize"] }
|
dioxus-core = { workspace = true, features = ["serialize"] }
|
||||||
dioxus-html = { workspace = true }
|
dioxus-html = { workspace = true, features = ["eval"]}
|
||||||
askama_escape = "0.10.3"
|
askama_escape = "0.10.3"
|
||||||
thiserror = "1.0.23"
|
thiserror = "1.0.23"
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
|
|||||||
Reference in new issue
Block a user