1
//! `acts` is the one answer to "does this intent do anything here".
2

            
3
use super::*;
4
use crate::form::Form;
5
use crate::test_support::app;
6

            
7
6
fn app_on(tab: Tab) -> App {
8
6
    let mut app = app();
9
6
    app.switch_tab(tab);
10
6
    app
11
6
}
12

            
13
#[test]
14
1
fn new_and_delete_row_act_only_on_the_tabs_that_handle_them() {
15
1
    for (tab, new, delete) in [
16
1
        (Tab::Accounts, true, false),
17
1
        (Tab::Transactions, true, true),
18
1
        (Tab::Commodities, true, false),
19
1
        (Tab::Config, true, false),
20
1
        (Tab::Tags, true, true),
21
1
    ] {
22
5
        let app = app_on(tab);
23
5
        assert_eq!(acts(&app, Intent::NewRow), new, "{tab:?} new");
24
5
        assert_eq!(acts(&app, Intent::DeleteRow), delete, "{tab:?} delete");
25
    }
26
1
    assert!(!acts(&app_on(Tab::SshKeys), Intent::EditRow));
27
1
}
28

            
29
#[test]
30
1
fn quit_does_not_act_under_a_modal() {
31
1
    let mut app = app();
32
1
    assert!(acts(&app, Intent::Quit));
33
1
    app.overlays.push(Modal::Form(Form::config_set()));
34
1
    assert!(!acts(&app, Intent::Quit));
35
1
}
36

            
37
#[test]
38
1
fn help_acts_with_a_help_window_or_a_form_open() {
39
1
    let mut app = app();
40
1
    assert!(acts(&app, Intent::OpenHelp));
41
1
    apply(&mut app, Intent::OpenHelp);
42
1
    assert!(acts(&app, Intent::OpenHelp));
43
1
    app.overlays.push(Modal::Form(Form::config_set()));
44
1
    assert!(acts(&app, Intent::OpenHelp));
45
1
}
46

            
47
#[test]
48
1
fn form_keys_act_only_where_the_focused_field_takes_them() {
49
1
    let mut app = app();
50
1
    app.overlays.push(Modal::Form(Form::config_set()));
51
1
    assert!(!acts(&app, Intent::ToggleSplitTags));
52
1
    assert!(!acts(&app, Intent::OpenFilterBuilder));
53
1
    app.overlays.pop();
54
1
    app.overlays.push(Modal::Form(Form::template_create()));
55
1
    assert!(acts(&app, Intent::ToggleSplitTags));
56
1
}
57

            
58
#[test]
59
1
fn an_intent_with_no_rule_acts() {
60
1
    assert!(acts(&app(), Intent::MoveLeft));
61
1
}