Lines
100 %
Functions
Branches
//! A key that presses a dialog button draws it down and acts a moment later.
use super::tests::{key, press};
use crate::app::{App, KEY_PRESS};
use crate::event::Intent;
use crate::form::Form;
use crate::keymap::handle_key;
use crate::modal::{ConfirmAction, Modal};
use ratatui::crossterm::event::KeyCode;
use std::time::{Duration, Instant};
fn confirm_app() -> App {
let mut app = crate::test_support::app();
app.overlays.push(Modal::Confirm {
prompt: "Discard changes?".to_string(),
action: ConfirmAction::DiscardForm,
focus: None,
});
app
}
fn later() -> Instant {
Instant::now() + Duration::from_secs(1)
fn on_close(app: &mut App) {
for _ in 0..3 {
press(app, key(KeyCode::Tab));
#[test]
fn enter_on_the_default_button_draws_it_down_and_acts_when_the_time_is_up() {
let mut app = confirm_app();
handle_key(&mut app, key(KeyCode::Enter));
assert_eq!(app.pressed_button(), Some(1));
assert!(app.overlays.top().is_some());
app.tick(later());
assert!(app.overlays.top().is_none());
assert_eq!(app.pressed_button(), None);
fn space_on_the_focused_form_button_presses_it() {
app.open_dialog_on_front(Modal::Form(Form::config_set()));
on_close(&mut app);
handle_key(&mut app, key(KeyCode::Char(' ')));
fn the_hotkey_letter_of_a_confirm_button_presses_it() {
handle_key(&mut app, key(KeyCode::Char('n')));
fn a_key_that_is_no_button_press_acts_at_once() {
handle_key(&mut app, key(KeyCode::Esc));
fn enter_in_a_field_draws_the_default_button_down_and_submits_when_the_time_is_up() {
assert_eq!(app.pressed_button(), Some(0));
assert!(app.status.is_empty());
assert_eq!(app.status, "console not connected");
fn a_press_is_dropped_when_the_dialog_changed_while_it_waited() {
app.overlays.pop();
prompt: "Another?".to_string(),
fn the_press_waits_a_hundred_milliseconds_and_no_less() {
let base = Instant::now();
app.hold_button_by_key(0, Intent::ConfirmYes, base);
assert_eq!(app.next_deadline(base), Some(KEY_PRESS));
assert_eq!(KEY_PRESS, Duration::from_millis(100));
app.tick(base + Duration::from_millis(99));
app.tick(base + KEY_PRESS);
assert_eq!(app.next_deadline(base), None);
fn the_next_key_lets_the_press_act_before_it_is_handled() {
handle_key(&mut app, key(KeyCode::Char('x')));
fn enter_on_a_message_draws_its_only_button_down_and_closes_after_the_timer() {
crate::test_support::open_draft(&mut app);