Lines
98.41 %
Functions
100 %
Branches
use super::*;
use crate::widgets::grid::CellId;
use crate::widgets::splits::{COL_FROM, COL_TO, COL_VALUE};
use forms::{FormValues, Row};
const SPLITS: usize = 3;
fn row(cells: &[(&str, &str)]) -> Row {
cells
.iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect()
}
fn transaction() -> Form {
let mut loaded = FormValues::default();
loaded.set("id", "tx-1");
loaded.set("revision", "3");
loaded.set("date", "2024-06-15T10:00");
for key in ["r1", "r2"] {
loaded.push_row(
"splits",
row(&[("key", key), ("from", "a"), ("to", "b"), ("value", "1")]),
);
loaded.set_rows("split-tags");
loaded.push_row("split-tags", row(&[("row", "r1"), ("name", "k")]));
Form::transaction_edit(&loaded)
fn splits(form: &mut Form) -> &mut crate::widgets::SplitsWidget {
match form.fields.get_mut(SPLITS).map(|field| &mut field.widget) {
Some(Widget::Splits(splits)) => splits,
_ => panic!("field {SPLITS} is not the splits"),
fn cell(row: usize, col: usize) -> CellId {
CellId {
tag: false,
row,
col,
#[test]
fn focusing_a_split_cell_moves_the_form_and_the_cell() {
let mut form = transaction();
form.focus_cell(SPLITS, cell(1, COL_VALUE));
assert_eq!(form.focus, SPLITS);
assert!(form.cell_focused(SPLITS, cell(1, COL_VALUE)));
assert!(!form.cell_focused(SPLITS, cell(0, COL_VALUE)));
fn a_cell_of_another_field_is_not_focused() {
form.focus_cell(SPLITS, cell(0, COL_TO));
form.focus_field(0);
assert!(!form.cell_focused(SPLITS, cell(0, COL_TO)));
fn a_field_that_is_not_a_grid_ignores_a_cell_focus() {
form.focus_cell(0, cell(0, 0));
assert_eq!(form.focus, 0);
fn a_tag_cell_opens_the_tag_list_and_a_split_cell_closes_it() {
let tag = CellId {
tag: true,
row: 0,
col: 1,
};
form.focus_cell(SPLITS, tag);
assert!(splits(&mut form).tags_open());
assert!(form.cell_focused(SPLITS, tag));
form.focus_cell(SPLITS, cell(1, COL_FROM));
assert!(!splits(&mut form).tags_open());
assert!(form.cell_focused(SPLITS, cell(1, COL_FROM)));