test(iced): add selection feature tests
This commit is contained in:
@@ -3,6 +3,10 @@ name = "hcie-iced-gui"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "hcie_iced_gui"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["tablet-evdev"]
|
default = ["tablet-evdev"]
|
||||||
tablet-evdev = ["dep:evdev"]
|
tablet-evdev = ["dep:evdev"]
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
//! HCIE Iced GUI library — re-exports selection types for integration tests.
|
||||||
|
|
||||||
|
pub mod selection;
|
||||||
@@ -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");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user