1
use super::*;
2
use ratatui::Terminal;
3
use ratatui::backend::TestBackend;
4

            
5
const USER: Uuid = Uuid::from_u128(0xbf4f_e43d_1ed0_45e2_b2f7_fe0a_d929_68c7);
6

            
7
#[test]
8
1
fn the_tail_is_the_short_user_then_the_indicator() {
9
1
    assert_eq!(status_tail(USER, "[cua]"), "user=bf4fe43d  [cua]");
10
1
}
11

            
12
8
fn bottom_row(width: u16, tab: crate::view::Tab) -> String {
13
8
    let mut app = crate::test_support::app_for(USER);
14
8
    app.switch_tab(tab);
15
8
    let mut terminal = Terminal::new(TestBackend::new(width, 24)).expect("test terminal");
16
8
    terminal
17
8
        .draw(|frame| crate::draw::draw(frame, &app, &mut crate::hits::Hits::default()))
18
8
        .expect("draw");
19
8
    let buffer = terminal.backend().buffer();
20
880
    (0..width).map(|x| buffer[(x, 23)].symbol()).collect()
21
8
}
22

            
23
#[test]
24
1
fn the_short_user_and_the_indicator_are_always_on_the_bar() {
25
    use crate::view::Tab;
26
1
    for tab in [Tab::Console, Tab::Tags, Tab::Transactions] {
27
3
        for width in [80, 120] {
28
6
            let row = bottom_row(width, tab);
29
6
            assert!(row.contains("user=bf4fe43d"), "{tab:?} {width}: {row}");
30
6
            assert!(row.trim_end().ends_with("[cua]"), "{row}");
31
6
            assert!(row.contains("F10 Menu"), "{row}");
32
        }
33
    }
34
1
}
35

            
36
#[test]
37
1
fn the_console_keeps_its_hints_at_80_columns() {
38
1
    let row = bottom_row(80, crate::view::Tab::Console);
39
1
    assert!(row.contains("i Focus"), "{row}");
40
1
}
41

            
42
#[test]
43
1
fn the_user_is_short_however_wide_the_bar_is() {
44
1
    let wide = bottom_row(200, crate::view::Tab::Tags);
45
1
    assert!(wide.contains("user=bf4fe43d"), "{wide}");
46
1
    assert!(!wide.contains("bf4fe43d-1ed0"), "{wide}");
47
1
}