2026-09-10 23:07:22 -04:00
|
|
|
//! Composer Enter must send chat to the selected friend, not only slash commands.
|
|
|
|
|
|
2026-09-11 22:33:55 -04:00
|
|
|
use onionwire::tui::{
|
|
|
|
|
composer_enter, take_job_result, ComposerAction, SlashCmd, WipeKind, TUI_POLL,
|
|
|
|
|
};
|
|
|
|
|
use std::sync::mpsc;
|
|
|
|
|
use std::time::{Duration, Instant};
|
2026-09-10 23:07:22 -04:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn enter_plain_text_is_send() {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
composer_enter("hello wire"),
|
|
|
|
|
Some(ComposerAction::Send("hello wire".into()))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn enter_trims_but_sends() {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
composer_enter(" hi there "),
|
|
|
|
|
Some(ComposerAction::Send("hi there".into()))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn enter_empty_does_nothing() {
|
|
|
|
|
assert_eq!(composer_enter(""), None);
|
|
|
|
|
assert_eq!(composer_enter(" "), None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn enter_slash_cmds_are_not_chat() {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
composer_enter("/wipe"),
|
|
|
|
|
Some(ComposerAction::Cmd(SlashCmd::Wipe(WipeKind::Messages)))
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
composer_enter("/who"),
|
|
|
|
|
Some(ComposerAction::Cmd(SlashCmd::Who))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn enter_unknown_slash_is_not_chat() {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
composer_enter("/nope"),
|
|
|
|
|
Some(ComposerAction::UnknownSlash("/nope".into()))
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-09-11 22:33:55 -04:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn take_job_result_is_nonblocking_when_empty() {
|
|
|
|
|
let (tx, rx) = mpsc::channel::<String>();
|
|
|
|
|
let start = Instant::now();
|
|
|
|
|
assert_eq!(take_job_result(&rx), None);
|
|
|
|
|
assert!(
|
|
|
|
|
start.elapsed() < Duration::from_millis(50),
|
|
|
|
|
"empty job rx must not wait on the 180s send retry"
|
|
|
|
|
);
|
|
|
|
|
drop(tx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn take_job_result_reads_status_without_blocking() {
|
|
|
|
|
let (tx, rx) = mpsc::channel();
|
|
|
|
|
tx.send("sent".into()).unwrap();
|
|
|
|
|
assert_eq!(take_job_result(&rx).as_deref(), Some("sent"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn tui_poll_is_short_so_keys_keep_working() {
|
|
|
|
|
assert!(TUI_POLL <= Duration::from_millis(200));
|
|
|
|
|
assert!(TUI_POLL > Duration::ZERO);
|
|
|
|
|
}
|