fix events test
This commit is contained in:
1 parent
b090f662f4
commit
70687748d3
2 files changed
+49
-8
No files matched your search
@@ -11,10 +11,12 @@ fn mock_event(cx: &ScopeState, id: &'static str, value: &'static str) {
|
|||||||
use_effect(cx, (), |_| {
|
use_effect(cx, (), |_| {
|
||||||
let desktop_context: DesktopContext = cx.consume_context().unwrap();
|
let desktop_context: DesktopContext = cx.consume_context().unwrap();
|
||||||
async move {
|
async move {
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||||
desktop_context.eval(&format!(
|
desktop_context.eval(&format!(
|
||||||
r#"let element = document.getElementById('{}');
|
r#"let element = document.getElementById('{}');
|
||||||
// Dispatch a synthetic event
|
// Dispatch a synthetic event
|
||||||
const event = {};
|
const event = {};
|
||||||
|
console.log(element, event);
|
||||||
element.dispatchEvent(event);
|
element.dispatchEvent(event);
|
||||||
"#,
|
"#,
|
||||||
id, value
|
id, value
|
||||||
@@ -103,9 +105,12 @@ fn app(cx: Scope) -> Element {
|
|||||||
&cx,
|
&cx,
|
||||||
"wheel_div",
|
"wheel_div",
|
||||||
r#"new WheelEvent("wheel", {
|
r#"new WheelEvent("wheel", {
|
||||||
|
view: window,
|
||||||
deltaX: 1.0,
|
deltaX: 1.0,
|
||||||
deltaY: 2.0,
|
deltaY: 2.0,
|
||||||
deltaZ: 3.0,
|
deltaZ: 3.0,
|
||||||
|
deltaMode: 0x00,
|
||||||
|
bubbles: true,
|
||||||
})"#,
|
})"#,
|
||||||
);
|
);
|
||||||
// key_down_div
|
// key_down_div
|
||||||
@@ -117,6 +122,17 @@ fn app(cx: Scope) -> Element {
|
|||||||
code: "KeyA",
|
code: "KeyA",
|
||||||
location: 0,
|
location: 0,
|
||||||
repeat: true,
|
repeat: true,
|
||||||
|
keyCode: 65,
|
||||||
|
charCode: 97,
|
||||||
|
char: "a",
|
||||||
|
charCode: 0,
|
||||||
|
altKey: false,
|
||||||
|
ctrlKey: false,
|
||||||
|
metaKey: false,
|
||||||
|
shiftKey: false,
|
||||||
|
isComposing: false,
|
||||||
|
which: 65,
|
||||||
|
bubbles: true,
|
||||||
})"#,
|
})"#,
|
||||||
);
|
);
|
||||||
// key_up_div
|
// key_up_div
|
||||||
@@ -128,6 +144,17 @@ fn app(cx: Scope) -> Element {
|
|||||||
code: "KeyA",
|
code: "KeyA",
|
||||||
location: 0,
|
location: 0,
|
||||||
repeat: false,
|
repeat: false,
|
||||||
|
keyCode: 65,
|
||||||
|
charCode: 97,
|
||||||
|
char: "a",
|
||||||
|
charCode: 0,
|
||||||
|
altKey: false,
|
||||||
|
ctrlKey: false,
|
||||||
|
metaKey: false,
|
||||||
|
shiftKey: false,
|
||||||
|
isComposing: false,
|
||||||
|
which: 65,
|
||||||
|
bubbles: true,
|
||||||
})"#,
|
})"#,
|
||||||
);
|
);
|
||||||
// key_press_div
|
// key_press_div
|
||||||
@@ -139,19 +166,30 @@ fn app(cx: Scope) -> Element {
|
|||||||
code: "KeyA",
|
code: "KeyA",
|
||||||
location: 0,
|
location: 0,
|
||||||
repeat: false,
|
repeat: false,
|
||||||
|
keyCode: 65,
|
||||||
|
charCode: 97,
|
||||||
|
char: "a",
|
||||||
|
charCode: 0,
|
||||||
|
altKey: false,
|
||||||
|
ctrlKey: false,
|
||||||
|
metaKey: false,
|
||||||
|
shiftKey: false,
|
||||||
|
isComposing: false,
|
||||||
|
which: 65,
|
||||||
|
bubbles: true,
|
||||||
})"#,
|
})"#,
|
||||||
);
|
);
|
||||||
// focus_in_div
|
// focus_in_div
|
||||||
mock_event(
|
mock_event(
|
||||||
&cx,
|
&cx,
|
||||||
"focus_in_div",
|
"focus_in_div",
|
||||||
r#"new FocusEvent("focusin")"#,
|
r#"new FocusEvent("focusin", {bubbles: true})"#,
|
||||||
);
|
);
|
||||||
// focus_out_div
|
// focus_out_div
|
||||||
mock_event(
|
mock_event(
|
||||||
&cx,
|
&cx,
|
||||||
"focus_out_div",
|
"focus_out_div",
|
||||||
r#"new FocusEvent("focusout")"#,
|
r#"new FocusEvent("focusout",{bubbles: true})"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -223,6 +261,9 @@ fn app(cx: Scope) -> Element {
|
|||||||
}
|
}
|
||||||
div{
|
div{
|
||||||
id: "wheel_div",
|
id: "wheel_div",
|
||||||
|
width: "100px",
|
||||||
|
height: "100px",
|
||||||
|
background_color: "red",
|
||||||
onwheel: move |event| {
|
onwheel: move |event| {
|
||||||
println!("{:?}", event.data);
|
println!("{:?}", event.data);
|
||||||
let dioxus_html::geometry::WheelDelta::Pixels(delta)= event.data.delta()else{
|
let dioxus_html::geometry::WheelDelta::Pixels(delta)= event.data.delta()else{
|
||||||
@@ -232,7 +273,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
recieved_events.modify(|x| *x + 1)
|
recieved_events.modify(|x| *x + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
div{
|
input{
|
||||||
id: "key_down_div",
|
id: "key_down_div",
|
||||||
onkeydown: move |event| {
|
onkeydown: move |event| {
|
||||||
println!("{:?}", event.data);
|
println!("{:?}", event.data);
|
||||||
@@ -245,7 +286,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
recieved_events.modify(|x| *x + 1)
|
recieved_events.modify(|x| *x + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
div{
|
input{
|
||||||
id: "key_up_div",
|
id: "key_up_div",
|
||||||
onkeyup: move |event| {
|
onkeyup: move |event| {
|
||||||
println!("{:?}", event.data);
|
println!("{:?}", event.data);
|
||||||
@@ -258,7 +299,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
recieved_events.modify(|x| *x + 1)
|
recieved_events.modify(|x| *x + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
div{
|
input{
|
||||||
id: "key_press_div",
|
id: "key_press_div",
|
||||||
onkeypress: move |event| {
|
onkeypress: move |event| {
|
||||||
println!("{:?}", event.data);
|
println!("{:?}", event.data);
|
||||||
@@ -271,14 +312,14 @@ fn app(cx: Scope) -> Element {
|
|||||||
recieved_events.modify(|x| *x + 1)
|
recieved_events.modify(|x| *x + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
div{
|
input{
|
||||||
id: "focus_in_div",
|
id: "focus_in_div",
|
||||||
onfocusin: move |event| {
|
onfocusin: move |event| {
|
||||||
println!("{:?}", event.data);
|
println!("{:?}", event.data);
|
||||||
recieved_events.modify(|x| *x + 1)
|
recieved_events.modify(|x| *x + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
div{
|
input{
|
||||||
id: "focus_out_div",
|
id: "focus_out_div",
|
||||||
onfocusout: move |event| {
|
onfocusout: move |event| {
|
||||||
println!("{:?}", event.data);
|
println!("{:?}", event.data);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub(crate) fn check_app_exits(app: Component) {
|
|||||||
let should_panic = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(true));
|
let should_panic = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(true));
|
||||||
let should_panic_clone = should_panic.clone();
|
let should_panic_clone = should_panic.clone();
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(10));
|
std::thread::sleep(std::time::Duration::from_secs(100));
|
||||||
if should_panic_clone.load(std::sync::atomic::Ordering::SeqCst) {
|
if should_panic_clone.load(std::sync::atomic::Ordering::SeqCst) {
|
||||||
std::process::exit(exitcode::SOFTWARE);
|
std::process::exit(exitcode::SOFTWARE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user