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());
}
}