From 19ed458045cfa4acf4c40dec12b9ce7ed12e1795 Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:18:26 +0300 Subject: [PATCH] Test the Delete Anchor Point options bar --- crates/ui-egui/src/tools/vector_ui.rs | 3 +++ .../vector_ui/add_anchor_options_bar_tests.rs | 14 +++++++---- .../delete_anchor_options_bar_tests.rs | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 crates/ui-egui/src/tools/vector_ui/delete_anchor_options_bar_tests.rs diff --git a/crates/ui-egui/src/tools/vector_ui.rs b/crates/ui-egui/src/tools/vector_ui.rs index 07f1d065f4..5633acd4cb 100644 --- a/crates/ui-egui/src/tools/vector_ui.rs +++ b/crates/ui-egui/src/tools/vector_ui.rs @@ -220,6 +220,9 @@ mod paint_tests; #[cfg(test)] mod add_anchor_options_bar_tests; +#[cfg(test)] +mod delete_anchor_options_bar_tests; + pub(crate) use pen::freeform_locked_shape; /// Where a Pen draft goes, captured at its first anchor. diff --git a/crates/ui-egui/src/tools/vector_ui/add_anchor_options_bar_tests.rs b/crates/ui-egui/src/tools/vector_ui/add_anchor_options_bar_tests.rs index 44d1720f70..a03da7149e 100644 --- a/crates/ui-egui/src/tools/vector_ui/add_anchor_options_bar_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/add_anchor_options_bar_tests.rs @@ -12,7 +12,7 @@ use crate::state::Tool; const NO_OPTIONS: &str = "No options for the Add Anchor Point Tool."; const WIDTH: f32 = 1280.0; -fn harness(tool: Tool) -> Harness<'static, PhotocraftApp> { +pub(super) fn harness(tool: Tool) -> Harness<'static, PhotocraftApp> { let mut s = photocraft_engine::Session::new(); s.execute("file.new", json!({"width": 200, "height": 100})).unwrap(); let mut h = Harness::builder().with_size(vec2(WIDTH, 800.0)).build_eframe(move |cc| { @@ -28,12 +28,16 @@ fn harness(tool: Tool) -> Harness<'static, PhotocraftApp> { #[test] fn add_anchor_point_bar_says_it_has_no_options() { let h = harness(Tool::AddAnchorPoint); - let text = h.get_by_label(NO_OPTIONS); assert!(h.query_by_label_contains("Click a segment to add an anchor point").is_none(), "the Alt hint is gone"); - // Centred between the preset picker and the bar's right edge; the tolerance covers the bar's padding. + assert_centred_after_picker(&h, Tool::AddAnchorPoint, NO_OPTIONS); +} + +/// The text is centred between the preset picker and the bar's right edge; the tolerance covers +/// the bar's padding. +pub(super) fn assert_centred_after_picker(h: &Harness<'static, PhotocraftApp>, tool: Tool, label: &str) { + let rect = h.get_by_label(label).rect(); // The toolbox has a button of the same name; the bar's picker is the one on the text's row. - let rect = text.rect(); - let picker = h.query_all_by_label(Tool::AddAnchorPoint.label()).map(|n| n.rect()).find(|r| r.y_range().contains(rect.center().y)).unwrap(); + let picker = h.query_all_by_label(tool.label()).map(|n| n.rect()).find(|r| r.y_range().contains(rect.center().y)).unwrap(); let centre = (picker.max.x + WIDTH) / 2.0; let mid = (rect.min.x + rect.max.x) / 2.0; assert!((mid - centre).abs() < 20.0, "text centre {mid} vs remaining bar centre {centre}"); diff --git a/crates/ui-egui/src/tools/vector_ui/delete_anchor_options_bar_tests.rs b/crates/ui-egui/src/tools/vector_ui/delete_anchor_options_bar_tests.rs new file mode 100644 index 0000000000..0e839372a2 --- /dev/null +++ b/crates/ui-egui/src/tools/vector_ui/delete_anchor_options_bar_tests.rs @@ -0,0 +1,24 @@ +//! #12827: the Delete Anchor Point options bar holds the preset picker and "No options for the +//! Delete Anchor Point Tool." centred in the rest of the bar, as in Photoshop. + +use egui_kittest::kittest::Queryable; + +use super::add_anchor_options_bar_tests::{assert_centred_after_picker, harness}; +use crate::state::Tool; + +const NO_OPTIONS: &str = "No options for the Delete Anchor Point Tool."; + +#[test] +fn delete_anchor_point_bar_says_it_has_no_options() { + let h = harness(Tool::DeleteAnchorPoint); + assert!(h.query_by_label_contains("Click an anchor point to delete it").is_none(), "the Alt hint is gone"); + assert!(h.query_by_label("No options for the Add Anchor Point Tool.").is_none()); + assert_centred_after_picker(&h, Tool::DeleteAnchorPoint, NO_OPTIONS); +} + +#[test] +fn other_pen_group_bars_do_not_say_it() { + for tool in [Tool::Pen, Tool::FreeformPen, Tool::CurvaturePen, Tool::AddAnchorPoint, Tool::ConvertPoint] { + assert!(harness(tool).query_by_label(NO_OPTIONS).is_none(), "{tool:?}"); + } +}