Add tests

This commit is contained in:
Daniel Edrisian
2025-10-14 10:28:59 -07:00
parent e26d2db1a0
commit 29bf645bef
2 changed files with 57 additions and 0 deletions
@@ -0,0 +1,13 @@
---
source: tui/src/chatwidget/tests.rs
expression: terminal.backend().vt100().screen().contents()
---
✨ New version available! Would you like to update?
Full release notes: https://github.com/openai/codex/releases/latest
› 1. Yes, update now
2. No, not now
Press enter to confirm or esc to go back
+44
View File
@@ -52,6 +52,29 @@ use tempfile::NamedTempFile;
use tokio::sync::mpsc::error::TryRecvError;
use tokio::sync::mpsc::unbounded_channel;
struct EnvVarGuard {
key: &'static str,
original: Option<std::ffi::OsString>,
}
impl EnvVarGuard {
fn set(key: &'static str, value: &str) -> Self {
let original = std::env::var_os(key);
unsafe { std::env::set_var(key, value) };
Self { key, original }
}
}
impl Drop for EnvVarGuard {
fn drop(&mut self) {
if let Some(value) = self.original.take() {
unsafe { std::env::set_var(self.key, value) };
} else {
unsafe { std::env::remove_var(self.key) };
}
}
}
fn test_config() -> Config {
// Use base defaults to avoid depending on host state.
Config::load_from_base_config_with_overrides(
@@ -1606,6 +1629,27 @@ fn status_widget_active_snapshot() {
assert_snapshot!("status_widget_active", terminal.backend());
}
#[test]
fn update_popup_snapshot() {
let _guard = EnvVarGuard::set("CODEX_MANAGED_BY_NPM", "1");
let (mut chat, _rx, _op_rx) = make_chatwidget_manual();
chat.open_update_popup();
let height = chat.desired_height(80);
let mut terminal =
crate::custom_terminal::Terminal::with_options(VT100Backend::new(80, height))
.expect("create terminal");
terminal.set_viewport_area(Rect::new(0, 0, 80, height));
terminal
.draw(|f| f.render_widget_ref(&chat, f.area()))
.expect("render update popup");
assert_snapshot!(
"update_popup",
terminal.backend().vt100().screen().contents()
);
}
#[test]
fn apply_patch_events_emit_history_cells() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual();