tui(history): payment history and tx detail screen #83

Merged
sirius merged 4 commits from wt/t_935bf84e into feat/wallet-create-import 2026-09-16 04:01:38 +00:00
3 changed files with 572 additions and 9 deletions
Showing only changes of commit b7e3d79777 - Show all commits

tui(history): payment history and tx detail screen (card t_935bf84e)
All checks were successful
ci / test (pull_request) Successful in 4m30s
ci / sdk (pull_request) Successful in 1m19s

Add Screen::History with draw_history, history_row_text, history_detail.
- Per-friend payment list: direction marker, amount, verified state, age, txid
- Enter opens detail view; Esc closes
- h key from main + wallet opens history via Node::list_payments
- Empty state: 'no payments with this friend yet'
- ASCII fallback: drops ✓/✗ glyphs, uses words only
- Peer text (memo, address) sanitized via display_text
- Tests: 5 new in tui_spec.rs (row text, detail, empty, ascii), 2 frame dumps in tui_frames.rs

Signed-off-by: tui-design <tui-design@hermes>
agent 2026-09-15 21:29:40 -04:00
No known key found for this signature in database

View file

@ -15,7 +15,7 @@ use crate::node::{DaemonSync, Node, WalletChildState};
use crate::outbox::DEFAULT_MAX_ATTEMPTS;
use crate::qr::{self, QrPayload};
use crate::sanitize;
use crate::store::{Friend, FriendProfile, Message, OutboxEntry, OutboxStatus};
use crate::store::{Friend, FriendProfile, Message, OutboxEntry, OutboxStatus, Payment};
use crate::wallet::{self, ChainSource, Readiness};
const C_ACCENT: Color = Color::Rgb(232, 165, 75);
@ -492,7 +492,8 @@ OnionWire keys\n\
F3 paste invite\n\
F4 rotate onion locator\n\
F5 selected friend's profile (/who)\n\
F6 wallet (receive address, chain, balance, history)\n\
F6 wallet (receive address, chain, balance)\n\
F6 h payment history with selected friend\n\
F6 s chain source: receive-only / local / remote\n\
F6 n start or stop the app-owned daemon\n\
F6 r show / hide the receive-address QR\n\
@ -1169,6 +1170,12 @@ enum Screen {
qr_modal: Option<QrModal>,
copy_note: Option<String>,
},
History {
friend_pk: Vec<u8>,
payments: Vec<Payment>,
selected: usize,
detail: bool,
},
ChainSetup(ChainSetup),
WalletSetup(WalletSetup),
Quit {
@ -1570,6 +1577,7 @@ impl App {
}
KeyCode::F(5) => self.who_open = true,
KeyCode::F(6) => self.open_wallet()?,
KeyCode::Char('h') => self.open_history()?,
KeyCode::Esc => self.composer.clear(),
KeyCode::Backspace => {
if self.focus == Pane::Composer {
@ -1764,6 +1772,24 @@ impl App {
});
}
KeyCode::Char('y') => self.wallet_copy_address(),
KeyCode::Char('h') => self.open_history()?,
_ => {}
},
Screen::History { selected, payments, detail, .. } => match key.code {
KeyCode::Esc => self.screen = Screen::Main,
KeyCode::Up => {
if !payments.is_empty() {
*selected = selected.saturating_sub(1);
}
}
KeyCode::Down => {
if !payments.is_empty() {
*selected = (*selected + 1).min(payments.len().saturating_sub(1));
}
}
KeyCode::Enter => {
*detail = !*detail;
}
_ => {}
},
Screen::ChainSetup(_) => self.handle_chain_setup(key)?,
@ -1980,6 +2006,25 @@ impl App {
Ok(())
}
/// `h` from main or the wallet screen: open payment history for the
/// selected friend. The list is loaded once on open and re-read only on
/// an explicit refresh, so the 100ms poll never hits the store per frame.
fn open_history(&mut self) -> Result<(), String> {
let Some(friend) = self.friends.get(self.selected) else {
self.status_note = Some("no friend selected".into());
return Ok(());
};
let pk = friend.pubkey.clone();
let payments = self.node.list_payments(&pk).unwrap_or_default();
self.screen = Screen::History {
friend_pk: pk,
payments,
selected: 0,
detail: false,
};
Ok(())
}
/// Draw state for the wallet screen.
///
/// One probe per open/refresh, then everything the screen says comes from
@ -2569,6 +2614,12 @@ impl App {
Screen::Wallet { view, qr_modal, copy_note } => {
draw_wallet(f, view.as_ref(), qr_modal.as_ref(), copy_note.as_deref())
}
Screen::History { friend_pk, payments, selected, detail } => {
let name = self.friends.iter().find(|fr| &fr.pubkey == friend_pk)
.and_then(|fr| fr.petname.as_deref())
.unwrap_or("friend");
draw_history(f, payments, *selected, *detail, name, unix_now_secs())
}
Screen::ChainSetup(setup) => draw_chain_setup(f, setup),
Screen::WalletSetup(setup) => draw_wallet_setup(f, setup),
}
@ -2868,7 +2919,7 @@ fn footer_fits(parts: &[String], extra: &[&str], help: &str, gap: &str, w: usize
/// Main-screen key hints. Kept short so width 80 still shows TOR + identity + `? help`.
pub fn main_footer_hints() -> &'static str {
"Tab F2 F3 F4 F5 ? help Ctrl-Q"
"Tab F2 F3 F4 F5 F6 h ? help Ctrl-Q"
}
fn footer_hints(screen: &Screen) -> &'static str {
@ -2888,7 +2939,8 @@ match screen {
BackupKind::Restore => "type RESTORE Esc cancel ? help",
},
Screen::Passphrase { .. } => "Enter submit Esc cancel ? help",
Screen::Wallet { .. } => "s chain n node c create i import r qr y copy Esc back ? help",
Screen::Wallet { .. } => "s chain n node c create i import h history r qr y copy Esc back ? help",
Screen::History { .. } => "Enter detail Esc back ? help",
Screen::ChainSetup(_) => "Enter select/save Esc back ? help",
Screen::WalletSetup(WalletSetup::CreateWarn { .. }) => "type SPEND Esc cancel ? help",
Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::ImportPass { .. }) => {
@ -3325,6 +3377,233 @@ pub fn draw_wallet(f: &mut Frame, view: &WalletView, modal: Option<&QrModal>, co
);
}
/// Payment-history helpers (card t_935bf84e).
///
/// These are pure: they take `&[Payment]` fixtures and render parameters so
/// the tests never need to reach into the store. Every peer-supplied field
/// (memo, address) is run through `sanitize::display_text` before it touches
/// a `Paragraph`.
/// Age string derived from `created_at` relative to `now`: just-seconds,
/// minutes, hours, or a date fallback for older entries.
fn payment_age(created_at: i64, now: i64) -> String {
let delta = now.saturating_sub(created_at).max(0);
if delta < 60 {
format!("{delta}s")
} else if delta < 3600 {
format!("{}m", delta / 60)
} else if delta < 86400 {
format!("{}h", delta / 3600)
} else {
format!("{}d", delta / 86400)
}
}
/// Human-readable direction word for a `Payment` row.
fn payment_direction(p: &Payment) -> &'static str {
if p.dir == "out" { "outbound" } else { "inbound" }
}
/// Verified glyph + word — never colour-only. ASCII chrome drops the glyph.
fn verified_text(p: &Payment) -> String {
if ascii_chrome() {
if p.verified { "verified" } else { "unverified" }.to_string()
} else {
format!("{} {}", if p.verified { "✓" } else { "✗" }, if p.verified { "verified" } else { "unverified" })
}
}
/// The txid column: truncated on the row, full in the detail view.
fn txid_display(p: &Payment, max: usize) -> String {
match &p.txid {
Some(txid) => truncate_chars(txid, max),
None => "awaiting receipt".to_string(),
}
}
/// Build one history list row from a `Payment`. Direction marker (`> `/`< `),
/// amount through `pay::atomic_to_xmr_str`, verified word + glyph, and a
/// truncated txid (or `awaiting receipt`). The result is truncated to `width`.
pub fn history_row_text(p: &Payment, width: usize, now: i64) -> String {
let dir_mark = if p.dir == "out" { "> " } else { "< " };
let xmr = crate::pay::atomic_to_xmr_str(&p.amount_atomic);
let verified = verified_text(p);
let txid = txid_display(p, 16);
let age = payment_age(p.created_at, now);
let raw = format!("{dir_mark}{xmr} XMR {verified} {txid} {age}");
truncate_chars(&raw, width)
}
/// Build the detail-view lines for a single `Payment`. Every peer-supplied
/// field (memo, address) goes through `sanitize::display_text` first.
pub fn history_detail(p: &Payment, width: usize, now: i64) -> Vec<String> {
let xmr = crate::pay::atomic_to_xmr_str(&p.amount_atomic);
let dir_word = payment_direction(p);
let verified_word = if p.verified { "verified" } else { "unverified" };
let txid_line = match &p.txid {
Some(txid) => format!("txid {}", sanitize::display_text(txid.as_bytes())),
None => "txid awaiting receipt".to_string(),
};
let memo_line = if p.memo.is_empty() {
"memo (none)".to_string()
} else {
let clean = sanitize::display_text(p.memo.as_bytes());
let wrapped = wrap_text(&clean, width.saturating_sub(6).max(1));
format!("memo {}", wrapped.join("\n "))
};
let address_line = if p.address.is_empty() {
"address (none)".to_string()
} else {
let addr_w = width.saturating_sub(10).max(1);
let clean = sanitize::display_text(p.address.as_bytes());
format!("address {}", truncate_chars(&clean, addr_w))
};
let amount_line = format!("amount {xmr} XMR");
let kind_line = format!("kind {}", p.kind);
let dir_line = format!("direction {dir_word}");
let verified_line = format!("verified {verified_word}");
let age = payment_age(p.created_at, now);
let ts_line = format!("timestamp {} ({} ago)", p.created_at, age);
vec![
truncate_chars(&txid_line, width),
truncate_chars(&address_line, width),
truncate_chars(&memo_line, width),
truncate_chars(&amount_line, width),
truncate_chars(&kind_line, width),
truncate_chars(&dir_line, width),
truncate_chars(&verified_line, width),
truncate_chars(&ts_line, width),
]
}
/// Wrap text at `width` columns to whole words, truncating the last chunk with
/// an ellipsis if a word is too long. Used for the memo line in the detail view.
fn wrap_text(s: &str, width: usize) -> Vec<String> {
if width == 0 {
return vec![s.to_string()];
}
let mut lines: Vec<String> = Vec::new();
let mut current = String::new();
for word in s.split_whitespace() {
let w = word.chars().count();
if current.is_empty() {
if w > width {
lines.push(truncate_chars(word, width));
} else {
current = word.to_string();
}
} else if char_len(&current) + 1 + w <= width {
current.push(' ');
current.push_str(word);
} else {
lines.push(std::mem::take(&mut current));
if w > width {
lines.push(truncate_chars(word, width));
} else {
current = word.to_string();
}
}
}
if !current.is_empty() {
lines.push(current);
}
if lines.is_empty() {
lines.push(String::new());
}
lines
}
/// Full-screen draw for the payment-history list (or detail view when
/// `show_detail` is true). `friend_name` is the petname or fingerprint of the
/// selected friend, already sanitized upstream.
pub fn draw_history(
f: &mut Frame,
payments: &[Payment],
selected: usize,
show_detail: bool,
friend_name: &str,
now: i64,
) {
let area = f.area();
let width = area.width;
let inner_w = width.saturating_sub(2) as usize;
let title = if show_detail && !payments.is_empty() {
format!("history {friend_name} detail")
} else {
format!("history {friend_name}")
};
let block = pane_block_for(&title, true);
let cols = Layout::vertical([
Constraint::Min(1),
Constraint::Length(1),
])
.split(area);
if payments.is_empty() {
let body = wrap_text("no payments with this friend yet", inner_w.max(1)).join("\n");
f.render_widget(
Paragraph::new(body)
.style(style_text())
.wrap(Wrap { trim: false })
.block(block),
cols[0],
);
f.render_widget(
Paragraph::new("Enter detail Esc back ? help").style(style_dim()),
cols[1],
);
return;
}
let idx = selected.min(payments.len() - 1);
if show_detail {
let detail = history_detail(&payments[idx], inner_w, now);
f.render_widget(
Paragraph::new(detail.join("\n"))
.style(style_text())
.wrap(Wrap { trim: false })
.block(block),
cols[0],
);
f.render_widget(
Paragraph::new("Esc back ? help").style(style_dim()),
cols[1],
);
return;
}
let items: Vec<ListItem> = payments
.iter()
.enumerate()
.map(|(i, p)| {
let row = history_row_text(p, inner_w, now);
let style = if i == selected {
style_highlight()
} else {
style_text()
};
ListItem::new(row).style(style)
})
.collect();
let mut list_state = ListState::default();
list_state.select(Some(idx));
f.render_stateful_widget(
List::new(items)
.highlight_style(style_highlight())
.block(block),
cols[0],
&mut list_state,
);
f.render_widget(
Paragraph::new("Enter detail Esc back ? help").style(style_dim()),
cols[1],
);
}
/// The chain-source picker and the remote-daemon trust shift, before anything
/// is saved.
fn draw_chain_setup(f: &mut Frame, setup: &ChainSetup) {

View file

@ -13,9 +13,10 @@
use onionwire::qr;
use onionwire::node::{DaemonSync, WalletChildState};
use onionwire::Payment;
use onionwire::tui::{
backup_screen_text, banner_for_width, chain_view, compact_banner, draw_share, draw_wallet,
fingerprint_mismatch_banner, help_overlay_text, main_footer_hints, onion_glyph,
backup_screen_text, banner_for_width, chain_view, compact_banner, draw_history, draw_share,
draw_wallet, fingerprint_mismatch_banner, help_overlay_text, main_footer_hints, onion_glyph,
osc52_copy, quit_screen_text, restore_screen_text, rotate_screen_text, status_footer,
wallet_readiness, wallet_view, who_overlay_text, wipe_screen_text, wordmark_banner,
ChainChoice, ProfileEditor, WalletReadiness, WALLET_LINE_MAX, WipeKind,
@ -1176,3 +1177,76 @@ fn wallet_view_only_badge_renders_at_80_and_120() {
}
}
}
fn history_payment_fixture() -> Payment {
Payment {
id: 1,
dir: "out".into(),
kind: "payment".into(),
amount_atomic: "1000000000".into(),
txid: Some("abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789".into()),
verified: true,
created_at: 1700000000,
address: "4AdYaG7wVQ3nHvWoXbN9dQkXj1uYcR2mS8pT5LzE6fK7gB3aD".into(),
memo: "for pizza".into(),
}
}
#[test]
fn dump_history_frames() {
unsafe { std::env::remove_var("ONIONWIRE_ASCII") };
let payments = vec![
history_payment_fixture(),
Payment {
id: 2,
dir: "in".into(),
amount_atomic: "50000000000".into(),
txid: Some("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".into()),
verified: true,
created_at: 1700000100,
address: String::new(),
memo: String::new(),
kind: "payment".into(),
},
Payment {
id: 3,
dir: "out".into(),
amount_atomic: "500000000".into(),
txid: None,
verified: false,
created_at: 1700000200,
address: "4AdYaG7wVQ3nHvWoXbN9dQkXj1uYcR2mS8pT5LzE6fK7gB3aD".into(),
memo: String::new(),
kind: "payment".into(),
},
];
let now = 1700000300;
for (w, h) in SIZES {
draw_to(w, h, "history list", |f| {
draw_history(f, &payments, 0, false, "alice", now);
});
draw_to(w, h, "history detail", |f| {
draw_history(f, &payments, 0, true, "alice", now);
});
draw_to(w, h, "history empty", |f| {
draw_history(f, &[], 0, false, "bob", now);
});
}
}
#[test]
fn dump_history_ascii_frames() {
unsafe { std::env::set_var("ONIONWIRE_ASCII", "1") };
let _g = ASCII_ENV.lock();
let payments = vec![history_payment_fixture()];
let now = 1700000300;
for (w, h) in SIZES {
draw_to(w, h, "history ascii list", |f| {
draw_history(f, &payments, 0, false, "alice", now);
});
}
unsafe { std::env::remove_var("ONIONWIRE_ASCII") };
}
/// Lock for env-var-touching tests (mirrors tui_spec.rs pattern).
static ASCII_ENV: std::sync::Mutex<()> = std::sync::Mutex::new(());

