1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40: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:
Lucas Meurer
2025-06-17 12:17:38 +02:00
committed by GitHub
parent 8c2df4802c
commit 0152a87519
20 changed files with 359 additions and 305 deletions

View File

@@ -371,8 +371,8 @@ fn file_menu_button(ui: &mut Ui) {
#[cfg(test)]
mod tests {
use crate::{demo::demo_app_windows::DemoGroups, Demo as _};
use egui::Vec2;
use egui_kittest::kittest::Queryable as _;
use egui_kittest::kittest::{NodeT as _, Queryable as _};
use egui_kittest::{Harness, SnapshotOptions, SnapshotResults};
#[test]
@@ -399,12 +399,12 @@ mod tests {
demo.show(ctx, &mut true);
});
let window = harness.node().children().next().unwrap();
let window = harness.queryable_node().children().next().unwrap();
// TODO(lucasmerlin): Windows should probably have a label?
//let window = harness.get_by_label(name);
let size = window.raw_bounds().expect("window bounds").size();
harness.set_size(Vec2::new(size.width as f32, size.height as f32));
let size = window.rect().size();
harness.set_size(size);
// Run the app for some more frames...
harness.run_ok();

View File

@@ -190,7 +190,7 @@ mod tests {
assert!(harness.ctx.memory(|mem| mem.any_popup_open()));
assert!(harness.state().user_modal_open);
harness.press_key(Key::Escape);
harness.key_press(Key::Escape);
harness.run_ok();
assert!(!harness.ctx.memory(|mem| mem.any_popup_open()));
assert!(harness.state().user_modal_open);
@@ -214,7 +214,7 @@ mod tests {
assert!(harness.state().user_modal_open);
assert!(harness.state().save_modal_open);
harness.press_key(Key::Escape);
harness.key_press(Key::Escape);
harness.run();
assert!(harness.state().user_modal_open);
@@ -267,7 +267,7 @@ mod tests {
harness.run_ok();
harness.get_by_label("Yes Please").simulate_click();
harness.get_by_label("Yes Please").click();
harness.run_ok();

View File

@@ -113,8 +113,8 @@ impl crate::View for TextEditDemo {
#[cfg(test)]
mod tests {
use egui::{accesskit, CentralPanel};
use egui_kittest::kittest::{Key, Queryable as _};
use egui::{accesskit, CentralPanel, Key, Modifiers};
use egui_kittest::kittest::Queryable as _;
use egui_kittest::Harness;
#[test]
@@ -133,8 +133,9 @@ mod tests {
let text_edit = harness.get_by_role(accesskit::Role::TextInput);
assert_eq!(text_edit.value().as_deref(), Some("Hello, world!"));
text_edit.focus();
text_edit.key_combination(&[Key::Command, Key::A]);
harness.key_press_modifiers(Modifiers::COMMAND, Key::A);
text_edit.type_text("Hi ");
harness.run();

View File

@@ -737,8 +737,9 @@ mod tests {
});
{
// Expand color-test collapsing header
harness.get_by_label("Color test").click();
// Expand color-test collapsing header. We accesskit-click since collapsing header
// might not be on screen at this point.
harness.get_by_label("Color test").click_accesskit();
harness.run();
}