Files
makeCAD/crates/engine/src/schema/view_navigation_tests.rs
T
phanoob ba52632985 Tabs: Ctrl+Tab shows the next design tab, Ctrl+Shift+Tab the previous one (#8565) (#8597)
Two new commands, view.next_tab and view.previous_tab, with Ctrl+Tab and
Ctrl+Shift+Tab as their default keys: they appear on the Keyboard Shortcuts
page and can be rebound or cleared like any other. The window steps along the
tab strip and goes round at either end; one design alone stays as it is, and
a "save changes?" prompt keeps its tab shown. The engine only echoes the
step (no design edit, no undo step); engine.batch refuses them like the
other steps that go to another design.

Co-authored-by: Phanoob <phanoob@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 01:25:12 +00:00

55 lines
2.4 KiB
Rust

use serde_json::{Value, json};
use super::{AngleReadoutParams, TabStep, TabStepParams};
use crate::Session;
use crate::schema::tests::{assert_keys, assert_strict_keeps_todays_errors, conforms};
use crate::schema::{ParamCheck, input_schema_for, output_schema_for};
#[test]
fn schemas_and_the_key_check_agree() {
assert_keys(input_schema_for::<AngleReadoutParams>(), &["enabled"]);
}
#[test]
fn strict_keeps_todays_errors() {
assert_strict_keeps_todays_errors(&[
("view.angle_readout", json!({"enabled": 1})),
("view.angle_readout", json!({"enabled": "true"})),
("view.angle_readout", json!({"enabled": null})),
]);
}
#[test]
fn angle_readout_replies_match_the_output_schema() {
let schema = output_schema_for::<super::AngleReadoutResult>();
let schema = schema.as_value();
let mut s = Session { param_check: ParamCheck::Warn, ..Session::default() };
for enabled in [true, false] {
let r = s.execute("view.angle_readout", &json!({"enabled": enabled})).unwrap_or_else(|e| panic!("{e}"));
assert!(conforms(schema, schema, &r), "{r} doesn't match {schema}");
assert_eq!(r.get("param_warnings"), None, "{r}");
assert_eq!(r["enabled"], Value::Bool(enabled));
}
assert!(!conforms(schema, schema, &json!({"enabled": "yes"})));
assert!(!conforms(schema, schema, &json!({})));
}
/// #8565: the next and previous tab take nothing, say which way the window goes, and leave the
/// design and its undo as they were.
#[test]
fn next_and_previous_tab_echo_their_step_without_editing_the_design() {
assert_keys(input_schema_for::<TabStepParams>(), &[]);
let schema = output_schema_for::<TabStep>();
let schema = schema.as_value();
let mut s = Session { param_check: ParamCheck::Strict, ..Session::default() };
s.execute("solid.box", &json!({"length": 10, "width": 10, "height": 10})).unwrap_or_else(|e| panic!("{e}"));
let (before, undo) = (s.doc.to_json(), s.undo.len());
for (id, step) in [("view.next_tab", 1), ("view.previous_tab", -1)] {
let r = s.execute(id, &json!({})).unwrap_or_else(|e| panic!("{id}: {e}"));
assert_eq!(r, json!({"step": step}), "{id}");
assert!(conforms(schema, schema, &r), "{r} doesn't match {schema}");
assert!(s.execute(id, &json!({"step": 2})).is_err(), "{id} takes no parameters (strict check)");
}
assert_eq!((s.doc.to_json(), s.undo.len()), (before, undo), "nothing in the design changes");
}