Lines
98.98 %
Functions
100 %
Branches
//! Two windows of one kind: a reply reaches the window that asked and no other.
use super::*;
use crate::tabs::list::ListTab;
use crate::tabs::reports::{ReportKind, ReportsTab};
use crate::tabs::ssh_keys::SshKeysTab;
use crate::window::{View, WindowId};
use forms::FormValues;
fn error_wire(id: i64) -> String {
format!(r#"(:id {id} :error (:code db :message "boom"))"#)
}
fn list_state(app: &mut App, window: WindowId) -> Option<Fetch<Vec<ListRow>>> {
app.win_mut::<ListTab>(window)
.map(|list| list.state.clone())
fn keys_state(app: &mut App, window: WindowId) -> Option<Fetch<()>> {
app.win_mut::<SshKeysTab>(window)
.map(|keys| keys.state.clone())
fn loading_id<T>(state: Option<Fetch<T>>) -> anyhow::Result<i64> {
match state {
Some(Fetch::Loading { id }) => Ok(id),
_ => anyhow::bail!("not loading"),
fn second_transactions(app: &mut App) -> WindowId {
app.open_new_window(View::List(ViewId::Transactions, ListTab::paged()))
#[tokio::test]
async fn a_page_reply_reaches_only_its_transactions_window() -> anyhow::Result<()> {
let mut app = crate::test_support::app();
app.attach_echo();
let first = app.window_of(ViewId::Transactions);
let second = second_transactions(&mut app);
app.ensure_list_loaded(first);
app.ensure_list_loaded(second);
let id = loading_id(list_state(&mut app, first))?;
let other = loading_id(list_state(&mut app, second))?;
app.route_reply(id, &error_wire(id));
assert!(matches!(list_state(&mut app, first), Some(Fetch::Error(_))));
assert_eq!(
list_state(&mut app, second),
Some(Fetch::Loading { id: other })
);
Ok(())
#[test]
fn a_report_reply_reaches_only_its_reports_window() {
let first = app.window_of(ViewId::Reports);
let second = app.open_new_window(View::Reports(ReportsTab::new()));
let route = Route {
target: Some(first),
ctx: RouteCtx::Reports {
kind: ReportKind::Balance,
seq: 0,
values: FormValues::default(),
},
};
app.deliver_reply(route, &error_wire(1));
assert!(matches!(
app.win_mut::<ReportsTab>(first)
.map(|tab| tab.state.clone()),
Some(Fetch::Error(_))
));
app.win_mut::<ReportsTab>(second)
Some(Fetch::Idle)
async fn a_list_reply_reaches_only_its_ssh_keys_window() -> anyhow::Result<()> {
let first = app.window_of(ViewId::SshKeys);
let second = app.open_new_window(View::SshKeys(SshKeysTab::new()));
app.fetch_ssh_keys(first);
app.fetch_ssh_keys(second);
let id = loading_id(keys_state(&mut app, first))?;
let other = loading_id(keys_state(&mut app, second))?;
assert!(matches!(keys_state(&mut app, first), Some(Fetch::Error(_))));
keys_state(&mut app, second),
async fn a_reply_to_a_closed_window_is_dropped() -> anyhow::Result<()> {
let waiting = loading_id(keys_state(&mut app, first))?;
let id = 900;
app.pending_routes.insert(
id,
Route {
target: Some(second),
ctx: RouteCtx::SshKeyRemove {
fingerprint: "fp".into(),
app.close_window(second);
keys_state(&mut app, first),
Some(Fetch::Loading { id: waiting })
assert!(!app.pending_routes.contains_key(&id));
assert!(app.status.is_empty());