added: deferred tests-only items (extra wizard snapshots + library/asset downloads)
Closes the "zero production touches" subset of the deferred coverage items the audit had flagged. - src/tui/widgets/popups/new_instance/render.rs: three new snapshots for the Version, LoaderVersion, and Confirm steps. Each pre-populates WIZARD_STATE so ensure_versions_loaded and ensure_loader_versions_loaded short-circuit on LoadState::Loaded and never spawn a network task. The TEST_SERIAL mutex established in the earlier batch serialises against the existing Name/Loader snapshots. - src/tui/widgets/popups/import_modpack/render.rs: two new snapshots for the Version step (synthetic VersionInfo entries) and the Confirm step (synthetic ImportSummary). Same serialisation pattern. - tests/net_mojang.rs: three new wiremock tests. download_libraries_writes_artifact_to_meta_dir constructs a synthetic VersionMeta whose single library points at the wiremock server, then asserts the bytes land at meta_dir/libraries/<artifact.path>. download_libraries_skips_when_destination_exists verifies the cache hit path via wiremock's expect(0). download_assets_writes_index_when_objects_is_empty exercises the index fetch+write code path with an empty objects map so the per-asset download loop never fires. Zero production touches. download_libraries already takes a VersionMeta whose libraries carry their own URLs; download_assets' index fetch reads from meta.asset_index.url (also configurable per-call), so the empty-objects path doesn't need ASSETS_BASE_URL overridable. Full per-asset coverage lands in a separate commit.
This commit is contained in:
1 parent
d612f83446
commit
0d1b7984fc
8 files changed
+431
-1
No files matched your search
@@ -371,4 +371,104 @@ mod tests {
|
||||
.unwrap();
|
||||
insta::assert_snapshot!(terminal.backend());
|
||||
}
|
||||
|
||||
// Version step: pre-populate versions as LoadState::Loaded so
|
||||
// ensure_versions_loaded short-circuits and never spawns a network task.
|
||||
// the three synthetic versions are marked stable=true so they show with
|
||||
// show_snapshots=false (the default).
|
||||
#[test]
|
||||
fn new_instance_renders_version_step() {
|
||||
use crate::instance::loader::GameVersion;
|
||||
|
||||
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
|
||||
{
|
||||
let mut guard = WIZARD_STATE.lock().expect("WIZARD_STATE lock");
|
||||
*guard = WizardState::default();
|
||||
guard.step = WizardStep::Version;
|
||||
guard.versions = LoadState::Loaded(vec![
|
||||
GameVersion {
|
||||
id: "1.20.1".into(),
|
||||
stable: true,
|
||||
},
|
||||
GameVersion {
|
||||
id: "1.19.4".into(),
|
||||
stable: true,
|
||||
},
|
||||
GameVersion {
|
||||
id: "1.18.2".into(),
|
||||
stable: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
let backend = TestBackend::new(60, 14);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
terminal
|
||||
.draw(|f| render(f, f.area(), FocusedArea::Popup))
|
||||
.unwrap();
|
||||
insta::assert_snapshot!(terminal.backend());
|
||||
}
|
||||
|
||||
// LoaderVersion step: needs both versions and loader_versions pre-loaded.
|
||||
// pick a non-Vanilla loader (loader_idx=2 = Forge) so the step doesn't
|
||||
// skip itself to Confirm.
|
||||
#[test]
|
||||
fn new_instance_renders_loader_version_step() {
|
||||
use crate::instance::loader::GameVersion;
|
||||
|
||||
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
|
||||
{
|
||||
let mut guard = WIZARD_STATE.lock().expect("WIZARD_STATE lock");
|
||||
*guard = WizardState::default();
|
||||
guard.step = WizardStep::LoaderVersion;
|
||||
guard.loader_idx = 2; // Forge
|
||||
guard.versions = LoadState::Loaded(vec![GameVersion {
|
||||
id: "1.20.1".into(),
|
||||
stable: true,
|
||||
}]);
|
||||
guard.loader_versions = LoadState::Loaded(vec![
|
||||
"47.2.0".into(),
|
||||
"47.1.0".into(),
|
||||
"47.0.50".into(),
|
||||
]);
|
||||
}
|
||||
|
||||
let backend = TestBackend::new(60, 14);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
terminal
|
||||
.draw(|f| render(f, f.area(), FocusedArea::Popup))
|
||||
.unwrap();
|
||||
insta::assert_snapshot!(terminal.backend());
|
||||
}
|
||||
|
||||
// Confirm step: paints a summary, no network, no list. requires
|
||||
// versions + loader_versions Loaded so selected_*() return Some.
|
||||
#[test]
|
||||
fn new_instance_renders_confirm_step() {
|
||||
use crate::instance::loader::GameVersion;
|
||||
use tui_prompts::TextState;
|
||||
|
||||
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
|
||||
{
|
||||
let mut guard = WIZARD_STATE.lock().expect("WIZARD_STATE lock");
|
||||
*guard = WizardState::default();
|
||||
guard.step = WizardStep::Confirm;
|
||||
guard.loader_idx = 1; // Fabric
|
||||
guard.versions = LoadState::Loaded(vec![GameVersion {
|
||||
id: "1.20.1".into(),
|
||||
stable: true,
|
||||
}]);
|
||||
guard.loader_versions = LoadState::Loaded(vec!["0.15.0".into()]);
|
||||
// TextState exposes only constructors; rebuilding with the
|
||||
// desired initial value is the supported path.
|
||||
guard.name_state = TextState::new().with_value("MyPack");
|
||||
}
|
||||
|
||||
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