Lines
88.17 %
Functions
100 %
Branches
//! The cursor keys inside the cells of the splits and rows grids, under every preset.
use super::tests::{key, press, type_text};
use crate::app::App;
use crate::form::Form;
use crate::modal::Modal;
use crate::widgets::splits::{COL_FROM, COL_VALUE};
use crate::widgets::{FocusedSubWidget, Widget};
use ratatui::crossterm::event::KeyCode;
const SPLITS: usize = 3;
fn presets() -> [(&'static str, App); 3] {
[
("cua", crate::test_support::app()),
("emacs", crate::test_support::emacs_app()),
("vim", crate::test_support::vim_app()),
]
}
fn on_splits(mut app: App, col: usize) -> App {
let mut form = Form::transaction_create();
form.focus = SPLITS;
if let Widget::Splits(sw) = &mut form.fields[SPLITS].widget {
sw.col_focus = col;
app.overlays.push(Modal::Form(form));
app
fn amount(app: &mut App) -> (String, usize) {
let Some(form) = app.overlays.form_mut() else {
panic!("the form is open");
};
let Widget::Splits(sw) = &mut form.fields[SPLITS].widget else {
panic!("the splits field");
match sw.focused_subwidget_mut() {
Some(FocusedSubWidget::Amount(a)) => (a.value().to_string(), a.editor().cursor()),
_ => panic!("an amount cell"),
#[test]
fn left_inserts_in_the_middle_of_an_amount_cell_under_every_preset() {
for (name, app) in presets() {
let mut app = on_splits(app, COL_VALUE);
type_text(&mut app, "1234");
press(&mut app, key(KeyCode::Left));
type_text(&mut app, "9");
assert_eq!(amount(&mut app), ("12934".to_string(), 3), "{name}");
fn home_then_delete_removes_the_first_character_under_every_preset() {
press(&mut app, key(KeyCode::Home));
press(&mut app, key(KeyCode::Delete));
assert_eq!(amount(&mut app), ("234".to_string(), 0), "{name}");
press(&mut app, key(KeyCode::End));
press(&mut app, key(KeyCode::Right));
assert_eq!(amount(&mut app).1, 3, "{name}");
fn the_cursor_keys_leave_a_select_cell_alone_and_tab_still_moves_on() {
let mut app = on_splits(app, COL_FROM);
for code in [KeyCode::Left, KeyCode::Right, KeyCode::Home, KeyCode::End] {
press(&mut app, key(code));
let Widget::Splits(sw) = &form.fields[SPLITS].widget else {
assert_eq!((sw.row_focus, sw.col_focus), (0, COL_FROM), "{name}");
press(&mut app, key(KeyCode::Tab));
assert_eq!(sw.col_focus, COL_FROM + 1, "{name}");
fn left_inserts_in_the_middle_of_a_text_cell_of_a_rows_grid_under_every_preset() {
let tags = form
.fields
.iter()
.position(|f| matches!(f.widget, Widget::Rows(_)))
.expect("a rows field");
form.focus = tags;
if let Widget::Rows(rw) = &mut form.fields[tags].widget {
rw.add_row();
let mut app = app;
let Widget::Rows(rw) = &form.fields[tags].widget else {
panic!("the rows field");
assert_eq!(rw.focused_text("name"), "12934", "{name}");
fn help_lists_the_line_editing_keys_on_a_grid_cell() {
let app = on_splits(crate::test_support::app(), COL_VALUE);
let lines = super::help::help_lines(&app);
assert!(lines.iter().any(|l| l == "Line editing"), "{lines:?}");
assert!(
lines.iter().any(|l| l.contains("Move the cursor left")),
"{lines:?}"
);