Lines
100 %
Functions
Branches
//! The View menu opens a new window of a view, and every window of a view acts alone.
use super::open::app_on;
use super::*;
use crate::event::{Intent, apply};
use crate::tabs::list::ListTab;
use crate::test_support::{key, press};
use ratatui::crossterm::event::KeyCode;
fn page_wire(ids: &[&str]) -> String {
let rows: String = ids
.iter()
.map(|i| format!(r#"(:ID "{i}" :DATE "2026-10-01T00:00:00Z" :DATE-TEXT "2026-10-01 00:00" :NOTE "n" :AMOUNT "5")"#))
.collect::<Vec<_>>()
.join(" ");
format!(r#"(:id 1 :value (:ROWS ({rows}) :HAS-MORE nil :TOTAL 2))"#)
}
fn deliver(app: &mut App, window: WindowId, wire: &str) {
let route = Route {
target: Some(window),
ctx: RouteCtx::None,
};
app.deliver_reply(route, wire);
fn open_from_menu(app: &mut App, kind: ViewId) {
press(app, key(KeyCode::F(10)));
app.select_menu_item(kind.index());
press(app, key(KeyCode::Enter));
fn loading(app: &App, window: WindowId) -> bool {
app.win_by(window).is_some_and(|win| win.view.loading())
fn marked(app: &mut App, window: WindowId) -> Vec<String> {
app.win_mut::<ListTab>(window)
.map(|list| list.marked_ids())
.unwrap_or_default()
/// Two Transactions windows, the older raised and unzoomed so that both are drawn.
fn two_transactions() -> (App, WindowId, WindowId) {
let mut app = app_on(120, 36);
app.attach_echo();
app.switch_tab(ViewId::Transactions);
app.toggle_zoom();
let first = app.window_of(ViewId::Transactions);
open_from_menu(&mut app, ViewId::Transactions);
let second = app.window_of(ViewId::Transactions);
(app, first, second)
#[tokio::test]
async fn the_view_menu_opens_a_second_window_and_both_load() {
let (app, first, second) = two_transactions();
assert_ne!(first, second);
assert_eq!(app.window_ids(ViewId::Transactions), [second, first]);
assert_eq!(app.front_window(), Some(second));
assert!(loading(&app, first));
assert!(loading(&app, second));
async fn a_key_acts_on_the_front_window_only() {
let (mut app, first, second) = two_transactions();
deliver(&mut app, first, &page_wire(&["a", "b"]));
deliver(&mut app, second, &page_wire(&["a", "b"]));
apply(&mut app, Intent::ListMark);
assert_eq!(marked(&mut app, second), ["a"]);
assert!(marked(&mut app, first).is_empty());
app.activate_window(first);
assert_eq!(marked(&mut app, first), ["a", "b"]);
async fn a_dialog_belongs_to_the_window_it_was_opened_in() {
for window in [second, first, second] {
app.activate_window(window);
apply(&mut app, Intent::ListFilter);
assert_eq!(app.overlays.origin().map(|o| o.window), Some(window));
apply(&mut app, Intent::CloseTopmost);
assert!(app.overlays.is_empty());
async fn every_view_opens_a_second_window_from_the_menu() {
for kind in ViewId::ALL {
let before = app.window_ids(kind);
open_from_menu(&mut app, kind);
let after = app.window_ids(kind);
assert_eq!(after.len(), before.len() + 1, "{kind:?}");
assert_eq!(app.front_window(), after.first().copied(), "{kind:?}");
assert_eq!(app.window_view(after[0]), Some(kind));
#[test]
fn a_view_is_marked_while_one_of_its_windows_is_open() {
let mut app = crate::test_support::app();
let tags = ViewId::Tags.index();
app.open_menu();
assert!(app.menu_entries()[tags].marked);
app.close_menu();
app.close_window(app.window_of(ViewId::Tags));
assert!(!app.menu_entries()[tags].marked);
app.select_menu_item(tags);
apply(&mut app, Intent::MenuSelect);
fn a_digit_raises_the_most_recent_window_of_its_view_and_opens_none() {
let older = app.window_of(ViewId::Transactions);
let newer = app.open_extra(ViewId::Transactions);
app.switch_tab(ViewId::Config);
let count = app.windows.len();
press(&mut app, key(KeyCode::Char('2')));
assert_eq!(app.front_window(), Some(newer));
assert_eq!(app.windows.len(), count);
assert_ne!(Some(older), app.front_window());