-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic test for egui accesskit output. (#4716)
For a project I am currently attempting to use the acceskit output of egui to preform end-to-end integration tests of my application. However, the output is currently quite basic (buttons for example don't report that they are disabled). Before adding new features to the acceskit integration, I thought it would be a good idea to add some testing to egui's accesskit output. I have started with a simple test for button texts, to get feedback on whether this is the correct direction to go in. --------- Co-authored-by: Wybe Westra <[email protected]>
- Loading branch information
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
//! Tests the accesskit accessibility output of egui. | ||
use accesskit::Role; | ||
use egui::{Context, RawInput}; | ||
|
||
/// Baseline test that asserts there are no spurious nodes in the | ||
/// accesskit output when the ui is empty. | ||
/// | ||
/// This gives reasonable certainty that any nodes appearing in the other accesskit outputs | ||
/// are put there because of the widgets rendered. | ||
#[test] | ||
fn empty_ui_should_return_tree_with_only_root_window() { | ||
let ctx = Context::default(); | ||
ctx.enable_accesskit(); | ||
|
||
let output = ctx.run(RawInput::default(), |ctx| { | ||
egui::CentralPanel::default().show(ctx, |_| {}); | ||
}); | ||
|
||
let tree_update = output | ||
.platform_output | ||
.accesskit_update | ||
.expect("Missing accesskit update"); | ||
|
||
let tree = tree_update.tree.unwrap(); | ||
|
||
assert_eq!( | ||
tree_update.nodes.len(), | ||
1, | ||
"Empty ui should produce only the root window." | ||
); | ||
let (id, root) = &tree_update.nodes[0]; | ||
|
||
assert_eq!(*id, tree.root); | ||
assert_eq!(root.role(), Role::Window); | ||
} | ||
|
||
#[test] | ||
fn button_text() { | ||
let button_text = "This is a test button!"; | ||
|
||
let ctx = Context::default(); | ||
ctx.enable_accesskit(); | ||
|
||
let output = ctx.run(RawInput::default(), |ctx| { | ||
egui::CentralPanel::default().show(ctx, |ui| ui.button(button_text)); | ||
}); | ||
|
||
let nodes = output | ||
.platform_output | ||
.accesskit_update | ||
.expect("Missing accesskit update") | ||
.nodes; | ||
|
||
assert_eq!( | ||
nodes.len(), | ||
2, | ||
"Expected only the root node and the button." | ||
); | ||
|
||
nodes | ||
.iter() | ||
.find(|(_, node)| node.role() == Role::Button && node.name() == Some(button_text)) | ||
.expect("Button should exist in the accesskit output"); | ||
} | ||
|
||
#[test] | ||
fn toggle_button_text() { | ||
let button_text = "A toggle button"; | ||
|
||
let ctx = Context::default(); | ||
ctx.enable_accesskit(); | ||
|
||
let mut selected = false; | ||
let output = ctx.run(RawInput::default(), |ctx| { | ||
egui::CentralPanel::default().show(ctx, |ui| ui.toggle_value(&mut selected, button_text)); | ||
}); | ||
|
||
let nodes = output | ||
.platform_output | ||
.accesskit_update | ||
.expect("Missing accesskit update") | ||
.nodes; | ||
|
||
assert_eq!( | ||
nodes.len(), | ||
2, | ||
"Expected only the root node and the button." | ||
); | ||
|
||
nodes | ||
.iter() | ||
.find(|(_, node)| node.role() == Role::ToggleButton && node.name() == Some(button_text)) | ||
.expect("Toggle button should exist in the accesskit output"); | ||
} |