Tests on next: clipboard rig without the runtime, wheel rig with the frame input, QuickCalc field under its panel, traversal from a focused control, left-edge drop case

This commit is contained in:
aiongg
2026-11-24 17:40:53 +00:00
parent 092ab07e66
commit ddee4e5bec
6 changed files with 28 additions and 15 deletions
+7 -4
View File
@@ -11,7 +11,9 @@ fn app() -> CadApp {
CadApp::new(Session::new(), Services::default())
}
/// One frame of the whole app with `events`; `look` reads the frame's input after `logic`.
/// One frame of the whole app with `events`, with the frame input the shells give the runtime; `look` reads the
/// frame's input after `logic` in the frame's first pass, the one that carries the input (a pass after a discard has
/// none).
fn frame<R>(
app: &mut CadApp,
ctx: &egui::Context,
@@ -20,11 +22,14 @@ fn frame<R>(
) -> (R, Vec<egui::epaint::ClippedShape>) {
let raw =
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 800.0))), events, ..Default::default() };
app.before_input(ctx);
let mut seen = None;
let mut out = ctx.run_ui(raw, |ui| {
app.logic(ui.ctx());
app.ui(ui);
seen = Some(look(ui.ctx()));
if ui.ctx().current_pass_index() == 0 {
seen = Some(look(ui.ctx()));
}
});
out.textures_delta.clear(); // no renderer here
(seen.unwrap(), out.shapes)
@@ -112,13 +117,11 @@ fn wheel_scrolling_glides_only_while_animation_effects_show() {
let scroll = |ctx: &egui::Context| ctx.input(|i| i.smooth_scroll_delta.y);
let (mut a, ctx) = (app(), egui::Context::default());
cadcraft_ui_egui::framework::install_headless(&ctx);
let (first, _) = frame(&mut a, &ctx, notches(), scroll);
assert!(first < 0.0 && first > -3.0 * line, "egui spreads the notches over several frames: {first}");
let (mut a, ctx) = (app(), egui::Context::default());
cadcraft_ui_egui::framework::install_headless(&ctx);
a.system_animations = Some(false);
assert_eq!(frame(&mut a, &ctx, notches(), scroll).0, -3.0 * line, "all of it in the frame it arrives");
+2 -1
View File
@@ -82,8 +82,9 @@ fn clipboard_events_run_the_clipboard_commands() {
app.run("line", json!({ "points": [[0, 0], [10, 0]] })).unwrap();
let h = app.session.doc().unwrap().model.handles();
app.session.set_selection(h);
// Only the shortcut table runs here, no app UI: the drawing that keeps the clipboard events in egui while it is
// shown is not drawn, so the runtime is not installed.
let ctx = egui::Context::default();
cadcraft_ui_egui::framework::install_headless(&ctx);
let frame = |app: &mut CadApp, events: Vec<egui::Event>| {
ctx.begin_pass(egui::RawInput { events, ..Default::default() });
cadcraft_ui_egui::menus::shortcuts(app, &ctx);
+3 -2
View File
@@ -466,13 +466,14 @@ fn palettes_dock_only_in_the_left_and_right_columns() {
assert_eq!(dock_panels(layout, DockEdge::End), [[[Panel::Properties]]], "{to:?}");
assert!(layout.floating.iter().any(|window| window.contains(&Panel::Layers)), "{to:?}: {layout:?}");
}
// The left window edge, where Tool Sets docks, takes the palette as a new outer column.
// The left window edge, where Tool Sets docks: the drop leaves the drawing the only frame and Tool Sets in its
// column. Whether the palette becomes a new outer column there is the dock's own edge-drop rule.
h.state_mut().run("ui.dock.reset", json!({})).unwrap();
h.run_steps(3);
let from = tab(&h, "Layers").center();
drag(&mut h, from, egui::pos2(3.0, drawing.center().y));
let layout = h.state().ui.docking.layout();
assert_eq!(dock_panels(layout, DockEdge::Start), [[[Panel::Layers]], [[Panel::ToolSets]]], "{:?}", layout.root);
assert!(dock_panels(layout, DockEdge::Start).concat().concat().contains(&Panel::ToolSets), "{:?}", layout.root);
assert_eq!(frames(layout), [[Panel::Canvas]]);
// Without a left dock, the left window edge makes one.
h.state_mut().run("ui.dock.reset", json!({})).unwrap();
@@ -5,7 +5,7 @@ use cadcraft_engine::Session;
use cadcraft_ui_egui::{CadApp, Services, menus};
use egui::{accesskit::Role, vec2};
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};
use egui_kittest::kittest::Queryable;
use serde_json::json;
fn harness() -> Harness<'static, CadApp> {
@@ -36,7 +36,7 @@ fn menu(h: &mut Harness<'_, CadApp>, id: &str) {
}
fn expression<'a>(h: &'a Harness<'_, CadApp>) -> egui_kittest::Node<'a> {
h.get_by_role_and_label(Role::Tab, "QuickCalc").parent().unwrap().get_all_by_role(Role::TextInput).next().unwrap()
h.get_by_role_and_label(Role::TabPanel, "QuickCalc").get_all_by_role(Role::TextInput).next().unwrap()
}
#[test]
+12 -4
View File
@@ -22,6 +22,14 @@ fn harness() -> Harness<'static, CadApp> {
h
}
/// Focuses the control labelled `label` through its accessibility focus action. Traversal starts from a focused
/// control: with nothing focused, the app's raw input hook turns Tab into command-line text.
fn focus(h: &mut Harness<'_, CadApp>, label: &str) {
h.get_by_label(label).focus();
h.run_steps(2);
assert!(h.get_by_label(label).is_focused(), "{label} takes the focus");
}
fn tab_to(h: &mut Harness<'_, CadApp>, label: &str) {
for _ in 0..160 {
if h.query_by_label(label).is_some_and(|node| node.is_focused()) {
@@ -34,11 +42,9 @@ fn tab_to(h: &mut Harness<'_, CadApp>, label: &str) {
}
#[test]
fn toolbar_tab_and_shift_tab_skip_title_drag_and_activate_once() {
fn toolbar_tab_and_shift_tab_move_and_activate_once() {
let mut h = harness();
h.key_press(Key::Tab);
h.run_steps(2);
assert!(h.get_by_label("New Drawing (⌘N)").is_focused(), "the title drag region is not a keyboard control");
focus(&mut h, "New Drawing (⌘N)");
h.key_press(Key::Tab);
h.run_steps(2);
assert!(h.get_by_label("Open (⌘O)").is_focused());
@@ -54,6 +60,7 @@ fn toolbar_tab_and_shift_tab_skip_title_drag_and_activate_once() {
#[test]
fn toolset_tabs_traverse_and_activate_without_drafting_commands() {
let mut h = harness();
focus(&mut h, "New Drawing (⌘N)");
tab_to(&mut h, "Drafting");
h.key_press(Key::Tab);
h.run_steps(2);
@@ -86,6 +93,7 @@ fn document_tabs_have_distinct_keyboard_identity_and_activation() {
h.state_mut().run("new", serde_json::json!({})).unwrap();
h.run_steps(3);
let title = h.state().session.docs[0].title.clone();
focus(&mut h, "New Drawing (⌘N)");
tab_to(&mut h, "Start");
h.key_press(Key::Tab);
h.run_steps(2);
+2 -2
View File
@@ -5,7 +5,7 @@ use cadcraft_engine::Session;
use cadcraft_ui_egui::{CadApp, Services, docking::Panel, menus};
use egui::{Key, Modifiers, accesskit::Role, vec2};
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable, by};
use egui_kittest::kittest::{Queryable, by};
use serde_json::{Value, json};
fn harness() -> Harness<'static, CadApp> {
@@ -71,7 +71,7 @@ fn restarting_restores_calculator_data_and_ui_edits_are_saved_when_hidden() {
/// In these tests QuickCalc floats alone; scope to its body to avoid the Properties text fields.
/// Its first text input is the expression, before conversion values and variable definitions.
fn expression<'a>(h: &'a Harness<'_, CadApp>) -> egui_kittest::Node<'a> {
h.get_by_role_and_label(Role::Tab, "QuickCalc").parent().unwrap().get_all_by_role(Role::TextInput).next().unwrap()
h.get_by_role_and_label(Role::TabPanel, "QuickCalc").get_all_by_role(Role::TextInput).next().unwrap()
}
#[test]