use gpui_kit::test::TestWindowExt as _;
use gpui_kit::{
AppContext as _, Bounds, Context, IntoElement, ParentElement as _, Pixels, Point, Render,
Styled as _, TestAppContext, Window, WindowBounds, WindowOptions, canvas, div, px, size,
};
use std::{cell::Cell, rc::Rc, time::Duration};
use u0ui::t3::Status;
use u0ui::t3::review::ThreadHoverCard;
type Slot = Rc<Cell<Option<Bounds<Pixels>>>>;
struct Page {
card: Slot,
}
impl Render for Page {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
let slot = self.card.clone();
div().flex().items_start().child(
div()
.relative()
.child(
ThreadHoverCard::new("Fix flaky date picker test", "carbon-ui")
.status(Status::NeedsYou)
.provider("Codex \u{b7} GPT")
.time("3m ago")
.last_message(
"I need approval to run the full e2e suite against the staging \
database. It takes about 6 minutes.",
),
)
.child(
canvas(move |bounds, _, _| slot.set(Some(bounds)), |_, _, _, _| {})
.absolute()
.top_0()
.left_0()
.size_full(),
),
)
}
}
#[gpui_kit::test]
fn the_last_message_is_a_16_on_24_paragraph(cx: &mut TestAppContext) {
cx.update(|cx| {
gpui_kit::init(cx);
u0ui::init(cx);
});
let card: Slot = Rc::default();
let window = cx.update(|cx| {
let card = card.clone();
gpui_kit::open_window(
WindowOptions {
window_bounds: Some(WindowBounds::Windowed(Bounds {
origin: Point::default(),
size: size(px(960.), px(400.)),
})),
..Default::default()
},
cx,
move |_, cx| cx.new(|_| Page { card }),
)
.expect("open test window")
.0
});
cx.executor().advance_clock(Duration::from_secs(1));
cx.run_until_parked();
cx.update_window(window, |_, window, cx| window.render_frame(cx))
.unwrap();
let card = card.get().expect("measured");
assert!((f32::from(card.size.width) - 320.).abs() < 0.5, "{card:?}");
assert!(
(f32::from(card.size.height) - 181.42).abs() < 2.,
"{card:?}"
);
}