Skip to content

Commit 128d0d6

Browse files
committed
test(render/list_cards): cover natural_height's non-ImageLinkedList fallback arm, render_cards and draw_text zero-dimension no-op guards, and the draw_thumbnail path via a missing-file card whose image-load error is swallowed
1 parent dfe38fd commit 128d0d6

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

‎src/render/list_cards.rs‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,4 +568,89 @@ mod tests {
568568
let row0 = row_text(&buf, 0);
569569
assert_eq!(row0.find('a'), Some(6));
570570
}
571+
572+
#[test]
573+
fn natural_height_returns_one_for_non_image_linked_body() {
574+
// A renderer is only ever dispatched its accepted shape, but `natural_height` keeps a
575+
// defensive fallback for a mismatched body — exercise that arm directly.
576+
let registry = Registry::with_builtins();
577+
let renderer = ListCardsRenderer;
578+
let body = Body::Text(crate::payload::TextData {
579+
value: "not a card list".into(),
580+
});
581+
assert_eq!(
582+
renderer.natural_height(&body, &RenderOptions::default(), 40, &registry),
583+
1,
584+
);
585+
}
586+
587+
#[test]
588+
fn render_cards_ignores_zero_sized_area() {
589+
use ratatui::{Terminal, backend::TestBackend};
590+
591+
let data = ImageLinkedListData {
592+
items: vec![item("dropped", None, None)],
593+
};
594+
let opts = RenderOptions::default();
595+
let theme = Theme::default();
596+
let mut terminal = Terminal::new(TestBackend::new(10, 3)).unwrap();
597+
terminal
598+
.draw(|f| {
599+
// Zero width and zero height must both no-op before any cell write.
600+
render_cards(
601+
f,
602+
Rect {
603+
x: 0,
604+
y: 0,
605+
width: 0,
606+
height: 3,
607+
},
608+
&data,
609+
&opts,
610+
&theme,
611+
);
612+
render_cards(
613+
f,
614+
Rect {
615+
x: 0,
616+
y: 0,
617+
width: 10,
618+
height: 0,
619+
},
620+
&data,
621+
&opts,
622+
&theme,
623+
);
624+
})
625+
.unwrap();
626+
let buf = terminal.backend().buffer();
627+
assert!((0..3).all(|y| row_text(buf, y).trim().is_empty()));
628+
}
629+
630+
#[test]
631+
fn card_with_thumbnail_path_runs_thumbnail_draw_path() {
632+
let registry = Registry::with_builtins();
633+
let spec = RenderSpec::Short("list_cards".into());
634+
let card = ImageLinkedItem {
635+
title: "with thumb".into(),
636+
url: None,
637+
thumbnail_path: Some("/nonexistent/splashboard-test-thumb.png".into()),
638+
subtitle: None,
639+
};
640+
// A non-empty `thumbnail_path` drives `draw_card` into `draw_thumbnail`; the missing
641+
// file makes the image load fail and the error is swallowed, so the render still
642+
// completes and the title column stays populated.
643+
let buf = render_to_buffer_with_spec(&payload(vec![card]), Some(&spec), &registry, 40, 3);
644+
assert!(row_text(&buf, 0).contains("with thumb"));
645+
}
646+
647+
#[test]
648+
fn draw_text_skips_zero_dimensions() {
649+
let mut buf = Buffer::empty(Rect::new(0, 0, 10, 3));
650+
let card = item("title", None, Some("subtitle"));
651+
let theme = Theme::default();
652+
draw_text(&mut buf, 0, 0, 0, 3, &card, &theme);
653+
draw_text(&mut buf, 0, 0, 10, 0, &card, &theme);
654+
assert!((0..3).all(|y| row_text(&buf, y).trim().is_empty()));
655+
}
571656
}

0 commit comments

Comments
 (0)