use gpui_kit::component::v_flex;
use gpui_kit::test::TestWindowExt as _;
use gpui_kit::{
Context, InteractiveElement as _, IntoElement, ParentElement as _, Render, Styled as _,
TestAppContext, TestSupportExt as _, Window, div, px,
};
use super::{fact, fact_with_wide_label};
struct Facts;
impl Render for Facts {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
.child(
v_flex()
.w(px(300.))
.child(fact("Repository", value("default"), cx))
.child(fact_with_wide_label("Current task", value("current"), cx))
.child(fact_with_wide_label("Changed paths", value("paths"), cx)),
)
.child(
v_flex()
.w(px(180.))
.child(fact_with_wide_label("Task status", value("narrow"), cx).test_support()),
)
}
}
fn value(id: &'static str) -> impl IntoElement {
div().id(id).w_full().test_support().child("Example value")
}
#[gpui_kit::test]
fn wide_labels_align_values_and_give_back_space_in_a_narrow_dock(cx: &mut TestAppContext) {
cx.update(gpui_kit::init);
let (_, cx) = cx.add_window_view(|_, _| Facts);
cx.update(|window, cx| {
window.render_frame(cx);
let current = window.find("current").bounds();
assert!(current.left() > window.find("default").bounds().left());
assert_eq!(current.left(), window.find("paths").bounds().left());
let row = window.find("inspector-fact:Task status").bounds();
let value = window.find("narrow").bounds();
assert!(value.size.width > row.size.width / 2.);
assert_eq!(value.right(), row.right());
});
}