Lines
100 %
Functions
Branches
//! A press on the `[■]` of a dialog closes it on release, as Cancel does.
use super::click_tests::{now, press};
use super::*;
use crate::form::Form;
use crate::hits::Target;
use crate::modal::ConfirmAction;
use crate::test_support::redraw;
const LEFT: MouseButton = MouseButton::Left;
/// The middle of the `[■]` of the dialog on top, drawn after any window's.
fn middle(app: &App) -> Position {
let found = app
.hits
.entries()
.into_iter()
.rfind(|(_, target)| *target == Target::Close);
let (area, _) = found.expect("a close icon was drawn");
Position::new(area.x + area.width / 2, area.y)
}
fn press_close(app: &mut App) {
redraw(app);
let at = middle(app);
press(app, at, MouseEventKind::Down(LEFT), now());
fn dialog_app() -> App {
let mut app = crate::test_support::app();
crate::test_support::open_overlay(&mut app);
redraw(&mut app);
app
#[test]
fn a_release_on_the_close_icon_closes_the_dialog() {
let mut app = dialog_app();
press_close(&mut app);
assert!(app.overlays.top().is_some());
let at = middle(&app);
press(&mut app, at, MouseEventKind::Up(LEFT), now());
assert!(app.overlays.is_empty());
fn a_release_off_the_close_icon_does_nothing() {
press(
&mut app,
Position::new(0, 0),
MouseEventKind::Up(LEFT),
now(),
);
fn the_close_icon_of_a_confirm_cancels_it_and_leaves_the_form_below_open() {
app.overlays.push(Modal::Form(Form::config_set()));
app.overlays.push(Modal::Confirm {
prompt: "Discard changes?".to_string(),
action: ConfirmAction::DiscardForm,
focus: None,
});
assert_eq!(app.overlays.len(), 1);
assert!(matches!(app.overlays.top(), Some(Modal::Form(_))));
fn an_overlay_opened_between_the_press_and_the_release_keeps_the_dialog() {
assert_eq!(app.overlays.len(), 2);