Group Black & White presets and exercise every mix

This commit is contained in:
Dan committed 2026-11-24 23:55:37 +00:00
1 parent 9868184029
commit 2b1afe637c
2 files changed
+48 -1

No files matched your search

@@ -15,9 +15,10 @@ use super::{AdjustAsk, AdjustOut, AdjustValue};
type Mix = [f64; 6];
/// The presets change the grayscale mix and keep the layer's tint settings.
fn entries() -> [Entry<Option<Mix>>; 14] {
fn entries() -> [Entry<Option<Mix>>; 16] {
[
Entry::new(Some(BlackWhite::DEFAULT_WEIGHTS), tl!("Default")),
Entry::separator(),
Entry::new(Some([22.0, 38.0, 25.0, 36.0, 10.0, 50.0]), tl!("Darker")),
Entry::new(Some([60.0, 77.0, 64.0, 78.0, 47.0, 92.0]), tl!("Lighter")),
Entry::new(Some([8.0; 6]), tl!("Deep Shadows")),
@@ -30,6 +31,7 @@ fn entries() -> [Entry<Option<Mix>>; 14] {
Entry::new(Some([100.0, 73.0, 24.0, 7.0, 5.0, 64.0]), tl!("Strong Red Filter")),
Entry::new(Some([4.0, 12.0, 27.0, 71.0, 100.0, 44.0]), tl!("Strong Blue Filter")),
Entry::new(Some([58.0, 89.0, 97.0, 38.0, 8.0, 33.0]), tl!("Infrared Foliage")),
Entry::separator(),
Entry::new(None, tl!("Custom")),
]
}
@@ -497,6 +497,51 @@ fn assert_black_white_preset(h: &Harness<'_, Box<PhotocraftApp>>, name: &str) {
assert_eq!(h.get_by_role_and_label(Role::ComboBox, "Preset").accesskit_node().value().as_deref(), Some(name));
}
#[test]
fn black_white_presets_each_set_a_distinct_mix_and_keep_tint() {
let mut h = app_harness("blackWhite", "rgb", 8);
// Leave enough vertical space for the complete dropdown to be visible at once.
h.set_size(vec2(1440.0, 1350.0));
let (id, _) = layer(&h);
h.state_mut().run("layer.setAdjustment", json!({"layer": id.0, "tint": true, "tintColor": "#336699"})).unwrap();
h.run_steps(4);
let (_, original) = layer(&h);
let Adjustment::BlackWhite { tint: original_tint, .. } = &original else { panic!("{original:?}") };
let mut seen = Vec::new();
for name in [
"Darker",
"Lighter",
"Deep Shadows",
"Bright Highlights",
"Even Color Weights",
"Red Filter",
"Yellow Filter",
"Green Filter",
"Blue Filter",
"Strong Red Filter",
"Strong Blue Filter",
"Infrared Foliage",
"Default",
] {
let history = history_len(&h);
h.get_by_role_and_label(Role::ComboBox, "Preset").click();
h.run_steps(3);
h.get_by_role_and_label(Role::ListBoxOption, name).click();
h.run_steps(4);
let (_, applied) = layer(&h);
let Adjustment::BlackWhite { weights, tint } = applied else { panic!("{applied:?}") };
assert!(!seen.contains(&weights), "{name} must set a distinct mix");
seen.push(weights);
assert_black_white_preset(&h, name);
assert_eq!(&tint, original_tint, "{name} preserves Tint");
assert_eq!(history_len(&h), history + 1, "{name} is one history step");
assert!(h.state().live_adjust.is_none(), "{name} finishes the preview");
}
assert_eq!(layer(&h).1, original, "Default restores the original mix");
}
#[test]
fn black_white_presets_apply_through_properties_and_undo() {
let mut h = app_harness("blackWhite", "rgb", 8);