Lines
100 %
Functions
Branches
//! The list windows the app creates at startup and the lookups over them.
use super::*;
use crate::tabs::config::ConfigTab;
use crate::tabs::list::ListTab;
use crate::tabs::nms::ConsoleState;
use crate::tabs::reports::ReportsTab;
use crate::tabs::scripts::ScriptsTab;
use crate::tabs::ssh_keys::SshKeysTab;
use crate::tabs::tags::TagsTab;
use crate::tabs::templates::TemplatesTab;
use crate::window::{View, WindowId};
#[test]
fn each_list_kind_has_its_window() {
let mut app = crate::test_support::app();
for kind in [ViewId::Accounts, ViewId::Transactions, ViewId::Commodities] {
assert!(
app.win_mut::<ListTab>(app.window_of(kind)).is_some(),
"{kind:?}"
);
assert_eq!(app.window_view(app.window_of(kind)), Some(kind));
}
fn startup_windows_have_distinct_ids() {
let app = crate::test_support::app();
let ids: std::collections::HashSet<_> = ViewId::ALL
.into_iter()
.map(|kind| app.window_of(kind))
.collect();
assert_eq!(ids.len(), ViewId::ALL.len());
fn a_front_list_is_the_front_window_of_that_kind_only() {
assert!(app.front_list(ViewId::Accounts).is_some());
assert!(app.front_list(ViewId::Transactions).is_none());
assert!(app.front_list(ViewId::Reports).is_none());
fn each_single_view_has_its_window() {
app.win_mut::<ReportsTab>(app.window_of(ViewId::Reports))
.is_some()
app.win_mut::<ConfigTab>(app.window_of(ViewId::Config))
app.win_mut::<SshKeysTab>(app.window_of(ViewId::SshKeys))
app.win_mut::<TagsTab>(app.window_of(ViewId::Tags))
app.win_mut::<TemplatesTab>(app.window_of(ViewId::Templates))
app.win_mut::<ScriptsTab>(app.window_of(ViewId::Scripts))
app.win_mut::<ConsoleState>(app.window_of(ViewId::Console))
for kind in ViewId::ALL {
fn no_last_report_before_one_ran() {
assert!(app.last_report(app.window_of(ViewId::Reports)).is_none());
fn a_reply_window_is_a_list_window_only() {
app.win_mut::<ListTab>(app.window_of(ViewId::Config))
.is_none()
assert!(app.win_mut::<ListTab>(WindowId(u32::MAX)).is_none());
fn a_gone_window_has_no_view() {
assert_eq!(app.window_view(WindowId(u32::MAX)), None);
fn a_lookup_takes_the_most_recent_window_of_its_kind() {
let mut newer = ConfigTab::new();
newer.follow = Some("newer".into());
let id = app.open_new_window(View::Config(newer));
assert_eq!(app.config().follow.as_deref(), Some("newer"));
assert_eq!(app.window_view(id), Some(ViewId::Config));
fn the_active_view_is_the_window_of_the_active_kind() {
app.switch_tab(kind);
assert_eq!(app.active_view().map(View::kind), Some(kind));
assert_eq!(app.active_view_mut().map(|view| view.kind()), Some(kind));
fn the_selected_id_is_read_from_the_front_window_only() {
assert_eq!(app.selected_id(ViewId::Accounts), None);
let rows = || {
Fetch::Loaded(vec![ListRow {
id: Some("a1".into()),
cells: vec!["x".into()],
}])
};
app.accounts_mut().state = rows();
app.transactions_mut().state = rows();
assert_eq!(app.selected_id(ViewId::Accounts).as_deref(), Some("a1"));
assert_eq!(app.selected_id(ViewId::Transactions), None);