Lines
100 %
Functions
Branches
use super::open::app_on;
use super::report_chart::env;
use crate::app::App;
use crate::app::windows::desktop_area;
use ratatui::layout::Rect;
use rpc::chart::ChartBackend;
use tvui::{Place, Window};
fn place_front(app: &mut App, rect: Rect) {
let id = app.front_window().expect("a front window");
let window = app.desktop.window(id).expect("it is open");
app.desktop.restore(Window {
place: Place::from(rect),
zoomed: false,
..window
});
}
fn front_place(app: &App) -> Place {
let place = app.desktop.restored_place(id, app.desktop_rect());
place.expect("it is open")
fn resize_to(app: &mut App, width: u16, height: u16) {
app.sync_terminal(env(width, height, ChartBackend::Halfblocks));
#[test]
fn a_shrinking_terminal_scales_the_windows_with_it() {
let mut app = app_on(80, 24);
let before = desktop_area(env(80, 24, ChartBackend::Halfblocks));
place_front(&mut app, Rect::new(40, before.y + 4, 30, 10));
resize_to(&mut app, 40, 24);
let place = front_place(&app);
assert_eq!((place.x, place.width), (20, 16));
assert_eq!((place.y, place.height), (i32::from(before.y) + 4, 10));
fn a_shrunk_window_keeps_its_minimum_and_stays_usable() {
place_front(&mut app, Rect::new(60, 18, 20, 6));
resize_to(&mut app, 30, 10);
let area = app.desktop_rect();
assert!(place.width >= 16 && place.height >= 3, "{place:?}");
assert!(place.visible_in(area).width >= 2, "{place:?}");
assert!(!place.visible_in(area).is_empty());
fn growing_the_terminal_again_scales_back() {
let start = Rect::new(50, 10, 30, 8);
place_front(&mut app, start);
resize_to(&mut app, 40, 12);
resize_to(&mut app, 80, 24);
assert!(place.x >= 40 && place.x <= 55, "{place:?}");
assert!(place.width >= 30, "{place:?}");
fn an_unchanged_screen_leaves_the_windows_alone() {
place_front(&mut app, Rect::new(50, 10, 30, 8));
let before = front_place(&app);
assert_eq!(front_place(&app), before);