Lines
99.05 %
Functions
100 %
Branches
//! The status-bar hints of the focused chain, and how they follow the keymap.
use super::shown::{KeyView, in_modal};
use crate::app::App;
use crate::event::Intent;
use crate::form::Form;
use crate::modal::{Csv, Draft, Modal};
use crate::test_support::hint_pairs;
use crate::view::Tab;
fn labels(app: &App) -> Vec<String> {
hint_pairs(app)
.into_iter()
.map(|(key, label)| format!("{key} {label}"))
.collect()
}
fn has(app: &App, hint: &str) -> bool {
labels(app).iter().any(|shown| shown == hint)
fn app_with(overrides: &str) -> App {
let mut app = crate::test_support::app();
app.keys = match app.keys.overridden(overrides) {
Ok(keys) => keys,
Err(err) => panic!("the override parses: {err}"),
};
app
fn csv() -> Modal {
Modal::Csv(Csv::new(String::new(), String::new()))
fn draft() -> Modal {
Modal::Draft(Draft::new(Vec::new()))
#[test]
fn cua_shows_its_menu_help_and_quit_keys_first() {
app.switch_tab(Tab::Transactions);
let shown = labels(&app);
assert_eq!(shown[..3], ["F10 Menu", "F1 Help", "M-x Quit"], "{shown:?}");
assert!(!has(&app, "q Quit"), "{shown:?}");
fn emacs_shows_its_quit_help_and_command_keys() {
let app = crate::test_support::emacs_app();
for hint in ["q Close/Quit", "? Help", ": Cmd"] {
assert!(has(&app, hint), "{hint}: {:?}", labels(&app));
assert!(!has(&app, "F1 Help"), "{:?}", labels(&app));
fn the_chain_decides_which_hints_show() {
assert!(has(&app, "f Filter"), "{:?}", labels(&app));
app.switch_tab(Tab::Accounts);
assert!(!has(&app, "f Filter"), "{:?}", labels(&app));
crate::test_support::open_draft(&mut app);
assert!(has(&app, "Esc Close"), "{:?}", labels(&app));
assert!(!has(&app, "c New"), "{:?}", labels(&app));
fn only_keys_that_act_are_shown() {
assert!(
has(&app, "c New") && !has(&app, "d Delete"),
"{:?}",
labels(&app)
);
has(&app, "d Delete") && has(&app, "c New"),
app.switch_tab(Tab::Commodities);
app.overlays.push(Modal::Form(Form::config_set()));
assert!(!has(&app, "M-x Quit"), "{:?}", labels(&app));
fn a_rebound_key_keeps_its_hint() {
let app = app_with("global: F1 = none; global: F2 = open-help");
assert!(has(&app, "F2 Help"), "{:?}", labels(&app));
fn an_override_can_change_the_hint_list() {
let app = app_with("global: hint = quit");
assert!(has(&app, "M-x Quit"), "{:?}", labels(&app));
fn an_action_hinted_by_an_inner_scope_is_not_hinted_again() {
let mut app = app_with("modal-csv: F5 = close; modal-csv: hint = close");
app.overlays.push(csv());
assert!(has(&app, "F5 Close"), "{:?}", labels(&app));
assert!(!has(&app, "Esc Close"), "{:?}", labels(&app));
fn an_inner_binding_of_a_chord_hides_the_outer_one() {
let app = app_with("modal-csv: q = copy-csv");
let view = in_modal(&app, &csv());
assert_eq!(view.all(Intent::CloseTopmost), "Esc / c");
assert_eq!(view.all(Intent::CsvCopy), "y / q");
fn several_chords_of_one_action_in_one_scope_all_show() {
let app = crate::test_support::app();
let view: KeyView<'_> = in_modal(&app, &draft());
assert_eq!(view.all(Intent::ScrollLineUp), "Up / k");
fn the_confirm_prompt_hints_yes_and_no() {
app.overlays.push(Modal::Confirm {
focus: None,
prompt: "Sure?".to_string(),
action: crate::modal::ConfirmAction::DiscardForm,
});
assert!(has(&app, "y Yes") && has(&app, "n No"), "{shown:?}");
fn a_detail_window_hints_close_and_edit() {
app.show_viewer(
crate::viewer::Source::Detail { id: String::new() },
Vec::new(),
for hint in ["Esc Close", "e Edit"] {