Lines
100 %
Functions
Branches
//! Tests for the generic Form type.
mod carried;
mod choice;
mod config;
mod convert;
mod create;
mod report;
mod rows;
mod split_tags;
mod suggest;
mod tags;
mod transaction;
mod uncarried;
use super::*;
#[test]
fn cycle_forward_walks_the_fields_then_the_buttons_and_wraps() {
let mut form = Form::config_set();
let mut seen = Vec::new();
for _ in 0..5 {
seen.push((form.focus, form.focused_button()));
form.cycle(true);
}
assert_eq!(
seen,
[(0, None), (1, None), (2, Some(0)), (3, Some(1)), (0, None)]
);
fn cycle_backward_goes_from_the_first_field_to_the_last_button() {
form.cycle(false);
assert_eq!((form.focus, form.focused_button()), (3, Some(1)));
assert_eq!((form.focus, form.focused_button()), (2, Some(0)));
assert_eq!((form.focus, form.focused_button()), (1, None));
fn no_field_is_focused_on_a_button() {
form.focus = 2;
assert!(form.focused_field_mut().is_none());
assert_eq!(form.focused_widget_kind(), None);
fn focused_editor_mut_targets_focused_field() {
form.fields[0].widget.set_text("a");
form.fields[1].widget.set_text("b");
form.focused_editor_mut()
.expect("focused field")
.insert_char('x');
assert_eq!(form.fields[0].widget.value(), "ax");
.insert_char('y');
assert_eq!(form.fields[1].widget.value(), "by");
fn transaction_create_form_has_four_fields() {
let form = Form::transaction_create();
assert_eq!(form.fields.len(), 4);
assert_eq!(form.fields[0].label, "Date");
assert_eq!(form.fields[1].label, "Note");
assert_eq!(form.fields[2].label, "Tags");
assert_eq!(form.fields[3].label, "Splits");