Add basic test for editor context menu

This commit is contained in:
Keith Simmons 2022-07-12 15:35:01 -07:00 committed by K Simmons
parent b850e41d6f
commit 5366ed4404
2 changed files with 47 additions and 0 deletions

View File

@ -124,6 +124,10 @@ impl ContextMenu {
} }
} }
pub fn visible(&self) -> bool {
self.visible
}
fn action_dispatched(&mut self, action_id: TypeId, cx: &mut ViewContext<Self>) { fn action_dispatched(&mut self, action_id: TypeId, cx: &mut ViewContext<Self>) {
if let Some(ix) = self if let Some(ix) = self
.items .items

View File

@ -58,3 +58,46 @@ pub fn deploy_context_menu(
}); });
cx.notify(); 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()));
}
}