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:
1 parent
6ac9f4e239
commit
41d6da8008
9 files changed
+235
No files matched your search
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user