Skip to content

Commit b26711f

Browse files
Refactor spline tool test to use click_tool and add draw_spline helper method
1 parent c15a8fe commit b26711f

File tree

2 files changed

+40
-55
lines changed

2 files changed

+40
-55
lines changed

editor/src/messages/tool/tool_messages/spline_tool.rs

+31-55
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ fn delete_preview(tool_data: &mut SplineToolData, responses: &mut VecDeque<Messa
536536
}
537537
#[cfg(test)]
538538
mod test_spline_tool {
539-
use crate::messages::input_mapper::utility_types::input_mouse::{EditorMouseState, ScrollDelta};
540539
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
541540
use crate::messages::tool::tool_messages::spline_tool::find_spline;
542541
use crate::test_utils::test_prelude::*;
@@ -548,7 +547,6 @@ mod test_spline_tool {
548547
editor.new_document().await;
549548

550549
editor.drag_tool(ToolType::Artboard, 0., 0., 500., 500., ModifierKeys::empty()).await;
551-
552550
let document = editor.active_document();
553551
let artboard_layer = document.network_interface.selected_nodes().selected_layers(document.metadata()).next().unwrap();
554552

@@ -561,75 +559,53 @@ mod test_spline_tool {
561559
})
562560
.await;
563561

564-
let spline_start = DVec2::new(100., 100.);
565-
let spline_mid = DVec2::new(200., 150.);
566-
let spline_end = DVec2::new(300., 100.);
567-
568-
editor.select_tool(ToolType::Spline).await;
569-
editor.move_mouse(spline_start.x, spline_start.y, ModifierKeys::empty(), MouseKeys::empty()).await;
570-
editor.left_mousedown(spline_start.x, spline_start.y, ModifierKeys::empty()).await;
571-
editor
572-
.mouseup(
573-
EditorMouseState {
574-
editor_position: spline_start,
575-
mouse_keys: MouseKeys::empty(),
576-
scroll_delta: ScrollDelta::default(),
577-
},
578-
ModifierKeys::empty(),
579-
)
580-
.await;
581-
582-
editor.move_mouse(spline_mid.x, spline_mid.y, ModifierKeys::empty(), MouseKeys::empty()).await;
583-
editor.left_mousedown(spline_mid.x, spline_mid.y, ModifierKeys::empty()).await;
584-
editor
585-
.mouseup(
586-
EditorMouseState {
587-
editor_position: spline_mid,
588-
mouse_keys: MouseKeys::empty(),
589-
scroll_delta: ScrollDelta::default(),
590-
},
591-
ModifierKeys::empty(),
592-
)
593-
.await;
594-
595-
editor.move_mouse(spline_end.x, spline_end.y, ModifierKeys::empty(), MouseKeys::empty()).await;
596-
editor.left_mousedown(spline_end.x, spline_end.y, ModifierKeys::empty()).await;
597-
editor
598-
.mouseup(
599-
EditorMouseState {
600-
editor_position: spline_end,
601-
mouse_keys: MouseKeys::empty(),
602-
scroll_delta: ScrollDelta::default(),
603-
},
604-
ModifierKeys::empty(),
605-
)
606-
.await;
607-
608-
editor.press(Key::Enter, ModifierKeys::empty()).await;
562+
let spline_points = [DVec2::new(100., 100.), DVec2::new(200., 150.), DVec2::new(300., 100.)];
609563

610-
// Execute the graph to ensure everything is processed
611-
let _instrumented = editor.eval_graph().await;
564+
editor.draw_spline(&spline_points).await;
612565

613566
let document = editor.active_document();
614567

615568
let mut layers = document.metadata().all_layers();
616-
617569
layers.next();
618570

619571
let spline_layer = layers.next().expect("Failed to find the spline layer");
620-
621572
assert!(find_spline(document, spline_layer).is_some(), "Spline node not found in the layer");
622573

623-
let vector_data = document.network_interface.compute_modified_vector(spline_layer);
624-
assert!(vector_data.is_some(), "Vector data not found for the spline layer");
625-
626-
let vector_data = vector_data.unwrap();
574+
let vector_data = document.network_interface.compute_modified_vector(spline_layer).expect("Vector data not found for the spline layer");
627575

628576
// Verify we have the correct number of points and segments
629577
let point_count = vector_data.point_domain.ids().len();
630578
let segment_count = vector_data.segment_domain.ids().len();
631579

632580
assert_eq!(point_count, 3, "Expected 3 points in the spline, found {}", point_count);
633581
assert_eq!(segment_count, 2, "Expected 2 segments in the spline, found {}", segment_count);
582+
583+
let layer_to_viewport = document.metadata().transform_to_viewport(spline_layer);
584+
585+
let points_in_viewport: Vec<DVec2> = vector_data
586+
.point_domain
587+
.ids()
588+
.iter()
589+
.filter_map(|&point_id| {
590+
let position = vector_data.point_domain.position_from_id(point_id)?;
591+
Some(layer_to_viewport.transform_point2(position))
592+
})
593+
.collect();
594+
595+
// Verify each point position is close to the expected position
596+
let epsilon = 1e-10;
597+
for (i, expected_point) in spline_points.iter().enumerate() {
598+
let actual_point = points_in_viewport[i];
599+
let distance = (actual_point - *expected_point).length();
600+
601+
assert!(
602+
distance < epsilon,
603+
"Point {} position mismatch: expected {:?}, got {:?} (distance: {})",
604+
i,
605+
expected_point,
606+
actual_point,
607+
distance
608+
);
609+
}
634610
}
635611
}

editor/src/test_utils.rs

+9
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ impl EditorTestUtils {
230230
})
231231
.await;
232232
}
233+
pub async fn draw_spline(&mut self, points: &[DVec2]) {
234+
self.select_tool(ToolType::Spline).await;
235+
236+
for &point in points {
237+
self.click_tool(ToolType::Spline, MouseKeys::LEFT, point, ModifierKeys::empty()).await;
238+
}
239+
240+
self.press(Key::Enter, ModifierKeys::empty()).await;
241+
}
233242
}
234243

235244
pub trait FrontendMessageTestUtils {

0 commit comments

Comments
 (0)