use super::*;
use insta::assert_snapshot;
use ratatui::{backend::TestBackend, Terminal};
fn render_stateful(name: &str, popup: FileBrowserPopup, state: &mut FileBrowserState) {
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());
}
fn make_state() -> FileBrowserState {
FileBrowserState {
entries: vec![
FileEntry {
name: "Documentos".to_string(),
is_dir: true,
path: "/home/user/Documentos".into(),
},
FileEntry {
name: "foto.jpg".to_string(),
is_dir: false,
path: "/home/user/foto.jpg".into(),
},
FileEntry {
name: "notas.txt".to_string(),
is_dir: false,
path: "/home/user/notas.txt".into(),
},
],
items: vec![
("📁 Documentos".to_string(), Style::new().fg(Color::Cyan)),
("📄 foto.jpg".to_string(), Style::default()),
("📄 notas.txt".to_string(), Style::default()),
],
cwd: "/home/user".into(),
choose_popup_state: ChoosePopupState::default(),
show_hidden: false,
}
}
#[test]
fn snapshot_default() {
let popup = FileBrowserPopup::new();
let mut state = make_state();
render_stateful("file_browser_default", popup, &mut state);
}
#[test]
fn snapshot_bg_color() {
let popup = FileBrowserPopup::new()
.bg_color(Color::Blue);
let mut state = make_state();
render_stateful("file_browser_bg_color", popup, &mut state);
}
#[test]
fn snapshot_with_height() {
let popup = FileBrowserPopup::new().height(PopupSize::Fixed(15));
let mut state = make_state();
render_stateful("file_browser_with_height", popup, &mut state);
}
#[test]
fn snapshot_with_position() {
let popup = FileBrowserPopup::new().position(5, 5);
let mut state = make_state();
render_stateful("file_browser_with_position", popup, &mut state);
}