Skip to content

Commit

Permalink
feat: Testing events utils (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Sep 11, 2024
1 parent a53e134 commit 2295d6b
Show file tree
Hide file tree
Showing 32 changed files with 124 additions and 545 deletions.
9 changes: 1 addition & 8 deletions crates/components/src/accordion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,12 @@ mod test {
let content = root.get(0).get(1).get(0);
let label = content.get(0);
utils.wait_for_update().await;
utils.wait_for_update().await;

// Accordion is closed, therefore label is hidden.
assert!(!label.is_visible());

// Click on the accordion
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (5., 5.).into(),
button: Some(MouseButton::Left),
});

utils.wait_for_update().await;
utils.click_cursor((5., 5.)).await;

// State somewhere in the middle
sleep(Duration::from_millis(70)).await;
Expand Down
8 changes: 1 addition & 7 deletions crates/components/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,7 @@ mod test {

assert_eq!(label.get(0).text(), Some("false"));

utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (15.0, 15.0).into(),
button: Some(MouseButton::Left),
});

utils.wait_for_update().await;
utils.click_cursor((15.0, 15.0)).await;

assert_eq!(label.get(0).text(), Some("true"));

Expand Down
26 changes: 4 additions & 22 deletions crates/components/src/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,39 +176,21 @@ mod test {
assert!(root.get(1).get(0).get(0).get(0).is_placeholder());
assert!(root.get(2).get(0).get(0).get(0).is_placeholder());

utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (20.0, 50.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.click_cursor((20., 50.)).await;

assert!(root.get(0).get(0).get(0).get(0).is_placeholder());
assert!(root.get(1).get(0).get(0).get(0).is_element());
assert!(root.get(2).get(0).get(0).get(0).is_placeholder());

utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (10.0, 90.0).into(),
button: Some(MouseButton::Left),
});
utils.click_cursor((10., 90.)).await;
utils.wait_for_update().await;

assert!(root.get(0).get(0).get(0).get(0).is_placeholder());
assert!(root.get(1).get(0).get(0).get(0).is_element());
assert!(root.get(2).get(0).get(0).get(0).is_element());

utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (10.0, 10.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (10.0, 50.0).into(),
button: Some(MouseButton::Left),
});
utils.click_cursor((10., 10.)).await;
utils.click_cursor((10., 50.)).await;
utils.wait_for_update().await;

