mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge pull request #17458
Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
commit
4b4353d3a6
2 files changed
+65
-1
No files matched your search
@@ -296,8 +296,10 @@ fn set_scale(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
other => return Err(bad(CMD, format!("unknown preset `{other}` (default|custom)"))),
|
||||
};
|
||||
if next != cur {
|
||||
// The reference names the step after the submenu entry that made it (#17410).
|
||||
let label = if preset == "default" { "Set Default Measurement Scale" } else { "Custom Measurement Scale" };
|
||||
let n = next.clone();
|
||||
s.edit("Set Measurement Scale", move |d, _| {
|
||||
s.edit(label, move |d, _| {
|
||||
d.measurement.scale = n;
|
||||
Ok(())
|
||||
})?;
|
||||
@@ -1460,4 +1462,6 @@ mod data_points_one_list_tests;
|
||||
#[cfg(test)]
|
||||
mod record_no_data_points_tests;
|
||||
#[cfg(test)]
|
||||
mod scale_history_names_tests;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -0,0 +1,60 @@
|
||||
//! History step names of Image › Analysis › Set Measurement Scale, measured against the reference
|
||||
//! application (#17410): Custom (the dialog, a preset, a script set) adds one step "Custom
|
||||
//! Measurement Scale", Default adds one step "Set Default Measurement Scale", and a call that
|
||||
//! leaves the scale as it is adds no step.
|
||||
|
||||
use super::*;
|
||||
|
||||
const CMD: &str = "image.analysis.setMeasurementScale";
|
||||
|
||||
fn session() -> Session {
|
||||
let mut s = crate::session();
|
||||
s.execute("file.new", json!({"width": 40, "height": 30, "background": "white"})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
fn steps(s: &Session) -> usize {
|
||||
s.active().unwrap().history.past_len()
|
||||
}
|
||||
|
||||
fn last_step(s: &Session) -> String {
|
||||
s.active().unwrap().history.entries().last().cloned().unwrap_or_default()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_and_bare_values_add_one_custom_step() {
|
||||
for p in [
|
||||
json!({"preset": "custom", "pixelLength": 100, "logicalLength": 2.5, "units": "cm"}),
|
||||
json!({"pixelLength": 100, "logicalLength": 2.5, "units": "cm"}),
|
||||
json!({"units": "mm"}),
|
||||
] {
|
||||
let mut s = session();
|
||||
let before = steps(&s);
|
||||
s.execute(CMD, p.clone()).unwrap();
|
||||
assert_eq!(steps(&s), before + 1, "{p}");
|
||||
assert_eq!(last_step(&s), "Custom Measurement Scale", "{p}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_adds_one_default_step() {
|
||||
let mut s = session();
|
||||
s.execute(CMD, json!({"pixelLength": 10, "logicalLength": 1, "units": "cm"})).unwrap();
|
||||
let before = steps(&s);
|
||||
s.execute(CMD, json!({"preset": "default"})).unwrap();
|
||||
assert_eq!(steps(&s), before + 1);
|
||||
assert_eq!(last_step(&s), "Set Default Measurement Scale");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unchanged_scale_adds_no_step() {
|
||||
let mut s = session();
|
||||
let before = steps(&s);
|
||||
s.execute(CMD, json!({"preset": "default"})).unwrap();
|
||||
assert_eq!(steps(&s), before, "Default on a default scale");
|
||||
let p = json!({"pixelLength": 10, "logicalLength": 1, "units": "cm"});
|
||||
s.execute(CMD, p.clone()).unwrap();
|
||||
let before = steps(&s);
|
||||
s.execute(CMD, p).unwrap();
|
||||
assert_eq!(steps(&s), before, "the same custom values again");
|
||||
}
|
||||
Reference in new issue
Block a user