test(iced): add selection feature tests

This commit is contained in:
2026-07-15 03:34:13 +03:00
parent 12ccbf2688
commit 35cfcb1ddd
3 changed files with 79 additions and 0 deletions
@@ -0,0 +1,72 @@
//! Tests for selection types: SelectionTransform, TransformHandle, CropState.
use hcie_iced_gui::selection::{CropState, SelectionTransform, TransformHandle};
#[test]
fn test_selection_transform_is_empty() {
let tr = SelectionTransform {
pixels: vec![],
width: 0,
height: 0,
pos: iced::Vector::ZERO,
size: iced::Vector::ZERO,
rotation: 0.0,
};
assert!(tr.is_empty());
}
#[test]
fn test_selection_transform_with_data() {
let tr = SelectionTransform {
pixels: vec![255; 100],
width: 5,
height: 5,
pos: iced::Vector::new(10.0, 20.0),
size: iced::Vector::new(5.0, 5.0),
rotation: 0.0,
};
assert!(!tr.is_empty());
}
#[test]
fn test_crop_state_lifecycle() {
let mut crop = CropState::default();
assert!(!crop.active);
assert!(crop.rect.is_none());
crop.start_drag(10.0, 10.0);
assert!(crop.active);
assert!(crop.is_dragging);
crop.update_drag(100.0, 100.0);
assert!(crop.rect.is_some());
let (x, y, w, h) = crop.rect.unwrap();
assert_eq!(x, 10.0);
assert_eq!(y, 10.0);
assert_eq!(w, 90.0);
assert_eq!(h, 90.0);
crop.end_drag();
assert!(!crop.is_dragging);
let result = crop.confirm();
assert!(result.is_some());
assert!(!crop.active);
}
#[test]
fn test_crop_cancel() {
let mut crop = CropState::default();
crop.start_drag(10.0, 10.0);
crop.update_drag(100.0, 100.0);
crop.cancel();
assert!(!crop.active);
assert!(crop.rect.is_none());
}
#[test]
fn test_transform_handle_cursor_hints() {
assert_eq!(TransformHandle::Move.cursor_hint(), "move");
assert_eq!(TransformHandle::TopLeft.cursor_hint(), "nwse-resize");
assert_eq!(TransformHandle::Rotate.cursor_hint(), "crosshair");
}