Lines
95.79 %
Functions
100 %
Branches
//! The Reports tab's chart is fetched again when its pane or the report changes.
use super::report_chart::{
EMPTY, call_for, call_with_text, chart_requests, echoed, env, pending, png_wire, rendered,
show, stripes, text, with_table,
};
use crate::app::App;
use crate::route::RouteCtx;
use crate::test_support::{ctrl, press};
use ratatui::crossterm::event::KeyCode;
use rpc::chart::ChartBackend;
#[tokio::test]
async fn a_resize_fetches_the_chart_at_the_new_size() {
let (mut app, sent) = with_table(40, 20, ChartBackend::Halfblocks);
show(&mut app);
app.sync_terminal(env(30, 16, ChartBackend::Halfblocks));
assert_eq!(chart_requests(&app).len(), 2);
assert!(echoed(&mut app, &sent).await.contains(&call_for(280, 240)));
}
async fn a_new_cell_size_fetches_the_chart_again() {
let mut finer = env(40, 20, ChartBackend::Halfblocks);
finer.cell_pixels = (8, 16);
app.sync_terminal(finer);
assert!(
echoed(&mut app, &sent)
.await
.contains(&call_with_text(304, 256, 11))
);
async fn an_unchanged_terminal_does_not_refetch() {
let (mut app, _) = with_table(40, 20, ChartBackend::Halfblocks);
app.sync_terminal(env(40, 20, ChartBackend::Halfblocks));
assert_eq!(chart_requests(&app).len(), 1);
async fn a_hidden_chart_is_not_fetched_on_resize() {
assert!(chart_requests(&app).is_empty());
async fn running_the_report_again_fetches_the_chart_again() {
press(&mut app, ctrl(KeyCode::Char('r')));
let run = pending(&app, |ctx| matches!(ctx, RouteCtx::Reports { .. }))[0];
app.route_reply(run, EMPTY);
async fn the_reply_of_the_old_pane_size_is_dropped() {
let [old] = chart_requests(&app)[..] else {
panic!("one chart request");
app.sync_terminal(env(30, 20, ChartBackend::Halfblocks));
let [_, new] = chart_requests(&app)[..] else {
panic!("two chart requests");
app.route_reply(old, &png_wire(old, stripes(280, 240)));
assert!(text(&rendered(&app, 30, 20)).contains("Loading chart..."));
app.route_reply(new, &png_wire(new, stripes(280, 240)));
assert!(!text(&rendered(&app, 30, 20)).contains("Loading chart..."));
/// The `i=` id of the first kitty transmit drawn.
fn transmitted_id(app: &App, width: u16) -> String {
let drawn = text(&rendered(app, width, 20));
let after = drawn.split("\x1b_Gq=2,i=").nth(1).expect("a transmit");
after.split(',').next().expect("an id").to_string()
async fn every_kitty_transmit_of_a_session_carries_the_same_id() {
let (mut app, _) = with_table(40, 20, ChartBackend::Kitty);
let [first] = chart_requests(&app)[..] else {
app.route_reply(first, &png_wire(first, stripes(380, 240)));
let id = transmitted_id(&app, 40);
app.sync_terminal(env(30, 20, ChartBackend::Kitty));
let [second] = chart_requests(&app)[..] else {
app.route_reply(second, &png_wire(second, stripes(280, 240)));
assert_eq!(transmitted_id(&app, 30), id);
async fn a_theme_with_another_panel_colour_fetches_the_shown_chart_again() {
let before = chart_requests(&app).len();
app.set_theme(tvui::Theme::preset("turbo").expect("preset"));
assert_eq!(chart_requests(&app).len(), before + 1);
let echoed = echoed(&mut app, &sent).await;
assert!(echoed.contains(":background 170"), "{echoed}");
async fn a_theme_with_the_same_panel_colour_leaves_the_chart_alone() {
app.set_theme(app.theme.clone());
assert_eq!(chart_requests(&app).len(), before);
async fn a_depth_change_that_moves_the_panel_colour_fetches_the_chart_again() {
app.set_theme(app.theme.clone().with_depth(tvui::ColorDepth::Ansi16));
assert!(echoed.contains(":background 0"), "{echoed}");