use super::*;
use crate::tests::test_runtime;
#[test]
fn a_load_with_no_room_to_draw_is_skipped_rather_than_panicking() {
let (tx, _rx) = std::sync::mpsc::channel();
let mut app = crate::App::new(tx, test_runtime());
app.set_loading_phase("Scanning input", 10);
for (w, h) in [(1, 1), (4, 2), (11, 40), (200, 1)] {
let area = Rect::new(0, 0, w, h);
let mut buf = Buffer::empty(area);
render(area, &mut buf, &app, &RenderContext::for_test());
}
}
#[test]
fn the_footer_count_replaces_the_phase_while_it_is_running() {
let (tx, _rx) = std::sync::mpsc::channel();
let mut app = crate::App::new(tx, test_runtime());
app.loading_for_tests(
Some(std::path::PathBuf::from("/tmp/blocks")),
2048,
"Reading schema",
40,
);
let area = Rect::new(0, 0, 60, 20);
let painted = |app: &crate::App| {
let mut buf = Buffer::empty(area);
render(area, &mut buf, app, &RenderContext::for_test());
crate::tests::buffer_text(&buf)
};
assert!(
painted(&app).contains("Reading schema"),
"the phase, while nothing is being counted"
);
app.footer_progress().begin(6541);
for _ in 0..1203 {
app.footer_progress().advance();
}
app.begin_frame();
let text = painted(&app);
assert!(
text.contains("Reading footers: 1,203 of 6,541"),
"the count, grouped so six thousand does not read as sixty: {text}"
);
assert!(
!text.contains("Reading schema"),
"and it replaces the phase rather than crowding in beside it: {text}"
);
app.footer_progress().done();
app.begin_frame();
assert!(
painted(&app).contains("Reading schema"),
"once they have landed there is no wait left to count"
);
}
#[test]
fn the_listing_count_replaces_the_phase_while_it_is_running() {
let (tx, _rx) = std::sync::mpsc::channel();
let mut app = crate::App::new(tx, test_runtime());
app.loading_for_tests(
Some(std::path::PathBuf::from("/tmp/by_station")),
0,
"Reading schema",
40,
);
let area = Rect::new(0, 0, 60, 20);
let painted = |app: &crate::App| {
let mut buf = Buffer::empty(area);
render(area, &mut buf, app, &RenderContext::for_test());
crate::tests::buffer_text(&buf)
};
let progress = app.footer_progress().clone();
let listing = progress.listing();
for _ in 0..412_000 {
listing.advance();
}
app.begin_frame();
let text = painted(&app);
assert!(text.contains("Listing files: 412,000"), "{text}");
assert!(!text.contains("Reading schema"), "{text}");
drop(listing);
app.footer_progress().begin(2);
app.begin_frame();
let text = painted(&app);
assert!(text.contains("Reading footers: 0 of 2"), "{text}");
assert!(!text.contains("Listing files"), "{text}");
app.footer_progress().done();
app.begin_frame();
assert!(painted(&app).contains("Reading schema"));
}
#[test]
fn the_footer_count_is_cut_with_a_mark_rather_than_by_the_edge() {
let (tx, _rx) = std::sync::mpsc::channel();
let mut app = crate::App::new(tx, test_runtime());
app.loading_for_tests(
Some(std::path::PathBuf::from("/tmp/blocks")),
2048,
"Reading schema",
40,
);
app.footer_progress().begin(6541);
for _ in 0..1203 {
app.footer_progress().advance();
}
app.begin_frame();
let ellipsis = crate::glyphs::get().ellipsis;
for width in 12u16..=60 {
let area = Rect::new(0, 0, width, 20);
let mut buf = Buffer::empty(area);
render(area, &mut buf, &app, &RenderContext::for_test());
let line = (0..area.height)
.map(|y| {
(0..area.width)
.map(|x| buf[(x, y)].symbol().to_string())
.collect::<String>()
})
.find(|row| row.contains("Read"))
.map(|row| row.trim_end().to_string())
.unwrap_or_else(|| panic!("no phase line at {width}"));
assert!(
line.ends_with(ellipsis),
"at {width} the line ends with nothing to say it may be cut: {line:?}"
);
let whole = format!("Reading footers: 1,203 of 6,541{ellipsis}")
.chars()
.count()
+ 3; if width as usize >= whole {
assert!(
line.contains("1,203 of 6,541"),
"at {width} the whole count fits: {line:?}"
);
}
}
}
#[test]
fn the_phase_and_the_file_are_both_on_screen() {
let (tx, _rx) = std::sync::mpsc::channel();
let mut app = crate::App::new(tx, test_runtime());
app.loading_for_tests(
Some(std::path::PathBuf::from("/tmp/quarterly.parquet")),
2048,
"Reading schema",
40,
);
let area = Rect::new(0, 0, 60, 20);
let mut buf = Buffer::empty(area);
render(area, &mut buf, &app, &RenderContext::for_test());
let text = crate::tests::buffer_text(&buf);
assert!(text.contains("Reading schema"), "phase missing: {text:?}");
assert!(text.contains("quarterly.parquet"), "file missing: {text:?}");
assert!(text.contains("2.0 KiB"), "size missing: {text:?}");
}