hefesto-widgets 0.7.3

Ratatui widgets for the Hefesto TUI toolkit: popups, scrollable lists, trees, text input and spinners
Documentation
use super::*;
use insta::assert_snapshot;
use ratatui::{backend::TestBackend, Terminal};

use crate::{Badge, BadgeAnchor, BadgeStack};

fn render(name: &str, popup: ThemedConfirmationPopup<'_>) {
    let backend = TestBackend::new(60, 20);
    let mut terminal = Terminal::new(backend).unwrap();
    terminal.draw(|f| f.render_widget(popup, f.area())).unwrap();
    assert_snapshot!(name, terminal.backend());
}

// ── snapshots ──

#[test]
fn snapshot_default_success() {
    render("themed_confirmation_success", ThemedConfirmationPopup::new(
        "Operación completada",
        vec![Line::from("Todo salió bien.")],
        ConfirmationVariant::Success,
    ));
}

#[test]
fn snapshot_danger() {
    render("themed_confirmation_danger", ThemedConfirmationPopup::new(
        "Eliminar archivo",
        vec![Line::from("Esta acción no se puede deshacer.")],
        ConfirmationVariant::Danger,
    ));
}

#[test]
fn snapshot_warning() {
    render("themed_confirmation_warning", ThemedConfirmationPopup::new(
        "Advertencia",
        vec![Line::from("Revise los datos antes de continuar.")],
        ConfirmationVariant::Warning,
    ));
}

#[test]
fn snapshot_none() {
    render("themed_confirmation_none", ThemedConfirmationPopup::new(
        "Información",
        vec![Line::from("Operación finalizada.")],
        ConfirmationVariant::None,
    ));
}

#[test]
fn snapshot_bg_color_danger() {
    render("themed_confirmation_bg_color", ThemedConfirmationPopup::new(
        "Peligro",
        vec![Line::from("Esto es crítico.")],
        ConfirmationVariant::Danger,
    ).bg_color(Color::Red));
}

// ── resolve_rect ──

#[test]
fn resolve_rect_delegates_to_popup() {
    let popup = ThemedConfirmationPopup::new("t", vec![], ConfirmationVariant::None)
        .width(PopupSize::Fixed(30))
        .height(PopupSize::Fixed(10));
    assert_eq!(popup.resolve_rect(Rect::new(0, 0, 100, 50)).width, 30);
    assert_eq!(popup.resolve_rect(Rect::new(0, 0, 100, 50)).height, 10);
}

// ── snapshots de builders nuevos ──

#[test]
fn snapshot_positioned() {
    render("themed_confirmation_positioned", ThemedConfirmationPopup::new(
        "Posicionado",
        vec![Line::from("Popup en posición fija")],
        ConfirmationVariant::None,
    ).position(5, 5));
}

#[test]
fn snapshot_with_width() {
    render("themed_confirmation_with_width", ThemedConfirmationPopup::new(
        "Ancho custom",
        vec![Line::from("Usa width(PopupSize::Fixed(60))")],
        ConfirmationVariant::None,
    ).width(PopupSize::Fixed(60)));
}

#[test]
fn snapshot_header() {
    render("themed_confirmation_header", ThemedConfirmationPopup::new(
        "Con header",
        vec![Line::from("Header activado")],
        ConfirmationVariant::None,
    ).header());
}

// ── badges integration ──

#[test]
fn snapshot_with_badges() {
    let badges = BadgeStack::new()
        .push(Badge::new(" main", Color::Green).anchor(BadgeAnchor::TopLeft));
    let popup = ThemedConfirmationPopup::new(
        "Alerta",
        vec![Line::from("¿Continuar?")],
        ConfirmationVariant::Warning,
    )
    .badges(badges);
    render("themed_confirmation_with_badges", popup);
}