fix(tui): fit confirmation popups to content
This commit is contained in:
1 parent
992f15b082
commit
6527b24081
6 files changed
+31
-3
No files matched your search
@@ -44,6 +44,12 @@ fn discovery_version_rows_only_show_the_version_number() {
|
||||
assert_eq!(discovery_version_label(&version), "3.2.4-fabric-26.1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_confirmation_popup_fits_its_summary() {
|
||||
assert_eq!(version_popup_height(false), VERSION_POPUP_HEIGHT);
|
||||
assert_eq!(version_popup_height(true), 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_version_popup_renders_over_a_project_page() {
|
||||
use crate::instance::ContentKind;
|
||||
|
||||
@@ -155,6 +155,14 @@ fn import_modpack_renders_confirm_step() {
|
||||
insta::assert_snapshot!(terminal.backend());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modpack_confirmation_area_fits_its_summary() {
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
reset_import_state(ImportStep::Confirm);
|
||||
|
||||
assert_eq!(popup_rect(Rect::new(0, 0, 100, 30)).height, 8);
|
||||
}
|
||||
|
||||
// Confirm step with loader_version=None: covers the branch where the
|
||||
// pack didn't declare a loader version (rare upstream, but happens for
|
||||
// older mmc packs). render_confirm_step has to handle the Option.
|
||||
|
||||
@@ -138,3 +138,11 @@ fn new_instance_renders_confirm_step() {
|
||||
.unwrap();
|
||||
insta::assert_snapshot!(terminal.backend());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_instance_confirmation_area_fits_its_summary() {
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
reset_wizard_state(WizardStep::Confirm);
|
||||
|
||||
assert_eq!(popup_rect(Rect::new(0, 0, 100, 30)).height, 6);
|
||||
}
|
||||
@@ -618,7 +618,9 @@ fn render_version_popup(frame: &mut Frame, area: Rect, state: &DiscoveryState) {
|
||||
};
|
||||
let popup_area = area.centered(
|
||||
Constraint::Percentage(50),
|
||||
Constraint::Length(VERSION_POPUP_HEIGHT.min(area.height.saturating_sub(2))),
|
||||
Constraint::Length(
|
||||
version_popup_height(popup.confirming).min(area.height.saturating_sub(2)),
|
||||
),
|
||||
);
|
||||
let theme = THEME.as_ref();
|
||||
let title = popup.title();
|
||||
@@ -727,6 +729,10 @@ fn render_version_popup(frame: &mut Frame, area: Rect, state: &DiscoveryState) {
|
||||
frame.render_widget(popup, popup_area);
|
||||
}
|
||||
|
||||
fn version_popup_height(confirming: bool) -> u16 {
|
||||
if confirming { 6 } else { VERSION_POPUP_HEIGHT }
|
||||
}
|
||||
|
||||
fn confirmation_values(values: &[String]) -> String {
|
||||
if values.is_empty() {
|
||||
"Unknown".to_owned()
|
||||
|
||||
@@ -110,7 +110,7 @@ pub fn popup_rect(frame_area: Rect) -> Rect {
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
ImportStep::Confirm => {
|
||||
let h = 10u16.min(frame_area.height.saturating_sub(4));
|
||||
let h = 8u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ pub fn popup_rect(frame_area: Rect) -> Rect {
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
WizardStep::Confirm => {
|
||||
let h = 8u16.min(frame_area.height.saturating_sub(4));
|
||||
let h = 6u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user