1
//! A kitty chart in a window hanging off an edge: shown while its transmit cell is on screen.
2

            
3
use super::report_chart::{env, rendered, text};
4
use super::window_keys::{answer_chart, drawn_kitty_chart};
5
use crate::app::App;
6
use crate::test_support::{key, press};
7
use ratatui::crossterm::event::KeyCode;
8
use rpc::chart::ChartBackend;
9
use tvui::{Place, Window};
10

            
11
3
async fn unzoomed_chart() -> (App, u32) {
12
3
    let (mut app, image) = drawn_kitty_chart();
13
3
    press(&mut app, key(KeyCode::F(5)));
14
3
    answer_chart(&mut app);
15
3
    app.take_outbound();
16
3
    (app, image)
17
3
}
18

            
19
4
fn move_front_to(app: &mut App, x: i32) {
20
4
    let id = app.front_window().expect("a front window");
21
4
    let window = app.desktop.window(id).expect("it is open");
22
4
    let place = Place { x, ..window.place };
23
4
    app.desktop.restore(Window { place, ..window });
24
4
}
25

            
26
#[tokio::test]
27
1
async fn a_chart_off_the_right_edge_keeps_its_image_while_the_corner_shows() {
28
1
    let (mut app, _) = unzoomed_chart().await;
29
1
    move_front_to(&mut app, 20);
30
1
    assert!(text(&rendered(&app, 40, 20)).contains("a=T"));
31
1
}
32

            
33
#[tokio::test]
34
1
async fn a_chart_off_the_left_edge_hides_its_image_with_the_corner() {
35
1
    let (mut app, _) = unzoomed_chart().await;
36
1
    move_front_to(&mut app, -10);
37
1
    assert!(!text(&rendered(&app, 40, 20)).contains("a=T"));
38
1
}
39

            
40
#[tokio::test]
41
1
async fn a_resize_deletes_the_image_whose_corner_is_off_screen_and_only_that() {
42
1
    let (mut app, image) = unzoomed_chart().await;
43
1
    move_front_to(&mut app, 20);
44
1
    app.sync_terminal(env(40, 22, ChartBackend::Kitty));
45
1
    assert!(app.take_outbound().is_empty());
46
1
    answer_chart(&mut app);
47
1
    move_front_to(&mut app, -10);
48
1
    app.sync_terminal(env(40, 20, ChartBackend::Kitty));
49
1
    assert_eq!(app.take_outbound(), vec![tvui::kitty_delete(image)]);
50
1
}