Merge pull request #10299 from dotCooCoo/test/tab-overflow-footer-semantics

Tests: overflowing panel tabs work from the keyboard, and footer buttons announce their state
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-01 22:48:29 -08:00
commit 1cf61e3015
3 files changed
+149 -2

No files matched your search

+93 -2
View File
@@ -17,6 +17,8 @@ struct Harness {
ctx: egui::Context,
time: f64,
nodes: Vec<(egui::accesskit::NodeId, egui::accesskit::Node)>,
/// The node with key focus in the last frame's accessibility update.
focus: Option<egui::accesskit::NodeId>,
shapes: Vec<egui::epaint::ClippedShape>,
}
@@ -27,7 +29,7 @@ impl Harness {
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
let ctx = crate::testing::ui_context();
ctx.enable_accesskit();
let mut h = Self { app, ctx, time: 0.0, nodes: Vec::new(), shapes: Vec::new() };
let mut h = Self { app, ctx, time: 0.0, nodes: Vec::new(), focus: None, shapes: Vec::new() };
h.frames(3);
h
}
@@ -47,7 +49,9 @@ impl Harness {
/// Draw one application frame and retain its accessibility output and shapes for assertions.
fn run(&mut self, input: egui::RawInput) {
let out = crate::testing::app_frame(&mut self.app, &self.ctx, input);
self.nodes = out.platform_output.accesskit_update.map_or_else(Vec::new, |update| update.nodes);
let update = out.platform_output.accesskit_update;
self.focus = update.as_ref().map(|update| update.focus);
self.nodes = update.map_or_else(Vec::new, |update| update.nodes);
self.shapes = out.shapes;
}
@@ -1107,6 +1111,93 @@ fn a_docked_column_is_never_narrower_than_the_panel_minimum() {
assert!(body_width(&h, "Properties") >= PANEL_MIN_WIDTH - 0.5, "saved 100 pt wide: {}", body_width(&h, "Properties"));
}
impl Harness {
/// The node with key focus in the last frame.
fn focused_node(&self) -> Option<&egui::accesskit::Node> {
let focus = self.focus?;
self.nodes.iter().find(|(id, _)| *id == focus).map(|(_, node)| node)
}
/// The first node named `label` in the last frame.
fn node_named(&self, label: &str) -> Option<&egui::accesskit::Node> {
self.nodes.iter().map(|(_, node)| node).find(|node| node.label() == Some(label))
}
/// Whether key focus is on the tab strip of a panel group: the strip or one of its tabs.
fn strip_has_focus(&self) -> bool {
use egui::accesskit::Role;
self.focused_node().is_some_and(|node| node.role() == Role::Tab && !node.label().is_some_and(|l| l.starts_with("Untitled")))
|| self.focused_node().is_some_and(|node| node.role() == Role::TabList && node.label() == Some("Panels"))
}
}
/// The tabs of a docked group that does not fit them are reached from the keyboard through the strip's More tabs menu:
/// Tab moves key focus onto the strip, Alt+Down opens the menu with the focus on its first row, the arrow keys move
/// through its rows, Escape closes it and gives the focus back to the strip, and Enter shows the picked panel, with
/// the focus still on the strip. More tabs is announced as a button that opens a menu, expanded only while the menu is
/// open, and Alt+Down opens this menu and not the group's other menus.
#[test]
fn the_overflow_menu_of_a_docked_group_is_reached_and_used_from_the_keyboard() {
use egui::accesskit::Role;
use egui::{Key, Modifiers};
let mut h = Harness::new();
let panels =
"swatches stroke color gradient character paragraph appearance align pathfinder brushes symbols transparency graphicStyles transform";
for panel in panels.split(' ') {
h.app.run("window.panel.dock", json!({"panel": panel, "onto": "layers"})).unwrap();
}
h.frames(3);
assert!(showing(&h.app.ui, "transform"), "the last panel docked onto the group shows");
let more = h.node_named("More tabs").expect("the group's tabs do not fit, so the strip has a More tabs button");
assert_eq!(more.role(), Role::Button, "More tabs is a button");
assert_eq!(more.has_popup(), Some(egui::accesskit::HasPopup::Menu), "More tabs announces the menu it opens");
assert_eq!(more.is_expanded(), Some(false), "More tabs starts collapsed");
assert!(h.tab("swatches").is_none(), "Swatches is one of the tabs that do not fit");
let expanded = |h: &Harness| h.node_named("More tabs").and_then(|node| node.is_expanded());
let menu_focus = |h: &Harness| h.focused_node().filter(|node| node.role() == Role::MenuItem).and_then(|node| node.label()).map(str::to_owned);
// A press inside the group gives its strip key focus; Shift+Tab leaves the strip and Tab comes back to it.
let strip = h.named("Panels", Role::TabList).expect("the group's tab strip");
h.click(pos2(strip.center().x, strip.bottom() + 25.0));
assert!(h.strip_has_focus(), "a press in the group focuses its strip: {:?}", h.focused_node().map(|n| (n.role(), n.label())));
h.press(Key::Tab, Modifiers::SHIFT);
assert!(!h.strip_has_focus(), "Shift+Tab moves the focus off the strip");
h.press(Key::Tab, Modifiers::NONE);
assert!(h.strip_has_focus(), "Tab moves the focus back onto the strip");
// Alt+Down opens the overflow menu, listing the tabs that do not fit, with the focus on a row.
h.press(Key::ArrowDown, Modifiers::ALT);
assert_eq!(expanded(&h), Some(true), "More tabs is expanded while its menu is open");
let first = menu_focus(&h).expect("the focus enters the overflow menu");
let rows: Vec<&str> = h.nodes.iter().filter(|(_, n)| n.role() == Role::MenuItem).filter_map(|(_, n)| n.label()).collect();
assert!(rows.contains(&"Swatches"), "the menu lists a tab that does not fit: {rows:?}");
assert!(first != "Transform" && h.tab(&first).is_none(), "the focused row names a panel whose tab does not fit: {first}");
h.press(Key::ArrowDown, Modifiers::NONE);
let second = menu_focus(&h).expect("the focus stays in the menu");
assert_ne!(second, first, "Down moves the focus to the next row");
h.press(Key::ArrowUp, Modifiers::NONE);
assert_eq!(menu_focus(&h).as_deref(), Some(first.as_str()), "Up moves it back");
// Escape closes the menu and gives the focus back to the strip, with the shown panel unchanged.
h.press(Key::Escape, Modifiers::NONE);
assert_eq!(expanded(&h), Some(false), "Escape closes the overflow menu");
assert!(h.strip_has_focus(), "Escape gives the focus back to the strip");
assert!(showing(&h.app.ui, "transform"), "Escape picks nothing");
// Enter on a row shows that panel; its tab is drawn and selected, and the focus stays on the strip.
h.press(Key::ArrowDown, Modifiers::ALT);
h.press(Key::ArrowDown, Modifiers::NONE);
let picked = menu_focus(&h).expect("a row has the focus");
h.press(Key::Enter, Modifiers::NONE);
h.frames(1);
assert_eq!(expanded(&h), Some(false), "Enter closes the overflow menu");
assert!(!showing(&h.app.ui, "transform"), "the picked panel replaces Transform");
let tab = h.nodes.iter().map(|(_, n)| n).find(|n| n.role() == Role::Tab && n.label() == Some(picked.as_str()));
assert_eq!(tab.and_then(|n| n.is_selected()), Some(true), "the picked panel's tab, {picked}, is drawn and selected");
assert!(h.strip_has_focus(), "the focus stays on the strip after the pick");
}
/// A tab group dragged out of the icon column by its grip floats as an expanded panel: its tabs show
/// in the window, and a click on each tab shows that panel.
#[test]
@@ -23,6 +23,21 @@ fn picked(panel: &Panel) -> (Vec<RowKey>, Option<RowKey>, Option<RowKey>) {
(s.items.clone(), s.lead, s.anchor)
}
/// Every footer action is announced as a button named by its label, and none announces a pressed state: they are
/// plain actions. Add New Effect announces the menu it opens.
#[test]
fn the_footer_actions_are_buttons_without_a_pressed_state() {
use craft::ui::contract::{PopupKind, Role};
let panel = Panel::new(app_with_a_selected_rectangle(), show);
for name in ["Add New Stroke", "Add New Fill", "Add New Effect", "Delete Selected Item", "Duplicate Selected Item", "Clear Appearance"] {
assert!(panel.shows_role(name, Role::BUTTON), "{name} is a button");
assert_eq!(panel.toggled(name), None, "{name} announces no pressed state");
}
assert_eq!(panel.popup_kind("Add New Effect"), Some(PopupKind::Menu));
assert_eq!(panel.popup_kind("Clear Appearance"), None);
}
/// Duplicating rows picks the copies, each right above its original, as the Layers panel does:
/// the active row's copy becomes active, the anchor's copy the anchor.
#[test]
@@ -231,6 +231,47 @@ fn the_footer_menu_buttons_report_that_they_open_a_menu() {
}
}
/// Every footer action is announced as a button named by its label. Swatch Libraries and Show Swatch Kinds also
/// announce a pressed state that follows the panel: Show Swatch Kinds is pressed while a kind other than All shows, and
/// Swatch Libraries while a swatch library panel is open. The other actions announce no pressed state.
#[test]
fn the_footer_buttons_are_buttons_and_only_the_stateful_ones_announce_pressed() {
use crate::tests::panel_harness::Panel;
use craft::behavior::Mixed;
use craft::ui::contract::Role;
use egui::{Key, Modifiers};
let mut panel = Panel::new(app(), show);
for name in [SwatchLibraries::MENU, "Show Swatch Kinds", "Swatch Options", "Delete Swatch", "New Swatch", "New Color Group"] {
assert!(panel.shows_role(name, Role::BUTTON), "{name} is a button");
}
for name in ["Swatch Options", "Delete Swatch", "New Swatch", "New Color Group"] {
assert_eq!(panel.toggled(name), None, "{name} announces no pressed state");
}
assert_eq!(panel.toggled("Show Swatch Kinds"), Some(Mixed::Same(false)), "every kind shows");
assert_eq!(panel.toggled(SwatchLibraries::MENU), Some(Mixed::Same(false)), "no library is open");
// Space on the focused footer button opens its menu; the footer sits below the harness's room.
let pick = |panel: &mut Panel, kind: &str| {
panel.focus("Show Swatch Kinds");
panel.key(Key::Space, Modifiers::NONE);
panel.frame();
panel.click_role(kind, Role::MENU_ITEM_RADIO);
panel.frame();
};
pick(&mut panel, "Show Color Swatches");
assert_eq!(panel.app().ui.swatches_panel.kind, Kind::Color);
assert_eq!(panel.toggled("Show Swatch Kinds"), Some(Mixed::Same(true)), "a kind filter is on");
pick(&mut panel, "Show All Swatches");
assert_eq!(panel.app().ui.swatches_panel.kind, Kind::All);
assert_eq!(panel.toggled("Show Swatch Kinds"), Some(Mixed::Same(false)), "the filter is off again");
let id = library_panel::tests::menu_library_ids::<SwatchLibraries>(&panel.app()).into_iter().next().expect("a swatch library");
panel.app().run("window.swatchLibrary", json!({"library": id})).unwrap();
panel.frame();
assert_eq!(panel.toggled(SwatchLibraries::MENU), Some(Mixed::Same(true)), "a library panel is open");
}
/// The footer reads the panel's selection while the browser holds the panel's model: with one swatch selected, Swatch
/// Options and Delete Swatch are enabled.
#[test]