mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
tests: wait deterministically after simulating_keystrokes
This commit is contained in:
parent
e27b7d7812
commit
a4f96e6452
@ -3,8 +3,8 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
keymap_matcher::Keystroke, AnyWindowHandle, AppContext, ContextHandle, ModelContext,
|
executor::Foreground, keymap_matcher::Keystroke, AnyWindowHandle, AppContext, ContextHandle,
|
||||||
ViewContext, ViewHandle,
|
ModelContext, ViewContext, ViewHandle,
|
||||||
};
|
};
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use language::{Buffer, BufferSnapshot};
|
use language::{Buffer, BufferSnapshot};
|
||||||
@ -114,6 +114,7 @@ impl<'a> EditorTestContext<'a> {
|
|||||||
let keystroke = Keystroke::parse(keystroke_text).unwrap();
|
let keystroke = Keystroke::parse(keystroke_text).unwrap();
|
||||||
|
|
||||||
self.cx.dispatch_keystroke(self.window, keystroke, false);
|
self.cx.dispatch_keystroke(self.window, keystroke, false);
|
||||||
|
|
||||||
keystroke_under_test_handle
|
keystroke_under_test_handle
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +127,16 @@ impl<'a> EditorTestContext<'a> {
|
|||||||
for keystroke_text in keystroke_texts.into_iter() {
|
for keystroke_text in keystroke_texts.into_iter() {
|
||||||
self.simulate_keystroke(keystroke_text);
|
self.simulate_keystroke(keystroke_text);
|
||||||
}
|
}
|
||||||
|
// it is common for keyboard shortcuts to kick off async actions, so this ensures that they are complete
|
||||||
|
// before returning.
|
||||||
|
// NOTE: we don't do this in simulate_keystroke() because a possible cause of bugs is that typing too
|
||||||
|
// quickly races with async actions.
|
||||||
|
if let Foreground::Deterministic { cx_id: _, executor } = self.cx.foreground().as_ref() {
|
||||||
|
executor.run_until_parked();
|
||||||
|
} else {
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
|
|
||||||
keystrokes_under_test_handle
|
keystrokes_under_test_handle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,9 +186,6 @@ async fn test_selection_on_search(cx: &mut gpui::TestAppContext) {
|
|||||||
assert_eq!(bar.query(cx), "cc");
|
assert_eq!(bar.query(cx), "cc");
|
||||||
});
|
});
|
||||||
|
|
||||||
// wait for the query editor change event to fire.
|
|
||||||
search_bar.next_notification(&cx).await;
|
|
||||||
|
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
let highlights = editor.all_text_background_highlights(cx);
|
let highlights = editor.all_text_background_highlights(cx);
|
||||||
assert_eq!(3, highlights.len());
|
assert_eq!(3, highlights.len());
|
||||||
|
Loading…
Reference in New Issue
Block a user