Lines
98.61 %
Functions
100 %
Branches
//! An open Help follows the keymap: untouched by a re-read, closed by a change; focus stays per window.
use super::options::{answer_config, attached_with};
use super::options_save::{OK, press_button};
use crate::app::{App, CliConfig};
use crate::event::{Intent, apply};
use crate::form::Form;
use crate::modal::Modal;
use crate::test_support::{app, help_open, key, press, viewer_title};
use crate::view::ViewId;
use crate::viewer::{Source, Viewer};
use ratatui::crossterm::event::KeyCode;
const UNSET: [Option<&str>; 5] = [None; 5];
fn help_lines(app: &App) -> Vec<String> {
match app.front::<Viewer>() {
Some(viewer) => viewer.lines.clone(),
None => panic!("the front window is not a viewer"),
}
fn reread_config_in_options(app: &mut App, texts: [Option<&str>; 5]) {
apply(app, Intent::OpenOptions);
answer_config(app, texts);
#[tokio::test]
async fn opening_and_cancelling_options_leaves_an_open_help_alone() {
let (mut app, _) = attached_with(CliConfig::default(), UNSET);
apply(&mut app, Intent::OpenHelp);
let before = help_lines(&app);
reread_config_in_options(&mut app, UNSET);
apply(&mut app, Intent::CloseTopmost);
assert_eq!(app.windows_of(ViewId::Viewer), 1);
apply(&mut app, Intent::CloseWindow);
assert_eq!(help_lines(&app), before);
async fn a_changed_override_closes_helps_and_keeps_a_detail() {
let detail = Source::Detail {
id: "tx".to_string(),
};
app.show_viewer(detail.clone(), vec!["a".to_string()]);
reread_config_in_options(
&mut app,
[None, None, None, None, Some("global: F11 = open-help")],
);
assert!(app.viewer_of(&detail).is_some());
#[test]
fn a_console_keeps_its_prompt_focus_while_another_window_is_in_front() {
let mut app = app();
app.focus_console();
let first = app.front_window().expect("the console");
let second = app.open_extra(ViewId::Console);
assert!(!app.console_input_focused());
app.raise_window(first);
assert!(app.console_input_focused());
app.raise_window(second);
async fn a_form_still_submits_to_its_origin_with_help_in_front() {
app.attach_echo();
app.open_dialog_for(ViewId::Tags, Modal::Form(Form::tag_create()));
assert!(help_open(&app));
assert!(matches!(app.overlays.top(), Some(Modal::Form(_))));
press(&mut app, key(KeyCode::Char('x')));
press_button(&mut app, OK);
assert!(app.overlays.is_empty());
let tags = app.window_of(ViewId::Tags);
let targets: Vec<_> = app
.pending_routes
.values()
.map(|route| route.target)
.collect();
assert!(targets.contains(&Some(tags)), "{targets:?}");
fn the_topic_names_the_menu_and_the_console_prompt() {
let mut menu = app();
menu.open_menu();
apply(&mut menu, Intent::OpenHelp);
assert_eq!(viewer_title(&menu), "Help: menu");
let mut prompt = app();
prompt.focus_console();
apply(&mut prompt, Intent::OpenHelp);
assert_eq!(viewer_title(&prompt), "Help: console-prompt");