use std::cell::Cell;
use std::rc::Rc;
use std::sync::Arc;
use super::*;
use crate::widget::Widget;
const FONT_BYTES: &[u8] = include_bytes!("../../../../demo/assets/CascadiaCode.ttf");
fn font() -> Arc<Font> {
Arc::new(Font::from_slice(FONT_BYTES).expect("font"))
}
#[test]
fn scroll_watch_cell_mirrors_offset() {
let watch = Rc::new(Cell::new(-1.0));
let text = (0..200)
.map(|i| format!("line{i}"))
.collect::<Vec<_>>()
.join("\n");
let mut ta = TextArea::new(font())
.with_font_size(13.0)
.with_text(text)
.with_scroll_watch(Rc::clone(&watch));
ta.layout(Size::new(200.0, 80.0));
assert_eq!(watch.get(), 0.0, "watch starts at the top after layout");
assert!(ta.max_scroll_y() > 0.0, "200 lines must overflow an 80px box");
assert!(ta.scroll_by_wheel(-40.0), "wheel must move the offset");
assert!(ta.scroll_offset() > 0.0);
assert_eq!(
watch.get(),
ta.scroll_offset(),
"watch cell must mirror the live scroll offset after a wheel scroll"
);
ta.set_cursor_to_end();
ta.ensure_cursor_visible();
assert_eq!(
watch.get(),
ta.scroll_offset(),
"watch cell must mirror the offset after scroll-to-caret"
);
}