Merge pull request #17442

This commit is contained in:
autocraft-bot[bot] committed 2026-12-01 15:26:27 +00:00
commit 9b5c3555bd
2 files changed
+27 -1

No files matched your search

@@ -0,0 +1,22 @@
use super::{COMMAND, testing};
use crate::{PhotocraftApp, Services};
use serde_json::json;
#[test]
fn new_layer_dialog_trims_only_its_name() {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Services::default());
app.run("file.new", json!({"width": 16, "height": 16})).unwrap();
let ctx = app.ctx().clone();
for (typed, expected) in [(" sp a ", Some("sp a")), ("", None), (" ", None)] {
let default = app.session.active().unwrap().doc.next_layer_name("Layer");
crate::menus::invoke(&mut app, &ctx, COMMAND, json!({})).unwrap();
let id = testing::top(&app);
testing::set(&mut app, id, "name", json!(typed)).unwrap();
crate::dialogs::confirm(&mut app, &ctx, id).unwrap();
assert_eq!(app.session.active().unwrap().doc.layers.last().unwrap().name, expected.unwrap_or(&default));
}
app.run(COMMAND, json!({"name": "abc "})).unwrap();
assert_eq!(app.session.active().unwrap().doc.layers.last().unwrap().name, "abc ");
}
+5 -1
View File
@@ -88,7 +88,7 @@ pub fn params(f: &DialogFields) -> Value {
});
// An empty name gets the next "Layer N", as the Layers panel button does.
if let Some(name) = f.text("name").filter(|n| !n.trim().is_empty()) {
p["name"] = json!(name);
p["name"] = json!(name.trim_matches(' '));
}
p
}
@@ -130,6 +130,10 @@ pub(crate) mod testing {
}
}
#[cfg(test)]
#[path = "new_layer_name_trim_tests.rs"]
mod new_layer_name_trim_tests;
#[cfg(test)]
mod tests {
use serde_json::json;