use super::*;
fn toolbar_request(x: f64) -> crate::selection_toolbar::SelectionToolbarRequest {
crate::selection_toolbar::SelectionToolbarRequest {
anchor: Rect::new(x, 100.0, x + 50.0, 120.0),
actions: crate::selection_toolbar::SelectionToolbarActions {
copy: true,
cut: true,
paste: false,
select_all: true,
},
present_menu: true,
}
}
fn toolbar_level(x: f64) -> crate::selection_toolbar::SelectionToolbarRequest {
crate::selection_toolbar::SelectionToolbarRequest {
present_menu: false,
..toolbar_request(x)
}
}
#[test]
fn a_selection_toolbar_publish_resolves_and_only_a_menu_edge_moves_the_generation() {
let mut h = OverlayHarness::new(vec![]);
h.down(30.0, 120.0);
assert!(h.root.is_focus_active());
h.state.publish = Some(toolbar_request(10.0));
h.frame();
assert_eq!(h.root.selection_toolbar(), Some(toolbar_request(10.0)));
let first_gen = h.root.selection_toolbar_generation();
assert!(first_gen > 0, "appearing is an edge");
h.frame();
h.frame();
assert_eq!(h.root.selection_toolbar(), Some(toolbar_request(10.0)));
assert_eq!(h.root.selection_toolbar_generation(), first_gen);
h.state.publish = Some(toolbar_request(60.0));
h.frame();
assert_eq!(h.root.selection_toolbar(), Some(toolbar_request(60.0)));
assert_eq!(
h.root.selection_toolbar_generation(),
first_gen,
"an anchor following the selection is not a reason to re-present"
);
let mut fewer_verbs = toolbar_request(60.0);
fewer_verbs.actions.select_all = false;
h.state.publish = Some(fewer_verbs);
h.frame();
assert_eq!(h.root.selection_toolbar_generation(), first_gen + 1);
h.state.publish = None;
h.frame();
assert_eq!(h.root.selection_toolbar(), None);
assert_eq!(
h.root.selection_toolbar_generation(),
first_gen + 2,
"going away is an edge too, or a shell never learns to dismiss"
);
h.frame();
assert_eq!(h.root.selection_toolbar_generation(), first_gen + 2);
}
#[test]
fn only_the_menu_flag_going_up_asks_a_shell_to_present() {
let mut h = OverlayHarness::new(vec![]);
h.down(30.0, 120.0);
assert!(h.root.is_focus_active());
h.state.publish = Some(toolbar_level(10.0));
h.frame();
assert_eq!(h.root.selection_toolbar(), Some(toolbar_level(10.0)));
let level_gen = h.root.selection_toolbar_generation();
h.frame();
h.frame();
assert_eq!(h.root.selection_toolbar_generation(), level_gen);
h.state.publish = Some(toolbar_request(10.0));
h.frame();
assert_eq!(
h.root.selection_toolbar_generation(),
level_gen + 1,
"the flag going false to true is what presents the menu"
);
h.state.publish = Some(toolbar_level(10.0));
h.frame();
assert!(h.root.selection_toolbar().is_some());
assert_eq!(h.root.selection_toolbar_generation(), level_gen + 2);
}
#[test]
fn a_pass_that_publishes_nothing_still_moves_the_generation() {
let mut h = OverlayHarness::new(vec![]);
h.down(30.0, 120.0);
h.state.publish = Some(toolbar_request(10.0));
h.frame();
let standing = h.root.selection_toolbar_generation();
h.state.publish = None;
h.frame();
assert_eq!(h.root.selection_toolbar(), None);
assert_eq!(h.root.selection_toolbar_generation(), standing + 1);
}
#[test]
fn a_blur_clears_the_selection_toolbar_on_the_event_pass() {
let mut h = OverlayHarness::new(vec![]);
h.down(30.0, 120.0);
h.state.publish = Some(toolbar_request(10.0));
h.frame();
assert!(h.root.selection_toolbar().is_some());
let gen_before = h.root.selection_toolbar_generation();
h.down(150.0, 30.0);
assert!(!h.root.is_focus_active());
assert_eq!(
h.root.selection_toolbar(),
None,
"a toolbar cannot outlive the focus session its selection belonged to"
);
assert_eq!(h.root.selection_toolbar_generation(), gen_before + 1);
h.frame();
assert_eq!(h.root.selection_toolbar(), None);
}