mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
test(ui): pin the Shift+letter chords of every tool group in one table test
The fired sweeps hand the command to run_fired themselves, so no test pressed the Shift+<letter> chords: with the binding for Shift+V dropped at shortcut_dispatch::command_rows the branch stayed green where main fails three. New every_group_letter_shift_chord_reaches_its_group_step asserts the keymap chord of every tools.nextInGroup row over tool_shortcuts::group_letters() on one settled app - one lookup per letter, no frames - the Space anchor row included: its default text `Shift+ ` parses to no chord, so it pins that nothing binds it. Proven red by the temporary Shift+V neuter, green after restoring it. Also in this review round: correct the bare_app comment claiming the menu shortcut test presses these rows (menu_rows lists no tools.nextInGroup id); collapse the byte-identical press and press_in_one_frame in the dispatch tests into one press; split the guide rows by takes_guide || locked instead of tool name, count all 21 rows through the three apps, and guard the keeps app idle (no open text edit) before each row.
This commit is contained in:
1 parent
50a45d0318
commit
e8b696a6c8
3 files changed
+43
-25
No files matched your search
@@ -141,14 +141,17 @@ fn command_over_a_guide_takes_it_where_command_is_the_move_tool() {
|
||||
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:
|
||||
// One app for the rows whose ⌘ press the Move tool takes and for the 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).
|
||||
// guides are state the app reads each frame. The split is by what a row expects, not by tool name: a takes-row
|
||||
// puts the guide back with the ruler's own command (`view.moveGuide`, what a user does to move it again) and a
|
||||
// locked row moves nothing, so neither leaves state for the rows after it (#15941).
|
||||
let mut shared = harness(Tool::Brush);
|
||||
let mut ran = 0;
|
||||
for (tool, locked, latched, takes_guide) in rows {
|
||||
if takes_guide || matches!(tool, Tool::Brush | Tool::Frame) {
|
||||
if takes_guide || locked {
|
||||
check(&mut shared, tool, locked, latched, takes_guide);
|
||||
ran += 1;
|
||||
}
|
||||
}
|
||||
// The tools that keep ⌘ for themselves share an app too. The Type tool goes last: its ⌘-drag leaves an open
|
||||
@@ -157,8 +160,14 @@ fn command_over_a_guide_takes_it_where_command_is_the_move_tool() {
|
||||
// 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] {
|
||||
// Cheap guard on the reason this app is ordered: no row so far left an open text edit that would decide
|
||||
// this one instead of its tool.
|
||||
assert!(keeps.state().ui.text_edit.is_none(), "no text edit open before {tool:?} in the keeps app");
|
||||
check(&mut keeps, tool, false, false, false);
|
||||
ran += 1;
|
||||
}
|
||||
let mut crop = harness(Tool::Crop);
|
||||
check(&mut crop, Tool::Crop, false, false, false);
|
||||
ran += 1;
|
||||
assert_eq!(ran, rows.len(), "every row ran once: {} shared, 6 keeps, 1 crop", ran - 7);
|
||||
}
|
||||
@@ -82,23 +82,11 @@ pub(crate) fn tap(h: &mut Harness<'_, Box<PhotocraftApp>>, key: Key, mods: Modif
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
/// A press and release queued in one input frame, then the frames that take it and run its command: two, not
|
||||
/// [`tap`]'s three - the runtime takes the key in the first and the app runs the command it fired in the second
|
||||
/// (`quick_shift_press` in `tool_shift_cycle_order_tests` measures the same for the tool letters). The third frame
|
||||
/// only drew the app again (#15941).
|
||||
fn press(h: &mut Harness<'_, Box<PhotocraftApp>>, sc: &str) {
|
||||
let sc = parse(sc).unwrap_or_else(|| panic!("unparsable shortcut {sc}"));
|
||||
// Two frames, not [`tap`]'s three: the runtime takes the key in the first and the app runs the command it fired
|
||||
// in the second (`quick_shift_press` in `tool_shift_cycle_order_tests` measures the same for the tool letters).
|
||||
// The third frame only drew the app again (#15941).
|
||||
let m = platform(sc.modifiers);
|
||||
h.input_mut().events.extend([
|
||||
egui::Event::ModifiersChanged(m),
|
||||
egui::Event::Key { key: sc.logical_key, physical_key: None, pressed: true, repeat: false, modifiers: m },
|
||||
egui::Event::Key { key: sc.logical_key, physical_key: None, pressed: false, repeat: false, modifiers: m },
|
||||
egui::Event::ModifiersChanged(Modifiers::NONE),
|
||||
]);
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
/// Queue one press/release in one input frame, then let the runtime collect and the app dispatch it.
|
||||
fn press_in_one_frame(h: &mut Harness<'_, Box<PhotocraftApp>>, sc: &str) {
|
||||
let sc = parse(sc).unwrap_or_else(|| panic!("unparsable shortcut {sc}"));
|
||||
let m = platform(sc.modifiers);
|
||||
h.input_mut().events.extend([
|
||||
@@ -370,7 +358,7 @@ fn every_kind_of_shortcut_dispatches_from_where_focus_usually_is() {
|
||||
// A press the focused component holds (the Layers rows' stacking and visibility keys)
|
||||
// is the component's and reaches no app command.
|
||||
let held = focus_holds(&h.ctx, chord);
|
||||
press_in_one_frame(&mut h, &sc);
|
||||
press(&mut h, &sc);
|
||||
let log = take_log(&h.ctx);
|
||||
if typing && !chord.has_command() && !chord.is_function_key() {
|
||||
// A focused text field keeps its typing / editing keys: nothing may fire.
|
||||
@@ -396,7 +384,7 @@ fn every_kind_of_shortcut_dispatches_from_where_focus_usually_is() {
|
||||
for t in one.into_iter().chain(many) {
|
||||
let start = if t.key() == 'H' { Tool::Move } else { Tool::Hand };
|
||||
h.state_mut().ui.tool = start;
|
||||
press_in_one_frame(&mut h, &t.key().to_string());
|
||||
press(&mut h, &t.key().to_string());
|
||||
let want = if typing { start } else { t };
|
||||
if h.state().ui.tool.key() != want.key() {
|
||||
failures.push(format!("{place:?}: tool key {} left {:?}, expected a {} tool", t.key(), h.state().ui.tool, want.key()));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Shift+letter steps through a key's tool group in the toolbar flyout's order, wrapping, and the
|
||||
//! anchor point tools have no letter so P never reaches them.
|
||||
|
||||
use craft::keymap::Chord;
|
||||
use craft::ui::runtime::commands::{FirePhase, FireSource, Fired};
|
||||
use egui::{Key, Modifiers};
|
||||
use egui_kittest::Harness;
|
||||
@@ -68,9 +69,10 @@ fn quick_shift_press(h: &mut Harness<'static, Box<PhotocraftApp>>, key: Key) {
|
||||
/// call [`crate::shortcut_dispatch::run_fired`], which is the entry a fired Shift+letter reaches once the runtime
|
||||
/// has taken the key. One whole-app frame costs more than the pick itself (#15651), and 64 tool members x two frames
|
||||
/// per press made these three tests the slowest of their file. The keyboard's way to this entry stays pressed for
|
||||
/// one tool per kind of group in [`a_real_shift_letter_takes_the_next_tool_of_its_group`], and every
|
||||
/// `tools.nextInGroup` row's binding is pressed by
|
||||
/// `input::shortcut_dispatch::tests::every_displayed_shortcut_runs_its_menu_item`.
|
||||
/// one tool per kind of group in [`a_real_shift_letter_takes_the_next_tool_of_its_group`], and the chord itself is
|
||||
/// pinned for every group letter by [`every_group_letter_shift_chord_reaches_its_group_step`] below. These sweeps
|
||||
/// hand the command to [`crate::shortcut_dispatch::run_fired`] directly, and no menu shows a `tools.nextInGroup`
|
||||
/// row, so `input::shortcut_dispatch::tests::every_displayed_shortcut_runs_its_menu_item` never takes their branch.
|
||||
fn bare_app() -> (Box<PhotocraftApp>, egui::Context) {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 20, "height": 10})).unwrap();
|
||||
@@ -151,6 +153,25 @@ fn a_real_shift_letter_takes_the_next_tool_of_its_group() {
|
||||
assert_eq!(h.state().ui.tool, Tool::Frame, "Shift+K picks the only tool of the Frame group");
|
||||
}
|
||||
|
||||
/// The chord each group step hangs on: `command_rows` gives every `tools.nextInGroup` row its default
|
||||
/// `Shift+<LETTER>` binding, and the keymap is what turns the pressed chord into the command the fired sweeps hand to
|
||||
/// `run_fired` themselves. The sweeps and that entry point pin nothing here, and no menu shows a `tools.nextInGroup`
|
||||
/// row, so this table - one settled app, one keymap lookup per letter, no frames per letter - is what fails when a
|
||||
/// row's chord is dropped. The Space group of the Pen flyout's anchor tools (their `key()`, `state::tool`) takes the
|
||||
/// same loop: its default text is `Shift+ ` with no key name, which `Chord::parse` refuses, so production binds
|
||||
/// Shift+Space to nothing - pinned too, and this row changes the day a spellable binding for it is added.
|
||||
#[test]
|
||||
fn every_group_letter_shift_chord_reaches_its_group_step() {
|
||||
let h = app();
|
||||
for (letter, _) in crate::tool_shortcuts::group_letters() {
|
||||
let id = crate::shortcut_dispatch::next_in_group_id(letter);
|
||||
let command = crate::shortcut_dispatch::keymap_command(&id);
|
||||
let bound = craft::ui::runtime::commands::chord(&h.ctx, &command);
|
||||
let want = Chord::parse(&format!("Shift+{}", letter.to_ascii_uppercase())).ok();
|
||||
assert_eq!(bound, want, "Shift+{letter} reaches {id}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn w_cycles_object_selection_quick_selection_magic_wand() {
|
||||
assert_eq!(sequence('W', 4), vec![Tool::ObjectSelection, Tool::QuickSelection, Tool::MagicWand, Tool::ObjectSelection]);
|
||||
|
||||
Reference in new issue
Block a user