Lines
99.53 %
Functions
100 %
Branches
//! F6, S-F6 and F5: the stack of windows rotates and zooming uncovers what is behind.
use super::report_chart::{
call_for, chart_requests, echoed, env, png_wire, rendered, show, stripes, text, with_table,
};
use crate::app::App;
use crate::event::{Intent, apply};
use crate::test_support::{ctrl, key, press};
use crate::view::ViewId;
use crate::window::WindowId;
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use rpc::chart::ChartBackend;
fn shift(code: KeyCode) -> KeyEvent {
KeyEvent::new(code, KeyModifiers::SHIFT)
}
fn loads_of(app: &App, window: WindowId) -> usize {
app.pending_routes
.values()
.filter(|route| route.target == Some(window))
.count()
fn is_zoomed(app: &App, window: WindowId) -> bool {
app.desktop
.iter_back_to_front()
.any(|slot| slot.id == window && slot.zoomed)
#[test]
fn f6_from_the_start_walks_the_views_in_their_order() {
let mut app = crate::test_support::app();
let mut seen = Vec::new();
for _ in 0..ViewId::ALL.len() {
press(&mut app, key(KeyCode::F(6)));
seen.extend(app.front_kind());
assert_eq!(
seen,
[
ViewId::Transactions,
ViewId::Commodities,
ViewId::Reports,
ViewId::Config,
ViewId::SshKeys,
ViewId::Tags,
ViewId::Templates,
ViewId::Console,
ViewId::Scripts,
ViewId::Accounts,
]
);
fn f6_raises_the_rearmost_window_and_the_stack_rotates() {
let rearmost = app.desktop.rearmost();
let front = app.front_window();
assert_eq!(app.front_window(), rearmost);
app.desktop.iter_back_to_front().last().map(|w| w.id),
rearmost
assert_eq!(app.desktop.iter_back_to_front().nth(8).map(|w| w.id), front);
fn shift_f6_sends_the_front_window_to_the_back() {
let accounts = app.window_of(ViewId::Accounts);
press(&mut app, shift(KeyCode::F(6)));
assert_eq!(app.desktop.rearmost(), Some(accounts));
assert_eq!(app.front_kind(), Some(ViewId::Scripts));
assert_eq!(app.front_kind(), Some(ViewId::Console));
fn tab_and_shift_tab_no_longer_rotate_the_windows() {
let order: Vec<WindowId> = app.desktop.iter_back_to_front().map(|w| w.id).collect();
press(&mut app, key(KeyCode::Tab));
press(&mut app, shift(KeyCode::BackTab));
let after: Vec<WindowId> = app.desktop.iter_back_to_front().map(|w| w.id).collect();
assert_eq!(after, order);
assert_eq!(app.front_kind(), Some(ViewId::Accounts));
fn next_and_previous_with_a_single_window_stay_on_it() {
for kind in ViewId::ALL.into_iter().skip(1) {
app.close_window(app.window_of(kind));
fn next_and_previous_do_nothing_on_the_empty_desktop() {
while app.front_window().is_some() {
app.close_front_window();
press(&mut app, key(KeyCode::F(5)));
assert_eq!(app.front_window(), None);
fn both_leave_the_console_prompt() {
for code in [key(KeyCode::F(6)), shift(KeyCode::F(6))] {
app.focus_console();
press(&mut app, code);
assert!(!app.console_input_focused(), "{code:?}");
assert_ne!(app.front_kind(), Some(ViewId::Console), "{code:?}");
#[tokio::test]
async fn next_loads_the_window_it_raises() {
app.attach_echo();
let transactions = app.window_of(ViewId::Transactions);
assert_eq!(loads_of(&app, transactions), 0);
assert_eq!(loads_of(&app, transactions), 1);
async fn previous_loads_the_window_that_comes_to_the_front() {
app.switch_tab(ViewId::Scripts);
assert_eq!(loads_of(&app, accounts), 0);
assert_eq!(app.front_window(), Some(accounts));
assert_eq!(loads_of(&app, accounts), 1);
fn f5_zooms_and_restores_the_front_window() {
assert!(is_zoomed(&app, accounts));
assert!(!is_zoomed(&app, accounts));
async fn unzooming_loads_the_window_it_uncovers() {
app.sync_terminal(env(80, 24, ChartBackend::Halfblocks));
app.switch_tab(ViewId::Commodities);
async fn zooming_again_does_not_load_a_window_twice() {
for _ in 0..4 {
async fn zooming_a_reports_window_fetches_its_chart_at_the_new_size() {
let (mut app, sent) = with_table(40, 20, ChartBackend::Halfblocks);
show(&mut app);
assert_eq!(chart_requests(&app).len(), 1);
assert_eq!(chart_requests(&app).len(), 2);
// 40x20 screen: the 60x16 start rect at (3, 3) is cut to the desktop's width, 40x16 cells in
// full (it hangs 3 columns off the right), 38x14 inside the border.
assert!(echoed(&mut app, &sent).await.contains(&call_for(380, 280)));
fn control_r_refreshes_and_plain_r_does_not() {
app.switch_tab(ViewId::Accounts);
app.set_status("old");
press(&mut app, ctrl(KeyCode::Char('r')));
assert_ne!(app.status, "old");
press(&mut app, key(KeyCode::Char('r')));
assert_eq!(app.status, "old");
/// A Reports window showing a kitty chart that has been drawn once; returns its image id.
pub(super) fn drawn_kitty_chart() -> (App, u32) {
let (mut app, _) = with_table(40, 20, ChartBackend::Kitty);
answer_chart(&mut app);
let image = crate::tabs::reports::chart::kitty_image_id(app.window_of(ViewId::Reports));
app.take_outbound();
assert!(text(&rendered(&app, 40, 20)).contains("a=T"));
(app, image)
pub(super) fn answer_chart(app: &mut App) {
let Some(id) = chart_requests(app).last().copied() else {
panic!("a chart request");
app.route_reply(id, &png_wire(id, stripes(380, 320)));
async fn zooming_and_unzooming_delete_the_kitty_image_before_it_is_drawn_again() {
let (mut app, image) = drawn_kitty_chart();
let deleted = vec![tvui::kitty_delete(image)];
for _ in 0..2 {
assert_eq!(app.take_outbound(), deleted);
async fn tiling_and_cascading_delete_the_kitty_image_and_fetch_the_chart_again() {
for intent in [Intent::Tile, Intent::Cascade] {
let before = chart_requests(&app).len();
apply(&mut app, intent);
app.take_outbound(),
vec![tvui::kitty_delete(image)],
"{intent:?}"
assert_eq!(chart_requests(&app).len(), before + 1, "{intent:?}");
async fn zooming_again_fetches_the_chart_again() {
let (mut app, _) = with_table(40, 20, ChartBackend::Halfblocks);
for expected in [2, 3] {
assert_eq!(chart_requests(&app).len(), expected);
async fn previous_with_a_single_window_keeps_its_kitty_image() {
let (mut app, _) = drawn_kitty_chart();
for kind in ViewId::ALL {
if kind != ViewId::Reports {
assert!(app.take_outbound().is_empty());
assert!(!text(&rendered(&app, 40, 20)).contains("a=T"));