Fix first few asserts
This commit is contained in:
parent
1932a298cb
commit
a5ca58354d
3 changed files with 358 additions and 311 deletions
|
@ -1906,7 +1906,8 @@ impl<'a> WindowContext<'a> {
|
||||||
.platform_window
|
.platform_window
|
||||||
.on_should_close(Box::new(move || {
|
.on_should_close(Box::new(move || {
|
||||||
this.update(|_, cx| {
|
this.update(|_, cx| {
|
||||||
// Ensure that the window is removed from the app if it's been closed.
|
// Ensure that the window is removed from the app if it's been closed
|
||||||
|
// by always pre-empting the system close event.
|
||||||
if f(cx) {
|
if f(cx) {
|
||||||
cx.remove_window();
|
cx.remove_window();
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,8 +255,8 @@ impl Pane {
|
||||||
let focus_handle = cx.focus_handle();
|
let focus_handle = cx.focus_handle();
|
||||||
|
|
||||||
let subscriptions = vec![
|
let subscriptions = vec![
|
||||||
cx.on_focus_in(&focus_handle, move |this, cx| this.focus_in(cx)),
|
cx.on_focus_in(&focus_handle, Pane::focus_in),
|
||||||
cx.on_focus_out(&focus_handle, move |this, cx| this.focus_out(cx)),
|
cx.on_focus_out(&focus_handle, Pane::focus_out),
|
||||||
];
|
];
|
||||||
|
|
||||||
let handle = cx.view().downgrade();
|
let handle = cx.view().downgrade();
|
||||||
|
|
|
@ -672,7 +672,7 @@ impl Workspace {
|
||||||
// );
|
// );
|
||||||
|
|
||||||
// this.show_notification(1, cx, |cx| {
|
// this.show_notification(1, cx, |cx| {
|
||||||
// cx.build_view(|_cx| {
|
// cx.new_view(|_cx| {
|
||||||
// simple_message_notification::MessageNotification::new(format!("Error:"))
|
// simple_message_notification::MessageNotification::new(format!("Error:"))
|
||||||
// .with_click_message("click here because!")
|
// .with_click_message("click here because!")
|
||||||
// })
|
// })
|
||||||
|
@ -4363,12 +4363,15 @@ mod tests {
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::item::{
|
use crate::{
|
||||||
|
dock::{test::TestPanel, PanelEvent},
|
||||||
|
item::{
|
||||||
test::{TestItem, TestProjectItem},
|
test::{TestItem, TestProjectItem},
|
||||||
ItemEvent,
|
ItemEvent,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use fs::FakeFs;
|
use fs::FakeFs;
|
||||||
use gpui::TestAppContext;
|
use gpui::{px, DismissEvent, TestAppContext, VisualTestContext};
|
||||||
use project::{Project, ProjectEntryId};
|
use project::{Project, ProjectEntryId};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
|
@ -4935,362 +4938,405 @@ mod tests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[gpui::test]
|
#[gpui::test]
|
||||||
// async fn test_toggle_docks_and_panels(cx: &mut gpui::TestAppContext) {
|
async fn test_toggle_docks_and_panels(cx: &mut gpui::TestAppContext) {
|
||||||
// init_test(cx);
|
init_test(cx);
|
||||||
// let fs = FakeFs::new(cx.executor());
|
let fs = FakeFs::new(cx.executor());
|
||||||
|
|
||||||
// let project = Project::test(fs, [], cx).await;
|
let project = Project::test(fs, [], cx).await;
|
||||||
// let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
|
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
|
||||||
|
|
||||||
// let panel = workspace.update(cx, |workspace, cx| {
|
let panel = workspace.update(cx, |workspace, cx| {
|
||||||
// let panel = cx.build_view(|cx| TestPanel::new(DockPosition::Right, cx));
|
let panel = cx.new_view(|cx| TestPanel::new(DockPosition::Right, cx));
|
||||||
// workspace.add_panel(panel.clone(), cx);
|
workspace.add_panel(panel.clone(), cx);
|
||||||
|
|
||||||
// workspace
|
workspace
|
||||||
// .right_dock()
|
.right_dock()
|
||||||
// .update(cx, |right_dock, cx| right_dock.set_open(true, cx));
|
.update(cx, |right_dock, cx| right_dock.set_open(true, cx));
|
||||||
|
|
||||||
// panel
|
panel
|
||||||
// });
|
});
|
||||||
|
|
||||||
// let pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone());
|
let pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone());
|
||||||
// pane.update(cx, |pane, cx| {
|
pane.update(cx, |pane, cx| {
|
||||||
// let item = cx.build_view(|cx| TestItem::new(cx));
|
let item = cx.new_view(|cx| TestItem::new(cx));
|
||||||
// pane.add_item(Box::new(item), true, true, None, cx);
|
pane.add_item(Box::new(item), true, true, None, cx);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Transfer focus from center to panel
|
// Transfer focus from center to panel
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.toggle_panel_focus::<TestPanel>(cx);
|
workspace.toggle_panel_focus::<TestPanel>(cx);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// assert!(workspace.right_dock().read(cx).is_open());
|
assert!(workspace.right_dock().read(cx).is_open());
|
||||||
// assert!(!panel.is_zoomed(cx));
|
assert!(!panel.is_zoomed(cx));
|
||||||
// assert!(panel.read(cx).focus_handle(cx).contains_focused(cx));
|
assert!(panel.read(cx).focus_handle(cx).contains_focused(cx));
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Transfer focus from panel to center
|
// Transfer focus from panel to center
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.toggle_panel_focus::<TestPanel>(cx);
|
workspace.toggle_panel_focus::<TestPanel>(cx);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// assert!(workspace.right_dock().read(cx).is_open());
|
assert!(workspace.right_dock().read(cx).is_open());
|
||||||
// assert!(!panel.is_zoomed(cx));
|
assert!(!panel.is_zoomed(cx));
|
||||||
// assert!(!panel.read(cx).focus_handle(cx).contains_focused(cx));
|
assert!(!panel.read(cx).focus_handle(cx).contains_focused(cx));
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Close the dock
|
// Close the dock
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.toggle_dock(DockPosition::Right, cx);
|
workspace.toggle_dock(DockPosition::Right, cx);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// assert!(!workspace.right_dock().read(cx).is_open());
|
assert!(!workspace.right_dock().read(cx).is_open());
|
||||||
// assert!(!panel.is_zoomed(cx));
|
assert!(!panel.is_zoomed(cx));
|
||||||
// assert!(!panel.read(cx).focus_handle(cx).contains_focused(cx));
|
assert!(!panel.read(cx).focus_handle(cx).contains_focused(cx));
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Open the dock
|
// Open the dock
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.toggle_dock(DockPosition::Right, cx);
|
workspace.toggle_dock(DockPosition::Right, cx);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// assert!(workspace.right_dock().read(cx).is_open());
|
assert!(workspace.right_dock().read(cx).is_open());
|
||||||
// assert!(!panel.is_zoomed(cx));
|
assert!(!panel.is_zoomed(cx));
|
||||||
// assert!(panel.read(cx).focus_handle(cx).contains_focused(cx));
|
assert!(panel.read(cx).focus_handle(cx).contains_focused(cx));
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Focus and zoom panel
|
// Focus and zoom panel
|
||||||
// panel.update(cx, |panel, cx| {
|
panel.update(cx, |panel, cx| {
|
||||||
// cx.focus_self();
|
cx.focus_self();
|
||||||
// panel.set_zoomed(true, cx)
|
panel.set_zoomed(true, cx)
|
||||||
// });
|
});
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// assert!(workspace.right_dock().read(cx).is_open());
|
assert!(workspace.right_dock().read(cx).is_open());
|
||||||
// assert!(panel.is_zoomed(cx));
|
assert!(panel.is_zoomed(cx));
|
||||||
// assert!(panel.read(cx).focus_handle(cx).contains_focused(cx));
|
assert!(panel.read(cx).focus_handle(cx).contains_focused(cx));
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Transfer focus to the center closes the dock
|
// Transfer focus to the center closes the dock
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.toggle_panel_focus::<TestPanel>(cx);
|
workspace.toggle_panel_focus::<TestPanel>(cx);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// assert!(!workspace.right_dock().read(cx).is_open());
|
assert!(!workspace.right_dock().read(cx).is_open());
|
||||||
// assert!(panel.is_zoomed(cx));
|
assert!(panel.is_zoomed(cx));
|
||||||
// assert!(!panel.read(cx).focus_handle(cx).contains_focused(cx));
|
assert!(!panel.read(cx).focus_handle(cx).contains_focused(cx));
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Transferring focus back to the panel keeps it zoomed
|
// Transferring focus back to the panel keeps it zoomed
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.toggle_panel_focus::<TestPanel>(cx);
|
workspace.toggle_panel_focus::<TestPanel>(cx);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// assert!(workspace.right_dock().read(cx).is_open());
|
assert!(workspace.right_dock().read(cx).is_open());
|
||||||
// assert!(panel.is_zoomed(cx));
|
assert!(panel.is_zoomed(cx));
|
||||||
// assert!(panel.read(cx).focus_handle(cx).contains_focused(cx));
|
assert!(panel.read(cx).focus_handle(cx).contains_focused(cx));
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Close the dock while it is zoomed
|
// Close the dock while it is zoomed
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.toggle_dock(DockPosition::Right, cx)
|
workspace.toggle_dock(DockPosition::Right, cx)
|
||||||
// });
|
});
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// assert!(!workspace.right_dock().read(cx).is_open());
|
assert!(!workspace.right_dock().read(cx).is_open());
|
||||||
// assert!(panel.is_zoomed(cx));
|
assert!(panel.is_zoomed(cx));
|
||||||
// assert!(workspace.zoomed.is_none());
|
assert!(workspace.zoomed.is_none());
|
||||||
// assert!(!panel.read(cx).focus_handle(cx).contains_focused(cx));
|
assert!(!panel.read(cx).focus_handle(cx).contains_focused(cx));
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Opening the dock, when it's zoomed, retains focus
|
// Opening the dock, when it's zoomed, retains focus
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.toggle_dock(DockPosition::Right, cx)
|
workspace.toggle_dock(DockPosition::Right, cx)
|
||||||
// });
|
});
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// assert!(workspace.right_dock().read(cx).is_open());
|
assert!(workspace.right_dock().read(cx).is_open());
|
||||||
// assert!(panel.is_zoomed(cx));
|
assert!(panel.is_zoomed(cx));
|
||||||
// assert!(workspace.zoomed.is_some());
|
assert!(workspace.zoomed.is_some());
|
||||||
// assert!(panel.read(cx).focus_handle(cx).contains_focused(cx));
|
assert!(panel.read(cx).focus_handle(cx).contains_focused(cx));
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Unzoom and close the panel, zoom the active pane.
|
// Unzoom and close the panel, zoom the active pane.
|
||||||
// panel.update(cx, |panel, cx| panel.set_zoomed(false, cx));
|
panel.update(cx, |panel, cx| panel.set_zoomed(false, cx));
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.toggle_dock(DockPosition::Right, cx)
|
workspace.toggle_dock(DockPosition::Right, cx)
|
||||||
// });
|
});
|
||||||
// pane.update(cx, |pane, cx| pane.toggle_zoom(&Default::default(), cx));
|
pane.update(cx, |pane, cx| pane.toggle_zoom(&Default::default(), cx));
|
||||||
|
|
||||||
// // Opening a dock unzooms the pane.
|
// Opening a dock unzooms the pane.
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.toggle_dock(DockPosition::Right, cx)
|
workspace.toggle_dock(DockPosition::Right, cx)
|
||||||
// });
|
});
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// let pane = pane.read(cx);
|
let pane = pane.read(cx);
|
||||||
// assert!(!pane.is_zoomed());
|
assert!(!pane.is_zoomed());
|
||||||
// assert!(!pane.focus_handle(cx).is_focused(cx));
|
assert!(!pane.focus_handle(cx).is_focused(cx));
|
||||||
// assert!(workspace.right_dock().read(cx).is_open());
|
assert!(workspace.right_dock().read(cx).is_open());
|
||||||
// assert!(workspace.zoomed.is_none());
|
assert!(workspace.zoomed.is_none());
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[gpui::test]
|
struct TestModal(FocusHandle);
|
||||||
// async fn test_panels(cx: &mut gpui::TestAppContext) {
|
|
||||||
// init_test(cx);
|
|
||||||
// let fs = FakeFs::new(cx.executor());
|
|
||||||
|
|
||||||
// let project = Project::test(fs, [], cx).await;
|
impl TestModal {
|
||||||
// let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
|
fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||||
|
Self(cx.focus_handle())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// let (panel_1, panel_2) = workspace.update(cx, |workspace, cx| {
|
impl EventEmitter<DismissEvent> for TestModal {}
|
||||||
// // Add panel_1 on the left, panel_2 on the right.
|
|
||||||
// let panel_1 = cx.build_view(|cx| TestPanel::new(DockPosition::Left, cx));
|
|
||||||
// workspace.add_panel(panel_1.clone(), cx);
|
|
||||||
// workspace
|
|
||||||
// .left_dock()
|
|
||||||
// .update(cx, |left_dock, cx| left_dock.set_open(true, cx));
|
|
||||||
// let panel_2 = cx.build_view(|cx| TestPanel::new(DockPosition::Right, cx));
|
|
||||||
// workspace.add_panel(panel_2.clone(), cx);
|
|
||||||
// workspace
|
|
||||||
// .right_dock()
|
|
||||||
// .update(cx, |right_dock, cx| right_dock.set_open(true, cx));
|
|
||||||
|
|
||||||
// let left_dock = workspace.left_dock();
|
impl FocusableView for TestModal {
|
||||||
// assert_eq!(
|
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
|
||||||
// left_dock.read(cx).visible_panel().unwrap().panel_id(),
|
self.0.clone()
|
||||||
// panel_1.panel_id()
|
}
|
||||||
// );
|
}
|
||||||
// assert_eq!(
|
|
||||||
// left_dock.read(cx).active_panel_size(cx).unwrap(),
|
|
||||||
// panel_1.size(cx)
|
|
||||||
// );
|
|
||||||
|
|
||||||
// left_dock.update(cx, |left_dock, cx| {
|
impl ModalView for TestModal {}
|
||||||
// left_dock.resize_active_panel(Some(1337.), cx)
|
|
||||||
// });
|
|
||||||
// assert_eq!(
|
|
||||||
// workspace
|
|
||||||
// .right_dock()
|
|
||||||
// .read(cx)
|
|
||||||
// .visible_panel()
|
|
||||||
// .unwrap()
|
|
||||||
// .panel_id(),
|
|
||||||
// panel_2.panel_id(),
|
|
||||||
// );
|
|
||||||
|
|
||||||
// (panel_1, panel_2)
|
impl Render for TestModal {
|
||||||
// });
|
fn render(&mut self, _cx: &mut ViewContext<TestModal>) -> impl IntoElement {
|
||||||
|
div().track_focus(&self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// // Move panel_1 to the right
|
#[gpui::test]
|
||||||
// panel_1.update(cx, |panel_1, cx| {
|
async fn test_panels(cx: &mut gpui::TestAppContext) {
|
||||||
// panel_1.set_position(DockPosition::Right, cx)
|
init_test(cx);
|
||||||
// });
|
let fs = FakeFs::new(cx.executor());
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
let project = Project::test(fs, [], cx).await;
|
||||||
// // Since panel_1 was visible on the left, it should now be visible now that it's been moved to the right.
|
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
|
||||||
// // Since it was the only panel on the left, the left dock should now be closed.
|
|
||||||
// assert!(!workspace.left_dock().read(cx).is_open());
|
|
||||||
// assert!(workspace.left_dock().read(cx).visible_panel().is_none());
|
|
||||||
// let right_dock = workspace.right_dock();
|
|
||||||
// assert_eq!(
|
|
||||||
// right_dock.read(cx).visible_panel().unwrap().panel_id(),
|
|
||||||
// panel_1.panel_id()
|
|
||||||
// );
|
|
||||||
// assert_eq!(right_dock.read(cx).active_panel_size(cx).unwrap(), 1337.);
|
|
||||||
|
|
||||||
// // Now we move panel_2 to the left
|
let (panel_1, panel_2) = workspace.update(cx, |workspace, cx| {
|
||||||
// panel_2.set_position(DockPosition::Left, cx);
|
let panel_1 = cx.new_view(|cx| TestPanel::new(DockPosition::Left, cx));
|
||||||
// });
|
workspace.add_panel(panel_1.clone(), cx);
|
||||||
|
workspace
|
||||||
|
.left_dock()
|
||||||
|
.update(cx, |left_dock, cx| left_dock.set_open(true, cx));
|
||||||
|
let panel_2 = cx.new_view(|cx| TestPanel::new(DockPosition::Right, cx));
|
||||||
|
workspace.add_panel(panel_2.clone(), cx);
|
||||||
|
workspace
|
||||||
|
.right_dock()
|
||||||
|
.update(cx, |right_dock, cx| right_dock.set_open(true, cx));
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
let left_dock = workspace.left_dock();
|
||||||
// // Since panel_2 was not visible on the right, we don't open the left dock.
|
assert_eq!(
|
||||||
// assert!(!workspace.left_dock().read(cx).is_open());
|
left_dock.read(cx).visible_panel().unwrap().panel_id(),
|
||||||
// // And the right dock is unaffected in it's displaying of panel_1
|
panel_1.panel_id()
|
||||||
// assert!(workspace.right_dock().read(cx).is_open());
|
);
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// workspace
|
left_dock.read(cx).active_panel_size(cx).unwrap(),
|
||||||
// .right_dock()
|
panel_1.size(cx)
|
||||||
// .read(cx)
|
);
|
||||||
// .visible_panel()
|
|
||||||
// .unwrap()
|
|
||||||
// .panel_id(),
|
|
||||||
// panel_1.panel_id(),
|
|
||||||
// );
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // Move panel_1 back to the left
|
left_dock.update(cx, |left_dock, cx| {
|
||||||
// panel_1.update(cx, |panel_1, cx| {
|
left_dock.resize_active_panel(Some(px(1337.)), cx)
|
||||||
// panel_1.set_position(DockPosition::Left, cx)
|
});
|
||||||
// });
|
assert_eq!(
|
||||||
|
workspace
|
||||||
|
.right_dock()
|
||||||
|
.read(cx)
|
||||||
|
.visible_panel()
|
||||||
|
.unwrap()
|
||||||
|
.panel_id(),
|
||||||
|
panel_2.panel_id(),
|
||||||
|
);
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
(panel_1, panel_2)
|
||||||
// // Since panel_1 was visible on the right, we open the left dock and make panel_1 active.
|
});
|
||||||
// let left_dock = workspace.left_dock();
|
|
||||||
// assert!(left_dock.read(cx).is_open());
|
|
||||||
// assert_eq!(
|
|
||||||
// left_dock.read(cx).visible_panel().unwrap().panel_id(),
|
|
||||||
// panel_1.panel_id()
|
|
||||||
// );
|
|
||||||
// assert_eq!(left_dock.read(cx).active_panel_size(cx).unwrap(), 1337.);
|
|
||||||
// // And right the dock should be closed as it no longer has any panels.
|
|
||||||
// assert!(!workspace.right_dock().read(cx).is_open());
|
|
||||||
|
|
||||||
// // Now we move panel_1 to the bottom
|
// Move panel_1 to the right
|
||||||
// panel_1.set_position(DockPosition::Bottom, cx);
|
panel_1.update(cx, |panel_1, cx| {
|
||||||
// });
|
panel_1.set_position(DockPosition::Right, cx)
|
||||||
|
});
|
||||||
|
|
||||||
// workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
// // Since panel_1 was visible on the left, we close the left dock.
|
// Since panel_1 was visible on the left, it should now be visible now that it's been moved to the right.
|
||||||
// assert!(!workspace.left_dock().read(cx).is_open());
|
// Since it was the only panel on the left, the left dock should now be closed.
|
||||||
// // The bottom dock is sized based on the panel's default size,
|
assert!(!workspace.left_dock().read(cx).is_open());
|
||||||
// // since the panel orientation changed from vertical to horizontal.
|
assert!(workspace.left_dock().read(cx).visible_panel().is_none());
|
||||||
// let bottom_dock = workspace.bottom_dock();
|
let right_dock = workspace.right_dock();
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// bottom_dock.read(cx).active_panel_size(cx).unwrap(),
|
right_dock.read(cx).visible_panel().unwrap().panel_id(),
|
||||||
// panel_1.size(cx),
|
panel_1.panel_id()
|
||||||
// );
|
);
|
||||||
// // Close bottom dock and move panel_1 back to the left.
|
assert_eq!(
|
||||||
// bottom_dock.update(cx, |bottom_dock, cx| bottom_dock.set_open(false, cx));
|
right_dock.read(cx).active_panel_size(cx).unwrap(),
|
||||||
// panel_1.set_position(DockPosition::Left, cx);
|
px(1337.)
|
||||||
// });
|
);
|
||||||
|
|
||||||
// // Emit activated event on panel 1
|
// Now we move panel_2 to the left
|
||||||
// panel_1.update(cx, |_, cx| cx.emit(PanelEvent::Activate));
|
panel_2.set_position(DockPosition::Left, cx);
|
||||||
|
});
|
||||||
|
|
||||||
// // Now the left dock is open and panel_1 is active and focused.
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.update(cx, |workspace, cx| {
|
// Since panel_2 was not visible on the right, we don't open the left dock.
|
||||||
// let left_dock = workspace.left_dock();
|
assert!(!workspace.left_dock().read(cx).is_open());
|
||||||
// assert!(left_dock.read(cx).is_open());
|
// And the right dock is unaffected in it's displaying of panel_1
|
||||||
// assert_eq!(
|
assert!(workspace.right_dock().read(cx).is_open());
|
||||||
// left_dock.read(cx).visible_panel().unwrap().panel_id(),
|
assert_eq!(
|
||||||
// panel_1.panel_id(),
|
workspace
|
||||||
// );
|
.right_dock()
|
||||||
// assert!(panel_1.focus_handle(cx).is_focused(cx));
|
.read(cx)
|
||||||
// });
|
.visible_panel()
|
||||||
|
.unwrap()
|
||||||
|
.panel_id(),
|
||||||
|
panel_1.panel_id(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// // Emit closed event on panel 2, which is not active
|
// Move panel_1 back to the left
|
||||||
// panel_2.update(cx, |_, cx| cx.emit(PanelEvent::Close));
|
panel_1.update(cx, |panel_1, cx| {
|
||||||
|
panel_1.set_position(DockPosition::Left, cx)
|
||||||
|
});
|
||||||
|
|
||||||
// // Wo don't close the left dock, because panel_2 wasn't the active panel
|
workspace.update(cx, |workspace, cx| {
|
||||||
// workspace.update(cx, |workspace, cx| {
|
// Since panel_1 was visible on the right, we open the left dock and make panel_1 active.
|
||||||
// let left_dock = workspace.left_dock();
|
let left_dock = workspace.left_dock();
|
||||||
// assert!(left_dock.read(cx).is_open());
|
assert!(left_dock.read(cx).is_open());
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// left_dock.read(cx).visible_panel().unwrap().panel_id(),
|
left_dock.read(cx).visible_panel().unwrap().panel_id(),
|
||||||
// panel_1.panel_id(),
|
panel_1.panel_id()
|
||||||
// );
|
);
|
||||||
// });
|
assert_eq!(left_dock.read(cx).active_panel_size(cx).unwrap(), px(1337.));
|
||||||
|
// And the right dock should be closed as it no longer has any panels.
|
||||||
|
assert!(!workspace.right_dock().read(cx).is_open());
|
||||||
|
|
||||||
// // Emitting a ZoomIn event shows the panel as zoomed.
|
// Now we move panel_1 to the bottom
|
||||||
// panel_1.update(cx, |_, cx| cx.emit(PanelEvent::ZoomIn));
|
panel_1.set_position(DockPosition::Bottom, cx);
|
||||||
// workspace.update(cx, |workspace, _| {
|
});
|
||||||
// assert_eq!(workspace.zoomed, Some(panel_1.to_any().downgrade()));
|
|
||||||
// assert_eq!(workspace.zoomed_position, Some(DockPosition::Left));
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // Move panel to another dock while it is zoomed
|
workspace.update(cx, |workspace, cx| {
|
||||||
// panel_1.update(cx, |panel, cx| panel.set_position(DockPosition::Right, cx));
|
// Since panel_1 was visible on the left, we close the left dock.
|
||||||
// workspace.update(cx, |workspace, _| {
|
assert!(!workspace.left_dock().read(cx).is_open());
|
||||||
// assert_eq!(workspace.zoomed, Some(panel_1.to_any().downgrade()));
|
// The bottom dock is sized based on the panel's default size,
|
||||||
|
// since the panel orientation changed from vertical to horizontal.
|
||||||
|
let bottom_dock = workspace.bottom_dock();
|
||||||
|
assert_eq!(
|
||||||
|
bottom_dock.read(cx).active_panel_size(cx).unwrap(),
|
||||||
|
panel_1.size(cx),
|
||||||
|
);
|
||||||
|
// Close bottom dock and move panel_1 back to the left.
|
||||||
|
bottom_dock.update(cx, |bottom_dock, cx| bottom_dock.set_open(false, cx));
|
||||||
|
panel_1.set_position(DockPosition::Left, cx);
|
||||||
|
});
|
||||||
|
|
||||||
// assert_eq!(workspace.zoomed_position, Some(DockPosition::Right));
|
// Emit activated event on panel 1
|
||||||
// });
|
panel_1.update(cx, |_, cx| cx.emit(PanelEvent::Activate));
|
||||||
|
|
||||||
// // If focus is transferred to another view that's not a panel or another pane, we still show
|
// Now the left dock is open and panel_1 is active and focused.
|
||||||
// // the panel as zoomed.
|
workspace.update(cx, |workspace, cx| {
|
||||||
// let other_focus_handle = cx.update(|cx| cx.focus_handle());
|
let left_dock = workspace.left_dock();
|
||||||
// cx.update(|cx| cx.focus(&other_focus_handle));
|
assert!(left_dock.read(cx).is_open());
|
||||||
// workspace.update(cx, |workspace, _| {
|
assert_eq!(
|
||||||
// assert_eq!(workspace.zoomed, Some(panel_1.to_any().downgrade()));
|
left_dock.read(cx).visible_panel().unwrap().panel_id(),
|
||||||
// assert_eq!(workspace.zoomed_position, Some(DockPosition::Right));
|
panel_1.panel_id(),
|
||||||
// });
|
);
|
||||||
|
assert!(panel_1.focus_handle(cx).is_focused(cx));
|
||||||
|
});
|
||||||
|
|
||||||
// // If focus is transferred elsewhere in the workspace, the panel is no longer zoomed.
|
// Emit closed event on panel 2, which is not active
|
||||||
// workspace.update(cx, |_, cx| cx.focus_self());
|
panel_2.update(cx, |_, cx| cx.emit(PanelEvent::Close));
|
||||||
// workspace.update(cx, |workspace, _| {
|
|
||||||
// assert_eq!(workspace.zoomed, None);
|
|
||||||
// assert_eq!(workspace.zoomed_position, None);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // If focus is transferred again to another view that's not a panel or a pane, we won't
|
// Wo don't close the left dock, because panel_2 wasn't the active panel
|
||||||
// // show the panel as zoomed because it wasn't zoomed before.
|
workspace.update(cx, |workspace, cx| {
|
||||||
// cx.update(|cx| cx.focus(&other_focus_handle));
|
let left_dock = workspace.left_dock();
|
||||||
// workspace.update(cx, |workspace, _| {
|
assert!(left_dock.read(cx).is_open());
|
||||||
// assert_eq!(workspace.zoomed, None);
|
assert_eq!(
|
||||||
// assert_eq!(workspace.zoomed_position, None);
|
left_dock.read(cx).visible_panel().unwrap().panel_id(),
|
||||||
// });
|
panel_1.panel_id(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// // When focus is transferred back to the panel, it is zoomed again.
|
// Emitting a ZoomIn event shows the panel as zoomed.
|
||||||
// panel_1.update(cx, |_, cx| cx.focus_self());
|
panel_1.update(cx, |_, cx| cx.emit(PanelEvent::ZoomIn));
|
||||||
// workspace.update(cx, |workspace, _| {
|
workspace.update(cx, |workspace, _| {
|
||||||
// assert_eq!(workspace.zoomed, Some(panel_1.to_any().downgrade()));
|
assert_eq!(workspace.zoomed, Some(panel_1.to_any().downgrade()));
|
||||||
// assert_eq!(workspace.zoomed_position, Some(DockPosition::Right));
|
assert_eq!(workspace.zoomed_position, Some(DockPosition::Left));
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Emitting a ZoomOut event unzooms the panel.
|
// Move panel to another dock while it is zoomed
|
||||||
// panel_1.update(cx, |_, cx| cx.emit(PanelEvent::ZoomOut));
|
panel_1.update(cx, |panel, cx| panel.set_position(DockPosition::Right, cx));
|
||||||
// workspace.update(cx, |workspace, _| {
|
workspace.update(cx, |workspace, _| {
|
||||||
// assert_eq!(workspace.zoomed, None);
|
assert_eq!(workspace.zoomed, Some(panel_1.to_any().downgrade()));
|
||||||
// assert_eq!(workspace.zoomed_position, None);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // Emit closed event on panel 1, which is active
|
assert_eq!(workspace.zoomed_position, Some(DockPosition::Right));
|
||||||
// panel_1.update(cx, |_, cx| cx.emit(PanelEvent::Close));
|
});
|
||||||
|
|
||||||
// // Now the left dock is closed, because panel_1 was the active panel
|
// This is a helper for getting a:
|
||||||
// workspace.update(cx, |workspace, cx| {
|
// - valid focus on an element,
|
||||||
// let right_dock = workspace.right_dock();
|
// - that isn't a part of the panes and panels system of the Workspace,
|
||||||
// assert!(!right_dock.read(cx).is_open());
|
// - and doesn't trigger the 'on_focus_lost' API.
|
||||||
// });
|
let focus_other_view = {
|
||||||
// }
|
let workspace = workspace.clone();
|
||||||
|
move |cx: &mut VisualTestContext| {
|
||||||
|
workspace.update(cx, |workspace, cx| {
|
||||||
|
if let Some(_) = workspace.active_modal::<TestModal>(cx) {
|
||||||
|
workspace.toggle_modal(cx, TestModal::new);
|
||||||
|
workspace.toggle_modal(cx, TestModal::new);
|
||||||
|
} else {
|
||||||
|
workspace.toggle_modal(cx, TestModal::new);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// If focus is transferred to another view that's not a panel or another pane, we still show
|
||||||
|
// the panel as zoomed.
|
||||||
|
focus_other_view(cx);
|
||||||
|
workspace.update(cx, |workspace, _| {
|
||||||
|
assert_eq!(workspace.zoomed, Some(panel_1.to_any().downgrade()));
|
||||||
|
assert_eq!(workspace.zoomed_position, Some(DockPosition::Right));
|
||||||
|
});
|
||||||
|
|
||||||
|
// If focus is transferred elsewhere in the workspace, the panel is no longer zoomed.
|
||||||
|
workspace.update(cx, |_, cx| cx.focus_self());
|
||||||
|
workspace.update(cx, |workspace, _| {
|
||||||
|
assert_eq!(workspace.zoomed, None);
|
||||||
|
assert_eq!(workspace.zoomed_position, None);
|
||||||
|
});
|
||||||
|
|
||||||
|
// If focus is transferred again to another view that's not a panel or a pane, we won't
|
||||||
|
// show the panel as zoomed because it wasn't zoomed before.
|
||||||
|
focus_other_view(cx);
|
||||||
|
workspace.update(cx, |workspace, _| {
|
||||||
|
assert_eq!(workspace.zoomed, None);
|
||||||
|
assert_eq!(workspace.zoomed_position, None);
|
||||||
|
});
|
||||||
|
|
||||||
|
// When the panel is activated, it is zoomed again.
|
||||||
|
cx.dispatch_action(ToggleRightDock);
|
||||||
|
workspace.update(cx, |workspace, _| {
|
||||||
|
assert_eq!(workspace.zoomed, Some(panel_1.to_any().downgrade()));
|
||||||
|
assert_eq!(workspace.zoomed_position, Some(DockPosition::Right));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Emitting a ZoomOut event unzooms the panel.
|
||||||
|
panel_1.update(cx, |_, cx| cx.emit(PanelEvent::ZoomOut));
|
||||||
|
workspace.update(cx, |workspace, _| {
|
||||||
|
assert_eq!(workspace.zoomed, None);
|
||||||
|
assert_eq!(workspace.zoomed_position, None);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Emit closed event on panel 1, which is active
|
||||||
|
panel_1.update(cx, |_, cx| cx.emit(PanelEvent::Close));
|
||||||
|
|
||||||
|
// Now the left dock is closed, because panel_1 was the active panel
|
||||||
|
workspace.update(cx, |workspace, cx| {
|
||||||
|
let right_dock = workspace.right_dock();
|
||||||
|
assert!(!right_dock.read(cx).is_open());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init_test(cx: &mut TestAppContext) {
|
pub fn init_test(cx: &mut TestAppContext) {
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue