Lines
100 %
Functions
Branches
//! The list windows own the ids of their requests: a reply is applied only by the window that awaits it.
use forms::FormValues;
use crate::modal::Modal;
use crate::route::{Route, RouteCtx, ScriptRoute, TemplateRoute};
use crate::tabs::config::ConfigTab;
use crate::tabs::fetch::Fetch;
use crate::tabs::reports::ReportKind;
use crate::tabs::scripts::ScriptsTab;
use crate::tabs::seq::Seq;
use crate::tabs::ssh_keys::SshKeysTab;
use crate::tabs::tags::TagsTab;
use crate::tabs::templates::TemplatesTab;
use crate::view::ViewId;
const EMPTY_BALANCES: &str =
"(:id 1 :value \"(:balance-report :periods ((:label nil :roots ())))\")";
#[test]
fn a_balances_reply_is_applied_only_when_the_accounts_window_awaits_it() {
let mut app = crate::test_support::app();
let first = app.accounts_mut().balances_seq.advance();
let second = app.accounts_mut().balances_seq.advance();
assert!(app.accounts().balances_loading());
app.deliver_account_balances(
app.window_of(crate::view::ViewId::Accounts),
first,
EMPTY_BALANCES,
);
second,
assert!(!app.accounts().balances_loading());
}
fn a_filter_reply_is_applied_only_when_the_transactions_window_awaits_it() {
let mut filter = FormValues::default();
filter.set("account", "a1");
let first = app.transactions_mut().filter_seq.advance();
let second = app.transactions_mut().filter_seq.advance();
let wire = "(:id 1 :value nil)";
app.deliver_filter_reply(
app.window_of(crate::view::ViewId::Transactions),
&filter,
"stale".into(),
wire,
assert_eq!(app.transactions().filter().text("account"), None);
"fresh".into(),
assert_eq!(app.transactions().filter().text("account"), Some("a1"));
const NIL_REPLY: &str = "(:id 1 :value nil)";
fn reply(app: &mut crate::app::App, view: ViewId, ctx: RouteCtx, wire: &str) {
app.deliver_reply(
Route {
target: Some(app.window_of(view)),
ctx,
},
macro_rules! list_window_ownership {
($name:ident, $tab:ty, $view:expr, $ctx:expr) => {
fn $name() {
let window = app.window_of($view);
let (first, second) = {
let seq = &mut app.win_mut::<$tab>(window).expect("tab").seq;
(seq.advance(), seq.advance())
};
reply(&mut app, $view, $ctx(first), NIL_REPLY);
assert!(app.win::<$tab>(window).expect("tab").is_idle());
reply(&mut app, $view, $ctx(second), NIL_REPLY);
assert!(!app.win::<$tab>(window).expect("tab").is_idle());
list_window_ownership!(
a_tags_reply_is_applied_only_when_the_tags_window_awaits_it,
TagsTab,
ViewId::Tags,
|seq| RouteCtx::Tags { seq }
an_ssh_keys_reply_is_applied_only_when_the_keys_window_awaits_it,
SshKeysTab,
ViewId::SshKeys,
|seq| RouteCtx::SshKeys { seq }
a_config_reply_is_applied_only_when_the_config_window_awaits_it,
ConfigTab,
ViewId::Config,
|seq| RouteCtx::Config { seq }
a_templates_reply_is_applied_only_when_the_templates_window_awaits_it,
TemplatesTab,
ViewId::Templates,
|seq| RouteCtx::Template(TemplateRoute::List { seq })
a_scripts_reply_is_applied_only_when_the_scripts_window_awaits_it,
ScriptsTab,
ViewId::Scripts,
|seq| RouteCtx::Script(ScriptRoute::List { seq })
fn two_ids(seq: &mut Seq) -> (u64, u64) {
fn a_report_reply_is_applied_only_when_the_reports_window_awaits_it() {
let (first, second) = two_ids(&mut app.reports_mut().run_seq);
let ctx = |seq| RouteCtx::Reports {
kind: ReportKind::Balance,
seq,
values: FormValues::default(),
reply(&mut app, ViewId::Reports, ctx(first), NIL_REPLY);
assert!(matches!(app.reports().state, Fetch::Idle));
reply(&mut app, ViewId::Reports, ctx(second), NIL_REPLY);
assert!(!matches!(app.reports().state, Fetch::Idle));
fn a_csv_reply_is_applied_only_when_the_reports_window_awaits_it() {
let (first, second) = two_ids(&mut app.reports_mut().csv_seq);
let wire = "(:id 1 :value \"a,b\")";
let ctx = |seq| RouteCtx::ReportCsv {
file_name: "r.csv".into(),
reply(&mut app, ViewId::Reports, ctx(first), wire);
assert!(!matches!(app.overlays.top(), Some(Modal::Csv(_))));
reply(&mut app, ViewId::Reports, ctx(second), wire);
assert!(matches!(app.overlays.top(), Some(Modal::Csv(_))));