mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Lens Correction batch: test the dialog layout
Group order, captions, the two Correction Options columns, the Edge entries and their stored values, no Alt Reset, Escape cancels, Browse... and Choose... pick the folders, a field set to null shows and sends its default, and OK runs the command with the params the generic form sent. The harness helpers are pub(super) for the other dialog items of #13978.
This commit is contained in:
1 parent
be9f00969f
commit
4159a8a86c
2 files changed
+127
No files matched your search
@@ -0,0 +1,123 @@
|
||||
//! #13981: the batch Lens Correction dialog shows its controls in the reference application's four
|
||||
//! sections with the reference captions and the Edge entries in the reference order.
|
||||
|
||||
use craft::ui::dialog::DialogId;
|
||||
use craft::ui::patterns::form_dialogs::{HostedParamDialog, ParamKind};
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
|
||||
pub(super) type H = egui_kittest::Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
/// The open dialogs drawn over `app`, as the window shows them.
|
||||
pub(super) fn harness(app: Box<PhotocraftApp>) -> H {
|
||||
let mut h = egui_kittest::Harness::builder().with_context(app.ctx().clone()).with_size(egui::vec2(900.0, 1000.0)).build_ui_state(
|
||||
|ui, app: &mut Box<PhotocraftApp>| {
|
||||
if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
|
||||
crate::dialogs::run(app, ui);
|
||||
}
|
||||
},
|
||||
app,
|
||||
);
|
||||
PhotocraftApp::setup_context(&h.ctx, Default::default());
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
/// Opens the dialog from the File menu over `app`.
|
||||
pub(super) fn open_in(mut app: Box<PhotocraftApp>) -> (H, DialogId) {
|
||||
let ctx = app.ctx().clone();
|
||||
let reply = crate::menus::invoke(&mut app, &ctx, super::COMMAND, json!({})).unwrap();
|
||||
let want = reply["dialog"].as_str().expect("the reply names a dialog").to_owned();
|
||||
let id = app.framework.dialogs.open_dialogs().into_iter().map(|d| d.id).find(|id| id.value().to_string() == want).expect("the dialog is open");
|
||||
(harness(app), id)
|
||||
}
|
||||
|
||||
/// The dialog open over an app without a document (the command needs none).
|
||||
pub(super) fn opened() -> (H, DialogId) {
|
||||
open_in(PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()))
|
||||
}
|
||||
|
||||
pub(super) fn set(h: &mut H, id: DialogId, key: &str, value: Value) {
|
||||
let ctx = h.ctx.clone();
|
||||
h.state_mut().framework.dialogs.set_json_field(&ctx, id, key, value).unwrap_or_else(|e| panic!("{key}: {e}"));
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
/// The params OK sends.
|
||||
pub(super) fn params(h: &H, id: DialogId) -> Value {
|
||||
let fields = h.state().framework.dialogs.get_by_id::<HostedParamDialog>(id).unwrap().fields().clone();
|
||||
crate::filter_dialog::command_params(super::COMMAND, &fields)
|
||||
}
|
||||
|
||||
/// A fresh folder holding one source, `a.png`.
|
||||
pub(super) fn source_folder() -> tempfile::TempDir {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut image = photocraft_engine::Session::new();
|
||||
image.execute("file.new", json!({"width": 40, "height": 20, "background": "white"})).unwrap();
|
||||
let png = photocraft_io::export(&image.active().unwrap().doc, "a.png", &Default::default()).unwrap().bytes;
|
||||
std::fs::write(dir.path().join("a.png"), png).unwrap();
|
||||
dir
|
||||
}
|
||||
|
||||
/// The options of the list row `key`, as their labels.
|
||||
fn labels(key: &str) -> Vec<String> {
|
||||
let rows = super::rows(".".into());
|
||||
let row = rows.iter().find(|p| p.key == key).unwrap_or_else(|| panic!("a {key} row"));
|
||||
let ParamKind::Choice { options, .. } = &row.kind else { panic!("{key} is a list") };
|
||||
options.iter().map(|(_, label)| label.as_str().to_owned()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_four_sections_and_their_rows_follow_the_reference_order() {
|
||||
crate::i18n::with_language(crate::i18n::Lang::EN, || {
|
||||
let (h, _) = opened();
|
||||
let top = |label: &str| h.query_all_by_label(label).map(|n| n.rect().top()).reduce(f32::min).unwrap_or_else(|| panic!("no {label}"));
|
||||
let order = [
|
||||
"Source Files",
|
||||
"Input",
|
||||
"Destination Folder",
|
||||
"File Type",
|
||||
"Output",
|
||||
"Lens Correction Profile",
|
||||
"Profile",
|
||||
"Correction Options",
|
||||
"Geometric Distortion",
|
||||
"Chromatic Aberration",
|
||||
"Vignette",
|
||||
"Auto Scale Image",
|
||||
"Edge",
|
||||
];
|
||||
for pair in order.windows(2) {
|
||||
assert!(top(pair[0]) < top(pair[1]), "order: {pair:?}");
|
||||
}
|
||||
for generated in ["Auto scale", "Correct c a", "Correct distortion", "Correct vignette"] {
|
||||
assert!(h.query_by_label(generated).is_none(), "the generated label {generated} is gone");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edge_lists_the_reference_entries_in_order() {
|
||||
assert_eq!(labels("edge"), ["Edge Extension", "Transparency", "Black Color", "White Color"]);
|
||||
assert_eq!(labels("profile"), ["Auto", "Generic", "None"]);
|
||||
}
|
||||
|
||||
/// OK sends the params the form sent before the layout: the same keys and values.
|
||||
#[test]
|
||||
fn ok_runs_the_command_with_the_same_params() {
|
||||
let (mut h, id) = opened();
|
||||
assert_eq!(
|
||||
params(&h, id),
|
||||
json!({"input": ".", "output": "./corrected", "format": "same", "profile": "auto", "correctDistortion": true, "correctVignette": true, "correctCA": true, "autoScale": true, "edge": "transparency"})
|
||||
);
|
||||
let sources = source_folder();
|
||||
let results = tempfile::tempdir().unwrap();
|
||||
set(&mut h, id, "input", json!(sources.path().to_string_lossy()));
|
||||
set(&mut h, id, "output", json!(results.path().to_string_lossy()));
|
||||
crate::dialogs::testing::confirm(h.state_mut(), id).expect("OK is accepted");
|
||||
h.run_steps(4);
|
||||
assert!(h.state().framework.dialogs.is_empty(), "OK closes the dialog");
|
||||
assert!(std::fs::read_dir(results.path()).unwrap().next().is_some(), "OK runs the batch into the destination folder");
|
||||
}
|
||||
@@ -43,3 +43,7 @@ pub(crate) fn rows(dir: String) -> Vec<Param> {
|
||||
Param::new("edge", tl!("Edge"), ParamKind::choice(opts(&EDGES), Some("transparency".into()))),
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "lens_batch_layout_tests.rs"]
|
||||
mod lens_batch_layout_tests;
|
||||
Reference in new issue
Block a user