Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Separate shortcut capture checks from native snapshot rendering

IanHollow3834845a603f
diff --git a/crates/ui-egui/src/shortcut_capture_tests.rs b/crates/ui-egui/src/shortcut_capture_tests.rs
index d68ae57d9..57f7caee9 100644
--- a/crates/ui-egui/src/shortcut_capture_tests.rs
+++ b/crates/ui-egui/src/shortcut_capture_tests.rs
@@ -15,7 +15,13 @@ fn key(h: &mut Harness<'_, PhotocraftApp>, key: Key, pressed: bool, modifiers: M
/// The Keyboard Shortcuts dialog with `command` selected, filtered to it.
fn dialog(ppp: f32, command: &str, filter: &str) -> (Harness<'static, PhotocraftApp>, u64) {
- let mut h = Harness::builder().with_size(egui::vec2(1100.0, 760.0)).with_pixels_per_point(ppp).with_max_steps(64).build_eframe(|cc| {
+ dialog_with_renderer(ppp, command, filter, false)
+}
+
+fn dialog_with_renderer(ppp: f32, command: &str, filter: &str, gpu: bool) -> (Harness<'static, PhotocraftApp>, u64) {
+ let builder = Harness::builder().with_size(egui::vec2(1100.0, 760.0)).with_pixels_per_point(ppp).with_max_steps(64);
+ let builder = if gpu { builder.wgpu() } else { builder };
+ let mut h = builder.build_eframe(|cc| {
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default())
});
@@ -134,21 +140,43 @@ fn capture(h: &mut Harness<'_, PhotocraftApp>, button: &str, modifier: Key, held
h.run_steps(2);
}
+fn captured_ctrl_k(ppp: f32, gpu: bool) -> Harness<'static, PhotocraftApp> {
+ let (mut h, id) = dialog_with_renderer(ppp, "edit.search", "search…", gpu);
+ // Search's default is ⌘F (Photoshop); ⌘K is Preferences, so this also reports a conflict.
+ let current = crate::shortcuts::pretty("Cmd+F");
+ // On Windows and Linux the Ctrl key is the command modifier.
+ capture(&mut h, &current, Key::ControlLeft, Modifiers::COMMAND, Key::K);
+ assert_eq!(field(&h, id, "overrides")["edit.search"], json!("Cmd+K"), "@{ppp}x");
+ assert_eq!(field(&h, id, "capture"), json!(false));
+ let message = field(&h, id, "message");
+ assert!(!message.as_str().unwrap().contains("ontrol"), "@{ppp}x: {message}");
+ // The row shows the new shortcut.
+ h.get_by_label(&crate::shortcuts::pretty("Cmd+K"));
+ h
+}
+
#[test]
fn ctrl_k_is_recorded_as_ctrl_k_not_the_control_key() {
for ppp in [1.0, 2.0] {
- let (mut h, id) = dialog(ppp, "edit.search", "search…");
- // Search's default is ⌘F (Photoshop); ⌘K is Preferences, so this also reports a conflict.
- let current = crate::shortcuts::pretty("Cmd+F");
- // On Windows and Linux the Ctrl key is the command modifier.
- capture(&mut h, &current, Key::ControlLeft, Modifiers::COMMAND, Key::K);
- assert_eq!(field(&h, id, "overrides")["edit.search"], json!("Cmd+K"), "@{ppp}x");
- assert_eq!(field(&h, id, "capture"), json!(false));
- let message = field(&h, id, "message");
- assert!(!message.as_str().unwrap().contains("ontrol"), "@{ppp}x: {message}");
- // The row shows the new shortcut.
- h.get_by_label(&crate::shortcuts::pretty("Cmd+K"));
- h.render().ok();
+ let _h = captured_ctrl_k(ppp, false);
+ }
+}
+
+/// Opt-in visual check, following the Camera Raw localization snapshot convention.
+#[test]
+fn captured_shortcut_gpu_snapshots() {
+ let Some(directory) = std::env::var_os("PHOTOCRAFT_SHORTCUT_SNAPSHOTS") else {
+ eprintln!("set PHOTOCRAFT_SHORTCUT_SNAPSHOTS to capture the shortcut dialog at 1x and 2x");
+ return;
+ };
+ let _gpu = photocraft_testkit::gpu_lock();
+ let directory = std::path::PathBuf::from(directory);
+ std::fs::create_dir_all(&directory).unwrap();
+ for (scale, ppp) in [(1, 1.0), (2, 2.0)] {
+ let mut h = captured_ctrl_k(ppp, true);
+ let image = h.render().expect("render captured shortcut");
+ assert_eq!((image.width(), image.height()), (1100 * scale, 760 * scale));
+ image.save(directory.join(format!("ctrl-k-{scale}x.png"))).expect("save shortcut snapshot");
}
}
diff --git a/docs/development.md b/docs/development.md
index ceb679f5f..837f6c053 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -61,6 +61,37 @@ cargo test --doc --workspace # nextest does not run doctests
[cargo-nextest](https://nexte.st) runs each test in its own process. `.config/nextest.toml` puts the GPU tests (`photocraft-gpu`, and ui-egui's integration and canvas/GPU tests) in a group of at most 4 at a time, because each process opens its own wgpu device and the in-process `gpu_lock()` no longer serializes them. On a 32-thread Windows machine the full workspace went from 297 s (`cargo test`) to about 120 s (#2204). Ignored tests run with `cargo nextest run --run-ignored only`. CI still runs `cargo test`, and a full `cargo test` stays the final check before a PR.
+### Shortcut capture without a GPU, and native snapshots
+
+The ordinary `shortcut_capture_tests` check modifier capture, conflicts, restored bindings and
+visible labels without starting a GPU renderer. `captured_shortcut_gpu_snapshots` repeats the Ctrl+K
+capture assertions at 1x and 2x with a native renderer when `PHOTOCRAFT_SHORTCUT_SNAPSHOTS` names
+an output directory. Its `gpu` test name selects the existing Nextest GPU group. It also holds
+`photocraft_testkit::gpu_lock`, requires successful rendering and
+checks physical image dimensions before saving both PNGs. As with the Camera Raw localization
+snapshots, pixel appearance is reviewed from the saved images rather than a golden-image test.
+
+On a native host with a working wgpu adapter, capture the two images into a fresh directory:
+
+```sh
+(
+ set -eu
+ shortcut_snapshots="$(mktemp -d)"
+ PHOTOCRAFT_SHORTCUT_SNAPSHOTS="$shortcut_snapshots" cargo test -p photocraft-ui-egui --lib \
+ prefs_ui::shortcut_capture_tests::captured_shortcut_gpu_snapshots -- --exact
+ test -s "$shortcut_snapshots/ctrl-k-1x.png"
+ test -s "$shortcut_snapshots/ctrl-k-2x.png"
+ printf 'Review the shortcut row and conflict message in %s\n' "$shortcut_snapshots"
+)
+```
+
+The file checks intentionally reject a successful zero-test selection. Keep the fresh directory
+until both scales have been inspected: the row must show the captured shortcut without a stray ControlLeft
+key name, and the conflict message must remain readable. Rendering and file-write failures fail
+the opted-in test; an unset variable leaves the ordinary behavior tests available without a GPU.
+After review, remove only the two generated PNGs and their owned temporary directory. The same
+Rust test and variable work on Windows with the native shell's environment-variable syntax.
+
## Fonts (craft-fonts)
Font assets shared by the Crafting Apps live in [storytold/craft-fonts](https://github.com/storytold/craft-fonts), never in this repo: don't commit font files here (Inter and JetBrains Mono in `assets/fonts/` are the only exceptions; new fonts go to craft-fonts). The rules are in `craftrules/standards/fonts.md` in a sibling `craftrules` checkout (see below); that repository is not public, so outside contributors can ask a maintainer for the rules that apply to their change.