View file

@ -4,11 +4,13 @@
use onionwire::Message;
use onionwire::outbox::{OutboxEntry, OutboxStatus};
use onionwire::qr;
use onionwire::Payment;
use onionwire::tui::{
OutboxSummary, alert_line, ascii_chrome, chat_with_delivery, delivery_tag, draw_chat,
draw_share, draw_text_overlay, empty_friend_chat_text, help_overlay_text, is_onion_host,
main_footer_hints, main_header_line, parse_daemon_addr, paste_screen_text, retry_in_text,
roster_col_width, short_send_reason, status_footer, wrap_invite,
draw_history, draw_share, draw_text_overlay, empty_friend_chat_text, help_overlay_text,
history_detail, history_row_text, is_onion_host, main_footer_hints, main_header_line,
parse_daemon_addr, paste_screen_text, retry_in_text, roster_col_width, short_send_reason,
status_footer, wrap_invite,
};
use ratatui::Frame;
use ratatui::Terminal;
@ -844,3 +846,211 @@ fn onion_hosts_are_recognised_before_any_spawn() {
assert!(!is_onion_host("node.example.com"));
assert!(!is_onion_host("notonion"));
}
// ---------------------------------------------------------------------------
// Payment history rows (card t_935bf84e)
//
// Tests over test-local `Payment` fixtures — no store access from the render
// path. Direction marker, amount via `pay::atomic_to_xmr_str`, verified word
// + glyph, txid truncation, "awaiting receipt" for None txid, and hostile
// memo sanitization.
// ---------------------------------------------------------------------------
#[allow(clippy::too_many_arguments)]
fn payment(
id: i64,
dir: &str,
kind: &str,
amount_atomic: &str,
address: &str,
memo: &str,
txid: Option<String>,
verified: bool,
created_at: i64,
) -> Payment {
Payment {
id,
dir: dir.to_string(),
kind: kind.to_string(),
amount_atomic: amount_atomic.to_string(),
address: address.to_string(),
memo: memo.to_string(),
txid,
verified,
created_at,
}
}
const NOW: i64 = 1_700_000_000;
#[test]
fn history_row_outbound_verified_has_marker_word_and_glyph() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(1, "out", "tip", "1000000000", "addr", "coffee", Some("abcd1234".into()), true, 1_699_999_000);
let row = history_row_text(&p, 76, NOW);
assert!(row.starts_with("> "), "outbound row must start with '> ': {row:?}");
assert!(row.contains('✓'), "verified glyph missing: {row:?}");
assert!(row.contains("verified"), "verified word missing: {row:?}");
assert!(row.contains("0.001"), "amount missing: {row:?}");
}
#[test]
fn history_row_outbound_unverified_has_word_no_check() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(2, "out", "invoice", "500000000", "addr", "", Some("ef12".into()), false, 1_700_000_000);
let row = history_row_text(&p, 76, NOW);
assert!(row.starts_with("> "), "outbound row must start with '> ': {row:?}");
assert!(row.contains("unverified"), "unverified word missing: {row:?}");
assert!(!row.contains('✓'), "unverified must not have check glyph: {row:?}");
}
#[test]
fn history_row_inbound_uses_left_marker() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(3, "in", "payment", "2500000000", "addr", "", Some("deadbeef".into()), true, 1_700_000_000);
let row = history_row_text(&p, 76, NOW);
assert!(row.starts_with("< "), "inbound row must start with '< ': {row:?}");
assert!(row.contains("verified"), "verified word missing: {row:?}");
}
#[test]
fn history_row_no_txid_says_awaiting_receipt_not_dash() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(4, "in", "payment", "1000000000", "addr", "", None, false, 1_700_000_000);
let row = history_row_text(&p, 76, NOW);
assert!(row.contains("awaiting receipt"), "missing 'awaiting receipt': {row:?}");
assert!(!row.contains("--"), "bare dash instead of 'awaiting receipt': {row:?}");
}
#[test]
fn history_row_truncates_txid_within_width() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(5, "out", "tip", "1000", "addr", "memo", Some("a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3".into()), true, 1_700_000_000);
let row = history_row_text(&p, 40, NOW);
assert!(row.chars().count() <= 40, "row wider than 40: {} {row:?}", row.chars().count());
}
#[test]
fn history_row_ascii_fallback_has_no_emoji_glyphs() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
unsafe { std::env::set_var("ONIONWIRE_ASCII", "1") };
let p = payment(1, "out", "tip", "1000000000", "addr", "", Some("abcd".into()), true, 1_700_000_000);
let row = history_row_text(&p, 76, NOW);
assert!(row.is_ascii(), "ASCII fallback not pure ASCII: {row:?}");
assert!(row.contains("verified"), "ASCII verified word missing: {row:?}");
unsafe { std::env::remove_var("ONIONWIRE_ASCII") };
}
#[test]
fn history_detail_shows_all_fields_sanitized() {
let p = payment(
7,
"out",
"tip",
"2000000000",
"1A2B3C4D5E6F",
"for pizza",
Some("abcdef0123456789abcdef0123456789".into()),
true,
1_700_000_000,
);
let detail = history_detail(&p, 76, NOW);
let all = detail.join("\n");
assert!(all.contains("abcdef0123456789abcdef0123456789"), "full txid missing: {all:?}");
assert!(all.contains("1A2B3C4D5E6F"), "address missing: {all:?}");
assert!(all.contains("for pizza"), "memo missing: {all:?}");
assert!(all.contains("0.002"), "amount missing: {all:?}");
assert!(all.contains("outbound"), "direction missing: {all:?}");
assert!(all.contains("verified"), "verified state missing: {all:?}");
assert!(all.contains("1700000000") || all.contains("Nov"), "timestamp missing: {all:?}");
for line in &detail {
assert!(line.chars().count() <= 76, "detail line wider than 76: {} {line:?}", line.chars().count());
}
}
#[test]
fn history_detail_hostile_memo_is_sanitized_inert_text() {
// C0 control chars + bidi override — must render as inert text, not affect
// the terminal or carry hidden directionality.
let hostile = "pay\x01now\u{202E}\u{202E}reverse";
let p = payment(8, "in", "payment", "500000000", "addr", hostile, Some("cafebabe".into()), false, 1_700_000_000);
let detail = history_detail(&p, 76, NOW);
let all = detail.join("\n");
// Bidi override must be stripped — the word "reverse" must appear in
// reading order, not visually flipped by a leftover override mark.
assert!(!all.contains('\u{202E}'), "bidi override survived sanitize: {all:?}");
assert!(!all.contains('\x01'), "C0 control survived sanitize: {all:?}");
assert!(all.contains("reverse"), "sanitized memo text lost: {all:?}");
}
#[test]
fn history_detail_no_txid_shows_awaiting_receipt() {
let p = payment(9, "in", "payment", "1000", "addr", "", None, false, 1_700_000_000);
let detail = history_detail(&p, 76, NOW);
let all = detail.join("\n");
assert!(all.contains("awaiting receipt"), "detail missing 'awaiting receipt': {all:?}");
}
#[test]
fn draw_history_list_at_80x24_fits_and_shows_rows() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let payments = vec![
payment(1, "out", "tip", "1000000000", "addr", "coffee", Some("abcd1234".into()), true, 1_699_999_000),
payment(2, "in", "payment", "2500000000", "addr", "", Some("deadbeef".into()), true, 1_700_000_001),
payment(3, "out", "invoice", "500000000", "addr", "", None, false, 1_700_000_002),
];
let backend = TestBackend::new(80, 24);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal
.draw(|f| draw_history(f, &payments, 1, false, "alice", NOW))
.expect("draw");
let screen = screen_from(terminal.backend().buffer(), 80, 24);
for line in screen.lines() {
assert!(line.chars().count() <= 80, "80x24 history row wider than 80: {} {line:?}", line.chars().count());
}
assert!(screen.contains("alice"), "friend name missing from title: {screen}");
assert!(screen.contains("> "), "outbound marker missing: {screen}");
assert!(screen.contains("< "), "inbound marker missing: {screen}");
assert!(screen.contains("awaiting receipt"), "awaiting receipt missing: {screen}");
assert!(screen.contains("Enter detail"), "hint missing: {screen}");
assert!(screen.contains("Esc back"), "hint missing: {screen}");
}
#[test]
fn draw_history_empty_at_80x24_shows_designed_copy() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let backend = TestBackend::new(80, 24);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal
.draw(|f| draw_history(f, &[], 0, false, "bob", NOW))
.expect("draw");
let screen = screen_from(terminal.backend().buffer(), 80, 24);
for line in screen.lines() {
assert!(line.chars().count() <= 80, "row wider than 80: {line:?}");
}
assert!(screen.contains("no payments with this friend yet"), "empty copy missing: {screen}");
}
#[test]
fn draw_history_detail_at_80x24_fits() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(1, "out", "tip", "1000000000", "1A2B3C4D5E6F", "coffee", Some("abcdef0123456789abcdef0123456789".into()), true, 1_700_000_000);
let backend = TestBackend::new(80, 24);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal
.draw(|f| draw_history(f, std::slice::from_ref(&p), 0, true, "alice", NOW))
.expect("draw");
let screen = screen_from(terminal.backend().buffer(), 80, 24);
for line in screen.lines() {
assert!(line.chars().count() <= 80, "detail row wider than 80: {} {line:?}", line.chars().count());
}
assert!(screen.contains("awaiting receipt") || screen.contains("abcdef0123456789"), "detail content missing: {screen}");
}