use super::*;
use crate::text::Font;
use std::sync::Arc;
use std::time::Duration;
#[test]
fn focused_editor_deadline_reaches_app_root() {
let font = Arc::new(Font::from_slice(TEST_FONT).unwrap());
const FIELD_ID: u64 = 5150;
let mut inner = Container::new().with_padding(2.0);
inner.children_mut().push(Box::new(
TextField::new(Arc::clone(&font))
.with_font_size(14.0)
.with_focus_id(FIELD_ID),
));
let mut root = Container::new().with_padding(6.0);
root.children_mut().push(Box::new(inner));
let mut app = App::new(Box::new(root));
app.layout(Size::new(200.0, 120.0));
assert!(
app.next_draw_deadline().is_none(),
"an unfocused tree must not schedule a blink wake"
);
crate::focus::request_focus(FIELD_ID);
app.layout(Size::new(200.0, 120.0));
assert_eq!(
app.focused_widget_type_name(),
Some("TextField"),
"the field should now hold focus"
);
let now = web_time::Instant::now();
let deadline = app
.next_draw_deadline()
.expect("a focused editor must surface its blink deadline at the App root");
let remaining = deadline.saturating_duration_since(now);
assert!(
remaining > Duration::ZERO && remaining <= Duration::from_millis(500),
"aggregated deadline should be within one blink interval, got {remaining:?}"
);
crate::animation::clear_draw_request();
assert!(
app.next_draw_deadline().is_some(),
"the blink deadline must persist across a cleared frame so the loop re-arms"
);
}
#[test]
fn loop_accessor_is_nondestructive_and_rearms_scheduled_channel() {
let root = Container::new().with_padding(4.0);
let mut app = App::new(Box::new(root));
app.layout(Size::new(100.0, 100.0));
crate::animation::clear_draw_request();
assert!(
app.next_draw_deadline().is_none(),
"no scheduled draw after a clear"
);
crate::animation::request_draw_after(Duration::from_millis(500));
let first = app
.next_draw_deadline()
.expect("scheduled draw should be surfaced");
let again = app
.next_draw_deadline()
.expect("the scheduled deadline must persist across reads (lost-wakeup fix)");
assert_eq!(
first, again,
"successive idle reads report the same pending deadline"
);
crate::animation::clear_draw_request();
assert!(
app.next_draw_deadline().is_none(),
"a frame clear drains the scheduled channel"
);
crate::animation::request_draw_after(Duration::from_millis(500));
let second = app
.next_draw_deadline()
.expect("re-armed scheduled draw should be surfaced");
assert!(
second >= first,
"the re-armed deadline should be at or after the first"
);
}