Lines
97.37 %
Functions
100 %
Branches
//! The Config tab lists every key from `list-config`; a stale reply is dropped.
use super::App;
use crate::tabs::fetch::Fetch;
fn list_wire(id: i64, entries: &[(&str, &str)]) -> String {
let plists: String = entries
.iter()
.map(|(k, v)| format!(r#"(:KEY "{k}" :VALUE "{v}")"#))
.collect();
format!("(:id {id} :value ({plists}))")
}
fn loading_id(app: &App) -> anyhow::Result<i64> {
match app.config().state {
Fetch::Loading { id } => Ok(id),
ref other => anyhow::bail!("not loading: {other:?}"),
#[tokio::test]
async fn the_reply_populates_the_tab_with_all_keys() -> anyhow::Result<()> {
let mut app = crate::test_support::app();
app.attach_echo();
app.fetch_config(app.window_of(crate::view::ViewId::Config));
let id = loading_id(&app)?;
app.route_reply(id, &list_wire(id, &[("alpha", "1"), ("theme", "dark")]));
let shown: Vec<_> = app
.config()
.rows()
.map(|(k, v)| (k.as_str(), v.as_str()))
assert_eq!(shown, [("alpha", "1"), ("theme", "dark")]);
Ok(())
async fn a_stale_reply_is_dropped() -> anyhow::Result<()> {
let stale = loading_id(&app)?;
let current = loading_id(&app)?;
app.route_reply(stale, &list_wire(stale, &[("old", "x")]));
assert_eq!(app.config().state, Fetch::Loading { id: current });
app.route_reply(current, &list_wire(current, &[("new", "y")]));
assert!(app.config().rows().iter().any(|(k, _)| k == "new"));