* WIP deep rename (not for push) * WIP2 * WIP3 * WIP4 wxs fix * rustfmt * Rename the remaining identifiers in merged crash-report code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjGw4gA5ZvKrU8MQP6sBgT --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.5 KiB
Rust
72 lines
2.5 KiB
Rust
//! Regression tests: editing a sketch from the Browser or timeline can always be left again.
|
|
|
|
use crate::{Services, SolveApp};
|
|
use solidcraft_engine::Session;
|
|
use solidcraft_engine::doc::FeatureKind;
|
|
|
|
fn sample_app() -> SolveApp {
|
|
let mut s = Session::default();
|
|
s.run_script(&solidcraft_engine::sample::script()).unwrap();
|
|
SolveApp::new(s, Services::default())
|
|
}
|
|
|
|
fn first_sketch(app: &SolveApp) -> u64 {
|
|
app.session.doc.features.iter().find(|f| matches!(f.kind, FeatureKind::Sketch { .. })).map(|f| f.id).unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn edit_sketch_rolls_back_and_finish_restores() {
|
|
let mut app = sample_app();
|
|
let marker = app.session.doc.marker;
|
|
let id = first_sketch(&app);
|
|
app.edit_sketch(id);
|
|
assert_eq!(app.session.active_sketch, Some(id));
|
|
let idx = app.session.doc.feature_index(id).unwrap();
|
|
assert_eq!(app.session.doc.marker, Some(idx + 1), "later features are rolled back");
|
|
app.finish_sketch();
|
|
assert_eq!(app.session.active_sketch, None);
|
|
assert_eq!(app.session.doc.marker, marker, "marker restored");
|
|
}
|
|
|
|
#[test]
|
|
fn editing_twice_does_not_nest() {
|
|
let mut app = sample_app();
|
|
let marker = app.session.doc.marker;
|
|
let id = first_sketch(&app);
|
|
app.edit_sketch(id);
|
|
app.edit_sketch(id);
|
|
app.edit_feature(id);
|
|
app.finish_sketch();
|
|
assert_eq!(app.session.active_sketch, None);
|
|
assert_eq!(app.session.doc.marker, marker);
|
|
}
|
|
|
|
#[test]
|
|
fn editing_another_sketch_switches_cleanly() {
|
|
let mut app = sample_app();
|
|
let marker = app.session.doc.marker;
|
|
let ids: Vec<u64> = app.session.doc.features.iter().filter(|f| matches!(f.kind, FeatureKind::Sketch { .. })).map(|f| f.id).collect();
|
|
app.edit_sketch(ids[0]);
|
|
app.edit_sketch(ids[1]);
|
|
assert_eq!(app.session.active_sketch, Some(ids[1]));
|
|
app.finish_sketch();
|
|
assert_eq!(app.session.active_sketch, None);
|
|
assert_eq!(app.session.doc.marker, marker);
|
|
}
|
|
|
|
#[test]
|
|
fn toolbar_finish_and_other_feature_edit_leave_the_sketch() {
|
|
let mut app = sample_app();
|
|
let marker = app.session.doc.marker;
|
|
let id = first_sketch(&app);
|
|
app.edit_sketch(id);
|
|
app.start("sketch.finish");
|
|
assert_eq!(app.session.active_sketch, None);
|
|
assert_eq!(app.session.doc.marker, marker);
|
|
// Double-clicking a solid feature while sketching finishes the sketch first.
|
|
app.edit_sketch(id);
|
|
let extrude = app.session.doc.features.iter().find(|f| !matches!(f.kind, FeatureKind::Sketch { .. })).map(|f| f.id).unwrap();
|
|
app.edit_feature(extrude);
|
|
assert_eq!(app.session.active_sketch, None);
|
|
}
|