1
//! Tests for the generic Form type.
2

            
3
mod carried;
4
mod choice;
5
mod config;
6
mod convert;
7
mod create;
8
mod report;
9
mod rows;
10
mod split_tags;
11
mod suggest;
12
mod tags;
13
mod transaction;
14
mod uncarried;
15

            
16
use super::*;
17

            
18
#[test]
19
1
fn cycle_forward_walks_the_fields_then_the_buttons_and_wraps() {
20
1
    let mut form = Form::config_set();
21
1
    let mut seen = Vec::new();
22
1
    for _ in 0..5 {
23
5
        seen.push((form.focus, form.focused_button()));
24
5
        form.cycle(true);
25
    }
26
1
    assert_eq!(
27
1
        seen,
28
1
        [(0, None), (1, None), (2, Some(0)), (3, Some(1)), (0, None)]
29
    );
30
1
}
31

            
32
#[test]
33
1
fn cycle_backward_goes_from_the_first_field_to_the_last_button() {
34
1
    let mut form = Form::config_set();
35
1
    form.cycle(false);
36
1
    assert_eq!((form.focus, form.focused_button()), (3, Some(1)));
37
1
    form.cycle(false);
38
1
    assert_eq!((form.focus, form.focused_button()), (2, Some(0)));
39
1
    form.cycle(false);
40
1
    assert_eq!((form.focus, form.focused_button()), (1, None));
41
1
}
42

            
43
#[test]
44
1
fn no_field_is_focused_on_a_button() {
45
1
    let mut form = Form::config_set();
46
1
    form.focus = 2;
47
1
    assert!(form.focused_field_mut().is_none());
48
1
    assert_eq!(form.focused_widget_kind(), None);
49
1
}
50

            
51
#[test]
52
1
fn focused_editor_mut_targets_focused_field() {
53
1
    let mut form = Form::config_set();
54
1
    form.fields[0].widget.set_text("a");
55
1
    form.fields[1].widget.set_text("b");
56
1
    form.focused_editor_mut()
57
1
        .expect("focused field")
58
1
        .insert_char('x');
59
1
    assert_eq!(form.fields[0].widget.value(), "ax");
60
1
    form.cycle(true);
61
1
    form.focused_editor_mut()
62
1
        .expect("focused field")
63
1
        .insert_char('y');
64
1
    assert_eq!(form.fields[1].widget.value(), "by");
65
1
}
66

            
67
#[test]
68
1
fn transaction_create_form_has_four_fields() {
69
1
    let form = Form::transaction_create();
70
1
    assert_eq!(form.fields.len(), 4);
71
1
    assert_eq!(form.fields[0].label, "Date");
72
1
    assert_eq!(form.fields[1].label, "Note");
73
1
    assert_eq!(form.fields[2].label, "Tags");
74
1
    assert_eq!(form.fields[3].label, "Splits");
75
1
}