From 4e334b479be0b21eea400b40e57181f4a54e2a3f Mon Sep 17 00:00:00 2001 From: Scott C Hughes <1591011+dottedt@users.noreply.github.com> Date: Sun, 11 Oct 2026 17:20:26 -0500 Subject: [PATCH] test(gradient): guard the on-canvas midpoint diamond drag (#3172) (#3512) The midpoint diamond's hit-test and drag were untested, so a regression there would go unnoticed. Add a repro that drags the diamond and asserts the midpoint follows (and no stop is added). The path works on current main; this is coverage, not a behaviour change. --- crates/ui-egui/src/gradient_ui.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/ui-egui/src/gradient_ui.rs b/crates/ui-egui/src/gradient_ui.rs index dedea0685ce..5fd87393d3f 100644 --- a/crates/ui-egui/src/gradient_ui.rs +++ b/crates/ui-egui/src/gradient_ui.rs @@ -1115,6 +1115,18 @@ mod tests { assert!((get(&mut app)["from"][1].as_f64().unwrap() - 10.0).abs() < 1e-3); } + #[test] + fn dragging_the_midpoint_diamond_moves_it() { + let mut app = app_with_gradient("linear"); + drag(&mut app, [20.0, 60.0], [180.0, 60.0]); + // The untouched midpoint sits at the segment centre (doc x = 100). Drag it to a quarter. + drag(&mut app, [100.0, 60.0], [60.0, 60.0]); + let g = get(&mut app); + assert_eq!(g["stops"].as_array().map(Vec::len), Some(2), "a midpoint drag must not add a stop: {g}"); + let m = g["midpoints"][0].as_f64().unwrap_or(f64::NAN); + assert!((m - 0.25).abs() < 1e-3, "the midpoint did not move: {g}"); + } + #[test] fn shift_snaps_live_drags_to_45_degrees() { let mut app = app_with_gradient("linear");