added: ratatui snapshots for instance_list and wizard popups

Phase E added snapshots for the ErrorPopup; this extends the same
pattern to the three other high-value widgets the audit flagged.

- src/tui/widgets/instances.rs: two snapshots covering the instance
  list with three synthetic instances (verifies layout, "Never played"
  rendering, scrollbar gutter) and the empty list. State is passed in
  via the existing State::with_instances constructor; no global state
  involved.

- src/tui/widgets/popups/new_instance/render.rs: two snapshots covering
  the Name step (default) and Loader step (hardcoded loader list, no
  network). WIZARD_STATE is global, so the tests reset it under its
  mutex and serialise via a per-module TEST_SERIAL mutex to prevent
  cross-test races. The Version and LoaderVersion steps are skipped
  here because their render path calls ensure_versions_loaded which
  tokio::spawns a network task; covering them would need a fully
  pre-populated state and is deferred.

- src/tui/widgets/popups/import_modpack/render.rs: two snapshots
  covering the Input step (default) and the Fetching step (just a
  spinner + label, no network triggered by render). Same global-state
  serialisation pattern as new_instance.

Snapshots live next to each widget under snapshots/ as plain text and
are committed to git.
This commit is contained in:
objz committed 2026-05-27 17:22:33 +02:00
1 parent 6ac9f4e239
commit 41d6da8008
9 files changed
+235

No files matched your search

+53
View File
@@ -366,4 +366,57 @@ mod tests {
let dt = chrono::Utc::now() - chrono::Duration::seconds(seconds_ago);
assert_eq!(format_last_played(Some(dt)), expected);
}
use crate::instance::models::{InstanceConfig, ModLoader};
use ratatui::Terminal;
use ratatui::backend::TestBackend;
fn synthetic_instance(name: &str) -> InstanceConfig {
// last_played intentionally None so the rendered text is the
// deterministic "Never played" string. anything else would make the
// snapshot drift relative to chrono::Utc::now().
InstanceConfig {
name: name.to_string(),
game_version: "1.20.1".to_string(),
loader: ModLoader::Vanilla,
loader_version: None,
created: chrono::Utc::now(),
last_played: None,
java_path: None,
memory_max: None,
memory_min: None,
jvm_args: vec![],
resolution: None,
}
}
#[test]
fn instances_list_renders_three_instances() {
let mut state = State::with_instances(vec![
synthetic_instance("Vanilla 1.20.1"),
synthetic_instance("Forge Pack"),
synthetic_instance("Fabric Test"),
]);
let backend = TestBackend::new(40, 12);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::Instances, &mut state))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
#[test]
fn instances_list_renders_empty() {
let mut state = State::with_instances(vec![]);
let backend = TestBackend::new(40, 8);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::Instances, &mut state))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
}
@@ -238,3 +238,45 @@ fn step_keybinds(state: &ImportWizardState) -> Line<'static> {
ImportStep::Confirm => keybind_line(&[("h", " back"), ("Enter", " import")]),
}
}
#[cfg(test)]
mod tests {
use super::*;
use ratatui::Terminal;
use ratatui::backend::TestBackend;
// serialise against parallel tests of the same global IMPORT_STATE.
static TEST_SERIAL: std::sync::Mutex<()> = std::sync::Mutex::new(());
fn reset_import_state(step: ImportStep) {
let mut guard = IMPORT_STATE.lock().expect("IMPORT_STATE lock");
*guard = ImportWizardState::default();
guard.step = step;
}
#[test]
fn import_modpack_renders_input_step() {
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
reset_import_state(ImportStep::Input);
let backend = TestBackend::new(60, 12);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::ImportPopup))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
#[test]
fn import_modpack_renders_fetching_step() {
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
reset_import_state(ImportStep::Fetching);
let backend = TestBackend::new(60, 12);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::ImportPopup))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
}
@@ -0,0 +1,16 @@
---
source: src/tui/widgets/popups/import_modpack/render.rs
expression: terminal.backend()
---
"╭Import Modpack────────────────────────────────────────────╮"
"│Fetching modpack info... │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"╰──────────────────────────────────────────────[Esc] cancel╯"
@@ -0,0 +1,16 @@
---
source: src/tui/widgets/popups/import_modpack/render.rs
expression: terminal.backend()
---
"╭Import Modpack────────────────────────────────────────────╮"
"│URL, slug, or pack file path...█ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"╰─────────────────────────────────────────────[Enter] fetch╯"
@@ -324,3 +324,51 @@ fn render_confirm_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
.wrap(Wrap { trim: true })
.render(area, buf);
}
#[cfg(test)]
mod tests {
use super::*;
use ratatui::Terminal;
use ratatui::backend::TestBackend;
// WIZARD_STATE is a process-global static; without serialisation, parallel
// tests would race when each test sets the step and then renders, since
// render re-acquires the WIZARD_STATE mutex internally. this guard mutex
// ensures only one wizard snapshot test runs at a time.
static TEST_SERIAL: std::sync::Mutex<()> = std::sync::Mutex::new(());
fn reset_wizard_state(step: WizardStep) {
let mut guard = WIZARD_STATE.lock().expect("WIZARD_STATE lock");
*guard = WizardState::default();
guard.step = step;
}
#[test]
fn new_instance_renders_name_step() {
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
// Name is the default step; render touches no network helpers.
reset_wizard_state(WizardStep::Name);
let backend = TestBackend::new(60, 12);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::Popup))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
#[test]
fn new_instance_renders_loader_step() {
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
// Loader step is reached after Name; render just paints the hardcoded
// loader list, no network.
reset_wizard_state(WizardStep::Loader);
let backend = TestBackend::new(60, 12);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::Popup))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
}
@@ -0,0 +1,16 @@
---
source: src/tui/widgets/popups/new_instance/render.rs
expression: terminal.backend()
---
"╭New Instance──────────────────────────────────────────────╮"
"│▶ Vanilla │"
"│ Fabric │"
"│ Forge │"
"│ NeoForge │"
"│ Quilt │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"╰──────────────────────────────────[h] back [Enter] select╯"
@@ -0,0 +1,16 @@
---
source: src/tui/widgets/popups/new_instance/render.rs
expression: terminal.backend()
---
"╭New Instance──────────────────────────────────────────────╮"
"│Instance name...█ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"╰──────────────────────────────────────────[Enter] continue╯"
@@ -0,0 +1,12 @@
---
source: src/tui/widgets/instances.rs
expression: terminal.backend()
---
"╭Instances─────────────────────────────╮"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"╰──────────────────────────────────────╯"
@@ -0,0 +1,16 @@
---
source: src/tui/widgets/instances.rs
expression: terminal.backend()
---
"╭Instances─────────────────────────────╮"
"│▌ Vanilla 1.20.1 ▲"
"│▌ Never played ║"
"│ Forge Pack ║"
"│ Never played ║"
"│ Fabric Test ║"
"│ Never played ║"
"│ ║"
"│ ║"
"│ │"
"│ ▼"
"╰──────────────────────────────────────╯"