GraphiteEditor / GraphiteEditor/Graphite

Add tests for polygon shape, star shape, and grid snapping tools

Offen
#3,954 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
27.2k
Forks
1.3k
Ø Merge
20 Std. 5 Min.
Gemergte PRs (30 T.)
57

Beschreibung

## 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.
}
}

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.