mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Merge pull request #17442
This commit is contained in:
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 ");
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user