Skip to content

Add unit tests for spiral shape and arrow shape tools #3965

@tarone-saloni

Description

@tarone-saloni

Summary

This issue tracks adding `#[cfg(test)]` test coverage to two currently untested shape tool files. These follow the same patterns already established in `ellipse_shape.rs`, `line_shape.rs`, and `shape_utility.rs`.


Files to Test

1. `editor/src/messages/tool/common_functionality/shapes/spiral_shape.rs` (~204 LOC)

What to test:

  • `draw_spiral_simple` — drag with `ToolType::Shape` (spiral mode), assert a layer is created and `outer_radius` matches the drag distance
  • `draw_spiral_logarithmic` — verify `inner_radius` defaults to `0.1` for `SpiralType::Logarithmic` (set in `Spiral::create_node`, line 102)
  • `draw_spiral_archimedean` — verify `inner_radius` defaults to `0.0` for `SpiralType::Archimedean`
  • `draw_spiral_cancel_rmb` — use `drag_tool_cancel_rmb`, assert no layer created
  • `spiral_decrease_turns` — call `Spiral::update_turns(true, ...))` and assert turns clamps to minimum of `1.0`
  • `spiral_increase_turns` — call `Spiral::update_turns(false, ...)` and assert turns increments by `1.0`

Key parameters to assert (via `extract_spiral_parameters`):

  • `spiral_type: SpiralType`
  • `inner_radius: f64`
  • `outer_radius: f64` — should equal drag distance from origin
  • `turns: f64`

Reference pattern: `ellipse_shape.rs`; use `NodeGraphLayer::find_node_inputs` with `graphene_std::vector::generator_nodes::spiral::IDENTIFIER`


2. `editor/src/messages/tool/common_functionality/shapes/arrow_shape.rs` (~116 LOC)

What to test:

  • `draw_arrow_simple` — drag with `ToolType::Line` (arrow mode), assert a layer is created and `arrow_to` vector matches the drag delta
  • `draw_arrow_cancel_rmb` — use `drag_tool_cancel_rmb`, assert no layer created
  • `draw_arrow_snap_angle` — drag with `ModifierKeys::SHIFT` (snap angle), assert the `arrow_to` direction is constrained to a 15° multiple
  • `draw_arrow_zero_length` — drag start == end, assert no crash and no layer with non-zero `arrow_to` (guarded by the `< 1e-6` check at line 59)

Key parameters to assert:

  • `arrow_to: DVec2` — retrieved via `NodeGraphLayer::find_node_inputs` with `graphene_std::vector_nodes::arrow::IDENTIFIER`, input index `1`

Reference pattern: `line_shape.rs` (shares `generate_line` logic); use same `NodeGraphLayer` approach


Test Infrastructure

All tests should use the existing `EditorTestUtils` helper:

```rust
#[cfg(test)]
mod test_spiral {
use crate::test_utils::test_prelude::*;

#[tokio::test]
async fn draw_spiral_simple() {
    let mut editor = EditorTestUtils::create();
    editor.new_document().await;
    editor.drag_tool(ToolType::Shape, 0., 0., 40., 0., ModifierKeys::empty()).await;

    // Assert one layer created
    assert_eq!(editor.active_document().metadata().all_layers().count(), 1);

    // Extract outer_radius and assert it equals ~40.0
    // use extract_spiral_parameters or NodeGraphLayer::find_node_inputs with spiral::IDENTIFIER
}

}
```

Related files for reference:

  • `ellipse_shape.rs` — drag + assert pattern
  • `line_shape.rs` — angle-snapping test pattern
  • `shape_utility.rs` — `extract_spiral_parameters` helper
  • `graph_modification_utils.rs` — `get_spiral_id`, `get_arrow_id`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions