test(ui): one app per row group in the guide-cursor and held-key loops

`guide_cursor_tests` built a whole app for each of its 21 rows and dragged
through four intermediate points; `hold_keys::tests` built one app per tool in
five loops and pressed a stand-in for every tool that shares one family's
decision. Both loops re-entered the same production line dozens of times while
paying for the app's settle frames each round.

- guide cursor: the rows whose press the Move tool takes, and the two locked-
  guide rows, share one app; a row that moved the guide puts it back with the
  ruler's own command (`view.moveGuide`). The tools that keep the command for
  themselves share a second app, Type last and Crop on its own, because their
  drag leaves an open text edit or a pending crop that would decide the next
  row. The drag keeps two points instead of four: the guide follows the pointer.
- hold keys: one app per loop (`space_right_click...`, `command_or_alt_space...`,
  `cmd_alt_drag...`, `tilde_erases...`, `space_repositions...`), a fresh layer or
  an explicit deselect where a case would otherwise see the last one's pixels.
- the command-as-Move rule is now also asserted as data for every tool
  (`the_command_stand_in_rule_is_the_table`), so the drags can press one tool
  per decision: the vertical type tool, both path tools and the rectangle shape
  share `is_type` and the `Family::Vector` line with the tools that stayed.
This commit is contained in:
hnoerenberg committed 2026-11-21 04:58:42 +01:00
1 parent ad2d4ea082
commit c6e920c0c0
2 files changed
+135 -21

No files matched your search

