mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-11 00:11:46 +00:00
Test the Sharpen tool's layer alerts
Makes the Brush alert tests' helpers pub(super) and reuses them.
This commit is contained in:
1 parent
72dbfd9725
commit
551f9d2369
3 files changed
+105
-6
No files matched your search
@@ -9,7 +9,7 @@ use super::*;
|
||||
use crate::canvas::{ToolEvent, tool_event};
|
||||
|
||||
/// A 64 × 64 document with a painted layer active, black foreground, `tool`.
|
||||
fn app(tool: Tool) -> PhotocraftApp {
|
||||
pub(super) fn app(tool: Tool) -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
@@ -20,26 +20,26 @@ fn app(tool: Tool) -> PhotocraftApp {
|
||||
app
|
||||
}
|
||||
|
||||
fn active(app: &PhotocraftApp) -> u64 {
|
||||
pub(super) fn active(app: &PhotocraftApp) -> u64 {
|
||||
app.session.active().unwrap().active_layer.unwrap().0
|
||||
}
|
||||
|
||||
fn steps(app: &PhotocraftApp) -> usize {
|
||||
pub(super) fn steps(app: &PhotocraftApp) -> usize {
|
||||
app.session.active().unwrap().history.past_len()
|
||||
}
|
||||
|
||||
/// A press, a short drag and the release with the active tool.
|
||||
fn stroke(app: &mut PhotocraftApp) {
|
||||
pub(super) fn stroke(app: &mut PhotocraftApp) {
|
||||
tool_event(app, ToolEvent::Down { x: 20.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(app, ToolEvent::Move { x: 44.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(app, ToolEvent::Up { x: 44.0, y: 32.0 }, Modifiers::NONE);
|
||||
}
|
||||
|
||||
fn alerts(app: &PhotocraftApp) -> Vec<String> {
|
||||
pub(super) fn alerts(app: &PhotocraftApp) -> Vec<String> {
|
||||
app.ui.dialogs.iter().filter(|d| d.kind == DialogKind::Error).filter_map(|d| d.fields.get("message").and_then(Value::as_str).map(str::to_string)).collect()
|
||||
}
|
||||
|
||||
fn refused(app: &mut PhotocraftApp, want: &str) {
|
||||
pub(super) fn refused(app: &mut PhotocraftApp, want: &str) {
|
||||
let before = steps(app);
|
||||
stroke(app);
|
||||
assert_eq!(alerts(app), [want], "the alert, once");
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
//! #12952: when the Sharpen tool can't work on the layer (hidden target layer, Lock All, Lock Image
|
||||
//! Pixels, a group's pixels), a press opens the reference application's alert with OK and changes
|
||||
//! nothing; Lock transparent pixels still sharpens. The Brush keeps its alerts, the Dodge tool its
|
||||
//! colour-mode alert only.
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use super::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke};
|
||||
use super::*;
|
||||
use crate::control::{ControlRequest, Outcome, handle};
|
||||
|
||||
#[test]
|
||||
fn a_hidden_target_layer() {
|
||||
let mut app = app(Tool::Sharpen);
|
||||
let id = active(&app);
|
||||
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
|
||||
refused(&mut app, "Could not use the sharpen tool because the target layer is hidden.");
|
||||
assert!(app.ui.status.is_empty() || !app.ui.status_error, "no status-bar error as well: {:?}", app.ui.status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock_all_and_lock_image_pixels() {
|
||||
for lock in ["all", "pixels"] {
|
||||
let mut app = app(Tool::Sharpen);
|
||||
app.run("layer.lockLayers", json!({ lock: true })).unwrap();
|
||||
refused(&mut app, "Could not use the sharpen tool because the layer is locked.");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_group_is_active() {
|
||||
let mut app = app(Tool::Sharpen);
|
||||
app.run("layer.new.group", json!({})).unwrap();
|
||||
refused(&mut app, "Could not use the sharpen tool because the pixels in a group cannot be edited without merging the group.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_alert_is_listed_and_confirmed_over_the_control_channel() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = app(Tool::Sharpen);
|
||||
app.run("layer.lockLayers", json!({"pixels": true})).unwrap();
|
||||
stroke(&mut app);
|
||||
let mut call = |method: &str, params: serde_json::Value| {
|
||||
let (req, _rx) = ControlRequest::new(method, params);
|
||||
match handle(&mut app, &ctx, &req) {
|
||||
Outcome::Done(v) => v,
|
||||
_ => panic!("{method}: expected an immediate reply"),
|
||||
}
|
||||
};
|
||||
let inspect = call("ui.inspect", json!({}));
|
||||
let dialog = &inspect["result"]["dialogs"][0];
|
||||
assert_eq!(dialog["fields"]["message"], "Could not use the sharpen tool because the layer is locked.", "{inspect}");
|
||||
assert_eq!(call("ui.dialog.confirm", json!({"dialog": dialog["id"]}))["ok"], true);
|
||||
assert!(alerts(&app).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock_transparent_pixels_still_sharpens() {
|
||||
let mut app = app(Tool::Sharpen);
|
||||
app.run("layer.lockLayers", json!({"transparency": true})).unwrap();
|
||||
let before = steps(&app);
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty());
|
||||
assert_eq!(steps(&app), before + 1, "the stroke was applied");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_colour_mode_alert_comes_first() {
|
||||
// A hidden layer in an Indexed Color document: the mode alert, as before this change.
|
||||
let mut app = app(Tool::Sharpen);
|
||||
app.run("image.mode.indexedColor", json!({"palette": "exact", "dither": "none", "forced": "none"})).unwrap();
|
||||
let id = active(&app);
|
||||
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
|
||||
refused(&mut app, "Could not use the sharpen tool because it does not work with Indexed Color images (convert image to RGB Color mode to edit).");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_brush_and_the_dodge_tool_keep_todays_behaviour() {
|
||||
// The Brush: no alert for Lock Image Pixels.
|
||||
let mut app = app(Tool::Brush);
|
||||
app.run("layer.lockLayers", json!({"pixels": true})).unwrap();
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty());
|
||||
// The Dodge tool in an RGB document: no layer alerts, the status bar says a hidden target.
|
||||
let mut app = self::app(Tool::Dodge);
|
||||
let id = active(&app);
|
||||
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty());
|
||||
assert_eq!(app.ui.status, photocraft_engine::hidden_target::HIDDEN);
|
||||
let mut app = self::app(Tool::Dodge);
|
||||
app.run("layer.lockLayers", json!({"all": true})).unwrap();
|
||||
assert_eq!(alert(&app, Tool::Dodge, false), None);
|
||||
assert_eq!(tool_name(Tool::Dodge), None);
|
||||
}
|
||||
@@ -87,3 +87,7 @@ pub fn prompt(app: &mut PhotocraftApp, message: &str) {
|
||||
#[cfg(test)]
|
||||
#[path = "../brush_refusal_alert_tests.rs"]
|
||||
mod brush_refusal_alert_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../sharpen_refusal_alert_tests.rs"]
|
||||
mod sharpen_refusal_alert_tests;
|
||||
Reference in new issue
Block a user