fix(tui): wrap usage error card text

This commit is contained in:
Felipe Coury
2026-05-29 13:50:35 -03:00
parent cbfa50b9ba
commit 0671b870b0
3 changed files with 46 additions and 2 deletions
@@ -0,0 +1,13 @@
---
source: tui/src/chatwidget/tests/popups_and_settings.rs
expression: rendered
---
/usage
╭────────────────────────────────────────────────────────╮
│ Usage by token share │
│ Percent of consumed tokens in this selected range │
│ │
│ Failed to load usage: sqlite state database could not │
│ be opened because the configured path is unavailable │
╰────────────────────────────────────────────────────────╯
@@ -244,6 +244,33 @@ async fn usage_output_reports_unattributed_usage() {
assert_chatwidget_snapshot!("usage_output_unattributed", rendered);
}
#[tokio::test]
async fn usage_error_wraps_long_backend_message() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
chat.add_usage_output();
assert_matches!(
rx.try_recv(),
Ok(AppEvent::FetchUsage {
request_id: 0,
range: UsageRange::Day,
})
);
chat.on_usage_loaded(
/*request_id*/ 0,
Err(
"sqlite state database could not be opened because the configured path is unavailable"
.to_string(),
),
);
let Ok(AppEvent::InsertHistoryCell(cell)) = rx.try_recv() else {
panic!("expected usage history cell");
};
let rendered = lines_to_single_string(&cell.display_lines(/*width*/ 60));
assert_chatwidget_snapshot!("usage_error_wraps_long_backend_message", rendered);
}
#[tokio::test]
async fn usage_output_weekly_snapshot() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
+6 -2
View File
@@ -106,12 +106,16 @@ impl HistoryCell for UsageErrorHistoryCell {
let Some(available_width) = usage_card_available_width(width) else {
return Vec::new();
};
let lines = vec![
let mut lines = vec![
Line::from(USAGE_TITLE.bold()),
Line::from(USAGE_SUBTITLE.dim()),
Line::default(),
Line::from(format!(" Failed to load usage: {}", self.error)),
];
push_wrapped_text(
&mut lines,
format!(" Failed to load usage: {}", self.error),
available_width,
);
let inner_width = lines
.iter()
.map(line_display_width)