Lines
98.8 %
Functions
100 %
Branches
//! The app starts on an empty desktop: the first window comes from a key or a menu.
use crate::app::menu::MenuId;
use crate::test_support::{draw_frame, empty_app, key, press};
use crate::view::ViewId;
use ratatui::buffer::Buffer;
use ratatui::crossterm::event::KeyCode;
fn row_text(buffer: &Buffer, y: u16) -> String {
let width = buffer.area.width;
(0..width).map(|x| buffer[(x, y)].symbol()).collect()
}
#[test]
fn the_app_starts_without_windows() {
let app = empty_app();
assert_eq!(app.front_window(), None);
assert_eq!(app.front_kind(), None);
assert_eq!(app.windows_of(ViewId::Accounts), 0);
fn the_status_line_names_the_keys_that_start_work() {
let (buffer, _) = draw_frame(&app, 80, 24);
let status = row_text(&buffer, 23);
assert!(status.contains("F10 menu"), "{status}");
assert!(status.contains("1\u{2013}0 open a view"), "{status}");
fn the_hint_gives_way_once_a_window_is_open() {
let mut app = empty_app();
press(&mut app, key(KeyCode::Char('1')));
assert!(!row_text(&buffer, 23).contains("open a view"));
fn f10_opens_the_menu_on_an_empty_desktop() {
press(&mut app, key(KeyCode::F(10)));
assert_eq!(app.menu_title(), Some(MenuId::View));
fn a_digit_opens_the_first_window_zoomed() {
press(&mut app, key(KeyCode::Char('2')));
assert_eq!(app.front_kind(), Some(ViewId::Transactions));
let zoomed = app.desktop.iter_back_to_front().all(|slot| slot.zoomed);
assert!(zoomed);
assert_eq!(app.windows_of(ViewId::Transactions), 1);
fn closing_the_last_window_leaves_the_desktop_empty() {
app.close_front_window();
fn the_hint_gives_way_to_an_open_menu_and_to_a_dialog() {
assert!(status.contains("Close menu"), "{status}");
assert!(!status.contains("open a view"), "{status}");
app.close_menu();
crate::test_support::open_draft(&mut app);
assert!(status.contains("Scroll"), "{status}");
fn the_hint_names_the_keys_the_keymap_binds_in_every_preset() {
for (name, mut app) in [
("cua", crate::test_support::app()),
("emacs", crate::test_support::emacs_app()),
("vim", crate::test_support::vim_app()),
] {
app.close_all_windows();
let menu = crate::keymap::here(&app).key(crate::event::Intent::OpenMenu);
let expected = menu.map(|chord| format!("{chord} menu \u{b7} 1\u{2013}0 open a view"));
assert!(
expected.is_some_and(|text| status.contains(&text)),
"{name}: {status}"
);
fn a_rebound_menu_key_is_the_one_the_hint_names() {
let rebound = app
.keys
.overridden("global: F10 = none\nglobal: M-m = none\nglobal: C-o = open-menu");
match rebound {
Ok(keys) => app.keys = keys,
Err(err) => panic!("the override reads: {err}"),
status.contains("C-o menu \u{b7} 1\u{2013}0 open a view"),
"{status}"