Skip to content

Commit 0152a87

Browse files
authored
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
1 parent 8c2df48 commit 0152a87

File tree

20 files changed

+358
-304
lines changed

20 files changed

+358
-304
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2422,7 +2422,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
24222422
[[package]]
24232423
name = "kittest"
24242424
version = "0.1.0"
2425-
source = "git+https://github.com/rerun-io/kittest?branch=main#679f9ade828021295c5f86f38275d9271d001004"
2425+
source = "git+https://github.com/rerun-io/kittest?branch=main#91bf0fd98b5afe04427bb3aea4c68c6e0034b4bd"
24262426
dependencies = [
24272427
"accesskit",
24282428
"accesskit_consumer",
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

crates/egui_demo_app/tests/test_demo_app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn test_demo_app() {
5555
harness
5656
.get_by_role_and_label(Role::TextInput, "URI:")
5757
.focus();
58-
harness.press_key_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
58+
harness.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
5959

6060
harness
6161
.get_by_role_and_label(Role::TextInput, "URI:")

crates/egui_demo_lib/src/demo/demo_app_windows.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ fn file_menu_button(ui: &mut Ui) {
371371
#[cfg(test)]
372372
mod tests {
373373
use crate::{demo::demo_app_windows::DemoGroups, Demo as _};
374-
use egui::Vec2;
375-
use egui_kittest::kittest::Queryable as _;
374+
375+
use egui_kittest::kittest::{NodeT as _, Queryable as _};
376376
use egui_kittest::{Harness, SnapshotOptions, SnapshotResults};
377377

378378
#[test]
@@ -399,12 +399,12 @@ mod tests {
399399
demo.show(ctx, &mut true);
400400
});
401401

402-
let window = harness.node().children().next().unwrap();
402+
let window = harness.queryable_node().children().next().unwrap();
403403
// TODO(lucasmerlin): Windows should probably have a label?
404404
//let window = harness.get_by_label(name);
405405

406-
let size = window.raw_bounds().expect("window bounds").size();
407-
harness.set_size(Vec2::new(size.width as f32, size.height as f32));
406+
let size = window.rect().size();
407+
harness.set_size(size);
408408

409409
// Run the app for some more frames...
410410
harness.run_ok();

crates/egui_demo_lib/src/demo/modals.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ mod tests {
190190
assert!(harness.ctx.memory(|mem| mem.any_popup_open()));
191191
assert!(harness.state().user_modal_open);
192192

193-
harness.press_key(Key::Escape);
193+
harness.key_press(Key::Escape);
194194
harness.run_ok();
195195
assert!(!harness.ctx.memory(|mem| mem.any_popup_open()));
196196
assert!(harness.state().user_modal_open);
@@ -214,7 +214,7 @@ mod tests {
214214
assert!(harness.state().user_modal_open);
215215
assert!(harness.state().save_modal_open);
216216

217-
harness.press_key(Key::Escape);
217+
harness.key_press(Key::Escape);
218218
harness.run();
219219

220220
assert!(harness.state().user_modal_open);
@@ -267,7 +267,7 @@ mod tests {
267267

268268
harness.run_ok();
269269

270-
harness.get_by_label("Yes Please").simulate_click();
270+
harness.get_by_label("Yes Please").click();
271271

272272
harness.run_ok();
273273

crates/egui_demo_lib/src/demo/text_edit.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ impl crate::View for TextEditDemo {
113113

114114
#[cfg(test)]
115115
mod tests {
116-
use egui::{accesskit, CentralPanel};
117-
use egui_kittest::kittest::{Key, Queryable as _};
116+
use egui::{accesskit, CentralPanel, Key, Modifiers};
117+
use egui_kittest::kittest::Queryable as _;
118118
use egui_kittest::Harness;
119119

120120
#[test]
@@ -133,8 +133,9 @@ mod tests {
133133

134134
let text_edit = harness.get_by_role(accesskit::Role::TextInput);
135135
assert_eq!(text_edit.value().as_deref(), Some("Hello, world!"));
136+
text_edit.focus();
136137

137-
text_edit.key_combination(&[Key::Command, Key::A]);
138+
harness.key_press_modifiers(Modifiers::COMMAND, Key::A);
138139
text_edit.type_text("Hi ");
139140

140141
harness.run();

crates/egui_demo_lib/src/rendering_test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,9 @@ mod tests {
737737
});
738738

739739
{
740-
// Expand color-test collapsing header
741-
harness.get_by_label("Color test").click();
740+
// Expand color-test collapsing header. We accesskit-click since collapsing header
741+
// might not be on screen at this point.
742+
harness.get_by_label("Color test").click_accesskit();
742743
harness.run();
743744
}
744745

crates/egui_kittest/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Ui testing library for egui, based on [kittest](https://github.com/rerun-io/kitt
1010
## Example usage
1111
```rust
1212
use egui::accesskit::Toggled;
13-
use egui_kittest::{Harness, kittest::Queryable};
13+
use egui_kittest::{Harness, kittest::{Queryable, NodeT}};
1414

1515
fn main() {
1616
let mut checked = false;
@@ -21,13 +21,13 @@ fn main() {
2121
let mut harness = Harness::new_ui(app);
2222

2323
let checkbox = harness.get_by_label("Check me!");
24-
assert_eq!(checkbox.toggled(), Some(Toggled::False));
24+
assert_eq!(checkbox.accesskit_node().toggled(), Some(Toggled::False));
2525
checkbox.click();
2626

2727
harness.run();
2828

2929
let checkbox = harness.get_by_label("Check me!");
30-
assert_eq!(checkbox.toggled(), Some(Toggled::True));
30+
assert_eq!(checkbox.accesskit_node().toggled(), Some(Toggled::True));
3131

3232
// Shrink the window size to the smallest size possible
3333
harness.fit_contents();

crates/egui_kittest/src/event.rs

Lines changed: 0 additions & 194 deletions
This file was deleted.

0 commit comments

Comments
 (0)