use crate::tui::app::{App, Section};
use crate::tui::bench_state::View;
use crate::tui::render::harness::{has, screen};
fn tall_enough() -> u16 {
let n = metrale_bench::registry::all().len();
u16::try_from(n * 3 + 20).expect("fits a u16 terminal")
}
fn list_app(selected: usize) -> App {
let mut a = crate::tui::render::tests::app();
a.section = Section::Benchmarks;
a.bench.view = View::List;
a.bench.selected = selected;
a
}
#[test]
fn every_registered_benchmark_is_reachable_by_scrolling() {
let all = metrale_bench::registry::all();
for (i, descriptor) in all.iter().enumerate() {
let rows = screen(&list_app(i), 120, 24);
assert!(
has(&rows, descriptor.name),
"{} unreachable at 120x24:\n{rows:#?}",
descriptor.name
);
}
}
#[test]
fn the_clip_indicator_appears_only_when_the_list_is_clipped() {
let n = metrale_bench::registry::all().len();
let rows = screen(&list_app(0), 80, 24);
assert!(
rows.iter()
.any(|r| r.contains("─ 1-") && r.contains(&format!("of {n} ─"))),
"clipped list must name its window:\n{rows:#?}"
);
let rows = screen(&list_app(0), 160, tall_enough());
assert!(
!has(&rows, &format!("of {n} ─")),
"unclipped list must not draw an indicator:\n{rows:#?}"
);
}
#[test]
fn the_indicator_tracks_the_selection_to_the_bottom() {
let n = metrale_bench::registry::all().len();
let rows = screen(&list_app(n - 1), 80, 24);
assert!(
has(&rows, &format!("-{n} of {n} ─")),
"with the last entry selected the window must end at {n}:\n{rows:#?}"
);
}
#[test]
fn the_offset_is_clamped_at_both_ends() {
let all = metrale_bench::registry::all();
let rows = screen(&list_app(all.len() + 40), 80, 24);
assert!(
has(&rows, all[all.len() - 1].name),
"an over-large selection clamps to the last page:\n{rows:#?}"
);
let rows = screen(&list_app(0), 80, 24);
assert!(has(&rows, all[0].name), "{rows:#?}");
}
#[test]
fn compaction_keeps_the_summary_and_duration_on_every_entry() {
let all = metrale_bench::registry::all();
let rows = screen(&list_app(0), 80, 24);
assert!(
has(&rows, all[0].duration_hint),
"the duration line survives the compact layout:\n{rows:#?}"
);
}
#[test]
fn the_renderer_publishes_the_page_size_for_the_key_handler() {
let n = metrale_bench::registry::all().len();
let a = list_app(0);
screen(&a, 80, 24);
let page = a.bench.suite_page.get();
assert!(page > 0, "a viewport of zero would freeze the page keys");
assert!(
page < n,
"80x24 is clipped, so one page is less than the suite"
);
let tall = tall_enough();
screen(&a, 160, tall);
assert!(
a.bench.suite_page.get() >= n,
"a terminal sized from the registry ({n} entries, {tall} rows) holds \
the whole suite on one page; got {}",
a.bench.suite_page.get()
);
}
#[test]
fn the_list_survives_a_12x4_terminal() {
let n = metrale_bench::registry::all().len();
for selected in [0, n - 1] {
let rows = screen(&list_app(selected), 12, 4);
assert_eq!(rows.len(), 4, "selected {selected}");
}
}