Visual Studio Code, rebuilt in Rust
Rust
use std::path::Path;
use std::sync::{Arc, Mutex};
use exthost::scan::scan_extension;
use gpui::{TestAppContext, VisualTestContext};
use serde_json::{Value, json};
use storage::Storage;
use super::*;
use crate::host_sync::HostSync;
use crate::languages::Languages;
use crate::theme::load_theme;
use crate::workbench::problems_view::{MARKERS_CONTAINER_ID, MARKERS_VIEW_ID};
fn open(profile: Arc<Mutex<Storage>>, cx: &mut TestAppContext) -> (gpui::Entity<Workbench>, &mut VisualTestContext) {
let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
let theme = load_theme(&[scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap()], "Dark Modern").unwrap();
let (workbench, cx) = cx.add_window_view(|_, cx| {
let mut workbench = Workbench::new(theme, app_root, None, Languages::new(&[]), crate::default_settings(), HostSync::new(std::sync::mpsc::channel().0), cx);
workbench.restore_profile_state(profile.clone(), profile);
workbench.restore_workspace_state(Arc::new(Mutex::new(Storage::in_memory())));
// An empty window starts without the side bar, where the Explorer's panes are laid out.
workbench.set_part_hidden(Part::SideBar, false, cx);
workbench
});
cx.run_until_parked();
(workbench, cx)
}
fn stored(profile: &Arc<Mutex<Storage>>) -> Value {
serde_json::from_str(profile.lock().unwrap().get(VIEWS_CUSTOMIZATIONS_KEY).unwrap()).unwrap()
}
fn explorer_panes(workbench: &gpui::Entity<Workbench>, cx: &mut VisualTestContext) -> Vec<&'static str> {
workbench.read_with(cx, |workbench, _| workbench.panes(PaneContainer::Explorer).view.as_ref().unwrap().ids().to_vec())
}
#[gpui::test]
fn move_view_lists_only_the_visible_views(cx: &mut TestAppContext) {
let (workbench, cx) = open(Arc::new(Mutex::new(Storage::in_memory())), cx);
// layoutActions.ts lists `visibleViewDescriptors`: Open Editors is hidden by default.
let listed = workbench.read_with(cx, |workbench, _| {
workbench.views_in(EXPLORER_CONTAINER).into_iter().filter(|view| workbench.movable_view_shown(view)).map(|view| view.id).collect::<Vec<_>>()
});
assert!(!listed.contains(&OPEN_EDITORS_VIEW), "{listed:?}");
assert!(listed.contains(&OUTLINE_VIEW), "{listed:?}");
}
#[gpui::test]
fn outline_moved_to_a_new_panel_entry_gets_its_own_tab_and_comes_back_without_a_trace(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
let container = workbench.update(cx, |workbench, cx| {
let container = workbench.move_view_to_location(OUTLINE_VIEW, Part::Panel, cx);
workbench.open_view_container_of(container, OUTLINE_VIEW, cx);
container
});
cx.run_until_parked();
assert!(container.starts_with("workbench.views.service.panel."));
assert_eq!(stored(&profile), json!({ "viewContainerLocations": { container: 1 }, "viewLocations": { OUTLINE_VIEW: container }, "viewContainerBadgeEnablementStates": {} }));
let tabs = workbench.read_with(cx, |workbench, _| workbench.part_tabs(Part::Panel).iter().map(|tab| (tab.id, tab.title)).collect::<Vec<_>>());
assert_eq!(tabs.last(), Some(&(container, "Outline")));
assert!(workbench.read_with(cx, |workbench, _| workbench.is_view_visible(OUTLINE_VIEW)));
assert!(!explorer_panes(&workbench, cx).contains(&OUTLINE_VIEW));
// The panel hides first: left without the generated container it would show the default Terminal, whose shell's
// pty-read thread the test scheduler aborts on.
workbench.update(cx, |workbench, cx| {
workbench.hide_panel(cx);
workbench.move_view_to_container(OUTLINE_VIEW, EXPLORER_CONTAINER, cx);
});
cx.run_until_parked();
assert_eq!(stored(&profile), json!({ "viewContainerLocations": {}, "viewLocations": {}, "viewContainerBadgeEnablementStates": {} }));
assert!(explorer_panes(&workbench, cx).contains(&OUTLINE_VIEW));
assert!(!workbench.read_with(cx, |workbench, _| workbench.part_tabs(Part::Panel).iter().any(|tab| tab.id == container)));
}
#[gpui::test]
fn the_command_palette_takes_focus_from_the_view_so_move_focused_view_is_not_listed(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile, cx);
cx.update(|window, cx| {
workbench.update(cx, |workbench, cx| {
workbench.quick_access.menu = crate::command_palette::menu(&[]);
let focus = workbench.outline_pane.focus.clone();
window.focus(&focus, cx);
drop(workbench.execute_command("workbench.action.showCommands", Vec::new(), window, cx));
})
});
cx.run_until_parked();
let labels = workbench.read_with(cx, |workbench, _| {
let input = workbench.quick_inputs.current().unwrap();
input.rows.iter().map(|row| row.item.label.clone()).collect::<Vec<_>>()
});
assert!(labels.iter().any(|label| label == "View: Move View"), "{labels:?}");
assert!(!labels.iter().any(|label| label == "View: Move Focused View"), "{labels:?}");
}
#[gpui::test]
fn panel_views_move_to_the_secondary_side_bar_and_back(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
let panel_tabs = |workbench: &gpui::Entity<Workbench>, part, cx: &mut VisualTestContext| workbench.read_with(cx, |workbench, _| workbench.part_tabs(part).iter().map(|tab| tab.id).collect::<Vec<_>>());
let in_panel = panel_tabs(&workbench, Part::Panel, cx);
assert!(in_panel.contains(&MARKERS_CONTAINER_ID));
cx.update(|window, cx| {
workbench.update(cx, |workbench, cx| {
workbench.show_view_container(MARKERS_CONTAINER_ID, cx);
drop(workbench.execute_command("workbench.action.movePanelToSecondarySideBar", Vec::new(), window, cx));
})
});
cx.run_until_parked();
assert!(panel_tabs(&workbench, Part::Panel, cx).is_empty());
assert_eq!(panel_tabs(&workbench, Part::AuxiliaryBar, cx), in_panel);
assert!(workbench.read_with(cx, |workbench, _| workbench.is_part_visible(Part::AuxiliaryBar) && !workbench.is_part_visible(Part::Panel)));
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.active_container_in(Part::AuxiliaryBar)), Some(MARKERS_CONTAINER_ID));
// The panel hides in the same update: shown, it would start the default Terminal's shell.
cx.update(|window, cx| {
workbench.update(cx, |workbench, cx| {
drop(workbench.execute_command("workbench.action.moveSecondarySideBarToPanel", Vec::new(), window, cx));
workbench.hide_panel(cx);
})
});
cx.run_until_parked();
assert_eq!(panel_tabs(&workbench, Part::Panel, cx), in_panel);
assert_eq!(stored(&profile)["viewContainerLocations"], json!({}));
}
#[gpui::test]
fn problems_moved_into_the_explorer_leaves_the_panel_and_opens_there(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
workbench.update(cx, |workbench, cx| workbench.move_view_to_container(MARKERS_VIEW_ID, EXPLORER_CONTAINER, cx));
workbench.update(cx, |workbench, cx| workbench.open_panel_view(MARKERS_CONTAINER_ID, cx));
cx.run_until_parked();
assert_eq!(stored(&profile)["viewLocations"], json!({ MARKERS_VIEW_ID: EXPLORER_CONTAINER }));
assert!(!workbench.read_with(cx, |workbench, _| workbench.part_tabs(Part::Panel).iter().any(|tab| tab.id == MARKERS_CONTAINER_ID)));
assert_eq!(explorer_panes(&workbench, cx).last(), Some(&MARKERS_VIEW_ID));
assert!(workbench.read_with(cx, |workbench, _| workbench.side_bar_view == SideBarView::Explorer && workbench.panel_view_visible(MARKERS_CONTAINER_ID)));
}
#[gpui::test]
fn a_view_alone_in_a_new_side_bar_entry_is_not_offered_another_one(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile, cx);
let labels = workbench.update(cx, |workbench, cx| {
let container = workbench.move_view_to_location(TIMELINE_VIEW, Part::SideBar, cx);
let view = workbench.movable_view(TIMELINE_VIEW).unwrap();
workbench.move_destinations(&view, container).into_iter().map(|(separator, label, _)| (separator, label)).collect::<Vec<_>>()
});
assert_eq!(labels[..3], [(None, "New Panel Entry".to_string()), (None, "New Secondary Side Bar Entry".to_string()), (Some("Side Bar"), "Explorer".to_string())]);
assert_eq!(labels[3..6], [(None, "Search".to_string()), (None, "Source Control".to_string()), (None, "Run and Debug".to_string())]);
assert!(labels.contains(&(Some("Panel"), "Problems".to_string())));
assert!(labels.iter().all(|(_, label)| label != "Testing"));
}
#[gpui::test]
fn outline_header_dragged_onto_the_source_control_item_gets_a_new_container_before_it(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
let header = cx.debug_bounds("pane-header-outline").unwrap().center();
let item = cx.debug_bounds(SCM_CONTAINER).unwrap().center();
cx.simulate_mouse_down(header, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(header + gpui::point(gpui::px(10.), gpui::px(0.)), gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(item, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_up(item, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.run_until_parked();
// compositeBar.ts `CompositeDragAndDrop.drop` of a `view` on an item: `moveViewToLocation`, then `moveComposite`.
let container = workbench.read_with(cx, |workbench, _| workbench.view_container(&workbench.movable_view(OUTLINE_VIEW).unwrap()));
assert!(is_generated_container(container), "{container}");
let order: Vec<_> = workbench.read_with(cx, |workbench, _| workbench.activity_bar_containers().into_iter().map(|(id, _)| id).collect());
let scm = order.iter().position(|id| *id == SCM_CONTAINER).unwrap();
assert_eq!(order[scm - 1], container, "{order:?}");
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.side_bar_view), SideBarView::Generated(container));
}
#[gpui::test]
fn search_moved_into_the_explorer_is_one_of_its_panes_and_leaves_the_activity_bar(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
assert!(!workbench.read_with(cx, |workbench, _| workbench.container_hidden_if_empty(SEARCH_CONTAINER)));
workbench.update(cx, |workbench, cx| workbench.move_view_to_container(SEARCH_VIEW, EXPLORER_CONTAINER, cx));
cx.run_until_parked();
assert_eq!(stored(&profile)["viewLocations"], json!({ SEARCH_VIEW: EXPLORER_CONTAINER }));
assert_eq!(explorer_panes(&workbench, cx), [crate::workbench::view_panes::EMPTY_VIEW, OUTLINE_VIEW, TIMELINE_VIEW, SEARCH_VIEW]);
assert!(workbench.read_with(cx, |workbench, _| workbench.container_hidden_if_empty(SEARCH_CONTAINER)));
// Move View's `openView(id, true)`: the moved view opens in the Explorer with its search input focused.
let focused = workbench.update_in(cx, |workbench, window, cx| {
drop(workbench.execute_command("workbench.view.search.focus", Vec::new(), window, cx));
workbench.search.input(crate::workbench::search_view::SearchField::Query).focus.is_focused(window)
});
assert!(focused);
}
#[gpui::test]
fn breakpoints_and_the_empty_folder_view_move_out_of_their_containers(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile, cx);
workbench.update(cx, |workbench, cx| {
workbench.move_view_to_container(crate::workbench::view_panes::EMPTY_VIEW, SCM_CONTAINER, cx);
workbench.move_view_to_container(BREAKPOINTS_VIEW, EXPLORER_CONTAINER, cx);
});
cx.run_until_parked();
assert_eq!(explorer_panes(&workbench, cx), [OUTLINE_VIEW, TIMELINE_VIEW]);
let scm = workbench.read_with(cx, |workbench, _| workbench.panes(PaneContainer::Scm).view.as_ref().unwrap().ids().to_vec());
assert!(scm.contains(&crate::workbench::view_panes::EMPTY_VIEW));
assert!(workbench.read_with(cx, |workbench, _| workbench.views_in(EXPLORER_CONTAINER).iter().any(|view| view.id == BREAKPOINTS_VIEW)));
}
#[gpui::test]
fn outline_moved_into_problems_lies_beside_it_in_the_bottom_panel(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile, cx);
workbench.update(cx, |workbench, cx| {
workbench.move_view_to_container(OUTLINE_VIEW, MARKERS_CONTAINER_ID, cx);
workbench.open_view_container_of(MARKERS_CONTAINER_ID, OUTLINE_VIEW, cx);
});
cx.run_until_parked();
let (ids, horizontal) = workbench.read_with(cx, |workbench, _| {
let view = workbench.panes(PaneContainer::Generated(MARKERS_CONTAINER_ID)).view.as_ref().unwrap();
(view.ids().to_vec(), view.is_horizontal())
});
// viewContainerModel.ts `compareViewDescriptors`: Outline's `order` 2 before Problems' none.
assert_eq!(ids, [OUTLINE_VIEW, MARKERS_VIEW_ID]);
assert!(horizontal);
workbench.update(cx, |workbench, cx| workbench.hide_panel(cx));
}
#[gpui::test]
fn a_moved_view_is_hidden_by_the_state_of_the_container_it_is_in(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
let shown = |workbench: &gpui::Entity<Workbench>, cx: &mut VisualTestContext| workbench.read_with(cx, |workbench, _| workbench.movable_view_shown(&workbench.movable_view(OUTLINE_VIEW).unwrap()));
workbench.update(cx, |workbench, cx| {
workbench.toggle_view_visibility("explorer", OUTLINE_VIEW, cx);
workbench.move_view_to_container(OUTLINE_VIEW, SCM_CONTAINER, cx);
});
// viewContainerModel.ts `add`: Source Control has no state for Outline, which is not `hideByDefault`.
assert!(shown(&workbench, cx));
workbench.update(cx, |workbench, cx| workbench.toggle_view_visibility("scm", OUTLINE_VIEW, cx));
assert!(!shown(&workbench, cx));
workbench.update(cx, |workbench, cx| {
workbench.move_view_to_container(OUTLINE_VIEW, MARKERS_CONTAINER_ID, cx);
workbench.toggle_view_visibility(pane_container(MARKERS_CONTAINER_ID).key(), OUTLINE_VIEW, cx);
});
assert!(!shown(&workbench, cx));
assert!(profile.lock().unwrap().get("workbench.panel.markers.hidden").is_some());
}
#[gpui::test]
fn a_header_dropped_on_another_container_takes_the_drop_position(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile, cx);
workbench.update(cx, |workbench, cx| workbench.move_view_to_container(MARKERS_VIEW_ID, EXPLORER_CONTAINER, cx));
cx.run_until_parked();
assert_eq!(explorer_panes(&workbench, cx), [crate::workbench::view_panes::EMPTY_VIEW, OUTLINE_VIEW, TIMELINE_VIEW, MARKERS_VIEW_ID]);
let container = workbench.update(cx, |workbench, cx| workbench.move_view_to_location(OUTLINE_VIEW, Part::SideBar, cx));
cx.run_until_parked();
workbench.update(cx, |workbench, cx| workbench.drop_pane_from_container(OUTLINE_VIEW, PaneContainer::Explorer, MARKERS_VIEW_ID, false, cx));
cx.run_until_parked();
assert_eq!(explorer_panes(&workbench, cx), [crate::workbench::view_panes::EMPTY_VIEW, TIMELINE_VIEW, OUTLINE_VIEW, MARKERS_VIEW_ID]);
assert!(workbench.read_with(cx, |workbench, _| workbench.generated_containers().is_empty() && !workbench.generated_panes.contains_key(container)));
}
#[gpui::test]
fn a_container_moves_between_the_side_bar_and_the_panel_and_keeps_its_location_on_restart(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, window_cx) = open(profile.clone(), cx);
workbench.update_in(window_cx, |workbench, window, cx| {
workbench.move_view_container(EXPLORER_CONTAINER, Part::Panel, window, cx);
workbench.move_view_container(crate::workbench::output_view::OUTPUT_VIEW_ID, Part::SideBar, window, cx);
});
window_cx.run_until_parked();
assert_eq!(stored(&profile)["viewContainerLocations"], json!({ EXPLORER_CONTAINER: 1, "workbench.panel.output": 0 }));
workbench.read_with(window_cx, |workbench, _| {
assert!(workbench.part_tabs(Part::Panel).iter().any(|tab| tab.id == EXPLORER_CONTAINER));
assert!(!workbench.part_tabs(Part::Panel).iter().any(|tab| tab.id == crate::workbench::output_view::OUTPUT_VIEW_ID));
assert_eq!(workbench.side_bar_view, SideBarView::Generated(crate::workbench::output_view::OUTPUT_VIEW_ID));
});
let (restarted, window_cx) = open(profile.clone(), cx);
restarted.read_with(window_cx, |workbench, _| {
assert_eq!(workbench.container_location(EXPLORER_CONTAINER), Part::Panel);
assert_eq!(workbench.containers_in(Part::SideBar).last(), Some(&crate::workbench::output_view::OUTPUT_VIEW_ID));
});
restarted.update_in(window_cx, |workbench, window, cx| workbench.move_view_container(EXPLORER_CONTAINER, Part::SideBar, window, cx));
assert_eq!(stored(&profile)["viewContainerLocations"], json!({ "workbench.panel.output": 0 }));
}
/// The open context menu's root: each command's title and id, and a submenu as "{title} >" with its titles.
fn context_menu(workbench: &gpui::Entity<Workbench>, cx: &mut VisualTestContext) -> (Vec<(String, String)>, Vec<Value>) {
workbench.read_with(cx, |workbench, _| {
let menu = workbench.context_menu.as_ref().expect("a context menu shows");
let items = menu.levels[0].actions.iter().map(|action| match action {
crate::menus::MenuAction::Command { id, title, .. } => (title.clone(), id.clone()),
crate::menus::MenuAction::Submenu { title, actions, .. } => {
let titles: Vec<_> = actions.iter().map(|action| match action {
crate::menus::MenuAction::Command { title, .. } => title.clone(),
_ => "---".into(),
}).collect();
(format!("{title} >"), titles.join(", "))
}
crate::menus::MenuAction::Separator => ("---".into(), String::new()),
});
(items.collect(), menu.args.clone())
})
}
fn right_click(selector: &'static str, cx: &mut VisualTestContext) {
cx.update(|window, cx| drop(window.draw(cx)));
let point = cx.debug_bounds(selector).unwrap().center();
cx.simulate_mouse_down(point, gpui::MouseButton::Right, gpui::Modifiers::none());
cx.simulate_mouse_up(point, gpui::MouseButton::Right, gpui::Modifiers::none());
cx.run_until_parked();
}
/// Runs the open menu's item `title` with the menu's arguments, as a click on it does.
fn run_menu_item(workbench: &gpui::Entity<Workbench>, items: &[(String, String)], args: Vec<Value>, title: &str, cx: &mut VisualTestContext) {
let id = items.iter().find(|(item, _)| item == title).unwrap_or_else(|| panic!("{title} in {items:?}")).1.clone();
cx.simulate_keystrokes("escape");
workbench.update_in(cx, |workbench, window, cx| drop(workbench.execute_command(&id, args, window, cx)));
cx.run_until_parked();
}
/// paneCompositeBar.ts `getContextMenuActionsForComposite`: an item's Move To lists the other locations, and Reset
/// Location shows once its container left the default one.
#[gpui::test]
fn the_explorer_item_menu_moves_it_to_the_panel_and_its_tab_menu_resets_it(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
right_click(EXPLORER_CONTAINER, cx);
let (items, args) = context_menu(&workbench, cx);
assert_eq!(items[4], ("Move To >".to_string(), "Secondary Side Bar, Panel".to_string()));
assert_eq!(items[5].0, "---", "no Reset Location at the default location, then the activity bar's menu");
assert_eq!(args, [json!(EXPLORER_CONTAINER)]);
let move_to_panel = format!("moveViewContainerTo{}", location_code(Part::Panel));
cx.simulate_keystrokes("escape");
workbench.update_in(cx, |workbench, window, cx| drop(workbench.execute_command(&move_to_panel, args, window, cx)));
cx.run_until_parked();
assert_eq!(stored(&profile)["viewContainerLocations"], json!({ EXPLORER_CONTAINER: 1 }));
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.active_container_in(Part::Panel)), Some(EXPLORER_CONTAINER));
right_click("active-composite-tab", cx);
let (items, args) = context_menu(&workbench, cx);
assert_eq!(items[4..7], [("Move To >".to_string(), "Primary Side Bar, Secondary Side Bar".to_string()), ("Reset Location".to_string(), "resetLocationAction".to_string()), ("---".to_string(), String::new())]);
workbench.update(cx, |workbench, cx| workbench.hide_panel(cx));
run_menu_item(&workbench, &items, args, "Reset Location", cx);
assert_eq!(stored(&profile)["viewContainerLocations"], json!({}));
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.side_bar_view), SideBarView::Explorer);
}
/// compositeBarActions.ts `showContextMenu`: an item's menu opens with Configure Keybinding, Hide '{name}' and Hide
/// Badge, which unpin the item and turn its badges off (`viewContainerBadgeEnablementStates`). A panel tab's menu
/// ends with its bar's: the tabs checked while pinned, then panelPart.ts `fillExtraContextMenuActions`.
#[gpui::test]
fn an_item_menu_hides_the_item_and_its_badge_and_a_tab_menu_ends_with_the_panels(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
right_click(EXPLORER_CONTAINER, cx);
let (items, args) = context_menu(&workbench, cx);
let item = |title: &str, id: &str| (title.to_string(), id.to_string());
let head = [item("Configure Keybinding", "configureKeybinding/workbench.view.explorer"), item("Hide 'Explorer'", "show.toggleCompositePinned"), item("Hide Badge", "show.toggleCompositeBadge")];
assert_eq!(items[..3], head);
// paneCompositeBar.ts `getContextMenuActionsForComposite` opens with a separator.
assert_eq!(items[3..5].iter().map(|(title, _)| title.as_str()).collect::<Vec<_>>(), ["---", "Move To >"]);
run_menu_item(&workbench, &items, args.clone(), "Hide Badge", cx);
assert_eq!(stored(&profile)["viewContainerBadgeEnablementStates"], json!({ EXPLORER_CONTAINER: false }));
right_click(EXPLORER_CONTAINER, cx);
assert_eq!(context_menu(&workbench, cx).0[2], item("Show Badge", "show.toggleCompositeBadge"));
run_menu_item(&workbench, &items, args, "Hide 'Explorer'", cx);
cx.update(|window, cx| drop(window.draw(cx)));
assert!(cx.debug_bounds(EXPLORER_CONTAINER).is_none(), "a hidden item leaves the activity bar");
workbench.update(cx, |workbench, cx| workbench.open_panel_view(MARKERS_CONTAINER_ID, cx));
right_click("active-composite-tab", cx);
let (items, args) = context_menu(&workbench, cx);
assert_eq!(items[..3], [item("Configure Keybinding", "configureKeybinding/workbench.actions.view.problems"), item("Hide 'Problems'", "show.toggleCompositePinned"), item("Hide Badge", "show.toggleCompositeBadge")]);
let tail: Vec<_> = items[items.len() - 5..].iter().map(|(title, _)| title.as_str()).collect();
assert_eq!(tail, ["---", "Panel Position >", "Align Panel >", "Show Icons", "Hide Panel"]);
run_menu_item(&workbench, &items, args, "Output", cx);
assert!(!workbench.read_with(cx, |workbench, _| workbench.part_tabs(Part::Panel).iter().any(|tab| tab.id == crate::workbench::output_view::OUTPUT_VIEW_ID)), "an unpinned tab leaves the panel");
}
fn drag(from: gpui::Point<gpui::Pixels>, to: gpui::Point<gpui::Pixels>, cx: &mut VisualTestContext) {
cx.simulate_mouse_down(from, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(from + gpui::point(gpui::px(10.), gpui::px(0.)), gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(to, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_up(to, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.run_until_parked();
}
/// compositeBar.ts `CompositeDragAndDrop.drop` of a `composite`: an activity item dropped on the secondary side bar
/// moves its container there, and that bar's tab dropped on the activity bar moves it back.
#[gpui::test]
fn the_explorer_item_drags_to_the_secondary_side_bar_and_its_tab_back_to_the_activity_bar(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
workbench.update(cx, |workbench, cx| workbench.set_part_hidden(Part::AuxiliaryBar, false, cx));
cx.update(|window, cx| drop(window.draw(cx)));
let item = cx.debug_bounds(EXPLORER_CONTAINER).unwrap().center();
let title = cx.debug_bounds("pane-composite-title").unwrap().center();
drag(item, title, cx);
assert_eq!(stored(&profile)["viewContainerLocations"], json!({ EXPLORER_CONTAINER: 2 }));
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.active_container_in(Part::AuxiliaryBar)), Some(EXPLORER_CONTAINER));
cx.update(|window, cx| drop(window.draw(cx)));
let tab = cx.debug_bounds("active-composite-tab").unwrap().center();
let search = cx.debug_bounds(SEARCH_CONTAINER).unwrap().center();
drag(tab, search, cx);
assert_eq!(stored(&profile)["viewContainerLocations"], json!({}));
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.side_bar_view), SideBarView::Explorer);
}
/// compositeBar.ts `CompositeDragAndDrop.drop`: an item dropped on a tab's first half lands before it and opens
/// focused; an item dropped on its own bar's item moves there and stays there on restart.
#[gpui::test]
fn a_dropped_composite_takes_the_drop_index_and_reorders_its_own_bar(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, window_cx) = open(profile.clone(), cx);
workbench.update(window_cx, |workbench, cx| workbench.open_panel_view(MARKERS_CONTAINER_ID, cx));
window_cx.update(|window, cx| drop(window.draw(cx)));
let output = workbench.read_with(window_cx, |workbench, cx| workbench.drawn_action_bar_item_bounds("panel-composite-bar", crate::workbench::output_view::OUTPUT_VIEW_ID, cx));
let item = window_cx.debug_bounds(SEARCH_CONTAINER).unwrap().center();
drag(item, output.left_center() + gpui::point(gpui::px(3.), gpui::px(0.)), window_cx);
let tabs: Vec<_> = workbench.read_with(window_cx, |workbench, _| workbench.part_tabs(Part::Panel).iter().map(|tab| tab.id).collect());
let search = tabs.iter().position(|id| *id == SEARCH_CONTAINER).unwrap();
assert_eq!(tabs[search + 1], crate::workbench::output_view::OUTPUT_VIEW_ID, "{tabs:?}");
assert_eq!(window_cx.update(|window, cx| workbench.read(cx).focused_part(window, cx)), Some(crate::workbench::part_navigation::FocusPart::Panel));
window_cx.update(|window, cx| drop(window.draw(cx)));
let explorer = window_cx.debug_bounds(EXPLORER_CONTAINER).unwrap();
let scm = window_cx.debug_bounds(SCM_CONTAINER).unwrap();
drag(scm.center(), explorer.center() - gpui::point(gpui::px(0.), gpui::px(5.)), window_cx);
let bar: Vec<_> = workbench.read_with(window_cx, |workbench, _| workbench.activity_bar_containers().into_iter().map(|(id, _)| id).collect());
assert_eq!(bar[..2], [SCM_CONTAINER, EXPLORER_CONTAINER]);
let (restarted, window_cx) = open(profile, cx);
assert_eq!(restarted.read_with(window_cx, |workbench, _| workbench.activity_bar_containers()[0].0), SCM_CONTAINER);
}
/// A browser fires no mouse events during a drag and drop, so the item under the pointer shows no hover after the
/// drop until the pointer moves.
#[gpui::test]
fn a_composite_drop_leaves_no_hover_under_the_pointer(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile, cx);
workbench.update(cx, |workbench, cx| workbench.open_panel_view(MARKERS_CONTAINER_ID, cx));
cx.update(|window, cx| drop(window.draw(cx)));
let output = workbench.read_with(cx, |workbench, cx| workbench.drawn_action_bar_item_bounds("panel-composite-bar", crate::workbench::output_view::OUTPUT_VIEW_ID, cx));
let item = cx.debug_bounds(SEARCH_CONTAINER).unwrap().center();
drag(item, output.center(), cx);
cx.executor().advance_clock(std::time::Duration::from_millis(1500));
cx.run_until_parked();
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.hovers.shown_text().map(str::to_owned)), None);
}
/// compositeBarActions.ts `updateActivity`: a container moved to the panel shows its `ProgressBadge` on its tab.
#[gpui::test]
fn a_moved_container_tab_shows_its_progress_badge(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile, cx);
let extensions = crate::workbench::extensions_view::VIEWLET_ID;
workbench.update_in(cx, |workbench, window, cx| {
drop(workbench.execute_command(&format!("moveViewContainerTo{}", location_code(Part::Panel)), vec![json!(extensions)], window, cx));
workbench.start_activity_progress(1, &json!(5), None, None, window, cx);
});
cx.executor().advance_clock(std::time::Duration::from_millis(400));
cx.run_until_parked();
cx.update(|window, cx| drop(window.draw(cx)));
assert_eq!(cx.debug_bounds("panel-tab-status-badge").map(|bounds| bounds.size), Some(gpui::size(gpui::px(16.), gpui::px(16.))));
}
/// An activity item drags as the browser's image of its element: its icon, not its title.
#[gpui::test]
fn an_activity_item_drags_as_its_icon(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile, cx);
cx.update(|window, cx| drop(window.draw(cx)));
let item = cx.debug_bounds(EXPLORER_CONTAINER).unwrap().center();
cx.simulate_mouse_down(item, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(item + gpui::point(gpui::px(10.), gpui::px(0.)), gpui::MouseButton::Left, gpui::Modifiers::none());
cx.update(|window, cx| drop(window.draw(cx)));
assert_eq!(cx.debug_bounds("dragged-composite-icon").map(|bounds| bounds.size), Some(gpui::size(gpui::px(36.), gpui::px(36.))));
let icon = workbench.read_with(cx, |workbench, _| workbench.codicon_svg("explorer-view-icon"));
assert!(Path::new(icon.as_ref()).exists(), "{icon} is the registered icon's codicon");
}
/// paneCompositePart.ts: with `workbench.activityBar.location` `top`, the side bar's compact composite bar is the
/// activity bar's `PaneCompositeBar`: its tabs have the item menu and drag, reordering along the bar.
#[gpui::test]
fn the_compact_activity_bar_tabs_have_the_item_menu_and_drag(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile, cx);
let dir = std::env::temp_dir().join(format!("vsrustium-{}-{}", crate::test_name(), std::process::id()));
let user = dir.join("User");
workbench.update(cx, |workbench, cx| {
workbench.settings = Arc::new(Mutex::new(config::service::Settings::load(config::registry::Registry::with_extensions(&[]), user, None)));
workbench.update_setting("workbench.activityBar.location", json!("top"));
cx.notify();
});
right_click(SEARCH_CONTAINER, cx);
assert_eq!(cx.debug_bounds(SEARCH_CONTAINER).unwrap().size.height, gpui::px(32.), "the compact bar's tab");
let (items, _) = context_menu(&workbench, cx);
assert!(items.iter().any(|(title, _)| title == "Hide 'Search'"), "{items:?}");
workbench.update_in(cx, |workbench, window, cx| workbench.hide_context_menu(window, cx));
let focused = cx.update(|window, cx| {
window.focus(&workbench.read(cx).action_bar_focus(crate::workbench::side_bar::COMPACT_ACTIVITY_BAR, SEARCH_CONTAINER, cx), cx);
workbench.read(cx).focused_part(window, cx)
});
assert_eq!(focused, Some(crate::workbench::part_navigation::FocusPart::SideBar));
cx.update(|window, cx| drop(window.draw(cx)));
let explorer = cx.debug_bounds(EXPLORER_CONTAINER).unwrap();
let search = cx.debug_bounds(SEARCH_CONTAINER).unwrap();
// The reference's DOM (ui-pair bugs/top-activity-icons.json): 36x32 items without a gap (tabs.css `gap: 0`), the
// 16px icon 10px in and 8px down.
assert_eq!((explorer.size, search.origin - explorer.origin), (gpui::size(gpui::px(36.), gpui::px(32.)), gpui::point(gpui::px(36.), gpui::px(0.))));
let icon_center = cx.debug_bounds("codicon-explorer-view-icon").unwrap().center();
assert_eq!(icon_center - explorer.origin, gpui::point(gpui::px(18.), gpui::px(16.)), "the 16px icon's center");
drag(search.center(), explorer.left_center() + gpui::point(gpui::px(3.), gpui::px(0.)), cx);
let bar: Vec<_> = workbench.read_with(cx, |workbench, _| workbench.activity_bar_containers().into_iter().map(|(id, _)| id).collect());
assert_eq!(bar[..2], [SEARCH_CONTAINER, EXPLORER_CONTAINER]);
let _ = std::fs::remove_dir_all(dir);
}
/// extensions.contribution.ts and testing.contribution.ts register their containers without a fixed location: Move
/// To takes them to the panel and the secondary side bar, where their open commands show them.
#[gpui::test]
fn the_extensions_and_testing_containers_move_to_the_panel_and_the_secondary_side_bar(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
let extensions = crate::workbench::extensions_view::VIEWLET_ID;
workbench.update(cx, |workbench, cx| {
workbench.testing.controllers.insert("port".into(), crate::workbench::testing_service::Controller { label: "Port".into(), capabilities: 0 });
cx.notify();
});
cx.update(|window, cx| drop(window.draw(cx)));
assert!(cx.debug_bounds("workbench.view.testing").is_some(), "a test controller shows the Testing item");
workbench.update_in(cx, |workbench, window, cx| {
drop(workbench.execute_command(extensions, Vec::new(), window, cx));
drop(workbench.execute_command(&format!("moveViewContainerTo{}", location_code(Part::Panel)), vec![json!(extensions)], window, cx));
drop(workbench.execute_command(&format!("moveViewContainerTo{}", location_code(Part::AuxiliaryBar)), vec![json!("workbench.view.testing")], window, cx));
});
cx.run_until_parked();
assert_eq!(stored(&profile)["viewContainerLocations"], json!({ extensions: 1, TESTING_CONTAINER: 2 }));
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.side_bar_view), SideBarView::Explorer, "the side bar leaves the moved Extensions");
cx.update(|window, cx| drop(window.draw(cx)));
assert!(cx.debug_bounds(extensions).is_none(), "the Extensions item leaves the activity bar");
assert!(cx.debug_bounds("workbench.view.testing").is_none(), "the Testing item leaves the activity bar");
assert!(cx.debug_bounds("testing-tree").is_some(), "the secondary side bar shows the Test Explorer");
workbench.update_in(cx, |workbench, window, cx| {
workbench.hide_panel(cx);
drop(workbench.execute_command(extensions, Vec::new(), window, cx));
});
cx.run_until_parked();
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.active_panel_id()), Some(extensions));
cx.update(|window, cx| drop(window.draw(cx)));
assert!(cx.debug_bounds("extensions-panes").is_some(), "the panel shows the Extensions views");
workbench.update_in(cx, |workbench, window, cx| {
drop(workbench.execute_command("resetLocationAction", vec![json!(extensions)], window, cx));
drop(workbench.execute_command("resetLocationAction", vec![json!("workbench.view.testing")], window, cx));
});
cx.run_until_parked();
assert_eq!(stored(&profile)["viewContainerLocations"], json!({}));
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.side_bar_view), SideBarView::Testing);
}
#[gpui::test]
fn a_view_dropped_on_a_bar_item_gets_a_new_container_at_the_drop_position(cx: &mut TestAppContext) {
let (workbench, cx) = open(Arc::new(Mutex::new(Storage::in_memory())), cx);
workbench.update(cx, |workbench, cx| workbench.drop_view_on_location(OUTLINE_VIEW, Part::SideBar, Some((SEARCH_CONTAINER, false)), cx));
cx.run_until_parked();
workbench.read_with(cx, |workbench, _| {
let container = workbench.view_container(&workbench.movable_view(OUTLINE_VIEW).unwrap());
assert!(is_generated_container(container), "{container}");
let order: Vec<_> = workbench.activity_bar_containers().into_iter().map(|(id, _)| id).collect();
let search = order.iter().position(|id| *id == SEARCH_CONTAINER).unwrap();
assert_eq!(order.get(search + 1), Some(&container), "{order:?}");
assert_eq!(workbench.side_bar_view, SideBarView::Generated(container));
});
}
#[gpui::test]
fn a_container_dropped_on_a_pane_merges_its_views_beside_it(cx: &mut TestAppContext) {
let profile = Arc::new(Mutex::new(Storage::in_memory()));
let (workbench, cx) = open(profile.clone(), cx);
workbench.read_with(cx, |workbench, _| {
assert!(!workbench.can_merge_container(EXPLORER_CONTAINER, EXPLORER_CONTAINER));
assert!(!workbench.can_merge_container(MARKERS_CONTAINER_ID, crate::workbench::extensions_view::VIEWLET_ID));
assert!(!workbench.can_merge_container(crate::workbench::extensions_view::VIEWLET_ID, EXPLORER_CONTAINER));
});
let target = crate::workbench::view_panes::EMPTY_VIEW;
workbench.update(cx, |workbench, cx| workbench.merge_container_into(MARKERS_CONTAINER_ID, PaneContainer::Explorer, Some((target, true)), cx));
cx.run_until_parked();
assert_eq!(explorer_panes(&workbench, cx), [target, MARKERS_VIEW_ID, OUTLINE_VIEW, TIMELINE_VIEW]);
assert_eq!(stored(&profile)["viewLocations"], json!({ MARKERS_VIEW_ID: EXPLORER_CONTAINER }));
assert!(workbench.read_with(cx, |workbench, _| !workbench.part_tabs(Part::Panel).iter().any(|tab| tab.id == MARKERS_CONTAINER_ID)));
}
#[gpui::test]
fn a_header_dropped_on_a_panel_view_shown_alone_moves_into_its_container(cx: &mut TestAppContext) {
let (workbench, cx) = open(Arc::new(Mutex::new(Storage::in_memory())), cx);
let output = crate::workbench::output_view::OUTPUT_VIEW_ID;
workbench.update(cx, |workbench, cx| workbench.drop_pane_from_container(OUTLINE_VIEW, pane_container(output), output, false, cx));
cx.run_until_parked();
assert!(workbench.read_with(cx, |workbench, _| workbench.view_container(&workbench.movable_view(OUTLINE_VIEW).unwrap()) == output));
workbench.update(cx, |workbench, cx| workbench.show_view_container(output, cx));
cx.update(|window, cx| drop(window.draw(cx)));
let panes = workbench.read_with(cx, |workbench, _| workbench.panes(pane_container(output)).view.as_ref().unwrap().ids().to_vec());
assert_eq!(panes.first(), Some(&OUTLINE_VIEW), "dropped on the view's first half: {panes:?}");
}
#[gpui::test]
fn a_container_dropped_on_a_pane_puts_its_first_active_view_there(cx: &mut TestAppContext) {
let (workbench, cx) = open(Arc::new(Mutex::new(Storage::in_memory())), cx);
let output = crate::workbench::output_view::OUTPUT_VIEW_ID;
// Without a repository the hidden Repositories view is inactive (`scm.providerCount`), so Changes is the anchor.
workbench.update(cx, |workbench, cx| workbench.merge_container_into(SCM_CONTAINER, pane_container(output), Some((output, false)), cx));
workbench.update(cx, |workbench, cx| workbench.show_view_container(output, cx));
cx.update(|window, cx| drop(window.draw(cx)));
let panes = workbench.read_with(cx, |workbench, _| workbench.panes(pane_container(output)).view.as_ref().unwrap().ids().to_vec());
assert_eq!(panes, [crate::workbench::view_panes::SCM_CHANGES_VIEW, output]);
// viewPane.ts `calculateTitle`: the moved view's header names its default container.
let titles = workbench.read_with(cx, |workbench, _| [workbench.moved_view_title(crate::workbench::view_panes::SCM_CHANGES_VIEW, "Changes".into()), workbench.moved_view_title(output, "Output".into())]);
assert_eq!(titles, ["Source Control: Changes", "Output"]);
// paneview.css `.actions { display: none }`: the Output actions leave the title its room until hovered.
let actions = format!("pane-actions-{output}").leak();
assert!(cx.debug_bounds(actions).is_none());
let header = cx.debug_bounds(format!("pane-header-{output}").leak()).unwrap().center();
cx.simulate_mouse_move(header, None, gpui::Modifiers::none());
assert!(cx.debug_bounds(actions).is_some());
}
#[gpui::test]
fn a_pane_drop_overlay_goes_when_the_drag_leaves_the_pane(cx: &mut TestAppContext) {
let (workbench, cx) = open(Arc::new(Mutex::new(Storage::in_memory())), cx);
let header = cx.debug_bounds("pane-header-outline").unwrap().center();
let timeline = cx.debug_bounds("pane-header-timeline").unwrap().center();
cx.simulate_mouse_down(header, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(header + gpui::point(gpui::px(10.), gpui::px(0.)), gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(timeline, gpui::MouseButton::Left, gpui::Modifiers::none());
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.panes(PaneContainer::Explorer).drop.map(|(id, _)| id)), Some(TIMELINE_VIEW));
cx.simulate_mouse_move(gpui::point(gpui::px(600.), timeline.y), gpui::MouseButton::Left, gpui::Modifiers::none());
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.panes(PaneContainer::Explorer).drop), None);
cx.simulate_mouse_up(gpui::point(gpui::px(600.), timeline.y), gpui::MouseButton::Left, gpui::Modifiers::none());
}
#[gpui::test]
fn the_active_side_bar_container_is_restored_while_it_stays_in_the_side_bar(cx: &mut TestAppContext) {
let (workbench, cx) = open(Arc::new(Mutex::new(Storage::in_memory())), cx);
workbench.update(cx, |workbench, cx| workbench.drop_view_on_location(OUTLINE_VIEW, Part::SideBar, None, cx));
cx.run_until_parked();
let restart = |workbench: &mut Workbench| {
workbench.store_active_side_bar_container();
workbench.side_bar_view = SideBarView::Search;
workbench.restore_workspace_state(workbench.workspace_storage.clone());
workbench.side_bar_view
};
let container = workbench.read_with(cx, |workbench, _| workbench.view_container(&workbench.movable_view(OUTLINE_VIEW).unwrap()));
assert_eq!(workbench.update(cx, |workbench, _| restart(workbench)), SideBarView::Generated(container));
workbench.update_in(cx, |workbench, window, cx| workbench.drop_composite(container, Part::Panel, None, window, cx));
let restored = workbench.update(cx, |workbench, _| {
workbench.restore_workspace_state(workbench.workspace_storage.clone());
workbench.side_bar_view
});
assert_eq!(restored, SideBarView::Explorer);
assert!(workbench.read_with(cx, |workbench, _| workbench.workspace_storage.lock().unwrap().get(ACTIVE_VIEWLET_KEY).is_some()));
}
/// auxiliaryBarPart.ts `resolveConfiguration`: with the activity bar on top the secondary side bar cannot show labels,
/// so its composite bar is a header of 36x32 icon items over a title row without Hide Secondary Side Bar.
#[gpui::test]
fn the_secondary_side_bar_shows_icons_over_a_title_with_the_activity_bar_on_top(cx: &mut TestAppContext) {
let (workbench, cx) = open(Arc::new(Mutex::new(Storage::in_memory())), cx);
let dir = std::env::temp_dir().join(format!("vsrustium-{}-{}", crate::test_name(), std::process::id()));
workbench.update_in(cx, |workbench, window, cx| {
workbench.settings = Arc::new(Mutex::new(config::service::Settings::load(config::registry::Registry::with_extensions(&[]), dir.join("User"), None)));
workbench.update_setting("workbench.activityBar.location", json!("top"));
workbench.drop_composite(MARKERS_CONTAINER_ID, Part::AuxiliaryBar, None, window, cx);
workbench.set_part_hidden(Part::AuxiliaryBar, false, cx);
});
cx.update(|window, cx| drop(window.draw(cx)));
cx.update(|window, cx| drop(window.draw(cx)));
let tab = cx.debug_bounds(MARKERS_CONTAINER_ID).unwrap();
assert_eq!(tab.size, gpui::size(gpui::px(36.), gpui::px(32.)));
assert_eq!(cx.debug_bounds("pane-composite-title").unwrap().origin.y, tab.bottom(), "the title row under the icons");
assert!(cx.debug_bounds("workbench.action.toggleMaximizedAuxiliaryBar").is_some());
assert!(cx.debug_bounds("workbench.action.closeAuxiliaryBar").is_none(), "Hide shows only with the default location");
}
/// compositeBarActions.ts `DelayedDragHandler`: a header held over an unchecked activity item for 800ms opens it.
#[gpui::test]
fn a_header_held_over_an_activity_item_opens_it_after_800ms(cx: &mut TestAppContext) {
let (workbench, cx) = open(Arc::new(Mutex::new(Storage::in_memory())), cx);
let header = cx.debug_bounds("pane-header-outline").unwrap().center();
let item = cx.debug_bounds(SCM_CONTAINER).unwrap().center();
cx.simulate_mouse_down(header, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(header + gpui::point(gpui::px(10.), gpui::px(0.)), gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(item, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.executor().advance_clock(std::time::Duration::from_millis(700));
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.side_bar_view), SideBarView::Explorer);
cx.executor().advance_clock(std::time::Duration::from_millis(100));
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.side_bar_view), SideBarView::Scm);
cx.simulate_mouse_up(item, gpui::MouseButton::Left, gpui::Modifiers::none());
}
#[gpui::test]
fn a_composite_dropped_where_it_already_is_still_opens(cx: &mut TestAppContext) {
let (workbench, cx) = open(Arc::new(Mutex::new(Storage::in_memory())), cx);
workbench.update_in(cx, |workbench, window, cx| {
workbench.side_bar_view = SideBarView::Scm;
workbench.drop_composite(SEARCH_CONTAINER, Part::SideBar, Some((SCM_CONTAINER, true)), window, cx);
});
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.side_bar_view), SideBarView::Search);
}
#[gpui::test]
fn a_header_dragged_over_a_bar_item_shows_the_insert_line_on_its_side(cx: &mut TestAppContext) {
let (_workbench, cx) = open(Arc::new(Mutex::new(Storage::in_memory())), cx);
let header = cx.debug_bounds("pane-header-outline").unwrap().center();
let item = cx.debug_bounds(SCM_CONTAINER).unwrap();
let quarter = item.size.height / 4.;
cx.simulate_mouse_down(header, gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(header + gpui::point(gpui::px(10.), gpui::px(0.)), gpui::MouseButton::Left, gpui::Modifiers::none());
cx.simulate_mouse_move(item.center() - gpui::point(gpui::px(0.), quarter), gpui::MouseButton::Left, gpui::Modifiers::none());
let before = cx.debug_bounds("bar-insert-before").expect("the line above SCM");
assert_eq!((before.size.width, before.size.height, before.top()), (item.size.width, gpui::px(2.), item.top()));
cx.simulate_mouse_move(item.center() + gpui::point(gpui::px(0.), quarter), gpui::MouseButton::Left, gpui::Modifiers::none());
assert!(cx.debug_bounds("bar-insert-before").is_none() && cx.debug_bounds("bar-insert-after").is_some());
cx.simulate_mouse_move(header, gpui::MouseButton::Left, gpui::Modifiers::none());
assert!(cx.debug_bounds("bar-insert-after").is_none());
cx.simulate_mouse_up(header, gpui::MouseButton::Left, gpui::Modifiers::none());
}