mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Create custom egui_kittest::Node (#7138)
This adds a custom Node struct with proper support for egui types (`Key`, `Modifiers`, `egui::Event`, `Rect`) instead of needing to use the kittest / accesskit types. I also changed the `click` function to do a proper mouse move / mouse down instead of the accesskit click. Also added `accesskit_click` to trigger the accesskit event. This resulted in some changed snapshots, since the elements are now hovered. Also renamed `press_key` to `key_press` for consistency with `key_down/key_up`. Also removed the Deref to the AccessKit Node, to make it clearer when to expect egui and when to expect accesskit types. * Closes #5705 * [x] I have followed the instructions in the PR template
This commit is contained in:
@@ -95,7 +95,7 @@ fn menu_close_on_click_outside() {
|
||||
TestMenu::new(MenuConfig::new().close_behavior(PopupCloseBehavior::CloseOnClick))
|
||||
.into_harness();
|
||||
|
||||
harness.get_by_label("Menu A").simulate_click();
|
||||
harness.get_by_label("Menu A").click();
|
||||
harness.run();
|
||||
|
||||
harness
|
||||
@@ -106,9 +106,7 @@ fn menu_close_on_click_outside() {
|
||||
// We should be able to check the checkbox without closing the menu
|
||||
// Click a couple of times, just in case
|
||||
for expect_checked in [true, false, true, false] {
|
||||
harness
|
||||
.get_by_label("Checkbox in Submenu C")
|
||||
.simulate_click();
|
||||
harness.get_by_label("Checkbox in Submenu C").click();
|
||||
harness.run();
|
||||
assert_eq!(expect_checked, harness.state().checked);
|
||||
}
|
||||
@@ -119,7 +117,7 @@ fn menu_close_on_click_outside() {
|
||||
assert!(harness.query_by_label("Checkbox in Submenu C").is_some());
|
||||
|
||||
// Clicking outside should close the menu
|
||||
harness.get_by_label("Some other label").simulate_click();
|
||||
harness.get_by_label("Some other label").click();
|
||||
harness.run();
|
||||
assert!(harness.query_by_label("Checkbox in Submenu C").is_none());
|
||||
}
|
||||
@@ -130,14 +128,14 @@ fn menu_close_on_click() {
|
||||
TestMenu::new(MenuConfig::new().close_behavior(PopupCloseBehavior::CloseOnClick))
|
||||
.into_harness();
|
||||
|
||||
harness.get_by_label("Menu A").simulate_click();
|
||||
harness.get_by_label("Menu A").click();
|
||||
harness.run();
|
||||
|
||||
harness.get_by_label_contains("Submenu B with icon").hover();
|
||||
harness.run();
|
||||
|
||||
// Clicking the button should close the menu (even if ui.close() is not called by the button)
|
||||
harness.get_by_label("Button in Submenu B").simulate_click();
|
||||
harness.get_by_label("Button in Submenu B").click();
|
||||
harness.run();
|
||||
assert!(harness.query_by_label("Button in Submenu B").is_none());
|
||||
}
|
||||
@@ -145,21 +143,19 @@ fn menu_close_on_click() {
|
||||
#[test]
|
||||
fn clicking_submenu_button_should_never_close_menu() {
|
||||
// We test for this since otherwise the menu wouldn't work on touch devices
|
||||
// The other tests use .hover to open submenus, but this test explicitly uses .simulate_click
|
||||
// The other tests use .hover to open submenus, but this test explicitly uses .click
|
||||
let mut harness =
|
||||
TestMenu::new(MenuConfig::new().close_behavior(PopupCloseBehavior::CloseOnClick))
|
||||
.into_harness();
|
||||
|
||||
harness.get_by_label("Menu A").simulate_click();
|
||||
harness.get_by_label("Menu A").click();
|
||||
harness.run();
|
||||
|
||||
// Clicking the submenu button should not close the menu
|
||||
harness
|
||||
.get_by_label_contains("Submenu B with icon")
|
||||
.simulate_click();
|
||||
harness.get_by_label_contains("Submenu B with icon").click();
|
||||
harness.run();
|
||||
|
||||
harness.get_by_label("Button in Submenu B").simulate_click();
|
||||
harness.get_by_label("Button in Submenu B").click();
|
||||
harness.run();
|
||||
assert!(harness.query_by_label("Button in Submenu B").is_none());
|
||||
}
|
||||
@@ -174,7 +170,7 @@ fn menu_snapshots() {
|
||||
harness.run();
|
||||
results.add(harness.try_snapshot("menu/closed_hovered"));
|
||||
|
||||
harness.get_by_label("Menu A").simulate_click();
|
||||
harness.get_by_label("Menu A").click();
|
||||
harness.run();
|
||||
results.add(harness.try_snapshot("menu/opened"));
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ fn test_interactive_tooltip() {
|
||||
harness.run();
|
||||
harness.get_by_label("link").hover();
|
||||
harness.run();
|
||||
harness.get_by_label("link").simulate_click();
|
||||
harness.get_by_label("link").click();
|
||||
|
||||
harness.run();
|
||||
|
||||
|
||||
@@ -10,19 +10,19 @@ pub fn focus_should_skip_over_disabled_buttons() {
|
||||
ui.add(Button::new("Button 3"));
|
||||
});
|
||||
|
||||
harness.press_key(egui::Key::Tab);
|
||||
harness.key_press(egui::Key::Tab);
|
||||
harness.run();
|
||||
|
||||
let button_1 = harness.get_by_label("Button 1");
|
||||
assert!(button_1.is_focused());
|
||||
|
||||
harness.press_key(egui::Key::Tab);
|
||||
harness.key_press(egui::Key::Tab);
|
||||
harness.run();
|
||||
|
||||
let button_3 = harness.get_by_label("Button 3");
|
||||
assert!(button_3.is_focused());
|
||||
|
||||
harness.press_key(egui::Key::Tab);
|
||||
harness.key_press(egui::Key::Tab);
|
||||
harness.run();
|
||||
|
||||
let button_1 = harness.get_by_label("Button 1");
|
||||
@@ -41,13 +41,13 @@ pub fn focus_should_skip_over_disabled_drag_values() {
|
||||
ui.add(egui::DragValue::new(&mut value_3));
|
||||
});
|
||||
|
||||
harness.press_key(egui::Key::Tab);
|
||||
harness.key_press(egui::Key::Tab);
|
||||
harness.run();
|
||||
|
||||
let drag_value_1 = harness.get_by(|node| node.numeric_value() == Some(1.0));
|
||||
assert!(drag_value_1.is_focused());
|
||||
|
||||
harness.press_key(egui::Key::Tab);
|
||||
harness.key_press(egui::Key::Tab);
|
||||
harness.run();
|
||||
|
||||
let drag_value_3 = harness.get_by(|node| node.numeric_value() == Some(3.0));
|
||||
@@ -103,8 +103,7 @@ fn test_combobox() {
|
||||
results.add(harness.try_snapshot("combobox_opened"));
|
||||
|
||||
let item_2 = harness.get_by_role_and_label(Role::Button, "Item 2");
|
||||
// Node::click doesn't close the popup, so we use simulate_click
|
||||
item_2.simulate_click();
|
||||
item_2.click();
|
||||
|
||||
harness.run();
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b1d172484712e3e12038f8ff427db8c0073aba124aa1b6be17edcc7dccb12f74
|
||||
size 1656
|
||||
oid sha256:341658df1dfe665e79180d4540965a986a21de09c9cbc1a8744bdcff1a7c2086
|
||||
size 1892
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use egui::{include_image, Modifiers, Vec2};
|
||||
use egui_kittest::Harness;
|
||||
use kittest::{Key, Queryable as _};
|
||||
use kittest::Queryable as _;
|
||||
|
||||
#[test]
|
||||
fn test_shrink() {
|
||||
@@ -39,17 +39,15 @@ fn test_modifiers() {
|
||||
State::default(),
|
||||
);
|
||||
|
||||
harness.get_by_label("Click me").key_down(Key::Command);
|
||||
// This run isn't necessary, but allows us to test whether modifiers are remembered between frames
|
||||
harness.run();
|
||||
harness.get_by_label("Click me").click();
|
||||
harness.get_by_label("Click me").key_up(Key::Command);
|
||||
harness
|
||||
.get_by_label("Click me")
|
||||
.click_modifiers(Modifiers::COMMAND);
|
||||
harness.run();
|
||||
|
||||
harness.press_key_modifiers(Modifiers::COMMAND, egui::Key::Z);
|
||||
harness.key_press_modifiers(Modifiers::COMMAND, egui::Key::Z);
|
||||
harness.run();
|
||||
|
||||
harness.node().key_combination(&[Key::Command, Key::Y]);
|
||||
harness.key_combination_modifiers(Modifiers::COMMAND, &[egui::Key::Y]);
|
||||
harness.run();
|
||||
|
||||
let state = harness.state();
|
||||
|
||||
Reference in New Issue
Block a user