Files
figcraft/crates/engine/src/pixel_preview_tests.rs
T
BFlatandClaude Opus 5.5 6d7b30508b M1: 2x pixel preview (#68)
Pixel preview takes a resolution: `view.pixelPreview {scale: 1|2}` turns it on at 1x (one rendered
pixel per page pixel) or 2x (two, as on a high-density display); the canvas renders at that
resolution from a whole-pixel origin and magnifies it with hard edges once zoomed past it. The zoom
menu offers "Pixel preview 1x" and "2x" and now shows the on/off state of every view toggle.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 11:43:54 +07:00

39 lines
1.3 KiB
Rust

//! Pixel preview: toggling it, and its 1x / 2x resolution.
use serde_json::json;
use crate::Session;
fn preview(s: &Session) -> (bool, u8) {
let v = &s.ds().unwrap().view;
(v.pixel_preview, v.pixel_scale)
}
#[test]
fn toggles_and_sets_its_resolution() {
let mut s = Session::new();
assert_eq!(preview(&s), (false, 1));
s.execute("view.pixelPreview", &json!({})).unwrap();
assert_eq!(preview(&s), (true, 1));
s.execute("view.pixelPreview", &json!({})).unwrap();
assert_eq!(preview(&s), (false, 1));
// A resolution turns it on.
let r = s.execute("view.pixelPreview", &json!({"scale": 2})).unwrap();
assert_eq!(r, json!({"on": true, "scale": 2}));
assert_eq!(preview(&s), (true, 2));
// Turning it off keeps the resolution for next time.
s.execute("view.pixelPreview", &json!({"on": false})).unwrap();
assert_eq!(preview(&s), (false, 2));
s.execute("view.pixelPreview", &json!({"on": true, "scale": 1})).unwrap();
assert_eq!(preview(&s), (true, 1));
}
#[test]
fn rejects_other_resolutions() {
let mut s = Session::new();
for bad in [json!(3), json!(0), json!(1.5), json!("2"), json!(-1)] {
assert!(s.execute("view.pixelPreview", &json!({"scale": bad})).is_err(), "{bad}");
}
assert_eq!(preview(&s), (false, 1));
}