Merge pull request #10055 from dotCooCoo/fix/bristle-direction-commit-tests

Brush Options: test that a canceled Bristle slider drag leaves the brush as it was
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-29 09:08:41 -08:00
commit a6fdce3c51
1 file changed
+46
@@ -362,6 +362,52 @@ fn canceled_pattern_scale_edits_do_not_reach_the_brush() {
assert_eq!(panel.app().run("brush.get", json!({"name": "Diamonds"})).unwrap(), original);
}
/// Bristle Brush Options' sliders: a held drag ended with Escape leaves the open dialog's field as it
/// opened, and OK then leaves the brush as it was; a released drag is kept by OK.
#[test]
fn canceled_bristle_slider_drags_do_not_reach_the_brush() {
use crate::tests::panel_harness::Panel;
use craft::ui::contract::Role;
use egui::{Key, Modifiers};
for (key, label, _) in BRISTLE {
let mut app = app();
let params = json!({"length": 150.0, "density": 50.0, "thickness": 50.0, "opacity": 50.0, "stiffness": 50.0});
app.run("brush.options", json!({"name": "Bristle Round", "params": params})).unwrap();
let original = app.run("brush.get", json!({"name": "Bristle Round"})).unwrap();
let undo = app.session.active().unwrap().history.undo.len();
let mut panel = Panel::new(app, draw_hosted_options);
panel.room(egui::vec2(1000.0, 1000.0));
open(&mut panel.app(), "Bristle Round");
panel.frame();
let initial = fields_of(&panel.app()).number(key).unwrap();
panel.drag_hold_role(label, Role::SLIDER, egui::vec2(40.0, 0.0));
assert_ne!(fields_of(&panel.app()).number(key), Some(initial), "the held drag previews another {key}");
panel.key(Key::Escape, Modifiers::NONE);
panel.release();
assert!(is_open(&panel.app()));
assert_eq!(fields_of(&panel.app()).number(key), Some(initial), "the canceled drag restores the opening {key}");
panel.click("OK");
panel.frame();
assert!(!is_open(&panel.app()));
assert_eq!(panel.app().run("brush.get", json!({"name": "Bristle Round"})).unwrap(), original, "OK after a canceled {key} drag");
assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo);
open(&mut panel.app(), "Bristle Round");
panel.frame();
panel.drag_hold_role(label, Role::SLIDER, egui::vec2(40.0, 0.0));
panel.release();
let accepted = fields_of(&panel.app()).number(key).unwrap();
assert_ne!(accepted, initial);
panel.click("OK");
panel.frame();
assert_eq!(panel.app().run("brush.get", json!({"name": "Bristle Round"})).unwrap()[key], accepted);
assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo + 1);
panel.app().run("edit.undo", json!({})).unwrap();
assert_eq!(panel.app().run("brush.get", json!({"name": "Bristle Round"})).unwrap(), original);
}
}
/// What a step of the table expects at a JSON pointer of the saved brush.
enum Expect {
Is(Value),