Repository: GraphiteEditor/Graphite
File: editor/src/messages/tool/tool_messages/spline_tool.rs (Rust)

Code before:
		editor
			.handle_message(GraphOperationMessage::TransformSet {
				layer: artboard_layer,
				transform: DAffine2::from_scale_angle_translation(DVec2::new(1.5, 1.2), 30.0_f64.to_radians(), DVec2::new(50.0, 25.0)),
				transform_in: TransformIn::Local,
				skip_rerender: false,
			})
			.await;

		let spline_start = DVec2::new(100., 100.);
		let spline_mid = DVec2::new(200., 150.);
		let spline_end = DVec2::new(300., 100.);

		editor.select_tool(ToolType::Spline).await;
		editor.move_mouse(spline_start.x, spline_start.y, ModifierKeys::empty(), MouseKeys::empty()).await;
		editor.left_mousedown(spline_start.x, spline_start.y, ModifierKeys::empty()).await;
		editor
			.mouseup(
				EditorMouseState {
					editor_position: spline_start,
					mouse_keys: MouseKeys::empty(),
					scroll_delta: ScrollDelta::default(),
				},
				ModifierKeys::empty(),
			)
			.await;

		editor.move_mouse(spline_mid.x, spline_mid.y, ModifierKeys::empty(), MouseKeys::empty()).await;
		editor.left_mousedown(spline_mid.x, spline_mid.y, ModifierKeys::empty()).await;
		editor
			.mouseup(
				EditorMouseState {
					editor_position: spline_mid,
					mouse_keys: MouseKeys::empty(),
					scroll_delta: ScrollDelta::default(),
				},
				ModifierKeys::empty(),
			)
			.await;

		editor.move_mouse(spline_end.x, spline_end.y, ModifierKeys::empty(), MouseKeys::empty()).await;
		editor.left_mousedown(spline_end.x, spline_end.y, ModifierKeys::empty()).await;
		editor
			.mouseup(
				EditorMouseState {
					editor_position: spline_end,
					mouse_keys: MouseKeys::empty(),
					scroll_delta: ScrollDelta::default(),
				},
				ModifierKeys::empty(),
			)

Review comment (refactor):
Consider using `editor.click_tool(…)` to simplify the logic. You are also free to write your own helper functions e.g. on `EditorTestUtils`.

Code after:
			})
			.collect();

		// Verify each point position is close to the expected position
		for (i, expected_point) in expected_points.iter().enumerate() {
			let actual_point = points_in_viewport[i];
			let distance = (actual_point - *expected_point).length();

			assert!(
				distance < epsilon,
				"Point {} position mismatch: expected {:?}, got {:?} (distance: {})",
				i,
				expected_point,
				actual_point,
				distance
			);
		}
	}

	#[tokio::test]
	async fn test_continue_drawing_from_existing_spline() {
		let mut editor = EditorTestUtils::create();
		editor.new_document().await;

		let initial_points = [DVec2::new(100., 100.), DVec2::new(200., 150.), DVec2::new(300., 100.)];

		editor.select_tool(ToolType::Spline).await;

		for &point in &initial_points {
			editor.click_tool(ToolType::Spline, MouseKeys::LEFT, point, ModifierKeys::empty()).await;
		}

		editor.press(Key::Enter, ModifierKeys::empty()).await;

		let document = editor.active_document();
		let spline_layer = document
			.metadata()
			.all_layers()
			.find(|layer| find_spline(document, *layer).is_some())
			.expect("Failed to find a layer with a spline node");

		let first_spline_node = find_spline(document, spline_layer).expect("Spline node not found in the layer");

		let first_vector_data = document.network_interface.compute_modified_vector(spline_layer).expect("Vector data not found for the spline layer");

		// Verify initial spline has correct number of points and segments
		let initial_point_count = first_vector_data.point_domain.ids().len();
		let initial_segment_count = first_vector_data.segment_domain.ids().len();
		assert_eq!(initial_point_count, 3, "Expected 3 points in initial spline, found {}", initial_point_count);
		assert_eq!(initial_segment_count, 2, "Expected 2 segments in initial spline, found {}", initial_segment_count);