+50 -12
View File
@@ -47,8 +47,10 @@ fn drag(h: &mut Harness<'static, Box<PhotocraftApp>>, from: f32, to: f32, m: Mod
h.run_steps(1);
h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: true, modifiers: m });
h.run_steps(1);
for k in 1..=4 {
let q = screen(h, from + (to - from) * k as f32 / 4.0, 150.0);
// Two moves: the guide follows the pointer, so one intermediate point is enough to drive the drag and the
// fourth one only cost another whole-app frame each row (#15941).
for k in 1..=2 {
let q = screen(h, from + (to - from) * k as f32 / 2.0, 150.0);
h.event(egui::Event::PointerMoved(q));
h.run_steps(1);
}
@@ -57,20 +59,35 @@ fn drag(h: &mut Harness<'static, Box<PhotocraftApp>>, from: f32, to: f32, m: Mod
h.run_steps(2);
}
/// The vertical guides as they stand.
fn guides(h: &Harness<'static, Box<PhotocraftApp>>) -> Vec<f64> {
h.state().session.active().unwrap().doc.guides.vertical.clone()
}
/// Put the guide back at 200 after a row dragged it, through the ruler's own command, so the next row starts
/// where the first one did without paying for another app.
fn put_guide_back(h: &mut Harness<'static, Box<PhotocraftApp>>) {
h.state_mut().run("view.moveGuide", json!({"orientation": "vertical", "index": 0, "position": 200})).unwrap();
h.run_steps(2);
assert_eq!(guides(h), vec![200.0], "the guide is back at 200 for the next row");
}
/// The cursor over the guide with ⌘ held (or latched in Window › Modifier Keys, with no key held),
/// and where a ⌘-drag from 200 to 240 leaves it.
fn command_drag(tool: Tool, locked: bool, latched: bool) -> (egui::CursorIcon, Vec<f64>) {
let mut h = harness(tool);
/// and where a ⌘-drag from 200 to 240 leaves it, on the shared harness `h`.
fn command_drag(h: &mut Harness<'static, Box<PhotocraftApp>>, tool: Tool, locked: bool, latched: bool) -> (egui::CursorIcon, Vec<f64>) {
h.state_mut().ui.tool = tool;
h.state_mut().ui.extras.lock_guides = locked;
let held = if latched {
h.state_mut().ui.shell.latched = craft::keymap::Mods::CMD;
Modifiers::NONE
} else {
h.state_mut().ui.shell.latched = craft::keymap::Mods::NONE;
Modifiers::COMMAND
};
let c = hover(&mut h, 200.0, 150.0, held);
drag(&mut h, 200.0, 240.0, held);
(c, h.state().session.active().unwrap().doc.guides.vertical.clone())
h.run_steps(1);
let c = hover(h, 200.0, 150.0, held);
drag(h, 200.0, 240.0, held);
(c, guides(h))
}
const GUIDE: egui::CursorIcon = egui::CursorIcon::ResizeHorizontal;
@@ -114,13 +131,34 @@ fn command_over_a_guide_takes_it_where_command_is_the_move_tool() {
(Tool::Rectangle, false, false, false),
(Tool::Slice, false, false, false),
];
for (tool, locked, latched, takes_guide) in rows {
let (cursor, guides) = command_drag(tool, locked, latched);
let check = |h: &mut Harness<'static, Box<PhotocraftApp>>, tool: Tool, locked: bool, latched: bool, takes_guide: bool| {
let (cursor, moved) = command_drag(h, tool, locked, latched);
if takes_guide {
assert_eq!((cursor, guides), (GUIDE, vec![240.0]), "{tool:?} latched={latched}");
assert_eq!((cursor, moved), (GUIDE, vec![240.0]), "{tool:?} latched={latched}");
put_guide_back(h);
} else {
assert_ne!(cursor, GUIDE, "{tool:?} locked={locked}");
assert_eq!(guides, vec![200.0], "{tool:?} locked={locked}");
assert_eq!(moved, vec![200.0], "{tool:?} locked={locked}");
}
};
// One app for the rows whose ⌘ press the Move tool takes, and for the two rows that ask a locked guide to stay:
// `harness` builds the whole app and its settle frames, while the selected tool, the ⌘ latch and the locked
// guides are state the app reads each frame. Each row that moved the guide puts it back with the ruler's own
// command (`view.moveGuide`), which is what a user does to move it again (#15941).
let mut shared = harness(Tool::Brush);
for (tool, locked, latched, takes_guide) in rows {
if takes_guide || matches!(tool, Tool::Brush | Tool::Frame) {
check(&mut shared, tool, locked, latched, takes_guide);
}
}
// The tools that keep ⌘ for themselves share an app too. The Type tool goes last: its ⌘-drag leaves an open
// text edit, and `moves_with_command` refuses the guides while one is open, so a later row would be decided by
// that instead of by its tool. The Crop tool keeps an app of its own for the same reason: its drag leaves a
// pending crop frame holding the canvas.
let mut keeps = harness(Tool::Pen);
for tool in [Tool::Pen, Tool::Hand, Tool::Zoom, Tool::Rectangle, Tool::Slice, Tool::Type] {
check(&mut keeps, tool, false, false, false);
}
let mut crop = harness(Tool::Crop);
check(&mut crop, Tool::Crop, false, false, false);
}
+85 -9
View File
@@ -176,8 +176,13 @@ fn space_repositions_the_drag_being_drawn() {
slack: 1,
},
];
// One app for the three marquee and lasso cases: the tool is state, and each case starts from no selection.
let mut h = harness(Tool::RectMarquee);
for c in cases {
let mut h = harness(c.tool);
h.state_mut().run("select.deselect", json!({})).ok();
assert_eq!(selection(&h), Rect::EMPTY, "{:?}: the case starts with no selection", c.tool);
h.state_mut().ui.tool = c.tool;
h.run_steps(1);
press_at(&mut h, c.start.0, c.start.1);
for &(x, y) in c.before {
move_to(&mut h, x, y);
@@ -368,10 +373,11 @@ fn cmd_gives_the_move_tool_only_where_the_tool_does_not_take_cmd() {
}
// The Crop and Rotate View tools go last, in an app of their own: they leave a pending crop and
// a turned view behind.
let keeps = [
vec![Tool::Hand, Tool::Zoom, Tool::Pen, Tool::Rectangle, Tool::Type, Tool::VerticalType, Tool::PathSelection, Tool::DirectSelection],
vec![Tool::Crop, Tool::RotateView],
];
// One tool per decision the refusal comes from: the Hand, Zoom and Rotate-View families, the vector family's
// shared line (the Pen stands for the shapes and both path tools), and the Type tools' `is_type` line (the
// vertical type tool takes the same branch). Every tool's own decision is asserted in
// `the_command_stand_in_rule_is_the_table`, without a drag.
let keeps = [vec![Tool::Hand, Tool::Zoom, Tool::Pen, Tool::Type], vec![Tool::Crop, Tool::RotateView]];
for group in keeps {
let mut h = harness(group[0]);
for tool in group {
@@ -382,6 +388,61 @@ fn cmd_gives_the_move_tool_only_where_the_tool_does_not_take_cmd() {
}
}
/// The ⌘-as-Move rule read as data: `takes_command_stand_in` and the selection family decide which tool hands a ⌘
/// press to the Move tool, for every tool in the app. The drags above press one tool per decision; this pins each
/// tool by name, so a tool that moves into another family or starts refusing the stand-in fails here.
#[test]
fn the_command_stand_in_rule_is_the_table() {
use crate::canvas::tools::Family;
let hands_to_move = |t: Tool| crate::canvas::tools::takes_command_stand_in(t) || crate::canvas::tools::family(t) == Family::Selection;
let got: Vec<Tool> = Tool::ALL.into_iter().filter(|t| hands_to_move(*t)).collect();
let want: Vec<Tool> = vec![
Tool::Artboard,
Tool::RectMarquee,
Tool::EllipseMarquee,
Tool::SingleRowMarquee,
Tool::SingleColumnMarquee,
Tool::Lasso,
Tool::PolygonLasso,
Tool::MagneticLasso,
Tool::MagicWand,
Tool::Eyedropper,
Tool::ColorSampler,
Tool::Ruler,
Tool::Note,
Tool::Count,
Tool::Brush,
Tool::Pencil,
Tool::ColorReplacement,
Tool::MixerBrush,
Tool::Eraser,
Tool::BackgroundEraser,
Tool::MagicEraser,
Tool::Gradient,
Tool::PaintBucket,
Tool::SpotHealing,
Tool::Remove,
Tool::Healing,
Tool::Patch,
Tool::ContentAwareMove,
Tool::RedEye,
Tool::CloneStamp,
Tool::PatternStamp,
Tool::HistoryBrush,
Tool::ArtHistoryBrush,
Tool::Blur,
Tool::Sharpen,
Tool::Smudge,
Tool::Dodge,
Tool::Burn,
Tool::Sponge,
Tool::QuickSelection,
Tool::ObjectSelection,
Tool::Frame,
];
assert_eq!(got, want, "which tools hand a ⌘ press to the Move tool");
}
/// A ⌘-drag with `tool`, one that keeps ⌘ for itself, leaves a fresh layer where it is.
fn keeps_the_layer(h: &mut Harness<'static, Box<PhotocraftApp>>, tool: Tool) {
let id = with_layer(h);
@@ -397,8 +458,11 @@ fn keeps_the_layer(h: &mut Harness<'static, Box<PhotocraftApp>>, tool: Tool) {
/// brush to resize, such as the Gradient.
#[test]
fn cmd_alt_drag_duplicates_the_layer_then_moves_the_copy() {
// One app, one fresh layer per case (the `with_layer` each case already calls).
let mut h = harness(Tool::Brush);
for (tool, mods) in [(Tool::Brush, MAC_CMD_ALT), (Tool::Gradient, MAC_CMD_ALT), (Tool::Gradient, CTRL_ALT)] {
let mut h = harness(tool);
h.state_mut().ui.tool = tool;
h.run_steps(1);
let orig = with_layer(&mut h);
let n0 = h.state().session.active().unwrap().doc.layers.len();
let h0 = h.state().session.active().unwrap().history.past_len();
@@ -486,8 +550,11 @@ fn last_stroke_erases(h: &Harness<'static, Box<PhotocraftApp>>) -> Option<bool>
/// holds across frames (a second pass in a frame does not clear it) and goes with the release.
#[test]
fn tilde_erases_only_with_the_brush_and_pencil() {
// One app, a fresh layer per tool (`with_layer`), so the strokes of one tool never sit under the next one's.
let mut h = harness(Tool::Brush);
for (tool, label, erases) in [(Tool::Brush, "Brush Tool", true), (Tool::Pencil, "Pencil", true), (Tool::CloneStamp, "", false)] {
let mut h = harness(tool);
h.state_mut().ui.tool = tool;
h.run_steps(1);
with_layer(&mut h);
key(&mut h, Key::Backtick, true, Modifiers::NONE);
h.run_steps(3);
@@ -559,8 +626,13 @@ fn a_held_key_keeps_a_pending_crop_and_another_tools_key_commits_it() {
/// Photoshop, not the held-over tool's menu; the tool comes back on release (#11271).
#[test]
fn space_right_click_opens_the_hand_view_menu() {
// One app for the four tools: `harness` starts the whole app (its document, panels and settle frames), which is
// most of a case, while the selected tool is state the app takes between frames (#15941). The tool is switched
// the way the ⌘-Move test below does it.
let mut h = harness(Tool::Move);
for tool in [Tool::Move, Tool::Brush, Tool::RectMarquee, Tool::Pen] {
let mut h = harness(tool);
h.state_mut().ui.tool = tool;
h.run_steps(1);
let p = screen(&h, 200.0, 150.0);
h.event(Event::PointerMoved(p));
h.run_steps(1);
@@ -611,9 +683,13 @@ fn space_hand_view_menu_closes_when_the_tool_underneath_changes() {
/// ⌘/Ctrl+right-click, which lists the layers under the pointer for any tool (#307).
#[test]
fn command_or_alt_space_right_click_opens_no_view_menu() {
// One app for all four cases, as above; the menu a ⌘+right-click leaves open is closed before the next case.
let mut h = harness(Tool::Move);
for mods in [Modifiers::COMMAND, Modifiers::ALT] {
for tool in [Tool::Move, Tool::Brush] {
let mut h = harness(tool);
h.state_mut().ui.tool = tool;
h.state_mut().ui.canvas_tool_menu = None;
h.run_steps(1);
let p = screen(&h, 200.0, 150.0);
h.event(Event::PointerMoved(p));
h.run_steps(1);