Lines
100 %
Functions
Branches
//! Tile, Cascade and Close all.
use super::report_chart::env;
use crate::app::App;
use crate::event::{Intent, acts, apply};
use crate::form::Form;
use crate::route::{Route, RouteCtx};
use crate::view::ViewId;
use crate::window::WindowId;
use ratatui::layout::Rect;
use rpc::chart::ChartBackend;
fn rect_of(app: &App, id: WindowId) -> Option<Rect> {
let place = app.desktop.restored_place(id, app.desktop_rect())?;
Some(place.visible_in(app.desktop_rect()))
}
fn rects(app: &App) -> Vec<Option<Rect>> {
let slots = app.desktop.iter_back_to_front();
slots.map(|slot| rect_of(app, slot.id)).collect()
fn all_unzoomed(app: &App) -> bool {
app.desktop.iter_back_to_front().all(|slot| !slot.zoomed)
#[test]
fn tile_lays_ten_windows_out_from_the_rearmost_one() {
let mut app = crate::test_support::app();
app.toggle_zoom_of(ViewId::Transactions);
let (front, rearmost) = (app.front_window(), app.desktop.rearmost());
apply(&mut app, Intent::Tile);
assert_eq!(
rearmost.and_then(|id| rect_of(&app, id)),
Some(Rect::new(0, 1, 26, 7))
);
front.and_then(|id| rect_of(&app, id)),
Some(Rect::new(53, 17, 27, 6))
assert!(all_unzoomed(&app));
assert_eq!(app.front_window(), front);
fn tile_on_a_bigger_terminal_uses_the_whole_desktop() {
app.sync_terminal(env(120, 36, ChartBackend::Halfblocks));
app.tile_windows();
let area = app.desktop_rect();
let sum: u32 = rects(&app).iter().flatten().map(|rect| rect.area()).sum();
assert_eq!(sum, area.area());
fn tile_with_no_room_says_so_and_moves_nothing() {
app.sync_terminal(env(80, 4, ChartBackend::Halfblocks));
app.toggle_zoom_of(ViewId::Tags);
let before = rects(&app);
assert_eq!(app.status, "too many windows");
assert_eq!(rects(&app), before);
assert!(!all_unzoomed(&app));
fn cascade_steps_from_the_rearmost_window_and_keeps_the_corner() {
app.toggle_zoom_of(ViewId::Reports);
let front = app.front_window();
apply(&mut app, Intent::Cascade);
let found = rects(&app);
for (step, rect) in (0u16..).zip(&found) {
let expected = Rect::new(
area.x + step,
area.y + step,
area.width - step,
area.height - step,
assert_eq!(*rect, Some(expected), "window {step}");
fn cascade_with_no_room_says_so_and_moves_nothing() {
app.sync_terminal(env(80, 14, ChartBackend::Halfblocks));
app.cascade_windows();
fn close_all_leaves_the_desktop_empty() {
apply(&mut app, Intent::CloseAll);
assert!(app.windows.is_empty());
assert_eq!(app.front_window(), None);
assert!(!acts(&app, Intent::CloseAll));
fn close_all_settles_the_form_of_a_window() {
let accounts = app.window_of(ViewId::Accounts);
app.pending_routes.insert(
5,
Route {
target: Some(accounts),
ctx: RouteCtx::None,
},
app.lock_pending_form(5, Form::config_set());
app.close_all_windows();
assert!(app.pending_form.is_none());
assert!(app.status.contains("window closed"), "{}", app.status);
fn the_arrange_commands_need_a_window() {
let app = crate::test_support::empty_app();
for intent in [Intent::Tile, Intent::Cascade, Intent::CloseAll] {
assert!(!acts(&app, intent), "{intent:?}");
fn close_all_waits_while_a_dialog_is_open() {
app.overlays
.push(crate::modal::Modal::Form(Form::config_set()));
assert_eq!(app.windows.len(), ViewId::ALL.len());