Lines
100 %
Functions
Branches
//! A window change over a real ssh connection redraws the TUI at the new size.
//!
//! The daemon image has no tty, no `tput` and no `TERM`, so nothing in the
//! resize path may ask the local terminal for a size. Run this under
//! `env -u TERM setsid -w` to prove it.
use crate::eval_subsystem_tests::{
Daemon, insert_verified_user, random_key, register_key, setup, start_daemon,
};
use crate::tui_session::TuiSession;
use russh::Disconnect;
use russh::keys::PrivateKey;
use server::db::install_test_pool;
use sqlx::PgPool;
use sqlx::types::Uuid;
use std::time::Duration;
use supp_macro::local_db_sqlx_test;
const DEADLINE: Duration = Duration::from_secs(45);
/// The status bar is the only row that starts with a style, so this names the window height.
fn status_row(rows: usize) -> String {
format!("\x1b[{rows};1H\x1b[")
}
#[test]
fn the_status_marker_pins_the_height() {
let frame = format!("{}status", status_row(30));
assert!(frame.contains(&status_row(30)));
assert!(!frame.contains(&status_row(20)));
assert!(!"\x1b[20;1H║".contains(&status_row(20)));
async fn resize_session(daemon: &Daemon, key: PrivateKey) -> anyhow::Result<()> {
let mut session = TuiSession::open(daemon.addr, key, (100, 30), (0, 0)).await?;
session.channel.data(&b"1"[..]).await?;
session.read_until(|text| text.contains('╤')).await?;
session.forget();
session.channel.window_change(60, 20, 0, 0).await?;
session
.read_until(|text| text.contains(&status_row(20)))
.await?;
.handle
.disconnect(Disconnect::ByApplication, "done", "")
Ok(())
#[local_db_sqlx_test]
async fn a_window_change_redraws_at_the_new_size(pool: PgPool) -> anyhow::Result<()> {
let user_id = Uuid::new_v4();
insert_verified_user(&pool, user_id).await?;
let key = random_key()?;
register_key(user_id, &key).await?;
let daemon = start_daemon().await?;
let outcome = tokio::time::timeout(DEADLINE, resize_session(&daemon, key)).await;
daemon.stop().await?;
outcome??;