use gpui::{ AppContext as _, Context, IntoElement, ParentElement as _, Render, Styled as _, TestAppContext, VisualTestContext, Window, div, px, }; use gpui_native_core::separator::{Separator, SeparatorOrientation}; use gpui_native_theme::Theme; struct Harness { orientation: SeparatorOrientation, } impl Render for Harness { fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { let separator = Separator::horizontal() .orientation(self.orientation) .debug_selector(|| "test-separator".to_string()); if self.orientation == SeparatorOrientation::Horizontal { div() .w(px(200.)) .h(px(50.)) .flex() .flex_col() .child(separator) } else { div().w(px(200.)).h(px(50.)).flex().child(separator) } } } fn separator_window(orientation: SeparatorOrientation) -> (TestAppContext, VisualTestContext) { let mut cx = TestAppContext::single(); cx.update(Theme::init); let window = cx.add_window(move |_, _| Harness { orientation }); let window = window.into(); cx.update_window(window, |_, window, cx| { window.draw(cx).clear(cx); }) .unwrap(); let visual = VisualTestContext::from_window(window, &cx); (cx, visual) } #[test] fn the_horizontal_rule_spans_its_container_at_hairline_height() { let (_cx, mut visual) = separator_window(SeparatorOrientation::Horizontal); let bounds = visual .debug_bounds("test-separator") .expect("horizontal separator rendered"); assert_eq!(bounds.size.width, px(200.)); assert_eq!(bounds.size.height, px(1.)); } #[test] fn the_vertical_rule_spans_its_container_at_hairline_width() { let (_cx, mut visual) = separator_window(SeparatorOrientation::Vertical); let bounds = visual .debug_bounds("test-separator") .expect("vertical separator rendered"); assert_eq!(bounds.size.width, px(1.)); assert_eq!(bounds.size.height, px(50.)); }