fix(tui): contain settings profile input
This commit is contained in:
1 parent
70286ed9b8
commit
16e2f3204d
4 files changed
+108
-25
No files matched your search
+5
-6
@@ -546,11 +546,10 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.focused == FocusedArea::Settings {
|
if self.focused == FocusedArea::Settings {
|
||||||
let dismissed_input = key_event.code == KeyCode::Esc
|
let editing_profile = matches!(
|
||||||
&& matches!(
|
&self.settings_state.add_mode,
|
||||||
&self.settings_state.add_mode,
|
widgets::settings::AddMode::ProfileName(_)
|
||||||
widgets::settings::AddMode::ProfileName(_)
|
);
|
||||||
);
|
|
||||||
match widgets::settings::handle_key(
|
match widgets::settings::handle_key(
|
||||||
&key_event,
|
&key_event,
|
||||||
&mut self.settings_state,
|
&mut self.settings_state,
|
||||||
@@ -638,7 +637,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
widgets::settings::SettingsAction::None => {}
|
widgets::settings::SettingsAction::None => {}
|
||||||
}
|
}
|
||||||
if dismissed_input {
|
if editing_profile {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+99
-16
@@ -36,15 +36,26 @@ fn global_navigation_returns_from_log_overlay() {
|
|||||||
fn escape_returns_through_nested_sections() {
|
fn escape_returns_through_nested_sections() {
|
||||||
let mut ui = UiHarness::new();
|
let mut ui = UiHarness::new();
|
||||||
|
|
||||||
for focused in [
|
ui.app.focused = FocusedArea::Content;
|
||||||
FocusedArea::Content,
|
ui.app.mods_state.search.activate();
|
||||||
FocusedArea::Account,
|
ui.key(KeyCode::Esc);
|
||||||
FocusedArea::Settings,
|
assert_eq!(ui.app.focused, FocusedArea::Content);
|
||||||
] {
|
ui.key(KeyCode::Esc);
|
||||||
ui.app.focused = focused;
|
assert_eq!(ui.app.focused, FocusedArea::Instances);
|
||||||
ui.key(KeyCode::Esc);
|
|
||||||
assert_eq!(ui.app.focused, FocusedArea::Instances);
|
ui.app.focused = FocusedArea::Account;
|
||||||
}
|
ui.key(KeyCode::Char('a'));
|
||||||
|
ui.key(KeyCode::Esc);
|
||||||
|
assert_eq!(ui.app.focused, FocusedArea::Account);
|
||||||
|
ui.key(KeyCode::Esc);
|
||||||
|
assert_eq!(ui.app.focused, FocusedArea::Instances);
|
||||||
|
|
||||||
|
ui.app.focused = FocusedArea::Settings;
|
||||||
|
ui.key(KeyCode::Char('a'));
|
||||||
|
ui.key(KeyCode::Esc);
|
||||||
|
assert_eq!(ui.app.focused, FocusedArea::Settings);
|
||||||
|
ui.key(KeyCode::Esc);
|
||||||
|
assert_eq!(ui.app.focused, FocusedArea::Instances);
|
||||||
|
|
||||||
ui.app.focused = FocusedArea::Content;
|
ui.app.focused = FocusedArea::Content;
|
||||||
ui.app.content_tab = ContentTab::Worlds;
|
ui.app.content_tab = ContentTab::Worlds;
|
||||||
@@ -56,24 +67,94 @@ fn escape_returns_through_nested_sections() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unmatched_installed_content_has_no_version_action() {
|
fn installed_version_action_requires_selected_provider_match() {
|
||||||
let mut ui = UiHarness::new();
|
let mut ui = UiHarness::new();
|
||||||
ui.add_instance("Unmatched");
|
ui.add_instance("Unmatched");
|
||||||
ui.app.focused = FocusedArea::Content;
|
ui.app.focused = FocusedArea::Content;
|
||||||
ui.app.content_tab = ContentTab::Mods;
|
ui.app.content_tab = ContentTab::Mods;
|
||||||
let path = ui
|
let path = ui
|
||||||
.instance_path("Unmatched")
|
.instance_path("Unmatched")
|
||||||
.join("minecraft/mods/unknown.jar");
|
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
.join("mods/unknown.jar");
|
||||||
std::fs::write(&path, []).unwrap();
|
|
||||||
ui.app.mods_state.entries = vec![content_entry("Unknown mod", path)];
|
ui.app.mods_state.entries = vec![content_entry("Unknown mod", path)];
|
||||||
ui.app.mods_state.list_state.selected = Some(0);
|
ui.app.mods_state.list_state.selected = Some(0);
|
||||||
|
let record = managed_mod_record("mods/unknown.jar", "known", false, Vec::new());
|
||||||
|
let project = record.resolved_project().unwrap().clone();
|
||||||
|
ui.app.content_manifest = Some((
|
||||||
|
"Unmatched".to_owned(),
|
||||||
|
ContentManifest {
|
||||||
|
files: vec![record],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
ui.key(KeyCode::Char('v'));
|
||||||
|
assert!(ui.app.mods_discovery_state.version_popup.is_none());
|
||||||
|
|
||||||
|
ui.app.mods_state.entries[0].provider_project = Some(project);
|
||||||
|
ui.key(KeyCode::Char('v'));
|
||||||
|
assert!(ui.app.mods_discovery_state.version_popup.is_some());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn installed_version_hint_requires_selected_provider_match() {
|
||||||
|
let mut ui = UiHarness::new();
|
||||||
|
ui.app.focused = FocusedArea::Content;
|
||||||
|
ui.app.content_tab = ContentTab::Mods;
|
||||||
|
ui.app.mods_state.entries = vec![content_entry(
|
||||||
|
"Unknown mod",
|
||||||
|
PathBuf::from("mods/unknown.jar"),
|
||||||
|
)];
|
||||||
|
ui.app.mods_state.list_state.selected = Some(0);
|
||||||
|
|
||||||
ui.draw();
|
ui.draw();
|
||||||
assert!(!ui.screen().contains("[v] versions"));
|
assert!(!ui.screen().contains("[v] versions"));
|
||||||
|
|
||||||
|
ui.app.mods_state.entries[0].provider_project = Some(ProviderProject {
|
||||||
|
provider: "modrinth".to_owned(),
|
||||||
|
project_id: "known".to_owned(),
|
||||||
|
version_id: "known-version".to_owned(),
|
||||||
|
});
|
||||||
|
ui.draw();
|
||||||
|
assert!(ui.screen().contains("[v] versions"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn world_datapack_version_action_requires_selected_provider_match() {
|
||||||
|
let mut ui = UiHarness::new();
|
||||||
|
ui.add_instance("Datapacks");
|
||||||
|
ui.app.focused = FocusedArea::Content;
|
||||||
|
ui.app.content_tab = ContentTab::Worlds;
|
||||||
|
let world = ui
|
||||||
|
.instance_path("Datapacks")
|
||||||
|
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||||
|
.join("saves/World");
|
||||||
|
let path = world.join("datapacks/unknown.zip");
|
||||||
|
ui.app.world_datapacks_state.entries = vec![content_entry("Unknown datapack", path)];
|
||||||
|
ui.app.world_datapacks_state.list_state.selected = Some(0);
|
||||||
|
ui.app.open_world_datapacks = Some(("World".to_owned(), world));
|
||||||
|
let mut record = managed_mod_record(
|
||||||
|
"saves/World/datapacks/unknown.zip",
|
||||||
|
"known",
|
||||||
|
false,
|
||||||
|
Vec::new(),
|
||||||
|
);
|
||||||
|
record.kind = ContentKind::DataPack;
|
||||||
|
let project = record.resolved_project().unwrap().clone();
|
||||||
|
ui.app.content_manifest = Some((
|
||||||
|
"Datapacks".to_owned(),
|
||||||
|
ContentManifest {
|
||||||
|
files: vec![record],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
ui.key(KeyCode::Char('v'));
|
ui.key(KeyCode::Char('v'));
|
||||||
assert!(ui.app.mods_discovery_state.version_popup.is_none());
|
assert!(ui.app.datapacks_discovery_state.version_popup.is_none());
|
||||||
|
|
||||||
|
ui.app.world_datapacks_state.entries[0].provider_project = Some(project);
|
||||||
|
ui.key(KeyCode::Char('v'));
|
||||||
|
assert!(ui.app.datapacks_discovery_state.version_popup.is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -412,12 +493,14 @@ fn settings_profile_can_be_created_from_key_events() {
|
|||||||
ui.app.focused = FocusedArea::Settings;
|
ui.app.focused = FocusedArea::Settings;
|
||||||
|
|
||||||
ui.key(KeyCode::Char('a'));
|
ui.key(KeyCode::Char('a'));
|
||||||
for character in "shared".chars() {
|
for character in "qConfig".chars() {
|
||||||
ui.key(KeyCode::Char(character));
|
ui.key(KeyCode::Char(character));
|
||||||
}
|
}
|
||||||
ui.key(KeyCode::Enter);
|
ui.key(KeyCode::Enter);
|
||||||
|
|
||||||
assert_eq!(ui.app.settings_state.profiles, ["shared"]);
|
assert!(!ui.app.exit);
|
||||||
|
assert_eq!(ui.app.focused, FocusedArea::Settings);
|
||||||
|
assert_eq!(ui.app.settings_state.profiles, ["qConfig"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ fn entry(name: &str) -> ContentEntry {
|
|||||||
#[test]
|
#[test]
|
||||||
fn selected_provider_project_tracks_the_filtered_selection() {
|
fn selected_provider_project_tracks_the_filtered_selection() {
|
||||||
let mut state = ContentListState {
|
let mut state = ContentListState {
|
||||||
entries: vec![entry("Unmatched"), entry("Matched")],
|
entries: vec![entry("Local only"), entry("Provider match")],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
state.entries[1].provider_project = Some(crate::instance::ProviderProject {
|
state.entries[1].provider_project = Some(crate::instance::ProviderProject {
|
||||||
@@ -52,10 +52,11 @@ fn selected_provider_project_tracks_the_filtered_selection() {
|
|||||||
project_id: "matched".to_owned(),
|
project_id: "matched".to_owned(),
|
||||||
version_id: "version".to_owned(),
|
version_id: "version".to_owned(),
|
||||||
});
|
});
|
||||||
|
state.search.query = "local".to_owned();
|
||||||
state.list_state.selected = Some(0);
|
state.list_state.selected = Some(0);
|
||||||
|
|
||||||
assert!(!state.selected_has_provider_project());
|
assert!(!state.selected_has_provider_project());
|
||||||
state.list_state.selected = Some(1);
|
state.search.query = "provider".to_owned();
|
||||||
assert!(state.selected_has_provider_project());
|
assert!(state.selected_has_provider_project());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1125,7 +1125,7 @@ impl ContentListState {
|
|||||||
self.entries.get(*index)
|
self.entries.get(*index)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn selected_has_provider_project(&self) -> bool {
|
pub(crate) fn selected_has_provider_project(&self) -> bool {
|
||||||
self.selected_entry()
|
self.selected_entry()
|
||||||
.is_some_and(|entry| entry.provider_project.is_some())
|
.is_some_and(|entry| entry.provider_project.is_some())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user