refactor: add panel zoom and close toolbar
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
This commit is contained in:
@@ -20,12 +20,22 @@ const WINDOW_HEIGHT: f32 = 768.0;
|
||||
/// A full-size marker the tests measure through its debug selector.
|
||||
struct TagView {
|
||||
selector: SharedString,
|
||||
/// Whether the marker asks for the zoom and close toolbar.
|
||||
toolbar: bool,
|
||||
}
|
||||
|
||||
impl TagView {
|
||||
fn new(selector: &'static str) -> Self {
|
||||
Self {
|
||||
selector: SharedString::from(selector),
|
||||
toolbar: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn with_toolbar(selector: &'static str) -> Self {
|
||||
Self {
|
||||
toolbar: true,
|
||||
..Self::new(selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +53,10 @@ impl Panel for TagView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
self.selector.clone()
|
||||
}
|
||||
|
||||
fn toolbar(&self, _cx: &App) -> bool {
|
||||
self.toolbar
|
||||
}
|
||||
}
|
||||
|
||||
struct PanelHarness {
|
||||
@@ -60,6 +74,11 @@ fn tag(cx: &mut App, selector: &'static str) -> Entity<TagView> {
|
||||
cx.new(|_| TagView::new(selector))
|
||||
}
|
||||
|
||||
/// A marker view that shows the zoom and close toolbar.
|
||||
fn toolbar_tag(cx: &mut App, selector: &'static str) -> Entity<TagView> {
|
||||
cx.new(|_| TagView::with_toolbar(selector))
|
||||
}
|
||||
|
||||
/// Opens the test window over a stack seeded by `seed`.
|
||||
fn stack_window(
|
||||
cx: &mut TestAppContext,
|
||||
@@ -820,3 +839,153 @@ fn a_split_after_a_leading_one_opens_after_the_main_panel(cx: &mut TestAppContex
|
||||
"the split opens after the main panel again"
|
||||
);
|
||||
}
|
||||
|
||||
/// A panel's toolbar zooms it to fill the row and back, and closes it.
|
||||
#[gpui::test]
|
||||
fn the_toolbar_zooms_its_panel_and_closes_it(cx: &mut TestAppContext) {
|
||||
let (mut cx, _stack) = stack_window(cx, |stack, cx| {
|
||||
main_only(stack, cx);
|
||||
stack.insert(
|
||||
PanelSlot::Split,
|
||||
"split",
|
||||
Arc::new(toolbar_tag(cx, "panel-test-split")),
|
||||
cx,
|
||||
);
|
||||
});
|
||||
|
||||
let pane = cx
|
||||
.debug_bounds("panel-test-split")
|
||||
.expect("split panel laid out");
|
||||
let zoom = cx
|
||||
.debug_bounds("panel-harness-zoom-split")
|
||||
.expect("the split pane shows a zoom button");
|
||||
assert!(
|
||||
zoom.right() <= pane.right() && zoom.top() >= pane.top(),
|
||||
"the toolbar sits over the pane's top right: {:?}",
|
||||
zoom
|
||||
);
|
||||
assert!(
|
||||
cx.debug_bounds("panel-harness-zoom-main").is_none(),
|
||||
"a panel without the toolbar shows none"
|
||||
);
|
||||
|
||||
cx.simulate_click(zoom.center(), Modifiers::none());
|
||||
cx.run_until_parked();
|
||||
let zoomed = cx
|
||||
.debug_bounds("panel-test-split")
|
||||
.expect("split panel laid out zoomed");
|
||||
assert!(
|
||||
cx.debug_bounds("panel-test-main").is_none(),
|
||||
"zooming hides the main pane"
|
||||
);
|
||||
assert!(
|
||||
cx.debug_bounds("resize-handle").is_none(),
|
||||
"and the divider"
|
||||
);
|
||||
assert!(zoomed.size.width >= px(WINDOW_WIDTH - 40.0));
|
||||
|
||||
cx.simulate_click(zoom.center(), Modifiers::none());
|
||||
cx.run_until_parked();
|
||||
let restored = cx
|
||||
.debug_bounds("panel-test-split")
|
||||
.expect("split panel laid out restored");
|
||||
assert!(
|
||||
cx.debug_bounds("panel-test-main").is_some(),
|
||||
"unzooming brings the main pane back"
|
||||
);
|
||||
assert!(restored.size.width < px(WINDOW_WIDTH / 2.0));
|
||||
|
||||
let close = cx
|
||||
.debug_bounds("panel-harness-close-split")
|
||||
.expect("the split pane shows a close button");
|
||||
cx.simulate_click(close.center(), Modifiers::none());
|
||||
cx.run_until_parked();
|
||||
assert!(
|
||||
cx.debug_bounds("panel-test-split").is_none(),
|
||||
"close closes the panel"
|
||||
);
|
||||
assert!(
|
||||
cx.debug_bounds("panel-harness-zoom-split").is_none(),
|
||||
"and its toolbar leaves with it"
|
||||
);
|
||||
}
|
||||
|
||||
/// Without a split on screen, the toolbar's buttons do nothing.
|
||||
#[gpui::test]
|
||||
fn toolbar_buttons_do_nothing_without_a_split(cx: &mut TestAppContext) {
|
||||
let (mut cx, stack) = stack_window(cx, |stack, cx| {
|
||||
stack.insert(
|
||||
PanelSlot::Main,
|
||||
"main",
|
||||
Arc::new(toolbar_tag(cx, "panel-test-main")),
|
||||
cx,
|
||||
);
|
||||
});
|
||||
let before = cx
|
||||
.debug_bounds("panel-test-main")
|
||||
.expect("main panel laid out");
|
||||
let zoom = cx
|
||||
.debug_bounds("panel-harness-zoom-main")
|
||||
.expect("the main pane shows a zoom button");
|
||||
let close = cx
|
||||
.debug_bounds("panel-harness-close-main")
|
||||
.expect("the main pane shows a close button");
|
||||
|
||||
cx.simulate_click(zoom.center(), Modifiers::none());
|
||||
cx.simulate_click(close.center(), Modifiers::none());
|
||||
cx.run_until_parked();
|
||||
|
||||
assert_eq!(
|
||||
cx.debug_bounds("panel-test-main")
|
||||
.expect("main panel laid out"),
|
||||
before,
|
||||
"the buttons are disabled without a split"
|
||||
);
|
||||
cx.update(|_, cx| {
|
||||
assert!(
|
||||
stack
|
||||
.read(cx)
|
||||
.is_active(PanelSlot::Main, &SharedString::from("main"))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Zooming belongs to the panel: showing another split panel ends it.
|
||||
#[gpui::test]
|
||||
fn zoom_ends_when_another_split_panel_is_shown(cx: &mut TestAppContext) {
|
||||
let (mut cx, _stack) = stack_window(cx, |stack, cx| {
|
||||
main_only(stack, cx);
|
||||
stack.insert(
|
||||
PanelSlot::Split,
|
||||
"second",
|
||||
Arc::new(tag(cx, "panel-test-second")),
|
||||
cx,
|
||||
);
|
||||
stack.insert(
|
||||
PanelSlot::Split,
|
||||
"first",
|
||||
Arc::new(toolbar_tag(cx, "panel-test-first")),
|
||||
cx,
|
||||
);
|
||||
});
|
||||
let zoom = cx
|
||||
.debug_bounds("panel-harness-zoom-split")
|
||||
.expect("zoom button");
|
||||
cx.simulate_click(zoom.center(), Modifiers::none());
|
||||
cx.run_until_parked();
|
||||
assert!(
|
||||
cx.debug_bounds("panel-test-main").is_none(),
|
||||
"the first panel is zoomed"
|
||||
);
|
||||
|
||||
let second = cx
|
||||
.debug_bounds("panel-harness-split-tabs-tab-panel-test-second")
|
||||
.expect("the second panel's pill tab");
|
||||
cx.simulate_click(second.center(), Modifiers::none());
|
||||
cx.run_until_parked();
|
||||
assert!(cx.debug_bounds("panel-test-second").is_some());
|
||||
assert!(
|
||||
cx.debug_bounds("panel-test-main").is_some(),
|
||||
"the split is back once another panel is shown"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user