1
use super::{MAX_HEIGHT, MIN_HEIGHT, Placement, Span, placement, roomy};
2

            
3
const PHONE: Span = Span {
4
    top: 0.0,
5
    bottom: 400.0,
6
};
7

            
8
8
fn input_at(top: f64) -> Span {
9
8
    Span {
10
8
        top,
11
8
        bottom: top + 30.0,
12
8
    }
13
8
}
14

            
15
#[test]
16
1
fn an_input_near_the_top_opens_below_capped_at_the_maximum() {
17
1
    let at = placement(input_at(20.0), PHONE, 500.0);
18
1
    assert_eq!(
19
1
        at,
20
1
        Placement {
21
1
            above: false,
22
1
            max_height: MAX_HEIGHT
23
1
        }
24
    );
25
1
}
26

            
27
#[test]
28
1
fn an_input_near_the_bottom_opens_above_within_the_room() {
29
1
    let at = placement(input_at(330.0), PHONE, 500.0);
30
1
    assert!(at.above);
31
1
    assert_eq!(at.max_height, MAX_HEIGHT);
32
1
    let short = Span {
33
1
        top: 0.0,
34
1
        bottom: 300.0,
35
1
    };
36
1
    let tight = placement(input_at(150.0), short, 500.0);
37
1
    assert!(tight.above);
38
1
    assert_eq!(tight.max_height, 142.0);
39
1
}
40

            
41
#[test]
42
1
fn a_short_list_stays_below_while_it_fits() {
43
1
    let at = placement(input_at(300.0), PHONE, 60.0);
44
1
    assert!(!at.above);
45
1
    assert_eq!(at.max_height, MIN_HEIGHT);
46
1
}
47

            
48
#[test]
49
1
fn the_visual_viewport_offset_counts() {
50
1
    let keyboard = Span {
51
1
        top: 300.0,
52
1
        bottom: 650.0,
53
1
    };
54
1
    let at = placement(input_at(560.0), keyboard, 500.0);
55
1
    assert!(at.above);
56
1
    assert_eq!(at.max_height, 200.0);
57
1
    assert!(at.max_height <= 560.0 - keyboard.top);
58
1
}
59

            
60
#[test]
61
1
fn the_cap_never_drops_below_three_items() {
62
1
    let squeezed = Span {
63
1
        top: 0.0,
64
1
        bottom: 150.0,
65
1
    };
66
1
    assert!(!roomy(input_at(60.0), squeezed));
67
1
    assert_eq!(
68
1
        placement(input_at(60.0), squeezed, 500.0).max_height,
69
1
        MIN_HEIGHT
70
    );
71
1
    assert!(roomy(input_at(20.0), PHONE));
72
1
}