chore: clean up all tests
This commit is contained in:
@@ -1,544 +0,0 @@
|
||||
#![cfg(feature = "dock")]
|
||||
|
||||
use gpui::{
|
||||
AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, Modifiers, MouseButton,
|
||||
MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, Render, Styled as _,
|
||||
TestAppContext, VisualTestContext, Window, div, point, px,
|
||||
};
|
||||
use gpui_native_layout::dock::{Dock, DockSidebar, DockState, PanelDescriptor, SplitDirection};
|
||||
use gpui_native_theme::Theme;
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
struct Panel {
|
||||
tag: &'static str,
|
||||
}
|
||||
|
||||
impl Render for Panel {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.size_full()
|
||||
.debug_selector(move || format!("panel-{}", self.tag))
|
||||
}
|
||||
}
|
||||
|
||||
/// The right sidebar view a panel declares.
|
||||
struct SidePanel {
|
||||
tag: &'static str,
|
||||
}
|
||||
|
||||
impl Render for SidePanel {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.size_full()
|
||||
.debug_selector(move || format!("side-{}", self.tag))
|
||||
}
|
||||
}
|
||||
|
||||
fn descriptor(tag: &'static str) -> PanelDescriptor {
|
||||
PanelDescriptor::new(tag, move |_, cx| cx.new(|_| Panel { tag }).into()).title(tag)
|
||||
}
|
||||
|
||||
fn descriptor_with_right_sidebar(tag: &'static str) -> PanelDescriptor {
|
||||
PanelDescriptor::new(tag, move |_, cx| cx.new(|_| Panel { tag }).into())
|
||||
.title(tag)
|
||||
.right_sidebar(move |_, cx| cx.new(|_| SidePanel { tag }).into())
|
||||
}
|
||||
|
||||
struct Harness {
|
||||
dock: Entity<DockState>,
|
||||
}
|
||||
|
||||
impl Render for Harness {
|
||||
fn render(
|
||||
&mut self,
|
||||
_window: &mut Window,
|
||||
_cx: &mut gpui::Context<Self>,
|
||||
) -> impl gpui::IntoElement {
|
||||
div()
|
||||
.size_full()
|
||||
.child(Dock::new("test-dock", self.dock.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
fn dock_window(cx: &mut TestAppContext) -> (Entity<DockState>, VisualTestContext) {
|
||||
cx.update(Theme::init);
|
||||
let dock = cx.update(DockState::new);
|
||||
let dock_for_window = dock.clone();
|
||||
let window = cx.add_window(move |_, _| Harness {
|
||||
dock: dock_for_window,
|
||||
});
|
||||
let mut visual = VisualTestContext::from_window(window.into(), cx);
|
||||
redraw(&mut visual);
|
||||
(dock, visual)
|
||||
}
|
||||
|
||||
fn redraw(visual: &mut VisualTestContext) {
|
||||
visual.update(|window, cx| {
|
||||
window.draw(cx).clear(cx);
|
||||
});
|
||||
}
|
||||
|
||||
fn bounds(visual: &mut VisualTestContext, selector: &str) -> Option<gpui::Bounds<Pixels>> {
|
||||
visual.debug_bounds(Box::leak(selector.to_string().into_boxed_str()))
|
||||
}
|
||||
|
||||
fn center_of(bounds: gpui::Bounds<Pixels>) -> gpui::Point<Pixels> {
|
||||
point(bounds.center().x, bounds.center().y)
|
||||
}
|
||||
|
||||
fn press(visual: &mut VisualTestContext, at: gpui::Point<Pixels>, click_count: usize) {
|
||||
visual.simulate_event(MouseDownEvent {
|
||||
position: at,
|
||||
click_count,
|
||||
modifiers: Modifiers::default(),
|
||||
button: MouseButton::Left,
|
||||
first_mouse: false,
|
||||
});
|
||||
visual.simulate_event(MouseUpEvent {
|
||||
position: at,
|
||||
click_count,
|
||||
modifiers: Modifiers::default(),
|
||||
button: MouseButton::Left,
|
||||
});
|
||||
}
|
||||
|
||||
fn drag(visual: &mut VisualTestContext, from: gpui::Point<Pixels>, to: gpui::Point<Pixels>) {
|
||||
visual.simulate_mouse_down(from, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: to,
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
visual.simulate_mouse_up(to, MouseButton::Left, Modifiers::default());
|
||||
}
|
||||
|
||||
fn register(dock: &Entity<DockState>, tags: &[&'static str], cx: &mut TestAppContext) {
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, _cx| {
|
||||
for tag in tags {
|
||||
dock.register_panel(descriptor(tag));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn open(visual: &mut VisualTestContext, dock: &Entity<DockState>, tag: &'static str) {
|
||||
visual.update(|window, cx| {
|
||||
dock.update(cx, |dock, cx| dock.open_panel(tag, window, cx));
|
||||
});
|
||||
redraw(visual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_a_panel_adds_its_tab_and_activates_it() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(&mut cx);
|
||||
register(&dock, &["inbox", "explore"], &mut cx);
|
||||
|
||||
open(&mut visual, &dock, "inbox");
|
||||
assert!(
|
||||
bounds(&mut visual, "panel-inbox").is_some(),
|
||||
"opened panel missing"
|
||||
);
|
||||
assert!(
|
||||
bounds(&mut visual, "test-dock-pane-0-tabs-tab-inbox").is_some(),
|
||||
"tab missing"
|
||||
);
|
||||
|
||||
open(&mut visual, &dock, "explore");
|
||||
assert!(bounds(&mut visual, "panel-explore").is_some());
|
||||
assert!(
|
||||
bounds(&mut visual, "panel-inbox").is_none(),
|
||||
"the inactive view must not render"
|
||||
);
|
||||
assert!(
|
||||
bounds(&mut visual, "test-dock-pane-0-tabs-tab-inbox").is_some(),
|
||||
"the strip keeps both tabs"
|
||||
);
|
||||
|
||||
assert!(dock.read_with(&cx, |dock, _| dock.is_open("inbox")));
|
||||
assert!(dock.read_with(&cx, |dock, _| dock.is_open("explore")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clicking_a_tab_activates_its_panel() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(&mut cx);
|
||||
register(&dock, &["inbox", "explore"], &mut cx);
|
||||
open(&mut visual, &dock, "inbox");
|
||||
open(&mut visual, &dock, "explore");
|
||||
|
||||
let tab = bounds(&mut visual, "test-dock-pane-0-tabs-tab-inbox").expect("inbox tab missing");
|
||||
press(&mut visual, center_of(tab), 1);
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(bounds(&mut visual, "panel-inbox").is_some());
|
||||
assert!(bounds(&mut visual, "panel-explore").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tab_close_control_closes_its_panel() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(&mut cx);
|
||||
register(&dock, &["inbox", "explore"], &mut cx);
|
||||
open(&mut visual, &dock, "inbox");
|
||||
open(&mut visual, &dock, "explore");
|
||||
|
||||
let close = bounds(&mut visual, "test-dock-pane-0-tabs-close-inbox").expect("close missing");
|
||||
press(&mut visual, center_of(close), 1);
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0-tabs-tab-inbox").is_none());
|
||||
assert!(bounds(&mut visual, "panel-explore").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_the_active_tab_activates_the_neighbor() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(&mut cx);
|
||||
register(&dock, &["inbox", "explore"], &mut cx);
|
||||
open(&mut visual, &dock, "inbox");
|
||||
open(&mut visual, &dock, "explore");
|
||||
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| dock.close_panel("explore", cx));
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(
|
||||
bounds(&mut visual, "panel-inbox").is_some(),
|
||||
"the neighbor tab should activate"
|
||||
);
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0-tabs-tab-explore").is_none());
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0-tabs-tab-inbox").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn splitting_moves_the_tab_and_closing_collapses() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(&mut cx);
|
||||
register(&dock, &["inbox", "explore"], &mut cx);
|
||||
open(&mut visual, &dock, "inbox");
|
||||
open(&mut visual, &dock, "explore");
|
||||
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| {
|
||||
dock.split_panel("explore", SplitDirection::Right, cx)
|
||||
});
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(
|
||||
bounds(&mut visual, "resize-handle").is_some(),
|
||||
"the split renders a seam"
|
||||
);
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0").is_some());
|
||||
assert!(bounds(&mut visual, "test-dock-pane-1").is_some());
|
||||
assert!(
|
||||
bounds(&mut visual, "panel-explore").is_some(),
|
||||
"the moved tab activates in its new pane"
|
||||
);
|
||||
|
||||
// Closing the new pane's only tab collapses its split.
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| dock.close_panel("explore", cx));
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(bounds(&mut visual, "resize-handle").is_none());
|
||||
assert!(bounds(&mut visual, "test-dock-pane-1").is_none());
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0").is_some());
|
||||
assert!(bounds(&mut visual, "panel-inbox").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn splitting_at_a_target_pane_places_the_new_pane_there() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(&mut cx);
|
||||
register(&dock, &["inbox", "explore"], &mut cx);
|
||||
open(&mut visual, &dock, "inbox");
|
||||
open(&mut visual, &dock, "explore");
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| {
|
||||
dock.split_panel("explore", SplitDirection::Right, cx)
|
||||
});
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
// Move inbox into a new pane left of explore's pane (pane 1), not beside
|
||||
// inbox's own (pane 0, which empties and collapses).
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| {
|
||||
dock.split_panel_at("inbox", "explore", SplitDirection::Left, cx)
|
||||
});
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
let moved = bounds(&mut visual, "test-dock-pane-3").expect("the new pane missing");
|
||||
let target = bounds(&mut visual, "test-dock-pane-1").expect("target pane missing");
|
||||
// The flex split may round the shared seam by a hair.
|
||||
assert!(
|
||||
moved.right() <= target.left() + px(1.),
|
||||
"the new pane must sit left of the anchored pane"
|
||||
);
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dragging_the_seam_resizes_and_double_click_resets() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(&mut cx);
|
||||
register(&dock, &["inbox", "explore"], &mut cx);
|
||||
open(&mut visual, &dock, "inbox");
|
||||
open(&mut visual, &dock, "explore");
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| {
|
||||
dock.split_panel("explore", SplitDirection::Right, cx)
|
||||
});
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
let before_0 = bounds(&mut visual, "test-dock-pane-0").expect("pane 0 missing");
|
||||
let before_1 = bounds(&mut visual, "test-dock-pane-1").expect("pane 1 missing");
|
||||
let seam = bounds(&mut visual, "resize-handle").expect("seam missing");
|
||||
|
||||
drag(
|
||||
&mut visual,
|
||||
center_of(seam),
|
||||
center_of(seam) + point(px(40.), px(0.)),
|
||||
);
|
||||
let grown = bounds(&mut visual, "test-dock-pane-0").expect("pane 0 missing");
|
||||
let shrunk = bounds(&mut visual, "test-dock-pane-1").expect("pane 1 missing");
|
||||
assert!(
|
||||
grown.size.width > before_0.size.width,
|
||||
"the seam leads pane 0"
|
||||
);
|
||||
assert!(shrunk.size.width < before_1.size.width, "pane 1 gives way");
|
||||
|
||||
// Double-clicking the seam restores the default ratio.
|
||||
let seam = bounds(&mut visual, "resize-handle").expect("seam missing");
|
||||
press(&mut visual, center_of(seam), 2);
|
||||
redraw(&mut visual);
|
||||
let reset_0 = bounds(&mut visual, "test-dock-pane-0").expect("pane 0 missing");
|
||||
let reset_1 = bounds(&mut visual, "test-dock-pane-1").expect("pane 1 missing");
|
||||
// The flex split may round an odd-pixel span by a hair.
|
||||
assert!((reset_0.size.width - reset_1.size.width).abs() <= px(1.));
|
||||
|
||||
// A huge drag clamps instead of vanishing a side.
|
||||
let seam = bounds(&mut visual, "resize-handle").expect("seam missing");
|
||||
drag(
|
||||
&mut visual,
|
||||
center_of(seam),
|
||||
center_of(seam) + point(px(2000.), px(0.)),
|
||||
);
|
||||
let clamped = bounds(&mut visual, "test-dock-pane-1").expect("clamped pane missing");
|
||||
assert!(clamped.size.width > px(0.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dragging_a_tab_to_a_pane_edge_splits_it() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(&mut cx);
|
||||
register(&dock, &["inbox", "explore"], &mut cx);
|
||||
open(&mut visual, &dock, "inbox");
|
||||
open(&mut visual, &dock, "explore");
|
||||
|
||||
// Drag explore's tab onto the right edge band of the pane's content.
|
||||
let tab = bounds(&mut visual, "test-dock-pane-0-tabs-tab-explore").expect("tab missing");
|
||||
let content = bounds(&mut visual, "test-dock-content-0").expect("content missing");
|
||||
let drop_at = point(
|
||||
content.right() - content.size.width * 0.125,
|
||||
content.center().y,
|
||||
);
|
||||
|
||||
visual.simulate_mouse_down(center_of(tab), MouseButton::Left, Modifiers::default());
|
||||
// Past the drag threshold, the drag starts and the drop zones mount.
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: center_of(tab) + point(px(8.), px(2.)),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
redraw(&mut visual);
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: drop_at,
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
visual.simulate_mouse_up(drop_at, MouseButton::Left, Modifiers::default());
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(
|
||||
bounds(&mut visual, "resize-handle").is_some(),
|
||||
"the drop should have split the pane"
|
||||
);
|
||||
assert!(
|
||||
bounds(&mut visual, "test-dock-pane-1-tabs-tab-explore").is_some(),
|
||||
"the dragged tab lives in the new pane"
|
||||
);
|
||||
assert!(bounds(&mut visual, "panel-explore").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_a_panel_merges_panes_and_collapses_the_source() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(&mut cx);
|
||||
register(&dock, &["inbox", "explore"], &mut cx);
|
||||
open(&mut visual, &dock, "inbox");
|
||||
open(&mut visual, &dock, "explore");
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| {
|
||||
dock.split_panel("explore", SplitDirection::Right, cx)
|
||||
});
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| dock.move_panel("explore", "inbox", cx));
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(
|
||||
bounds(&mut visual, "resize-handle").is_none(),
|
||||
"the emptied source pane collapses"
|
||||
);
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0-tabs-tab-inbox").is_some());
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0-tabs-tab-explore").is_some());
|
||||
assert!(
|
||||
bounds(&mut visual, "panel-explore").is_some(),
|
||||
"the moved tab activates in its new pane"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn close_others_keeps_one_and_close_pane_empties() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(&mut cx);
|
||||
register(&dock, &["inbox", "explore", "settings"], &mut cx);
|
||||
open(&mut visual, &dock, "inbox");
|
||||
open(&mut visual, &dock, "explore");
|
||||
open(&mut visual, &dock, "settings");
|
||||
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| dock.close_others("inbox", cx));
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0-tabs-tab-inbox").is_some());
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0-tabs-tab-explore").is_none());
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0-tabs-tab-settings").is_none());
|
||||
assert!(bounds(&mut visual, "panel-inbox").is_some());
|
||||
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| dock.close_pane("inbox", cx));
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0-tabs-tab-inbox").is_none());
|
||||
assert!(
|
||||
bounds(&mut visual, "panel-inbox").is_none(),
|
||||
"the emptied pane renders nothing"
|
||||
);
|
||||
|
||||
// The dock is reusable: opening again fills the empty root pane.
|
||||
open(&mut visual, &dock, "inbox");
|
||||
assert!(bounds(&mut visual, "test-dock-pane-0-tabs-tab-inbox").is_some());
|
||||
}
|
||||
|
||||
struct SidebarHarness {
|
||||
dock: Entity<DockState>,
|
||||
}
|
||||
|
||||
impl Render for SidebarHarness {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.size_full()
|
||||
.flex()
|
||||
.flex_row()
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.child(Dock::new("test-dock", self.dock.clone())),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.w(px(160.))
|
||||
.child(DockSidebar::new("test-dock-sidebar", self.dock.clone())),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn sidebar_window(
|
||||
cx: &mut TestAppContext,
|
||||
) -> (Entity<DockState>, Rc<Cell<bool>>, VisualTestContext) {
|
||||
cx.update(Theme::init);
|
||||
let dock = cx.update(DockState::new);
|
||||
let opened = Rc::new(Cell::new(false));
|
||||
let opened_for_dock = opened.clone();
|
||||
let dock_for_window = dock.clone();
|
||||
let window = cx.add_window(move |_, _| SidebarHarness {
|
||||
dock: dock_for_window,
|
||||
});
|
||||
dock.update(cx, |dock, _| {
|
||||
dock.on_open_right_sidebar(move |cx| {
|
||||
opened_for_dock.set(true);
|
||||
let _ = cx;
|
||||
});
|
||||
});
|
||||
let mut visual = VisualTestContext::from_window(window.into(), cx);
|
||||
visual.update(|window, cx| window.draw(cx).clear(cx));
|
||||
(dock, opened, visual)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn activating_a_panel_with_a_right_view_opens_the_sidebar() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, opened, mut visual) = sidebar_window(&mut cx);
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, _cx| {
|
||||
dock.register_panel(descriptor_with_right_sidebar("overview"));
|
||||
dock.register_panel(descriptor("inbox"));
|
||||
});
|
||||
});
|
||||
|
||||
open(&mut visual, &dock, "overview");
|
||||
assert!(
|
||||
opened.get(),
|
||||
"activation must ask the app to open the sidebar"
|
||||
);
|
||||
assert!(
|
||||
bounds(&mut visual, "side-overview").is_some(),
|
||||
"the sidebar shows the panel's own view"
|
||||
);
|
||||
|
||||
// A panel without a right view leaves the sidebar showing the last one.
|
||||
open(&mut visual, &dock, "inbox");
|
||||
assert!(opened.get());
|
||||
assert!(bounds(&mut visual, "side-overview").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_the_displayed_tab_falls_back_to_another_right_view() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, opened, mut visual) = sidebar_window(&mut cx);
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, _cx| {
|
||||
dock.register_panel(descriptor_with_right_sidebar("overview"));
|
||||
dock.register_panel(descriptor_with_right_sidebar("explore"));
|
||||
});
|
||||
});
|
||||
open(&mut visual, &dock, "overview");
|
||||
open(&mut visual, &dock, "explore");
|
||||
assert!(bounds(&mut visual, "side-explore").is_some());
|
||||
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, cx| dock.close_panel("explore", cx));
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(
|
||||
bounds(&mut visual, "side-overview").is_some(),
|
||||
"the sidebar falls back to a remaining panel's view"
|
||||
);
|
||||
let _ = opened;
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
#![cfg(feature = "resizable")]
|
||||
|
||||
use gpui::{
|
||||
AppContext as _, Context, Entity, IntoElement, Modifiers, MouseButton, MouseDownEvent,
|
||||
MouseMoveEvent, ParentElement as _, Pixels, Render, Styled as _, Subscription, TestAppContext,
|
||||
VisualTestContext, Window, div, point, px,
|
||||
};
|
||||
use gpui_native_layout::resizable::{Resizable, ResizablePane, ResizableState};
|
||||
use gpui_native_theme::Theme;
|
||||
|
||||
const GROUP_WIDTH: f32 = 200.0;
|
||||
const GROUP_HEIGHT: f32 = 300.0;
|
||||
|
||||
struct Harness {
|
||||
state: Entity<ResizableState>,
|
||||
_observation: Subscription,
|
||||
}
|
||||
|
||||
impl Render for Harness {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div().w(px(GROUP_WIDTH)).h(px(GROUP_HEIGHT)).child(
|
||||
Resizable::new("test-split", self.state.clone())
|
||||
.debug_selector(|| "test-pane".to_string())
|
||||
.size_full()
|
||||
.pane(div())
|
||||
.pane(div()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn split_window(sizes: [Pixels; 1]) -> (TestAppContext, Entity<ResizableState>, VisualTestContext) {
|
||||
let mut cx = TestAppContext::single();
|
||||
cx.update(Theme::init);
|
||||
let state = cx.update(ResizableState::new);
|
||||
state.update(&mut cx, |state, cx| state.set_sizes(sizes, cx));
|
||||
let window_state = state.clone();
|
||||
let window = cx.add_window(move |_, cx: &mut Context<Harness>| {
|
||||
let observation = cx.observe(&window_state, |_, _, cx| cx.notify());
|
||||
Harness {
|
||||
state: window_state,
|
||||
_observation: observation,
|
||||
}
|
||||
});
|
||||
let window = window.into();
|
||||
cx.update_window(window, |_, window, cx| {
|
||||
window.draw(cx).clear(cx);
|
||||
})
|
||||
.unwrap();
|
||||
let visual = VisualTestContext::from_window(window, &cx);
|
||||
(cx, state, visual)
|
||||
}
|
||||
|
||||
fn divider_center(visual: &mut VisualTestContext) -> gpui::Point<gpui::Pixels> {
|
||||
let bounds = visual
|
||||
.debug_bounds("resize-handle")
|
||||
.expect("divider rendered");
|
||||
point(bounds.center().x, bounds.center().y)
|
||||
}
|
||||
|
||||
fn drag_divider(visual: &mut VisualTestContext, delta: gpui::Pixels) {
|
||||
let start = divider_center(visual);
|
||||
visual.simulate_mouse_down(start, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: point(start.x, start.y + delta),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
visual.simulate_mouse_up(start, MouseButton::Left, Modifiers::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drag_moves_the_pane_and_its_rendered_height() {
|
||||
let (mut cx, state, mut visual) = split_window([px(100.)]);
|
||||
drag_divider(&mut visual, px(60.));
|
||||
|
||||
state.update(&mut cx, |state, _| assert_eq!(state.sizes(), &[px(160.)]));
|
||||
|
||||
// The pane re-renders at the new size after the state notifies the owner.
|
||||
visual.update(|window, cx| window.draw(cx).clear(cx));
|
||||
let bounds = visual
|
||||
.debug_bounds("test-pane-0")
|
||||
.expect("first pane rendered");
|
||||
assert_eq!(bounds.size.height, px(160.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drag_stops_where_the_remainder_keeps_its_floor() {
|
||||
let (mut cx, state, mut visual) = split_window([px(100.)]);
|
||||
let floor = ResizablePane::DEFAULT_MIN;
|
||||
|
||||
drag_divider(&mut visual, px(1000.));
|
||||
|
||||
state.update(&mut cx, |state, _| {
|
||||
assert_eq!(state.sizes(), &[px(GROUP_HEIGHT) - floor]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_double_click_resets_the_pane_to_the_equal_split() {
|
||||
let (mut cx, state, mut visual) = split_window([px(240.)]);
|
||||
let start = divider_center(&mut visual);
|
||||
|
||||
visual.simulate_event(MouseDownEvent {
|
||||
position: start,
|
||||
modifiers: Modifiers::default(),
|
||||
button: MouseButton::Left,
|
||||
click_count: 2,
|
||||
first_mouse: false,
|
||||
});
|
||||
|
||||
state.update(&mut cx, |state, _| {
|
||||
assert_eq!(state.sizes(), &[px(GROUP_HEIGHT / 2.)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrow_keys_resize_the_focused_pane() {
|
||||
let (mut cx, state, mut visual) = split_window([px(100.)]);
|
||||
let start = divider_center(&mut visual);
|
||||
|
||||
// A single click focuses the handle without resetting anything.
|
||||
visual.simulate_mouse_down(start, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_mouse_up(start, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_keystrokes("down");
|
||||
visual.simulate_keystrokes("up");
|
||||
|
||||
state.update(&mut cx, |state, _| assert_eq!(state.sizes(), &[px(100.)]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unfocused_handle_ignores_arrow_keys() {
|
||||
let (mut cx, state, mut visual) = split_window([px(100.)]);
|
||||
let start = divider_center(&mut visual);
|
||||
let _ = start;
|
||||
|
||||
visual.simulate_keystrokes("down");
|
||||
|
||||
state.update(&mut cx, |state, _| assert_eq!(state.sizes(), &[px(100.)]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_panes_and_the_divider_fill_the_group_exactly() {
|
||||
let (_cx, _state, mut visual) = split_window([px(100.)]);
|
||||
visual.update(|window, cx| window.draw(cx).clear(cx));
|
||||
let first = visual
|
||||
.debug_bounds("test-pane-0")
|
||||
.expect("first pane rendered");
|
||||
let second = visual
|
||||
.debug_bounds("test-pane-1")
|
||||
.expect("remainder pane rendered");
|
||||
let divider = visual
|
||||
.debug_bounds("resize-handle")
|
||||
.expect("divider rendered");
|
||||
// The flex split may round the panes' shared edges by a hair.
|
||||
assert!((first.size.height + second.size.height - px(GROUP_HEIGHT)).abs() <= px(1.));
|
||||
// The divider owns no layout space: it straddles the seam between the panes.
|
||||
assert!((divider.center().y - first.bottom()).abs() <= px(1.));
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
#![cfg(feature = "resize_handle")]
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
Axis, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _,
|
||||
Pixels, Render, Styled as _, TestAppContext, VisualTestContext, Window, div, point, px,
|
||||
};
|
||||
use gpui_native_layout::resize_handle::ResizeHandle;
|
||||
use gpui_native_theme::Theme;
|
||||
|
||||
type DeltaSink = Rc<RefCell<Vec<Pixels>>>;
|
||||
type ResetSink = Rc<RefCell<usize>>;
|
||||
|
||||
struct Harness {
|
||||
deltas: Rc<RefCell<Vec<Pixels>>>,
|
||||
resets: Rc<RefCell<usize>>,
|
||||
axis: Axis,
|
||||
disabled: bool,
|
||||
}
|
||||
|
||||
impl Render for Harness {
|
||||
fn render(
|
||||
&mut self,
|
||||
_window: &mut Window,
|
||||
_cx: &mut gpui::Context<Self>,
|
||||
) -> impl gpui::IntoElement {
|
||||
let deltas = self.deltas.clone();
|
||||
let resets = self.resets.clone();
|
||||
let horizontal = self.axis == Axis::Horizontal;
|
||||
div()
|
||||
.size_full()
|
||||
.flex()
|
||||
.when(horizontal, |layout| layout.flex_row())
|
||||
.when(!horizontal, |layout| layout.flex_col())
|
||||
.child(if horizontal {
|
||||
div().w(px(120.)).h_full()
|
||||
} else {
|
||||
div().h(px(120.)).w_full()
|
||||
})
|
||||
.child(
|
||||
ResizeHandle::new("test-handle")
|
||||
.axis(self.axis)
|
||||
.disabled(self.disabled)
|
||||
.on_resize(move |delta, _, _| deltas.borrow_mut().push(delta))
|
||||
.on_reset(move |_, _| *resets.borrow_mut() += 1),
|
||||
)
|
||||
.child(if horizontal {
|
||||
div().flex_1().h_full()
|
||||
} else {
|
||||
div().flex_1().w_full()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_window(
|
||||
axis: Axis,
|
||||
disabled: bool,
|
||||
) -> (TestAppContext, DeltaSink, ResetSink, VisualTestContext) {
|
||||
let mut cx = TestAppContext::single();
|
||||
cx.update(Theme::init);
|
||||
let deltas = Rc::new(RefCell::new(Vec::new()));
|
||||
let resets = Rc::new(RefCell::new(0usize));
|
||||
let deltas_for_window = deltas.clone();
|
||||
let resets_for_window = resets.clone();
|
||||
let window = cx.add_window(move |_, _| Harness {
|
||||
deltas: deltas_for_window,
|
||||
resets: resets_for_window,
|
||||
axis,
|
||||
disabled,
|
||||
});
|
||||
let mut visual = VisualTestContext::from_window(window.into(), &cx);
|
||||
visual.update(|window, cx| {
|
||||
window.draw(cx).clear(cx);
|
||||
});
|
||||
(cx, deltas, resets, visual)
|
||||
}
|
||||
|
||||
fn handle_center(visual: &mut VisualTestContext) -> gpui::Point<gpui::Pixels> {
|
||||
let bounds = visual
|
||||
.debug_bounds("resize-handle")
|
||||
.expect("resize handle missing");
|
||||
point(bounds.center().x, bounds.center().y)
|
||||
}
|
||||
|
||||
fn click(visual: &mut VisualTestContext, position: gpui::Point<gpui::Pixels>) {
|
||||
visual.simulate_mouse_down(position, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_mouse_up(position, MouseButton::Left, Modifiers::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dragging_reports_signed_deltas() {
|
||||
let (_cx, deltas, _resets, mut visual) = handle_window(Axis::Horizontal, false);
|
||||
let start = handle_center(&mut visual);
|
||||
|
||||
visual.simulate_mouse_down(start, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: point(start.x + px(30.), start.y),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: point(start.x + px(10.), start.y),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
visual.simulate_mouse_up(start, MouseButton::Left, Modifiers::default());
|
||||
|
||||
assert_eq!(*deltas.borrow(), vec![px(30.), px(-20.)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vertical_seams_report_y_deltas() {
|
||||
let (_cx, deltas, _resets, mut visual) = handle_window(Axis::Vertical, false);
|
||||
let start = handle_center(&mut visual);
|
||||
|
||||
visual.simulate_mouse_down(start, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: point(start.x, start.y + px(40.)),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
visual.simulate_mouse_up(start, MouseButton::Left, Modifiers::default());
|
||||
|
||||
assert_eq!(*deltas.borrow(), vec![px(40.)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_without_a_drag_report_nothing() {
|
||||
let (_cx, deltas, _resets, mut visual) = handle_window(Axis::Horizontal, false);
|
||||
let start = handle_center(&mut visual);
|
||||
|
||||
// Hovering and moving across the seam without pressing does nothing.
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: point(start.x + px(30.), start.y),
|
||||
pressed_button: None,
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
// A press-and-move that started elsewhere must not reach the handle either.
|
||||
visual.simulate_mouse_down(
|
||||
point(px(20.), px(20.)),
|
||||
MouseButton::Left,
|
||||
Modifiers::default(),
|
||||
);
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: point(px(50.), px(20.)),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
|
||||
assert!(deltas.borrow().is_empty());
|
||||
}
|
||||
|
||||
/// The button may be released outside the window, where no MouseUp is
|
||||
/// delivered — the drag must end when a move reports no pressed button.
|
||||
#[test]
|
||||
fn releasing_outside_the_window_ends_the_drag() {
|
||||
let (_cx, deltas, _resets, mut visual) = handle_window(Axis::Horizontal, false);
|
||||
let start = handle_center(&mut visual);
|
||||
|
||||
visual.simulate_mouse_down(start, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: point(start.x + px(30.), start.y),
|
||||
pressed_button: None,
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: point(start.x + px(60.), start.y),
|
||||
pressed_button: None,
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
|
||||
assert!(deltas.borrow().is_empty(), "the drag outlived its button");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrow_keys_move_the_seam_when_focused() {
|
||||
let (_cx, deltas, _resets, mut visual) = handle_window(Axis::Horizontal, false);
|
||||
let center = handle_center(&mut visual);
|
||||
click(&mut visual, center);
|
||||
|
||||
visual.simulate_keystrokes("left");
|
||||
visual.simulate_keystrokes("right");
|
||||
assert_eq!(*deltas.borrow(), vec![px(-32.), px(32.)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_click_resets_and_starts_no_drag() {
|
||||
let (_cx, deltas, resets, mut visual) = handle_window(Axis::Horizontal, false);
|
||||
let center = handle_center(&mut visual);
|
||||
|
||||
for click_count in [1usize, 2] {
|
||||
visual.simulate_event(MouseDownEvent {
|
||||
position: center,
|
||||
click_count,
|
||||
modifiers: Modifiers::default(),
|
||||
button: MouseButton::Left,
|
||||
first_mouse: false,
|
||||
});
|
||||
visual.simulate_event(MouseUpEvent {
|
||||
position: center,
|
||||
click_count,
|
||||
modifiers: Modifiers::default(),
|
||||
button: MouseButton::Left,
|
||||
});
|
||||
}
|
||||
assert_eq!(*resets.borrow(), 1);
|
||||
|
||||
// The double click must not leave a drag behind.
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: point(center.x + px(20.), center.y),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
assert!(deltas.borrow().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disabled_handle_ignores_drag_and_keys() {
|
||||
let (_cx, deltas, resets, mut visual) = handle_window(Axis::Horizontal, true);
|
||||
let center = handle_center(&mut visual);
|
||||
|
||||
visual.simulate_mouse_down(center, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: point(center.x + px(30.), center.y),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
visual.simulate_mouse_up(center, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_keystrokes("left");
|
||||
|
||||
assert!(deltas.borrow().is_empty());
|
||||
assert_eq!(*resets.borrow(), 0);
|
||||
}
|
||||
@@ -1,615 +0,0 @@
|
||||
#![cfg(feature = "shell")]
|
||||
|
||||
use gpui::{
|
||||
Entity, InteractiveElement as _, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent,
|
||||
MouseUpEvent, ParentElement as _, Pixels, Render, Styled as _, TestAppContext,
|
||||
VisualTestContext, Window, div, point, px,
|
||||
};
|
||||
use gpui_native_data::sidebar::Sidebar;
|
||||
use gpui_native_layout::shell::{LayoutState, Shell, SidebarToggles};
|
||||
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size, Theme};
|
||||
|
||||
struct Harness {
|
||||
state: Entity<LayoutState>,
|
||||
}
|
||||
|
||||
impl Render for Harness {
|
||||
fn render(
|
||||
&mut self,
|
||||
_window: &mut Window,
|
||||
_cx: &mut gpui::Context<Self>,
|
||||
) -> impl gpui::IntoElement {
|
||||
div().size_full().child(
|
||||
Shell::new("test-layout", self.state.clone())
|
||||
.left_sidebar(Sidebar::new("test-left"))
|
||||
.center(
|
||||
div()
|
||||
.size_full()
|
||||
.debug_selector(|| "test-center".to_string()),
|
||||
)
|
||||
.right_sidebar(
|
||||
div()
|
||||
.size_full()
|
||||
.debug_selector(|| "test-right".to_string()),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn layout_window(cx: &mut TestAppContext) -> (Entity<LayoutState>, VisualTestContext) {
|
||||
cx.update(Theme::init);
|
||||
let state = cx.update(LayoutState::new);
|
||||
let state_for_window = state.clone();
|
||||
let window = cx.add_window(move |_, _| Harness {
|
||||
state: state_for_window,
|
||||
});
|
||||
let mut visual = VisualTestContext::from_window(window.into(), cx);
|
||||
redraw(&mut visual);
|
||||
(state, visual)
|
||||
}
|
||||
|
||||
fn redraw(visual: &mut VisualTestContext) {
|
||||
visual.update(|window, cx| {
|
||||
window.draw(cx).clear(cx);
|
||||
});
|
||||
}
|
||||
|
||||
fn bounds(visual: &mut VisualTestContext, selector: &'static str) -> Option<gpui::Bounds<Pixels>> {
|
||||
visual.debug_bounds(selector)
|
||||
}
|
||||
|
||||
fn center_of(bounds: gpui::Bounds<Pixels>) -> gpui::Point<Pixels> {
|
||||
point(bounds.center().x, bounds.center().y)
|
||||
}
|
||||
|
||||
fn press(visual: &mut VisualTestContext, at: gpui::Point<Pixels>, click_count: usize) {
|
||||
visual.simulate_event(MouseDownEvent {
|
||||
position: at,
|
||||
click_count,
|
||||
modifiers: Modifiers::default(),
|
||||
button: MouseButton::Left,
|
||||
first_mouse: false,
|
||||
});
|
||||
visual.simulate_event(MouseUpEvent {
|
||||
position: at,
|
||||
click_count,
|
||||
modifiers: Modifiers::default(),
|
||||
button: MouseButton::Left,
|
||||
});
|
||||
}
|
||||
|
||||
fn drag(visual: &mut VisualTestContext, from: gpui::Point<Pixels>, to: gpui::Point<Pixels>) {
|
||||
visual.simulate_mouse_down(from, MouseButton::Left, Modifiers::default());
|
||||
visual.simulate_event(MouseMoveEvent {
|
||||
position: to,
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
visual.simulate_mouse_up(to, MouseButton::Left, Modifiers::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn left_sidebar_starts_visible_and_right_hidden() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = layout_window(&mut cx);
|
||||
|
||||
assert!(state.read_with(&cx, |state, _| state.is_left_sidebar_visible()));
|
||||
assert!(!state.read_with(&cx, |state, _| state.is_right_sidebar_visible()));
|
||||
assert_eq!(
|
||||
state.read_with(&cx, |state, _| state.sidebar_toggles()),
|
||||
SidebarToggles::Tabbar,
|
||||
"the toggles default to the dock's tab bar"
|
||||
);
|
||||
|
||||
assert!(
|
||||
bounds(&mut visual, "sidebar-test-left").is_some(),
|
||||
"left region missing"
|
||||
);
|
||||
assert!(
|
||||
bounds(&mut visual, "test-center").is_some(),
|
||||
"center missing"
|
||||
);
|
||||
assert!(
|
||||
bounds(&mut visual, "test-right").is_none(),
|
||||
"right region must be hidden by default"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggling_a_sidebar_shows_and_hides_its_region() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = layout_window(&mut cx);
|
||||
|
||||
cx.update(|cx| {
|
||||
state.update(cx, |state, cx| state.set_right_sidebar_visible(true, cx));
|
||||
});
|
||||
redraw(&mut visual);
|
||||
assert!(
|
||||
bounds(&mut visual, "test-right").is_some(),
|
||||
"right region missing"
|
||||
);
|
||||
|
||||
cx.update(|cx| {
|
||||
state.update(cx, |state, cx| state.set_left_sidebar_visible(false, cx));
|
||||
});
|
||||
redraw(&mut visual);
|
||||
assert!(
|
||||
bounds(&mut visual, "sidebar-test-left").is_none(),
|
||||
"left region lingering"
|
||||
);
|
||||
// The center keeps filling the shell.
|
||||
assert!(
|
||||
bounds(&mut visual, "test-center").is_some(),
|
||||
"center missing"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_header_toggle_hides_its_sidebar() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = layout_window(&mut cx);
|
||||
|
||||
// The strip carries the toggle only under the strips placement.
|
||||
cx.update(|cx| {
|
||||
state.update(cx, |state, cx| {
|
||||
state.set_sidebar_toggles(SidebarToggles::Strips, cx)
|
||||
});
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
// The toggle sits at the trailing end of the sidebar's header strip, an
|
||||
// icon-only small button: derive its center from the theme metrics.
|
||||
let metrics = cx.update(|cx| cx.theme().sizes.resolve(Size::default()));
|
||||
let small = cx.update(|cx| cx.theme().sizes.resolve(Size::Small));
|
||||
let strip_height = cx.update(|cx| cx.theme().titlebar_height);
|
||||
let region = bounds(&mut visual, "sidebar-test-left").expect("left sidebar missing");
|
||||
// The Sidebar fills the content area below the strip; the toggle sits at
|
||||
// the strip's trailing end, one strip height above the sidebar's top.
|
||||
let toggle = point(
|
||||
region.right() - metrics.dense_padding_x - small.control_height / 2.0,
|
||||
region.top() - strip_height / 2.0,
|
||||
);
|
||||
press(&mut visual, toggle, 1);
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(
|
||||
!state.read_with(&cx, |state, _| state.is_left_sidebar_visible()),
|
||||
"the toggle should hide the left sidebar"
|
||||
);
|
||||
assert!(bounds(&mut visual, "sidebar-test-left").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dragging_the_seam_resizes_and_clamps() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = layout_window(&mut cx);
|
||||
|
||||
let before = state.read_with(&cx, |state, _| state.left_sidebar_width());
|
||||
let seam = bounds(&mut visual, "resize-handle").expect("left seam missing");
|
||||
|
||||
drag(
|
||||
&mut visual,
|
||||
center_of(seam),
|
||||
center_of(seam) + point(px(50.), px(0.)),
|
||||
);
|
||||
assert_eq!(
|
||||
state.read_with(&cx, |state, _| state.left_sidebar_width()),
|
||||
before + px(50.)
|
||||
);
|
||||
|
||||
// A huge drag clamps instead of collapsing the sidebar.
|
||||
let seam = bounds(&mut visual, "resize-handle").expect("seam missing");
|
||||
drag(
|
||||
&mut visual,
|
||||
center_of(seam),
|
||||
center_of(seam) + point(px(2000.), px(0.)),
|
||||
);
|
||||
assert_eq!(
|
||||
state.read_with(&cx, |state, _| state.left_sidebar_width()),
|
||||
px(480.)
|
||||
);
|
||||
|
||||
// Dragging back left shrinks it to the low clamp, no drift from the first.
|
||||
let seam = bounds(&mut visual, "resize-handle").expect("seam missing");
|
||||
drag(
|
||||
&mut visual,
|
||||
center_of(seam),
|
||||
center_of(seam) - point(px(2000.), px(0.)),
|
||||
);
|
||||
assert_eq!(
|
||||
state.read_with(&cx, |state, _| state.left_sidebar_width()),
|
||||
px(160.)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_right_seam_grows_the_right_sidebar_leftwards() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = layout_window(&mut cx);
|
||||
|
||||
// Hide the left sidebar so the shell has exactly one seam.
|
||||
cx.update(|cx| {
|
||||
state.update(cx, |state, cx| state.set_left_sidebar_visible(false, cx));
|
||||
state.update(cx, |state, cx| state.set_right_sidebar_visible(true, cx));
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
let before = state.read_with(&cx, |state, _| state.right_sidebar_width());
|
||||
let seam = bounds(&mut visual, "resize-handle").expect("right seam missing");
|
||||
|
||||
// Dragging left (negative) grows the right sidebar.
|
||||
drag(
|
||||
&mut visual,
|
||||
center_of(seam),
|
||||
center_of(seam) - point(px(30.), px(0.)),
|
||||
);
|
||||
let grown = state.read_with(&cx, |state, _| state.right_sidebar_width());
|
||||
assert_eq!(grown, before + px(30.));
|
||||
|
||||
// The right region's width follows the state.
|
||||
let region = bounds(&mut visual, "test-right").expect("right region missing");
|
||||
assert_eq!(region.size.width, grown);
|
||||
}
|
||||
|
||||
/// Toasts and alerts live on the shell's [`LayoutState`]; pushing one must
|
||||
/// show up in the rendered shell with no observing or manual overlay.
|
||||
#[cfg(feature = "toast")]
|
||||
mod toasts {
|
||||
use super::*;
|
||||
use gpui_native_core::toast::{Toast, ToastAction};
|
||||
use std::time::Duration;
|
||||
|
||||
#[test]
|
||||
fn a_pushed_toast_renders_in_the_shell() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = layout_window(&mut cx);
|
||||
|
||||
let id = cx.update(|cx| {
|
||||
state.update(cx, |state, cx| {
|
||||
state.push_toast(
|
||||
Toast::new("Draft deleted").action(ToastAction::new("Undo", |_| {
|
||||
// A real app restores the draft here.
|
||||
})),
|
||||
cx,
|
||||
)
|
||||
})
|
||||
});
|
||||
// No redraw, no observation: the shell repaints its own overlay.
|
||||
cx.run_until_parked();
|
||||
assert!(
|
||||
bounds(&mut visual, "toast-pill").is_some(),
|
||||
"the pushed toast must appear in the shell's overlay"
|
||||
);
|
||||
|
||||
cx.update(|cx| {
|
||||
state.update(cx, |state, cx| state.dismiss_toast(id, cx));
|
||||
});
|
||||
cx.run_until_parked();
|
||||
// The fade-out keeps the pill mounted briefly.
|
||||
assert!(
|
||||
bounds(&mut visual, "toast-pill").is_some(),
|
||||
"the dismissed toast must stay mounted through its fade-out"
|
||||
);
|
||||
cx.executor().advance_clock(Duration::from_secs(2));
|
||||
cx.run_until_parked();
|
||||
assert!(
|
||||
bounds(&mut visual, "toast-pill").is_none(),
|
||||
"the dismissed toast must leave the overlay once faded"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alert")]
|
||||
mod alerts {
|
||||
use super::*;
|
||||
use gpui_native_core::alert::{Alert, AlertSeverity};
|
||||
|
||||
#[test]
|
||||
fn a_pushed_alert_renders_in_the_shell() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = layout_window(&mut cx);
|
||||
|
||||
cx.update(|cx| {
|
||||
state.update(cx, |state, cx| {
|
||||
state.push_alert(
|
||||
Alert::new("shell-alert")
|
||||
.title("Backed up")
|
||||
.severity(AlertSeverity::Info),
|
||||
cx,
|
||||
);
|
||||
})
|
||||
});
|
||||
cx.run_until_parked();
|
||||
assert!(
|
||||
bounds(&mut visual, "alert-entry").is_some(),
|
||||
"the pushed alert must appear in the shell's overlay"
|
||||
);
|
||||
|
||||
cx.update(|cx| {
|
||||
state.update(cx, |state, cx| state.clear_alerts(cx));
|
||||
});
|
||||
cx.run_until_parked();
|
||||
assert!(
|
||||
bounds(&mut visual, "alert-entry").is_none(),
|
||||
"cleared alerts must leave the overlay"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Toggles placed in the dock's tab bar need both the shell and the dock.
|
||||
#[cfg(all(feature = "shell", feature = "dock"))]
|
||||
mod tabbar_toggles {
|
||||
use super::*;
|
||||
use gpui::{AppContext as _, ScrollDelta, ScrollEvent};
|
||||
use gpui_native_layout::dock::{Dock, DockState, PanelDescriptor};
|
||||
use gpui_native_layout::shell::SidebarToggles;
|
||||
|
||||
struct DockPanel;
|
||||
|
||||
impl Render for DockPanel {
|
||||
fn render(
|
||||
&mut self,
|
||||
_window: &mut Window,
|
||||
_cx: &mut gpui::Context<Self>,
|
||||
) -> impl gpui::IntoElement {
|
||||
div().size_full()
|
||||
}
|
||||
}
|
||||
|
||||
struct DockHarness {
|
||||
state: Entity<LayoutState>,
|
||||
dock: Entity<DockState>,
|
||||
}
|
||||
|
||||
impl Render for DockHarness {
|
||||
fn render(
|
||||
&mut self,
|
||||
_window: &mut Window,
|
||||
_cx: &mut gpui::Context<Self>,
|
||||
) -> impl gpui::IntoElement {
|
||||
div().size_full().child(
|
||||
Shell::new("test-layout", self.state.clone())
|
||||
.left_sidebar(Sidebar::new("test-left"))
|
||||
.center(
|
||||
Dock::new("test-dock", self.dock.clone())
|
||||
.sidebar_toggles(self.state.clone()),
|
||||
)
|
||||
.right_sidebar(
|
||||
div()
|
||||
.size_full()
|
||||
.debug_selector(|| "test-right".to_string()),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn tabbar_window(
|
||||
cx: &mut TestAppContext,
|
||||
open: &[&str],
|
||||
) -> (Entity<LayoutState>, VisualTestContext) {
|
||||
cx.update(Theme::init);
|
||||
let state = cx.update(LayoutState::new);
|
||||
let dock = cx.update(|cx| {
|
||||
let dock = DockState::new(cx);
|
||||
dock.update(cx, |dock, _| {
|
||||
dock.register_panel(
|
||||
PanelDescriptor::new("one", |_, cx| cx.new(|_| DockPanel).into()).title("One"),
|
||||
);
|
||||
for index in 0..14 {
|
||||
let tag = format!("panel-{index}");
|
||||
let id = tag.clone();
|
||||
dock.register_panel(
|
||||
PanelDescriptor::new(id, |_, cx| cx.new(|_| DockPanel).into()).title(tag),
|
||||
);
|
||||
}
|
||||
});
|
||||
dock
|
||||
});
|
||||
let state_for_window = state.clone();
|
||||
let dock_for_window = dock.clone();
|
||||
let window = cx.add_window(move |_, _| DockHarness {
|
||||
state: state_for_window,
|
||||
dock: dock_for_window,
|
||||
});
|
||||
let mut visual = VisualTestContext::from_window(window.into(), cx);
|
||||
visual.update(|window, cx| {
|
||||
for id in open {
|
||||
dock.update(cx, |dock, cx| dock.open_panel(id, window, cx));
|
||||
}
|
||||
});
|
||||
redraw(&mut visual);
|
||||
(state, visual)
|
||||
}
|
||||
|
||||
fn place_toggles_in_tabbar(state: &Entity<LayoutState>, cx: &mut TestAppContext) {
|
||||
cx.update(|cx| {
|
||||
state.update(cx, |state, cx| {
|
||||
state.set_sidebar_toggles(SidebarToggles::Tabbar, cx)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tabbar_toggles_sit_at_the_bar_edges() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = tabbar_window(&mut cx, &["one"]);
|
||||
place_toggles_in_tabbar(&state, &mut cx);
|
||||
redraw(&mut visual);
|
||||
|
||||
let metrics = cx.update(|cx| cx.theme().sizes.resolve(Size::default()));
|
||||
let small = cx.update(|cx| cx.theme().sizes.resolve(Size::Small));
|
||||
let bar = bounds(&mut visual, "test-dock-pane-0-bar").expect("tab bar missing");
|
||||
let left = bounds(&mut visual, "sidebar-toggle-left").expect("left toggle missing");
|
||||
let right = bounds(&mut visual, "sidebar-toggle-right").expect("right toggle missing");
|
||||
let scroll = bounds(&mut visual, "test-dock-pane-0-tabs-scroll")
|
||||
.expect("tab scroll container missing");
|
||||
|
||||
// The left toggle leads the bar after its leading pad; the right
|
||||
// toggle trails it at the trailing pad. The button's outer width is
|
||||
// its borders plus dense padding around the icon.
|
||||
let toggle_width = BORDER_WIDTH * 2.0 + small.dense_padding_x * 2.0 + small.icon_size;
|
||||
let left_center = bar.left() + metrics.dense_padding_x + toggle_width / 2.0;
|
||||
let right_center = bar.right() - metrics.dense_padding_x - toggle_width / 2.0;
|
||||
assert!(
|
||||
(left.center().x - left_center).abs() < px(1.0),
|
||||
"the left toggle must lead the tab bar"
|
||||
);
|
||||
assert!(
|
||||
(right.center().x - right_center).abs() < px(1.0),
|
||||
"the right toggle must trail the tab bar"
|
||||
);
|
||||
assert!(
|
||||
left.center().y > bar.top() && left.center().y < bar.bottom(),
|
||||
"the toggles must sit inside the tab bar"
|
||||
);
|
||||
let gap = scroll.left() - left.right();
|
||||
assert!(
|
||||
(gap - px(4.0)).abs() < px(0.5),
|
||||
"the toggle and the tabs must sit one tab gap apart"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_overflowing_tab_bar_keeps_the_trailing_toggle_pinned() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let open = [
|
||||
"one", "panel-0", "panel-1", "panel-2", "panel-3", "panel-4", "panel-5", "panel-6",
|
||||
"panel-7", "panel-8", "panel-9", "panel-10", "panel-11", "panel-12", "panel-13",
|
||||
];
|
||||
let (state, mut visual) = tabbar_window(&mut cx, &open);
|
||||
place_toggles_in_tabbar(&state, &mut cx);
|
||||
redraw(&mut visual);
|
||||
|
||||
let metrics = cx.update(|cx| cx.theme().sizes.resolve(Size::default()));
|
||||
let small = cx.update(|cx| cx.theme().sizes.resolve(Size::Small));
|
||||
let bar = bounds(&mut visual, "test-dock-pane-0-bar").expect("tab bar missing");
|
||||
let left = bounds(&mut visual, "sidebar-toggle-left").expect("left toggle missing");
|
||||
let right = bounds(&mut visual, "sidebar-toggle-right").expect("right toggle missing");
|
||||
let scroll = bounds(&mut visual, "test-dock-pane-0-tabs-scroll")
|
||||
.expect("tab scroll container missing");
|
||||
|
||||
// The tabs outgrow the bar: the drag strip collapses, the scroll
|
||||
// viewport spans between the toggles, and the trailing toggle stays
|
||||
// pinned inside the bar instead of being pushed out of the window.
|
||||
let leading_gap = scroll.left() - left.right();
|
||||
assert!((leading_gap - px(4.0)).abs() < px(0.5));
|
||||
let trailing_gap = right.left() - scroll.right();
|
||||
assert!(
|
||||
(trailing_gap - px(4.0)).abs() < px(0.5),
|
||||
"the viewport must reach the trailing toggle"
|
||||
);
|
||||
assert!(
|
||||
right.right() <= bar.right() + px(1.0),
|
||||
"the trailing toggle must stay inside the bar"
|
||||
);
|
||||
let toggle_width = BORDER_WIDTH * 2.0 + small.dense_padding_x * 2.0 + small.icon_size;
|
||||
let right_center = bar.right() - metrics.dense_padding_x - toggle_width / 2.0;
|
||||
assert!(
|
||||
(right.center().x - right_center).abs() < px(1.0),
|
||||
"the trailing toggle must stay at the bar's trailing pad"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_overflowing_tab_bar_scrolls_with_the_wheel() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let open = [
|
||||
"one", "panel-0", "panel-1", "panel-2", "panel-3", "panel-4", "panel-5", "panel-6",
|
||||
"panel-7", "panel-8", "panel-9", "panel-10", "panel-11", "panel-12", "panel-13",
|
||||
];
|
||||
let (state, mut visual) = tabbar_window(&mut cx, &open);
|
||||
place_toggles_in_tabbar(&state, &mut cx);
|
||||
redraw(&mut visual);
|
||||
|
||||
let scroll = bounds(&mut visual, "test-dock-pane-0-tabs-scroll")
|
||||
.expect("tab scroll container missing");
|
||||
let fit = bounds(&mut visual, "test-dock-pane-0-tabs-fit").expect("tab strip missing");
|
||||
// The pills row is wider than the viewport, so the bar can scroll.
|
||||
assert!(
|
||||
fit.size.width > scroll.size.width + px(1.0),
|
||||
"the tab strip must overflow the bar"
|
||||
);
|
||||
|
||||
// A plain vertical wheel over the bar scrolls the strip toward its
|
||||
// end: the bar only scrolls on the x axis, so gpui remaps the delta.
|
||||
visual.simulate_event(ScrollEvent {
|
||||
position: scroll.center(),
|
||||
delta: ScrollDelta::Pixels(point(px(0.), px(-60.))),
|
||||
modifiers: Modifiers::default(),
|
||||
..Default::default()
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
let fit_after =
|
||||
bounds(&mut visual, "test-dock-pane-0-tabs-fit").expect("tab strip missing");
|
||||
assert!(
|
||||
fit_after.left() < fit.left() - px(10.0),
|
||||
"the wheel must scroll the tab strip"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tabbar_toggle_shows_and_hides_the_left_sidebar() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = tabbar_window(&mut cx, &["one"]);
|
||||
place_toggles_in_tabbar(&state, &mut cx);
|
||||
redraw(&mut visual);
|
||||
|
||||
let toggle = bounds(&mut visual, "sidebar-toggle-left").expect("left toggle missing");
|
||||
press(&mut visual, center_of(toggle), 1);
|
||||
redraw(&mut visual);
|
||||
assert!(!state.read_with(&cx, |state, _| state.is_left_sidebar_visible()));
|
||||
assert!(bounds(&mut visual, "sidebar-test-left").is_none());
|
||||
|
||||
// The toggle outlives its hidden sidebar and brings it back.
|
||||
let toggle = bounds(&mut visual, "sidebar-toggle-left")
|
||||
.expect("left toggle missing while the sidebar is hidden");
|
||||
press(&mut visual, center_of(toggle), 1);
|
||||
redraw(&mut visual);
|
||||
assert!(state.read_with(&cx, |state, _| state.is_left_sidebar_visible()));
|
||||
assert!(bounds(&mut visual, "sidebar-test-left").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tabbar_right_toggle_opens_the_right_sidebar() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = tabbar_window(&mut cx, &["one"]);
|
||||
place_toggles_in_tabbar(&state, &mut cx);
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(bounds(&mut visual, "test-right").is_none());
|
||||
let toggle = bounds(&mut visual, "sidebar-toggle-right").expect("right toggle missing");
|
||||
press(&mut visual, center_of(toggle), 1);
|
||||
redraw(&mut visual);
|
||||
assert!(state.read_with(&cx, |state, _| state.is_right_sidebar_visible()));
|
||||
assert!(bounds(&mut visual, "test-right").is_some());
|
||||
|
||||
let toggle = bounds(&mut visual, "sidebar-toggle-right").expect("right toggle missing");
|
||||
press(&mut visual, center_of(toggle), 1);
|
||||
redraw(&mut visual);
|
||||
assert!(!state.read_with(&cx, |state, _| state.is_right_sidebar_visible()));
|
||||
assert!(bounds(&mut visual, "test-right").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hidden_placement_renders_no_toggles() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (state, mut visual) = layout_window(&mut cx);
|
||||
|
||||
cx.update(|cx| {
|
||||
state.update(cx, |state, cx| {
|
||||
state.set_sidebar_toggles(SidebarToggles::Hidden, cx)
|
||||
});
|
||||
});
|
||||
redraw(&mut visual);
|
||||
|
||||
assert!(
|
||||
bounds(&mut visual, "sidebar-toggle-left").is_none(),
|
||||
"the strip must not carry a toggle when they are hidden"
|
||||
);
|
||||
assert!(
|
||||
bounds(&mut visual, "sidebar-test-left").is_some(),
|
||||
"hiding the toggles must not hide the sidebar itself"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
//! The titlebar duties: traffic-light pads and window controls, asserted per
|
||||
//! platform — macOS draws only pads, Windows/Linux only draw their controls.
|
||||
|
||||
#![cfg(feature = "dock")]
|
||||
|
||||
use gpui::{
|
||||
AppContext as _, Entity, IntoElement, ParentElement as _, Pixels, Render, Styled as _,
|
||||
TestAppContext, VisualTestContext, Window, div, px,
|
||||
};
|
||||
use gpui_native_layout::dock::{Dock, DockState, PanelDescriptor};
|
||||
use gpui_native_layout::window_controls::TRAFFIC_LIGHT_PAD;
|
||||
use gpui_native_theme::Theme;
|
||||
|
||||
struct Panel {
|
||||
tag: &'static str,
|
||||
}
|
||||
|
||||
impl Render for Panel {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut gpui::Context<Self>) -> impl IntoElement {
|
||||
div().size_full().child(self.tag)
|
||||
}
|
||||
}
|
||||
|
||||
fn descriptor(tag: &'static str) -> PanelDescriptor {
|
||||
PanelDescriptor::new(tag, move |_, cx| cx.new(|_| Panel { tag }).into()).title(tag)
|
||||
}
|
||||
|
||||
struct Harness {
|
||||
dock: Entity<DockState>,
|
||||
window_controls: bool,
|
||||
traffic_light_pad: bool,
|
||||
}
|
||||
|
||||
impl Render for Harness {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut gpui::Context<Self>) -> impl IntoElement {
|
||||
div().size_full().child(
|
||||
Dock::new("test-dock", self.dock.clone())
|
||||
.window_controls(self.window_controls)
|
||||
.traffic_light_pad(self.traffic_light_pad),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn dock_window(
|
||||
window_controls: bool,
|
||||
traffic_light_pad: bool,
|
||||
cx: &mut TestAppContext,
|
||||
) -> (Entity<DockState>, VisualTestContext) {
|
||||
cx.update(Theme::init);
|
||||
let dock = cx.update(DockState::new);
|
||||
let dock_for_window = dock.clone();
|
||||
let window = cx.add_window(move |_, _| Harness {
|
||||
dock: dock_for_window,
|
||||
window_controls,
|
||||
traffic_light_pad,
|
||||
});
|
||||
let mut visual = VisualTestContext::from_window(window.into(), cx);
|
||||
visual.update(|window, cx| window.draw(cx).clear(cx));
|
||||
(dock, visual)
|
||||
}
|
||||
|
||||
fn bounds(visual: &mut VisualTestContext, selector: &str) -> Option<gpui::Bounds<Pixels>> {
|
||||
visual.debug_bounds(Box::leak(selector.to_string().into_boxed_str()))
|
||||
}
|
||||
|
||||
fn open(visual: &mut VisualTestContext, dock: &Entity<DockState>, tag: &'static str) {
|
||||
visual.update(|window, cx| {
|
||||
dock.update(cx, |dock, cx| dock.open_panel(tag, window, cx));
|
||||
});
|
||||
visual.update(|window, cx| window.draw(cx).clear(cx));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn the_pill_bar_pads_for_traffic_lights_when_it_leads_the_window() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(false, false, &mut cx);
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, _cx| dock.register_panel(descriptor("overview")));
|
||||
});
|
||||
open(&mut visual, &dock, "overview");
|
||||
|
||||
let bar = bounds(&mut visual, "test-dock-pane-0-bar").expect("pill bar missing");
|
||||
let tab = bounds(&mut visual, "test-dock-pane-0-tabs-tab-overview").expect("tab missing");
|
||||
let bare_inset = tab.left() - bar.left();
|
||||
|
||||
let (dock, mut visual) = dock_window(false, true, &mut cx);
|
||||
let _ = &dock;
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, _cx| dock.register_panel(descriptor("overview")));
|
||||
});
|
||||
open(&mut visual, &dock, "overview");
|
||||
|
||||
let padded_bar = bounds(&mut visual, "test-dock-pane-0-bar").expect("padded bar missing");
|
||||
let padded_tab =
|
||||
bounds(&mut visual, "test-dock-pane-0-tabs-tab-overview").expect("tab missing");
|
||||
let padded_inset = padded_tab.left() - padded_bar.left();
|
||||
|
||||
// The bare bar keeps the standard leading padding; the padded bar clears
|
||||
// the traffic lights.
|
||||
assert!(
|
||||
bare_inset < TRAFFIC_LIGHT_PAD,
|
||||
"the bare bar must not reserve the traffic-light pad (bare {bare_inset:?})"
|
||||
);
|
||||
assert!(
|
||||
padded_inset >= TRAFFIC_LIGHT_PAD - px(1.),
|
||||
"the pad must clear the traffic lights (bare {bare_inset:?}, padded {padded_inset:?})"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn window_controls_render_only_when_the_flag_is_set() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(false, false, &mut cx);
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, _cx| dock.register_panel(descriptor("overview")));
|
||||
});
|
||||
open(&mut visual, &dock, "overview");
|
||||
|
||||
// macOS: the system traffic lights own the controls — nothing renders;
|
||||
// the pad test above covers that mode.
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
assert!(
|
||||
bounds(&mut visual, "window-control-close").is_none(),
|
||||
"controls must not render without the flag"
|
||||
);
|
||||
#[cfg(target_os = "macos")]
|
||||
let _ = (&dock, &mut visual);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
#[test]
|
||||
fn the_flag_hosts_the_platform_controls_in_the_bar() {
|
||||
let mut cx = TestAppContext::single();
|
||||
let (dock, mut visual) = dock_window(true, false, &mut cx);
|
||||
cx.update(|cx| {
|
||||
dock.update(cx, |dock, _cx| dock.register_panel(descriptor("overview")));
|
||||
});
|
||||
open(&mut visual, &dock, "overview");
|
||||
|
||||
// The maximize control exists once; its restore flip follows the
|
||||
// window's maximized state, not a separate control.
|
||||
assert!(bounds(&mut visual, "window-control-close").is_some());
|
||||
assert!(bounds(&mut visual, "window-control-maximize").is_some());
|
||||
}
|
||||
Reference in New Issue
Block a user