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.
This commit is contained in:
Scott C Hughes authored and GitHub committed 2026-10-11 18:20:26 -04:00
1 parent f0d3156ad6
commit 4e334b479b
1 file changed
+12
+12
View File
@@ -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");