fix(discovery): warn for explicitly chosen Minecraft version

This commit is contained in:
objz committed 2026-09-25 10:37:49 +02:00
1 parent 1747e64278
commit 3259608c3b
2 files changed
+38 -22

No files matched your search

+23 -8
View File
@@ -60,11 +60,11 @@ fn discovery_confirmation_popup_fits_its_summary() {
VERSION_POPUP_HEIGHT
);
assert_eq!(version_popup_height(true, None, false, false), 6);
assert_eq!(version_popup_height(true, None, false, true), 8);
assert_eq!(version_popup_height(true, None, false, true), 7);
}
#[test]
fn install_summary_warns_only_when_selected_mod_does_not_support_instance_version() {
fn install_summary_warns_when_chosen_minecraft_or_mod_version_differs() {
use crate::instance::ContentKind;
use crate::net::modrinth::{DiscoveryProject, VersionInfo, VersionType};
use ratatui::{Terminal, backend::TestBackend};
@@ -95,13 +95,14 @@ fn install_summary_warns_only_when_selected_mod_does_not_support_instance_versio
project_id: "project".to_owned(),
name: "1.0".to_owned(),
version_number: "1.0".to_owned(),
game_versions: vec!["26.1".to_owned()],
game_versions: vec!["26.1".to_owned(), "26.3".to_owned()],
loaders: vec!["forge".to_owned()],
version_type: VersionType::Release,
dependencies: Vec::new(),
date_published: String::new(),
files: Vec::new(),
}];
popup.selected_minecraft_version = Some("26.1".to_owned());
let mut terminal = Terminal::new(TestBackend::new(100, 24)).unwrap();
let picker = ratatui_image::picker::Picker::halfblocks();
terminal
@@ -110,18 +111,32 @@ fn install_summary_warns_only_when_selected_mod_does_not_support_instance_versio
})
.unwrap();
let rendered = format!("{}", terminal.backend());
assert!(rendered.contains("Warning: This mod may be incompatible"));
assert!(rendered.contains("Minecraft 26.3"));
assert!(rendered.contains("Mod version may be incompatible with 26.3"));
assert!(!rendered.contains("Warning:"));
state.version_popup.as_mut().unwrap().versions[0]
.game_versions
.push("26.3".to_owned());
state
.version_popup
.as_mut()
.unwrap()
.selected_minecraft_version = Some("26.3".to_owned());
terminal
.draw(|frame| {
render_version_popup(frame, frame.area(), &mut state, &picker, Some("26.3"));
})
.unwrap();
assert!(!format!("{}", terminal.backend()).contains("may be incompatible"));
let popup = state.version_popup.as_mut().unwrap();
popup.selected_minecraft_version = None;
popup.versions[0].game_versions = vec!["26.1".to_owned()];
terminal
.draw(|frame| {
render_version_popup(frame, frame.area(), &mut state, &picker, Some("26.3"));
})
.unwrap();
assert!(
format!("{}", terminal.backend()).contains("Mod version may be incompatible with 26.3")
);
}
#[test]
+15 -14
View File
@@ -1388,17 +1388,19 @@ pub(crate) fn render_version_popup(
if popup.confirming && state.kind == crate::instance::ContentKind::Mod && !state.modpacks {
instance_game_version
.filter(|instance_version| {
popup.selected_version().is_some_and(|version| {
!version.game_versions.is_empty()
&& !version
.game_versions
.iter()
.any(|game| game == instance_version)
})
})
.map(|version| {
format!("Warning: This mod may be incompatible with Minecraft {version}.")
popup
.selected_minecraft_version
.as_deref()
.is_some_and(|selected| selected != *instance_version)
|| popup.selected_version().is_some_and(|version| {
!version.game_versions.is_empty()
&& !version
.game_versions
.iter()
.any(|game| game == instance_version)
})
})
.map(|version| format!("Mod version may be incompatible with {version}"))
} else {
None
};
@@ -1596,11 +1598,10 @@ pub(crate) fn render_version_popup(
let summary_height = rows.len() as u16;
Paragraph::new(warning)
.style(Style::default().fg(THEME.as_ref().warning()))
.wrap(Wrap { trim: false })
.render(
Rect {
y: area.y.saturating_add(summary_height),
height: area.height.saturating_sub(summary_height),
height: area.height.saturating_sub(summary_height).min(1),
..area
},
buffer,
@@ -1694,10 +1695,10 @@ fn version_popup_height(
return VERSION_POPUP_HEIGHT;
}
let Some(plan) = plan else {
return 6 + u16::from(has_world) + 2 * u16::from(has_warning);
return 6 + u16::from(has_world) + u16::from(has_warning);
};
6 + u16::from(has_world)
+ 2 * u16::from(has_warning)
+ u16::from(has_warning)
+ u16::from(plan.dependency_installs().next().is_some())
+ u16::from(plan.dependency_replacements().next().is_some())
+ u16::from(plan.optional_dependencies > 0)