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
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user