Verify keystrokes can be queried while views are on the stack

This commit is contained in:
Antonio Scandurra 2023-05-04 12:09:32 +02:00
parent 3d679ddb26
commit 5cc6304fa6

View file

@ -5678,7 +5678,7 @@ mod tests {
}
#[crate::test(self)]
fn test_keystrokes_for_action(cx: &mut AppContext) {
fn test_keystrokes_for_action(cx: &mut TestAppContext) {
actions!(test, [Action1, Action2, GlobalAction]);
struct View1 {}
@ -5708,12 +5708,13 @@ mod tests {
}
}
let (window_id, view_1) = cx.add_window(Default::default(), |_| View1 {});
let (_, view_1) = cx.add_window(|_| View1 {});
let view_2 = cx.add_view(&view_1, |cx| {
cx.focus_self();
View2 {}
});
cx.update(|cx| {
cx.add_action(|_: &mut View1, _: &Action1, _cx| {});
cx.add_action(|_: &mut View2, _: &Action2, _cx| {});
cx.add_global_action(|_: &GlobalAction, _| {});
@ -5723,8 +5724,12 @@ mod tests {
Binding::new("b", Action2, Some("View1 > View2")),
Binding::new("c", GlobalAction, Some("View3")), // View 3 does not exist
]);
});
cx.update_window(window_id, |cx| {
// Here we update the views to ensure that, even if they are on the stack,
// we can still retrieve keystrokes correctly.
view_1.update(cx, |_, cx| {
view_2.update(cx, |_, cx| {
// Sanity check
assert_eq!(
cx.keystrokes_for_action(view_1.id(), &Action1)
@ -5773,6 +5778,7 @@ mod tests {
],
);
});
});
// Produces a list of actions and key bindings
fn available_actions(