Lines
91.67 %
Functions
75 %
Branches
100 %
//! The Options dialog against a real session: a save survives a new attach.
use super::options::{attached_blank, choose, next_field, opened, saves};
use super::report_chart::echoed;
use crate::app::App;
use crate::keymap::VimState;
use crate::tabs::nms_eval::double::Sent;
use crate::test_support::{key, press};
use ratatui::crossterm::event::KeyCode;
use rpc::{ScriptCtx, Session};
use server::lossless::seed;
use sqlx::PgPool;
use tvui::{Role, Theme};
/// Sends the last request of `sent` to `session` and routes its reply into `app`.
async fn serve_last(app: &mut App, sent: &Sent, session: &mut Session) -> anyhow::Result<()> {
echoed(app, sent).await;
let frame = sent.frames().pop().unwrap_or_default();
let id: i64 = frame
.split_whitespace()
.nth(1)
.and_then(|id| id.parse().ok())
.ok_or_else(|| anyhow::anyhow!("no request id in {frame}"))?;
let wire = session.handle_form(&frame).await;
app.route_reply(id, &wire);
Ok(())
}
#[sqlx::test(migrator = "server::db::MIGRATOR")]
async fn a_save_restores_after_a_new_attach_and_writes_only_the_changed_keys(
pool: PgPool,
) -> anyhow::Result<()> {
let _guard = server::db::install_test_pool(pool.clone());
let fixture = seed(&pool).await?;
let mut session = Session::new(ScriptCtx::new(fixture.user))?;
let (mut app, sent) = opened([None; 5]);
choose(&mut app, KeyCode::Down, 1);
next_field(&mut app);
choose(&mut app, KeyCode::Down, 2);
for _ in 0..4 {
press(&mut app, key(KeyCode::Tab));
press(&mut app, key(KeyCode::Enter));
assert_eq!(saves(&app).len(), 1);
serve_last(&mut app, &sent, &mut session).await?;
assert!(app.pending_form.is_none() && app.overlays.is_empty());
let (mut again, sent) = attached_blank();
serve_last(&mut again, &sent, &mut session).await?;
let turbo = Theme::preset("turbo")?;
assert_eq!(again.theme.bg(Role::Desktop), turbo.bg(Role::Desktop));
assert_eq!(again.keys.vim(), VimState::Insert);
assert_eq!(again.keys.indicator(), "vim:insert");
let colors = session
.handle_form(r#"(:id 9 :form (get-config "tui-colors"))"#)
.await;
assert!(colors.contains("nil"), "{colors}");