use super::*;
use crate::scroll_list::ScrollListState;
use insta::assert_snapshot;
use ratatui::{backend::TestBackend, Terminal};
fn render_stateful(name: &str, popup: SpinPopup<'_>, state: &mut SpinState) {
let backend = TestBackend::new(60, 20);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| f.render_stateful_widget(popup, f.area(), state))
.unwrap();
assert_snapshot!(name, terminal.backend());
}
#[test]
fn resolve_rect_delegates_to_popup() {
let popup = SpinPopup::new()
.width(PopupSize::Fixed(30))
.height(PopupSize::Fixed(10));
let rect = popup.resolve_rect(Rect::new(0, 0, 100, 50));
assert_eq!(rect.width, 30);
assert_eq!(rect.height, 10);
}
#[test]
fn resolve_rect_clamps_when_larger_than_area() {
let popup = SpinPopup::new()
.width(PopupSize::Fixed(100))
.height(PopupSize::Fixed(50));
let rect = popup.resolve_rect(Rect::new(0, 0, 50, 20));
assert_eq!(rect.width, 50);
assert_eq!(rect.height, 20);
}
#[test]
fn snapshot_default() {
let popup = SpinPopup::new();
let mut state = SpinState::default();
render_stateful("spin_popup_default", popup, &mut state);
}
#[test]
fn snapshot_with_title() {
let popup = SpinPopup::new().title("Procesando archivos");
let mut state = SpinState::default();
render_stateful("spin_popup_with_title", popup, &mut state);
}
#[test]
fn snapshot_bg_color() {
let popup = SpinPopup::new()
.title("Procesando")
.bg_color(Color::Blue);
let mut state = SpinState::default();
render_stateful("spin_popup_bg_color", popup, &mut state);
}
#[test]
fn snapshot_finished() {
let popup = SpinPopup::new()
.title("Completado");
let mut state = SpinState {
finished: true,
exit_code: Some(0),
frame: 0,
scroll_list: ScrollListState::default(),
};
render_stateful("spin_popup_finished", popup, &mut state);
}
#[test]
fn snapshot_with_header() {
let popup = SpinPopup::new().header();
let mut state = SpinState::default();
render_stateful("spin_popup_with_header", popup, &mut state);
}