Skip to content

Commit 5ae3c6d

Browse files
committed
Test public widget footer metadata and narrow rendering
1 parent cfdc711 commit 5ae3c6d

1 file changed

Lines changed: 123 additions & 0 deletions

File tree

‎crates/jcode-tui/src/tui/info_widget_tests.rs‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,129 @@ fn metadata_footers_add_distinct_compact_facts() {
20312031
assert!(framed.title_right.is_none());
20322032
}
20332033

2034+
fn footer_probe(kind: WidgetKind, data: &InfoWidgetData, width: u16) -> (String, String) {
2035+
use ratatui::{Terminal, backend::TestBackend};
2036+
2037+
let mut terminal = Terminal::new(TestBackend::new(width, 16)).unwrap();
2038+
terminal
2039+
.draw(|frame| {
2040+
super::render_all(
2041+
frame,
2042+
&[super::WidgetPlacement {
2043+
kind,
2044+
rect: frame.area(),
2045+
side: super::Side::Right,
2046+
}],
2047+
data,
2048+
);
2049+
})
2050+
.unwrap();
2051+
let buffer = terminal.backend().buffer();
2052+
let bottom = (0..16)
2053+
.find(|&y| buffer[(0, y)].symbol() == "╰")
2054+
.expect("public renderer must preserve the bottom border");
2055+
assert_eq!(buffer[(width - 1, bottom)].symbol(), "╯");
2056+
let row = |y| {
2057+
(0..width)
2058+
.map(|x| buffer[(x, y)].symbol())
2059+
.collect::<String>()
2060+
};
2061+
let footer = row(bottom);
2062+
assert!(
2063+
footer
2064+
.chars()
2065+
.any(|ch| !ch.is_whitespace() && !"╰╯─".contains(ch)),
2066+
"{kind:?} at {width} cells lost its footer: {footer}"
2067+
);
2068+
let above = (0..bottom).map(row).collect::<Vec<_>>().join("\n");
2069+
(above, footer)
2070+
}
2071+
2072+
#[test]
2073+
fn public_runtime_footer_keeps_throughput_once_without_wrapping() {
2074+
let data = InfoWidgetData {
2075+
provider_name: Some("openai".into()),
2076+
service_tier: Some("priority".into()),
2077+
connection_type: Some("websocket".into()),
2078+
tokens_per_second: Some(61.7),
2079+
..Default::default()
2080+
};
2081+
for width in [8, 12, 24, 44] {
2082+
let (above, footer) = footer_probe(WidgetKind::ModelInfo, &data, width);
2083+
assert!(!above.contains("tok/s"));
2084+
assert!(!footer.contains("Runtime"));
2085+
if width >= 24 {
2086+
assert!(footer.contains("62 tok/s"), "{footer}");
2087+
assert_eq!(footer.matches("62 tok/s").count(), 1);
2088+
}
2089+
if width == 44 {
2090+
assert!(above.contains("fast tier") && above.contains("websocket"));
2091+
}
2092+
}
2093+
}
2094+
2095+
#[test]
2096+
fn public_workspace_footer_counts_visible_sessions_and_running_state() {
2097+
use crate::tui::workspace_map::{
2098+
VisibleWorkspaceRow, WorkspaceSessionTile, WorkspaceSessionVisualState,
2099+
};
2100+
2101+
let mut data = InfoWidgetData {
2102+
workspace_rows: vec![VisibleWorkspaceRow {
2103+
workspace: 0,
2104+
is_current: true,
2105+
focused_index: Some(0),
2106+
sessions: vec![WorkspaceSessionTile::new("雲")],
2107+
}],
2108+
..Default::default()
2109+
};
2110+
let (above, footer) = footer_probe(WidgetKind::WorkspaceMap, &data, 44);
2111+
assert!(above.contains("Workspace"));
2112+
assert!(footer.contains("1 session"));
2113+
assert!(!footer.contains("sessions"));
2114+
2115+
data.workspace_rows[0].sessions[0].state = WorkspaceSessionVisualState::Running;
2116+
data.workspace_rows.push(VisibleWorkspaceRow {
2117+
workspace: 1,
2118+
is_current: false,
2119+
focused_index: Some(0),
2120+
sessions: vec![
2121+
WorkspaceSessionTile::with_state("狐", WorkspaceSessionVisualState::Running),
2122+
WorkspaceSessionTile::new("bird"),
2123+
],
2124+
});
2125+
for width in [8, 12, 24, 44] {
2126+
let (above, footer) = footer_probe(WidgetKind::WorkspaceMap, &data, width);
2127+
assert!(!above.contains("3 sessions"));
2128+
if width == 44 {
2129+
assert!(footer.contains("3 sessions · 2 running"), "{footer}");
2130+
}
2131+
}
2132+
}
2133+
2134+
#[test]
2135+
fn public_diagram_footer_keeps_dimensions_when_image_is_not_cached() {
2136+
let mut data = InfoWidgetData::default();
2137+
let (_, footer) = footer_probe(WidgetKind::Diagrams, &data, 44);
2138+
assert!(footer.contains("image pending"));
2139+
data.diagrams = vec![
2140+
super::DiagramInfo {
2141+
hash: u64::MAX,
2142+
width: 640,
2143+
height: 480,
2144+
label: None,
2145+
};
2146+
2
2147+
];
2148+
for width in [8, 12, 24, 44] {
2149+
let (above, footer) = footer_probe(WidgetKind::Diagrams, &data, width);
2150+
assert!(!above.contains("640×480") && !above.contains("1/2"));
2151+
if width >= 24 {
2152+
assert!(footer.contains("640×480 · 1/2"), "{footer}");
2153+
}
2154+
}
2155+
}
2156+
20342157
#[test]
20352158
fn ambient_footer_moves_next_run_out_of_body() {
20362159
let data = InfoWidgetData {

0 commit comments

Comments
 (0)