Lines
100 %
Functions
Branches
//! Palette leaves that switch tabs or open the selected entity's edit form.
use crate::app::App;
use crate::event::{Intent, apply};
use crate::route::RouteCtx;
use crate::tabs::fetch::Fetch;
use crate::view::Tab;
use cli_core::render::ListRow;
const ID: &str = "550e8400-e29b-41d4-a716-446655440051";
fn run(app: &mut App, command: &str) {
apply(app, Intent::OpenCommandLine);
command
.chars()
.for_each(|c| apply(app, Intent::InsertChar(c)));
apply(app, Intent::Submit);
}
fn loaded() -> Fetch<Vec<ListRow>> {
Fetch::Loaded(vec![ListRow {
id: Some(ID.to_string()),
cells: vec!["x".to_string()],
}])
fn pending(app: &App) -> Vec<&RouteCtx> {
app.pending_routes
.values()
.map(|route| &route.ctx)
.collect()
#[test]
fn account_list_switches_to_the_accounts_tab() {
let mut app = crate::test_support::app();
run(&mut app, "account list");
assert_eq!(app.front_kind(), Some(Tab::Accounts));
assert!(
app.console().scrollback.is_empty(),
"nothing in the console"
);
fn commodity_list_switches_to_the_commodities_tab() {
run(&mut app, "commodity list");
assert_eq!(app.front_kind(), Some(Tab::Commodities));
fn account_edit_without_a_selection_says_so() {
run(&mut app, "account edit");
assert_eq!(app.status, "no account selected");
fn commodity_edit_without_a_selection_says_so() {
run(&mut app, "commodity edit");
assert_eq!(app.status, "no commodity selected");
#[tokio::test]
async fn account_edit_loads_the_selected_account() {
app.attach_echo();
app.accounts_mut().state = loaded();
assert!(matches!(pending(&app)[..], [RouteCtx::AccountEdit]));
async fn commodity_edit_loads_the_selected_commodity() {
app.commodities_mut().state = loaded();
app.switch_tab(Tab::Commodities);
assert!(matches!(pending(&app)[..], [RouteCtx::CommodityEdit]));
async fn a_palette_edit_raises_its_window_and_edits_that_selection() {
assert!(!app.front_is(Tab::Commodities));
assert!(app.front_is(Tab::Commodities));
async fn a_palette_edit_without_its_window_says_so() {
app.close_window(app.window_of(Tab::Commodities));
assert_eq!(app.status, "no Commodities window");
assert!(app.pending_routes.is_empty());
fn the_removed_account_tag_leaf_is_unknown() {
run(&mut app, "account tag");
assert_eq!(app.status, "unknown command: account tag");