1
//! A click on any cell of the `▐↓▌` mark of a form select field opens its list.
2

            
3
use super::caret_tests::{form_mut, select_field, with_field};
4
use super::click_tests::{now, presets, press};
5
use super::*;
6
use crate::test_support::{area_of, redraw};
7
use tvui::HISTORY_CELLS;
8

            
9
13
fn mark() -> Target {
10
13
    Target::Mark {
11
13
        field: 0,
12
13
        cell: None,
13
13
    }
14
13
}
15

            
16
9
fn click_cell(app: &mut App, dx: u16) {
17
9
    redraw(app);
18
9
    let area = area_of(app, mark());
19
9
    let position = Position::new(area.x + dx, area.y);
20
9
    press(
21
9
        app,
22
9
        position,
23
9
        MouseEventKind::Down(MouseButton::Left),
24
9
        now(),
25
9
    );
26
9
}
27

            
28
#[test]
29
1
fn a_click_on_each_cell_of_the_mark_opens_the_unfocused_select() {
30
1
    for dx in 0..HISTORY_CELLS {
31
3
        for app in presets() {
32
9
            let mut app = with_field(app, select_field());
33
9
            form_mut(&mut app).focus = 1;
34
9
            click_cell(&mut app, dx);
35
9
            let form = form_mut(&mut app);
36
9
            assert_eq!(form.focus, 0, "cell {dx}");
37
9
            assert!(
38
9
                form.focused_select().is_some_and(|select| select.open),
39
                "cell {dx}"
40
            );
41
        }
42
    }
43
1
}
44

            
45
#[test]
46
1
fn the_cell_before_the_mark_only_focuses_the_select() {
47
1
    for app in presets() {
48
3
        let mut app = with_field(app, select_field());
49
3
        form_mut(&mut app).focus = 1;
50
3
        redraw(&mut app);
51
3
        let area = area_of(&app, mark());
52
3
        let position = Position::new(area.x - 1, area.y);
53
3
        press(
54
3
            &mut app,
55
3
            position,
56
3
            MouseEventKind::Down(MouseButton::Left),
57
3
            now(),
58
3
        );
59
3
        let form = form_mut(&mut app);
60
3
        assert_eq!(form.focus, 0);
61
3
        assert!(form.focused_select().is_some_and(|select| !select.open));
62
    }
63
1
}
64

            
65
#[test]
66
1
fn a_click_past_the_mark_does_not_open_the_select() {
67
1
    let mut app = with_field(crate::test_support::app(), select_field());
68
1
    form_mut(&mut app).focus = 1;
69
1
    redraw(&mut app);
70
1
    let area = area_of(&app, mark());
71
1
    let position = Position::new(area.right(), area.y);
72
1
    press(
73
1
        &mut app,
74
1
        position,
75
1
        MouseEventKind::Down(MouseButton::Left),
76
1
        now(),
77
1
    );
78
1
    assert!(
79
1
        form_mut(&mut app)
80
1
            .focused_select()
81
1
            .is_none_or(|select| !select.open)
82
    );
83
1
}