use crate::components::choice_menu::ChoiceMenu;
use crate::components::renderable_content::RenderableContent;
use crate::model::choice::Choice;
use crate::model::common::Bounds;
#[test]
fn test_choice_sensitive_zones_generation() {
println!("=== DEBUG: Testing ChoiceMenu sensitive zones generation ===");
use crate::model::common::ExecutionMode;
let choices = vec![
Choice {
id: "choice1".to_string(),
content: Some("First Choice".to_string()),
script: None,
redirect_output: None,
append_output: None,
execution_mode: ExecutionMode::default(),
selected: false,
hovered: false,
waiting: false,
},
Choice {
id: "choice2".to_string(),
content: Some("Second Choice".to_string()),
script: None,
redirect_output: None,
append_output: None,
execution_mode: ExecutionMode::default(),
selected: false,
hovered: false,
waiting: false,
},
];
let choice_menu = ChoiceMenu::new("test_menu".to_string(), &choices);
let bounds = Bounds::new(2, 2, 23, 6);
println!(
"Muxbox bounds: left={}, top={}, right={}, bottom={}, width={}, height={}",
bounds.left(),
bounds.top(),
bounds.right(),
bounds.bottom(),
bounds.width(),
bounds.height()
);
let zones = choice_menu.get_box_relative_sensitive_zones();
println!("Generated {} sensitive zones", zones.len());
for (i, zone) in zones.iter().enumerate() {
println!(
"Zone {}: bounds=({},{} to {},{}), content_id={}, width={}, height={}",
i,
zone.bounds.x1,
zone.bounds.y1,
zone.bounds.x2,
zone.bounds.y2,
zone.content_id,
zone.bounds.width(),
zone.bounds.height()
);
}
let expected_click_x = 2; let expected_click_y = 0;
println!(
"Testing click at ({}, {}) for first choice",
expected_click_x, expected_click_y
);
let clicked_zone = zones.iter().find(|zone| {
let contains = zone
.bounds
.contains_point(expected_click_x, expected_click_y);
println!(
"Zone {} contains point ({}, {}): {}",
zone.content_id, expected_click_x, expected_click_y, contains
);
contains
});
if let Some(zone) = clicked_zone {
println!("SUCCESS: Found clicked zone: {}", zone.content_id);
assert_eq!(zone.content_id, "choice_0", "Should click on first choice");
} else {
println!(
"FAILURE: No sensitive zone found at ({}, {})",
expected_click_x, expected_click_y
);
panic!("Should find a sensitive zone at expected coordinates");
}
let second_choice_y = 1; println!(
"Testing click at ({}, {}) for second choice",
expected_click_x, second_choice_y
);
let second_clicked_zone = zones.iter().find(|zone| {
zone.bounds
.contains_point(expected_click_x, second_choice_y)
});
if let Some(zone) = second_clicked_zone {
println!("SUCCESS: Found second clicked zone: {}", zone.content_id);
assert_eq!(zone.content_id, "choice_1", "Should click on second choice");
} else {
println!("FAILURE: No sensitive zone found for second choice");
}
}