GraphiteEditor / GraphiteEditor/Graphite

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

Đang mở
#3,954 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Rust
Star
27.2k
Fork
1.3k
Merge trung bình
20 giờ 5 phút
Pull request đã merge (30 ngày)
57

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
rust
Lĩnh vực
testing
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
72/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.