assert!(root.get(0).get(0).get(0).get(0).is_element());
Expand Down
24 changes: 3 additions & 21 deletions crates/components/src/cursor_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,35 +97,17 @@ mod test {
// Initial cursor
assert_eq!(utils.cursor_icon(), CursorIcon::default());

utils.push_event(PlatformEvent::Mouse {
name: EventName::MouseOver,
cursor: (100., 100.).into(),
button: Some(MouseButton::Left),
});

utils.wait_for_update().await;
utils.move_cursor((100., 100.)).await;

// Cursor after hovering the first half
assert_eq!(utils.cursor_icon(), CursorIcon::Progress);

utils.push_event(PlatformEvent::Mouse {
name: EventName::MouseOver,
cursor: (100., 300.).into(),
button: Some(MouseButton::Left),
});

utils.wait_for_update().await;
utils.move_cursor((100., 300.)).await;

// Cursor after hovering the second half
assert_eq!(utils.cursor_icon(), CursorIcon::Pointer);

utils.push_event(PlatformEvent::Mouse {
name: EventName::MouseOver,
cursor: (-1., -1.).into(),
button: Some(MouseButton::Left),
});

utils.wait_for_update().await;
utils.move_cursor((-1., -1.)).await;

// Cursor after leaving the window
assert_eq!(utils.cursor_icon(), CursorIcon::default());
Expand Down
16 changes: 2 additions & 14 deletions crates/components/src/drag_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,9 @@ mod test {

utils.wait_for_update().await;

utils.push_event(PlatformEvent::Mouse {
name: EventName::MouseOver,
cursor: (5.0, 5.0).into(),
button: Some(MouseButton::Left),
});

utils.wait_for_update().await;
utils.move_cursor((5., 5.)).await;

utils.push_event(PlatformEvent::Mouse {
name: EventName::MouseOver,
cursor: (5.0, 300.0).into(),
button: Some(MouseButton::Left),
});

utils.wait_for_update().await;
utils.move_cursor((5., 300.)).await;

assert_eq!(root.get(0).get(0).get(0).get(0).text(), Some("Moving"));

Expand Down
27 changes: 4 additions & 23 deletions crates/components/src/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,42 +364,23 @@ mod test {
assert_eq!(label.get(0).text(), Some("Value A"));

// Open the dropdown
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (15.0, 15.0).into(),
button: Some(MouseButton::Left),
});
utils.click_cursor((15., 15.)).await;
utils.wait_for_update().await;

// Now that the dropwdown is opened, there are more nodes in the layout
assert!(utils.sdom().get().layout().size() > start_size);

// Close the dropdown by clicking outside of it
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (200.0, 200.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.click_cursor((200., 200.)).await;

// Now the layout size is like in the begining
assert_eq!(utils.sdom().get().layout().size(), start_size);

// Open the dropdown again
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (15.0, 15.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.click_cursor((15., 15.)).await;

// Click on the second option
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (45.0, 100.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.click_cursor((45., 100.)).await;
utils.wait_for_update().await;
utils.wait_for_update().await;

Expand Down
21 changes: 4 additions & 17 deletions crates/components/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,32 +273,19 @@ mod test {

let mut utils = launch_test(link_app);

utils.wait_for_update().await;
utils.wait_for_update().await;

// Check route is Home
assert_eq!(utils.root().get(2).get(0).text(), Some("Home"));

// Go to the "Somewhere" route
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (5., 60.).into(),
button: Some(MouseButton::Left),
});

utils.wait_for_update().await;
utils.wait_for_update().await;
utils.click_cursor((5., 60.)).await;

// Check route is Somewhere
assert_eq!(utils.root().get(2).get(0).text(), Some("Somewhere"));

// Go to the "Home" route again
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (5., 5.).into(),
button: Some(MouseButton::Left),
});
utils.click_cursor((5., 5.)).await;

utils.wait_for_update().await;
// Check route is Home
assert_eq!(utils.root().get(2).get(0).text(), Some("Home"));
}
}
43 changes: 6 additions & 37 deletions crates/components/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,7 @@ mod test {
assert_eq!(utils.sdom().get().layout().size(), 5);

// Open the Menu
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (15.0, 15.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.click_cursor((15., 15.)).await;

// Check the `Open` button exists
assert_eq!(
Expand All @@ -405,34 +400,18 @@ mod test {
assert!(utils.sdom().get().layout().size() > start_size);

// Close the Menu
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (15.0, 60.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.click_cursor((15., 60.)).await;

assert_eq!(utils.sdom().get().layout().size(), start_size);

// Open the Menu again
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (15.0, 15.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.wait_for_update().await;
utils.click_cursor((15., 15.)).await;

let one_submenu_opened = utils.sdom().get().layout().size();
assert!(one_submenu_opened > start_size);

// Open the SubMenu
utils.push_event(PlatformEvent::Mouse {
name: EventName::MouseOver,
cursor: (15.0, 130.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.move_cursor((15., 130.)).await;

// Check the `Option 1` button exists
assert_eq!(
Expand All @@ -455,22 +434,12 @@ mod test {
assert!(utils.sdom().get().layout().size() > one_submenu_opened);

// Stop showing the submenu
utils.push_event(PlatformEvent::Mouse {
name: EventName::MouseOver,
cursor: (15.0, 90.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.move_cursor((15., 90.)).await;

assert_eq!(utils.sdom().get().layout().size(), one_submenu_opened);

// Click somewhere also so all the menus hide
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (333.0, 333.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.click_cursor((333., 333.)).await;

assert_eq!(utils.sdom().get().layout().size(), start_size);
}
Expand Down
10 changes: 1 addition & 9 deletions crates/components/src/native_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,7 @@ mod test {

assert_eq!(utils.root().get(0).get(1).get(0).text(), Some("A"));

utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (5.0, 5.0).into(),
button: Some(MouseButton::Left),
});

utils.wait_for_update().await;
utils.click_cursor((5., 5.)).await;

assert_eq!(utils.root().get(0).get(1).get(0).text(), Some("B"));

Expand All @@ -129,7 +123,6 @@ mod test {
cursor: (5.0, 5.0).into(),
button: Some(MouseButton::Back),
});

utils.wait_for_update().await;

assert_eq!(utils.root().get(0).get(1).get(0).text(), Some("A"));
Expand All @@ -139,7 +132,6 @@ mod test {
cursor: (5.0, 5.0).into(),
button: Some(MouseButton::Forward),
});

utils.wait_for_update().await;

assert_eq!(utils.root().get(0).get(1).get(0).text(), Some("B"));
Expand Down
21 changes: 3 additions & 18 deletions crates/components/src/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,33 +216,18 @@ mod test {
assert_eq!(utils.sdom().get().layout().size(), 4);

// Open the popup
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (15.0, 15.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.click_cursor((15., 15.)).await;

// Check the popup is opened
assert_eq!(utils.sdom().get().layout().size(), 10);

utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (395.0, 180.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.click_cursor((395., 180.)).await;

// Check the popup is closed
assert_eq!(utils.sdom().get().layout().size(), 4);

// Open the popup
utils.push_event(PlatformEvent::Mouse {
name: EventName::Click,
cursor: (15.0, 15.0).into(),
button: Some(MouseButton::Left),
});
utils.wait_for_update().await;
utils.click_cursor((15., 15.)).await;

// Send a random keydown event
utils.push_event(PlatformEvent::Keyboard {
Expand Down
Loading

0 comments on commit 2295d6b

Please sign in to comment.