diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs index 85a6cd1e19..39477bc927 100644 --- a/crates/context_menu/src/context_menu.rs +++ b/crates/context_menu/src/context_menu.rs @@ -124,6 +124,10 @@ impl ContextMenu { } } + pub fn visible(&self) -> bool { + self.visible + } + fn action_dispatched(&mut self, action_id: TypeId, cx: &mut ViewContext) { if let Some(ix) = self .items diff --git a/crates/editor/src/mouse_context_menu.rs b/crates/editor/src/mouse_context_menu.rs index be083b2bce..f30bc0a678 100644 --- a/crates/editor/src/mouse_context_menu.rs +++ b/crates/editor/src/mouse_context_menu.rs @@ -58,3 +58,46 @@ pub fn deploy_context_menu( }); cx.notify(); } + +#[cfg(test)] +mod tests { + use indoc::indoc; + + use crate::test::EditorLspTestContext; + + use super::*; + + #[gpui::test] + async fn test_mouse_context_menu(cx: &mut gpui::TestAppContext) { + let mut cx = EditorLspTestContext::new_rust( + lsp::ServerCapabilities { + hover_provider: Some(lsp::HoverProviderCapability::Simple(true)), + ..Default::default() + }, + cx, + ) + .await; + + cx.set_state(indoc! {" + fn te|st() + do_work();"}); + let point = cx.display_point(indoc! {" + fn test() + do_w|ork();"}); + cx.update_editor(|editor, cx| { + deploy_context_menu( + editor, + &DeployMouseContextMenu { + position: Default::default(), + point, + }, + cx, + ) + }); + + cx.assert_editor_state(indoc! {" + fn test() + do_w|ork();"}); + cx.editor(|editor, app| assert!(editor.mouse_context_menu.read(app).visible())); + } +}