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());
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: src/tui/widgets/popups/import_modpack/render.rs
|
||||
expression: terminal.backend()
|
||||
---
|
||||
"╭Import Modpack────────────────────────────────────────────╮"
|
||||
"│Fetching modpack info... │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"╰──────────────────────────────────────────────[Esc] cancel╯"
|
||||
+16
@@ -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());
|
||||
}
|
||||
}
|
||||
+16
@@ -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╯"
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: src/tui/widgets/popups/new_instance/render.rs
|
||||
expression: terminal.backend()
|
||||
---
|
||||
"╭New Instance──────────────────────────────────────────────╮"
|
||||
"│Instance name...█ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"│ │"
|
||||
"╰──────────────────────────────────────────[Enter] continue╯"
|
||||
Reference in new issue
Block a user