GraphiteEditor / GraphiteEditor/Graphite
Add tests for polygon shape, star shape, and grid snapping tools
- Dominant language
- Rust
- Stars
- 27.2k
- Forks
- 1.3k
- Avg merge
- 20h 5m
- Merged PRs (30d)
- 57
Description
## Summary
This issue tracks adding `#[cfg(test)]` test coverage to three currently untested files in the tool and snapping systems. These are good starting points for GSoC test coverage work, as they follow the same pattern already established in `ellipse_shape.rs` and `line_shape.rs`.
---
## Files to Test
### 1. `editor/src/messages/tool/common_functionality/shapes/polygon_shape.rs` (~193 LOC)
**What to test:**
- `draw_polygon_simple` — drag with `ToolType::Shape` (polygon mode), assert vertex count and radius
- `draw_polygon_square_ratio` — drag with `ModifierKeys::SHIFT` (lock ratio), assert equal dimensions
- `draw_polygon_from_center` — drag with `ModifierKeys::ALT`, assert center origin
- `draw_polygon_cancel_rmb` — use `drag_tool_cancel_rmb`, assert no layer created
- `polygon_decrease_sides` — assert `decrease_or_increase_sides(true, ...)` clamps to minimum 3
- `polygon_increase_sides` — assert side count increments correctly
**Reference pattern:** `ellipse_shape.rs` (same file, same module structure)
---
### 2. `editor/src/messages/tool/common_functionality/shapes/star_shape.rs` (~172 LOC)
**What to test:**
- `draw_star_simple` — drag to create star, assert outer/inner radius values
- `draw_star_square_ratio` — with `ModifierKeys::SHIFT`
- `draw_star_from_center` — with `ModifierKeys::ALT`
- `draw_star_cancel_rmb` — assert no layer created on RMB cancel
- Verify inner radius is set to `outer_radius / 2.0` by default (`Star::update_shape` line 161)
**Reference pattern:** Same as `ellipse_shape.rs`; use `NodeGraphLayer::upstream_node_id_from_protonode` with `star::IDENTIFIER`
---
### 3. `editor/src/messages/tool/common_functionality/snapping/grid_snapper.rs` (~181 LOC)
**What to test:**
- `rectangular_grid_snap_on_line` — point exactly on a grid line snaps with distance ≈ 0
- `rectangular_grid_snap_within_tolerance` — point within tolerance snaps to nearest line
- `rectangular_grid_no_snap_outside_tolerance` — point beyond tolerance produces no snap result
- `isometric_grid_snap_vertical` — snap to vertical lines in isometric grid
- `isometric_grid_angle_lines` — snap to angled lines (angle_a / angle_b)
- `constrained_snap_to_grid_intersection` — constrained snap hits grid line correctly
## Test Infrastructure
All tests should use the existing `EditorTestUtils` helper:
```rust
#[cfg(test)]
mod test_polygon {
use crate::test_utils::test_prelude::*;
// ...
#[tokio::test]
async fn draw_polygon_simple() {
let mut editor = EditorTestUtils::create();
editor.new_document().await;
editor.drag_tool(ToolType::Shape, 10., 10., 50., 50., ModifierKeys::empty()).await;
// assert layer count, vertex count, radius etc.
}
}
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the existing tests in ellipse_shape.rs and line_shape.rs, then inspect polygon_shape.rs, star_shape.rs, and grid_snapper.rs. Use the documented EditorTestUtils patterns and run the relevant Rust tests; done means the listed shape, cancellation, radius, side-count, and grid-snapping cases have passing assertions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100