fix: reload editor saves and reject stale TUI actions
This commit is contained in:
1 parent
eb53c7164e
commit
9cd454cee2
33 files changed
+2297
-638
No files matched your search
+580
-1
@@ -4,6 +4,555 @@
|
||||
use super::*;
|
||||
use crate::tui::tests::harness::UiHarness;
|
||||
|
||||
fn key_kind(code: KeyCode, kind: KeyEventKind) -> KeyEvent {
|
||||
KeyEvent::new_with_kind(code, KeyModifiers::NONE, kind)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dispatch_repeats_navigation_but_not_launch_delete_or_confirmation() {
|
||||
let mut ui = UiHarness::new();
|
||||
for name in ["First", "Second", "Third"] {
|
||||
ui.add_instance(name);
|
||||
}
|
||||
ui.app.instances_state.list_state.selected = Some(0);
|
||||
ui.draw();
|
||||
|
||||
assert!(ui.key_event(key_kind(KeyCode::Down, KeyEventKind::Press)));
|
||||
assert_eq!(ui.app.instances_state.list_state.selected, Some(1));
|
||||
assert!(ui.key_event(key_kind(KeyCode::Down, KeyEventKind::Repeat)));
|
||||
assert_eq!(ui.app.instances_state.list_state.selected, Some(2));
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Up, KeyEventKind::Release)));
|
||||
assert_eq!(ui.app.instances_state.list_state.selected, Some(2));
|
||||
|
||||
for code in [
|
||||
KeyCode::Char('l'),
|
||||
KeyCode::Char('d'),
|
||||
KeyCode::Char('u'),
|
||||
KeyCode::Enter,
|
||||
] {
|
||||
assert!(!ui.key_event(key_kind(code, KeyEventKind::Repeat)));
|
||||
}
|
||||
assert_eq!(ui.app.focused, FocusedArea::Instances);
|
||||
assert!(crate::instance::runtime::get("Third").is_none());
|
||||
assert!(widgets::popups::confirm::pending_target().is_none());
|
||||
|
||||
ui.key(KeyCode::Char('d'));
|
||||
assert_eq!(ui.app.focused, FocusedArea::ConfirmDelete);
|
||||
// A search behind the confirmation cannot turn its 'y' into repeatable text.
|
||||
ui.app.instances_state.search.active = true;
|
||||
for kind in [KeyEventKind::Repeat, KeyEventKind::Release] {
|
||||
for code in [KeyCode::Enter, KeyCode::Char('y'), KeyCode::Char('n')] {
|
||||
assert!(!ui.key_event(key_kind(code, kind)));
|
||||
}
|
||||
}
|
||||
assert!(ui.instance_path("Third").exists());
|
||||
assert_eq!(ui.app.focused, FocusedArea::ConfirmDelete);
|
||||
ui.app.instances_state.search.active = false;
|
||||
ui.key(KeyCode::Char('y'));
|
||||
assert!(!ui.instance_path("Third").exists());
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Char('y'), KeyEventKind::Repeat)));
|
||||
assert_eq!(ui.app.instances_state.instances.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dispatch_repeats_text_and_backspace_in_search_rename_account_and_profile_inputs() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("Text Fields");
|
||||
|
||||
ui.app.instances_state.search.activate();
|
||||
ui.key_event(key_kind(KeyCode::Char('d'), KeyEventKind::Press));
|
||||
ui.key_event(key_kind(KeyCode::Char('d'), KeyEventKind::Repeat));
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Char('d'), KeyEventKind::Release)));
|
||||
assert_eq!(ui.app.instances_state.search.query, "dd");
|
||||
assert!(ui.key_event(key_kind(KeyCode::Backspace, KeyEventKind::Repeat)));
|
||||
assert_eq!(ui.app.instances_state.search.query, "d");
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
assert!(ui.app.instances_state.search.active);
|
||||
ui.app.instances_state.search.deactivate();
|
||||
|
||||
ui.app.instances_state.renaming = Some(String::new());
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('l'), KeyEventKind::Repeat)));
|
||||
assert_eq!(ui.app.instances_state.renaming.as_deref(), Some("l"));
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
assert!(ui.instance_path("Text Fields").exists());
|
||||
ui.app.instances_state.renaming = None;
|
||||
|
||||
ui.app.focused = FocusedArea::Account;
|
||||
ui.app.account_state.add_mode = widgets::account::AddMode::OfflineNameInput(String::new());
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('d'), KeyEventKind::Repeat)));
|
||||
assert!(
|
||||
matches!(&ui.app.account_state.add_mode, widgets::account::AddMode::OfflineNameInput(name) if name == "d")
|
||||
);
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
assert_eq!(ui.app.focused, FocusedArea::Account);
|
||||
|
||||
ui.app.focused = FocusedArea::Settings;
|
||||
ui.app.settings_state.add_mode = widgets::settings::AddMode::ProfileName(String::new());
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('q'), KeyEventKind::Repeat)));
|
||||
assert!(
|
||||
matches!(&ui.app.settings_state.add_mode, widgets::settings::AddMode::ProfileName(name) if name == "q")
|
||||
);
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
assert!(!ui.app.exit);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dispatch_does_not_repeat_content_toggles_or_install_confirmation() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("One Shot Content");
|
||||
let path = ui
|
||||
.instance_path("One Shot Content")
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join("mods/test.jar");
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
std::fs::write(&path, b"mod").unwrap();
|
||||
ui.app.focused = FocusedArea::Content;
|
||||
ui.app
|
||||
.mods_state
|
||||
.set_entries(vec![crate::instance::content::entry::ContentEntry {
|
||||
file_stem: "test".to_owned(),
|
||||
name: "Test Mod".to_owned(),
|
||||
source_slug: None,
|
||||
installed_path: None,
|
||||
provider_project: None,
|
||||
world_details: None,
|
||||
title_suffix: None,
|
||||
footer_label: None,
|
||||
footer_change: None,
|
||||
description: String::new(),
|
||||
enabled: true,
|
||||
icon_bytes: None,
|
||||
provider_icon: false,
|
||||
provider_description: false,
|
||||
path: path.clone(),
|
||||
icon_lines: None,
|
||||
}]);
|
||||
ui.app.mods_state.list_state.selected = Some(0);
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
assert!(path.exists());
|
||||
ui.key(KeyCode::Enter);
|
||||
assert!(!path.exists());
|
||||
assert!(path.with_extension("jar.disabled").exists());
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
assert!(!path.exists());
|
||||
|
||||
ui.app
|
||||
.mods_discovery_state
|
||||
.begin_managed_modpack_versions(
|
||||
"Install",
|
||||
crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: "test".to_owned(),
|
||||
version_id: "installed".to_owned(),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let popup = ui.app.mods_discovery_state.version_popup.as_mut().unwrap();
|
||||
popup.loading = false;
|
||||
popup.confirming = true;
|
||||
ui.app.mods_discovery_state.search.activate();
|
||||
for code in [KeyCode::Enter, KeyCode::Char('s'), KeyCode::Tab] {
|
||||
assert!(!ui.key_event(key_kind(code, KeyEventKind::Repeat)));
|
||||
}
|
||||
let popup = ui.app.mods_discovery_state.version_popup.as_ref().unwrap();
|
||||
assert!(!popup.installing);
|
||||
assert!(!popup.skip_dependencies);
|
||||
|
||||
let popup = ui.app.mods_discovery_state.version_popup.as_mut().unwrap();
|
||||
popup.confirming = false;
|
||||
popup.selecting_world = true;
|
||||
popup.worlds.search.activate();
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('d'), KeyEventKind::Repeat)));
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.mods_discovery_state
|
||||
.version_popup
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.worlds
|
||||
.search
|
||||
.query,
|
||||
"d"
|
||||
);
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dispatch_repeats_only_the_visible_content_search() {
|
||||
use widgets::content::{ContentMode, ContentTab};
|
||||
|
||||
let mut ui = UiHarness::new();
|
||||
ui.app.focused = FocusedArea::Content;
|
||||
for tab in [
|
||||
ContentTab::Mods,
|
||||
ContentTab::ResourcePacks,
|
||||
ContentTab::Shaders,
|
||||
ContentTab::Worlds,
|
||||
ContentTab::Screenshots,
|
||||
ContentTab::Logs,
|
||||
] {
|
||||
ui.app.content_tab = tab;
|
||||
ui.key(KeyCode::Char('/'));
|
||||
assert!(
|
||||
ui.key_event(key_kind(KeyCode::Char('d'), KeyEventKind::Repeat)),
|
||||
"{tab:?}"
|
||||
);
|
||||
let query = match tab {
|
||||
ContentTab::Mods => &ui.app.mods_state.search.query,
|
||||
ContentTab::ResourcePacks => &ui.app.resource_packs_state.search.query,
|
||||
ContentTab::Shaders => &ui.app.shaders_state.search.query,
|
||||
ContentTab::Worlds => &ui.app.worlds_state.search.query,
|
||||
ContentTab::Screenshots => &ui.app.screenshots_state.search.query,
|
||||
ContentTab::Logs => &ui.app.logs_state.search.query,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
assert_eq!(query, "d");
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Tab, KeyEventKind::Repeat)));
|
||||
ui.key(KeyCode::Esc);
|
||||
}
|
||||
ui.app.content_tab = ContentTab::Worlds;
|
||||
ui.app.open_world_datapacks = Some(("World".to_owned(), std::path::PathBuf::from("World")));
|
||||
ui.app.world_datapacks_state.search.activate();
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('u'), KeyEventKind::Repeat)));
|
||||
assert_eq!(ui.app.world_datapacks_state.search.query, "u");
|
||||
ui.app.open_world_datapacks = None;
|
||||
|
||||
ui.app.content_tab = ContentTab::Logs;
|
||||
ui.app.logs_state.viewer_focused = true;
|
||||
ui.app.logs_state.viewer_search.activate();
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('G'), KeyEventKind::Repeat)));
|
||||
assert_eq!(ui.app.logs_state.viewer_search.query, "G");
|
||||
|
||||
ui.app.content_tab = ContentTab::Mods;
|
||||
ui.app.content_mode = ContentMode::Discover;
|
||||
ui.app.mods_discovery_state.search.activate();
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('v'), KeyEventKind::Repeat)));
|
||||
assert_eq!(ui.app.mods_discovery_state.search.query, "v");
|
||||
assert!(ui.app.mods_discovery_state.version_popup.is_none());
|
||||
ui.app.mods_discovery_state.search.deactivate();
|
||||
ui.app.mods_discovery_state.sort_panel_open = true;
|
||||
ui.app.mods_discovery_state.sort_panel_focused = true;
|
||||
ui.app.mods_discovery_state.filter_version_picker_open = true;
|
||||
ui.app.mods_discovery_state.filter_version_search.activate();
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('s'), KeyEventKind::Repeat)));
|
||||
assert_eq!(ui.app.mods_discovery_state.filter_version_search.query, "s");
|
||||
assert!(!ui.app.mods_discovery_state.filter_show_snapshots);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dispatch_repeats_instance_setting_text_but_not_picker_selection_or_toggles() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("Settings Text");
|
||||
ui.key(KeyCode::Char('E'));
|
||||
for _ in 0..4 {
|
||||
ui.key_event(key_kind(KeyCode::Down, KeyEventKind::Repeat));
|
||||
}
|
||||
ui.key(KeyCode::Char('c'));
|
||||
assert!(
|
||||
ui.app
|
||||
.instance_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.text_input_active()
|
||||
);
|
||||
ui.key(KeyCode::Char('d'));
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('d'), KeyEventKind::Repeat)));
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Char('d'), KeyEventKind::Release)));
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
ui.key(KeyCode::Enter);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.java_path
|
||||
.as_deref(),
|
||||
Some("dd")
|
||||
);
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Right, KeyEventKind::Repeat)));
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Char('a'), KeyEventKind::Repeat)));
|
||||
|
||||
ui.key(KeyCode::Esc);
|
||||
ui.key(KeyCode::Char('E'));
|
||||
ui.key(KeyCode::Down);
|
||||
ui.key(KeyCode::Enter);
|
||||
let loader = ui.app.instance_settings.as_ref().unwrap().draft.loader;
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Right, KeyEventKind::Repeat)));
|
||||
assert_eq!(
|
||||
ui.app.instance_settings.as_ref().unwrap().draft.loader,
|
||||
loader
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dispatch_repeats_wizard_name_import_input_and_discovery_search() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.key(KeyCode::Char('a'));
|
||||
ui.key(KeyCode::Char('q'));
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('q'), KeyEventKind::Repeat)));
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Char('q'), KeyEventKind::Release)));
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("qq"));
|
||||
assert!(!ui.app.exit);
|
||||
ui.key(KeyCode::Esc);
|
||||
|
||||
ui.key(KeyCode::Char('m'));
|
||||
ui.key(KeyCode::Char('i'));
|
||||
ui.key(KeyCode::Char('q'));
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('q'), KeyEventKind::Repeat)));
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("qq"));
|
||||
ui.key(KeyCode::Esc);
|
||||
ui.key(KeyCode::Char('/'));
|
||||
assert!(ui.key_event(key_kind(KeyCode::Char('v'), KeyEventKind::Repeat)));
|
||||
assert!(!ui.key_event(key_kind(KeyCode::Enter, KeyEventKind::Repeat)));
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("/ v"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gui_editor_handoff_process() {}
|
||||
|
||||
#[test]
|
||||
fn unrelated_directory_events_do_not_postpone_an_edited_file_save() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let path = temp.path().join("instance.json");
|
||||
std::fs::write(&path, b"old").unwrap();
|
||||
let mut watch = EditedConfigWatch::new(path.clone()).unwrap();
|
||||
let (sender, events) = std::sync::mpsc::channel();
|
||||
watch.events = events;
|
||||
watch.pending = Some(std::time::Instant::now() - Duration::from_secs(1));
|
||||
std::fs::write(path, b"new").unwrap();
|
||||
sender
|
||||
.send(Ok(notify::Event::new(notify::EventKind::Modify(
|
||||
notify::event::ModifyKind::Any,
|
||||
))
|
||||
.add_path(temp.path().join("other.json"))))
|
||||
.unwrap();
|
||||
assert!(watch.changed());
|
||||
std::fs::write(temp.path().join("instance.json"), b"changed again").unwrap();
|
||||
sender
|
||||
.send(Ok(notify::Event::new(notify::EventKind::Modify(
|
||||
notify::event::ModifyKind::Any,
|
||||
))
|
||||
.add_path(temp.path().join("INSTANCE.JSON"))))
|
||||
.unwrap();
|
||||
assert!(!watch.changed());
|
||||
assert!(watch.pending.is_some());
|
||||
watch.pending = Some(std::time::Instant::now() - Duration::from_secs(1));
|
||||
assert!(watch.changed());
|
||||
}
|
||||
|
||||
fn wait_for_edited_config(ui: &mut UiHarness, changed: bool) {
|
||||
let deadline = std::time::Instant::now() + Duration::from_secs(5);
|
||||
let mut observed = false;
|
||||
loop {
|
||||
let reloaded = ui.app.drain_edited_configs();
|
||||
observed |= ui
|
||||
.app
|
||||
.edited_config_watches
|
||||
.iter()
|
||||
.any(|watch| watch.pending.is_some());
|
||||
if changed && reloaded {
|
||||
return;
|
||||
}
|
||||
assert!(!reloaded, "unchanged bytes must not reload");
|
||||
if !changed
|
||||
&& observed
|
||||
&& ui
|
||||
.app
|
||||
.edited_config_watches
|
||||
.iter()
|
||||
.all(|watch| watch.pending.is_none())
|
||||
{
|
||||
return;
|
||||
}
|
||||
assert!(
|
||||
std::time::Instant::now() < deadline,
|
||||
"edited file notification timed out"
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gui_editor_saves_reload_after_handoff_and_atomic_replacement_only_when_bytes_change() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("GUI Edited");
|
||||
let path = ui.instance_path("GUI Edited").join("instance.json");
|
||||
let mut config = ui.app.instances_state.selected_instance().unwrap().clone();
|
||||
config.memory_max = Some("4G".to_owned());
|
||||
ui.app.instance_manager.save(&config).unwrap();
|
||||
let original = std::fs::read(&path).unwrap();
|
||||
|
||||
let reaper = ui
|
||||
.app
|
||||
.launch_gui_editor(
|
||||
std::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args(["--exact", "tui::event::tests::gui_editor_handoff_process"]),
|
||||
&path,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(!ui.app.drain_edited_configs());
|
||||
reaper.join().unwrap();
|
||||
assert!(!ui.app.drain_edited_configs());
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.memory_max,
|
||||
None
|
||||
);
|
||||
ui.app.watch_edited_config(&path).unwrap();
|
||||
assert_eq!(ui.app.edited_config_watches.len(), 1);
|
||||
|
||||
std::fs::write(&path, &original).unwrap();
|
||||
wait_for_edited_config(&mut ui, false);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.memory_max,
|
||||
None
|
||||
);
|
||||
|
||||
config.memory_max = Some("8G".to_owned());
|
||||
std::fs::write(&path, serde_json::to_vec(&config).unwrap()).unwrap();
|
||||
wait_for_edited_config(&mut ui, true);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.memory_max
|
||||
.as_deref(),
|
||||
Some("8G")
|
||||
);
|
||||
|
||||
config.memory_max = Some("12G".to_owned());
|
||||
crate::storage::write_atomic(&path, &serde_json::to_vec(&config).unwrap()).unwrap();
|
||||
wait_for_edited_config(&mut ui, true);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.memory_max
|
||||
.as_deref(),
|
||||
Some("12G")
|
||||
);
|
||||
|
||||
config.memory_max = Some("16G".to_owned());
|
||||
std::fs::write(&path, serde_json::to_vec(&config).unwrap()).unwrap();
|
||||
wait_for_edited_config(&mut ui, true);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.memory_max
|
||||
.as_deref(),
|
||||
Some("16G")
|
||||
);
|
||||
|
||||
std::fs::write(&path, b"invalid instance config").unwrap();
|
||||
wait_for_edited_config(&mut ui, true);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.memory_max
|
||||
.as_deref(),
|
||||
Some("16G")
|
||||
);
|
||||
assert!(
|
||||
error_buffer::peek_error()
|
||||
.unwrap()
|
||||
.message
|
||||
.contains("Failed to reload edited instance")
|
||||
);
|
||||
config.memory_max = Some("20G".to_owned());
|
||||
crate::storage::write_atomic(&path, &serde_json::to_vec(&config).unwrap()).unwrap();
|
||||
wait_for_edited_config(&mut ui, true);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.memory_max
|
||||
.as_deref(),
|
||||
Some("20G")
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn launcher_config_save_process() {
|
||||
if std::env::var_os("RMCL_EDITOR_CONFIG_TEST").is_none() {
|
||||
return;
|
||||
}
|
||||
let mut ui = UiHarness::new();
|
||||
let config_path = crate::config::get_config_path().join("config.toml");
|
||||
let theme_path = crate::config::get_config_path().join("theme.toml");
|
||||
let mut theme = crate::config::theme::ThemeConfig::default();
|
||||
std::fs::write(&theme_path, toml::to_string(&theme).unwrap()).unwrap();
|
||||
ui.app.watch_edited_config(&config_path).unwrap();
|
||||
ui.app.watch_edited_config(&theme_path).unwrap();
|
||||
assert!(!ui.app.drain_edited_configs());
|
||||
|
||||
let mut config = crate::config::SETTINGS.read().clone();
|
||||
config.ui.error_auto_dismiss_ms += 1;
|
||||
let timeout = config.ui.error_auto_dismiss_ms;
|
||||
std::fs::write(&config_path, toml::to_string(&config).unwrap()).unwrap();
|
||||
wait_for_edited_config(&mut ui, true);
|
||||
assert_eq!(
|
||||
crate::config::SETTINGS.read().ui.error_auto_dismiss_ms,
|
||||
timeout
|
||||
);
|
||||
|
||||
theme.theme = "dracula".to_owned();
|
||||
theme.border_style = crate::config::theme::BorderStyle::Thick;
|
||||
crate::storage::write_atomic(&theme_path, toml::to_string(&theme).unwrap().as_bytes()).unwrap();
|
||||
wait_for_edited_config(&mut ui, true);
|
||||
assert_eq!(
|
||||
crate::config::theme::current_theme_config().theme,
|
||||
"dracula"
|
||||
);
|
||||
assert_eq!(
|
||||
crate::config::theme::BORDER_STYLE.current(),
|
||||
crate::config::theme::BorderStyle::Thick
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn watched_launcher_config_and_theme_saves_update_cached_settings() {
|
||||
let ui = UiHarness::new();
|
||||
let root = ui.app.instance_manager.instances_dir.parent().unwrap();
|
||||
let result = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args([
|
||||
"--exact",
|
||||
"tui::event::tests::launcher_config_save_process",
|
||||
"--nocapture",
|
||||
])
|
||||
.env("RMCL_EDITOR_CONFIG_TEST", "1")
|
||||
.env("HOME", root)
|
||||
.env("XDG_CONFIG_HOME", root)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
result.status.success(),
|
||||
"{}{}",
|
||||
String::from_utf8_lossy(&result.stdout),
|
||||
String::from_utf8_lossy(&result.stderr)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edited_instance_config_reloads_into_the_ui() {
|
||||
let mut ui = UiHarness::new();
|
||||
@@ -363,7 +912,37 @@ fn editor_kind_is_detected_from_the_executable_name() {
|
||||
assert!(editor_runs_in_terminal("/usr/bin/nvim"));
|
||||
assert!(editor_runs_in_terminal("nano"));
|
||||
assert!(!editor_runs_in_terminal("/usr/bin/code"));
|
||||
assert_eq!(editor_parts("nvim -u NONE"), ["nvim", "-u", "NONE"]);
|
||||
assert_eq!(
|
||||
editor_parts("nvim -u NONE").unwrap(),
|
||||
["nvim", "-u", "NONE"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editor_commands_preserve_quoted_paths_arguments_and_empty_arguments() {
|
||||
assert_eq!(
|
||||
editor_parts(r#""/path with spaces/editor" --wait "two words" """#).unwrap(),
|
||||
["/path with spaces/editor", "--wait", "two words", ""]
|
||||
);
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let executable = temp.path().join("editor with spaces");
|
||||
std::fs::write(&executable, b"executable").unwrap();
|
||||
assert_eq!(
|
||||
editor_parts(executable.to_str().unwrap()).unwrap(),
|
||||
[executable.to_string_lossy().into_owned()]
|
||||
);
|
||||
#[cfg(unix)]
|
||||
assert!(editor_parts("editor 'unterminated").is_err());
|
||||
#[cfg(windows)]
|
||||
assert_eq!(
|
||||
editor_parts(r#""C:\Program Files\editor.exe" --wait "C:\folder with spaces\file.txt""#)
|
||||
.unwrap(),
|
||||
[
|
||||
r"C:\Program Files\editor.exe",
|
||||
"--wait",
|
||||
r"C:\folder with spaces\file.txt"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+109
-28
@@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
|
||||
use super::harness::UiHarness;
|
||||
use crate::instance::content::entry::ContentEntry;
|
||||
use crate::instance::{
|
||||
ContentFileRecord, ContentKind, ContentManifest, FileFingerprint, ProviderProject, Resolution,
|
||||
ContentFileRecord, ContentKind, ContentManifest, ProviderProject, Resolution,
|
||||
};
|
||||
use crate::net::modrinth::DiscoveryProject;
|
||||
use crate::tui::{
|
||||
@@ -18,6 +18,22 @@ use crate::tui::{
|
||||
},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn remote_project_links_use_http_urls_and_encode_shell_metacharacters() {
|
||||
let url =
|
||||
crate::tui::input::project_link_url(r#"https://example.com/"&%USERNAME%?q=a b"#).unwrap();
|
||||
assert_eq!(url.as_str(), "https://example.com/%22&%USERNAME%?q=a%20b");
|
||||
for link in [
|
||||
"file:///C:/Windows/notepad.exe",
|
||||
"javascript:alert(1)",
|
||||
"shell:AppsFolder",
|
||||
r"C:\folder\file",
|
||||
"not a url",
|
||||
] {
|
||||
assert!(crate::tui::input::project_link_url(link).is_err(), "{link}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_navigation_returns_from_log_overlay() {
|
||||
let mut ui = UiHarness::new();
|
||||
@@ -72,13 +88,13 @@ fn installed_version_action_requires_selected_provider_match() {
|
||||
ui.add_instance("Unmatched");
|
||||
ui.app.focused = FocusedArea::Content;
|
||||
ui.app.content_tab = ContentTab::Mods;
|
||||
let path = ui
|
||||
.instance_path("Unmatched")
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join("mods/unknown.jar");
|
||||
let minecraft = crate::storage::InstancePaths::new(ui.instance_path("Unmatched")).minecraft();
|
||||
let path = minecraft.join("mods/unknown.jar");
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
std::fs::write(&path, b"unknown").unwrap();
|
||||
ui.app.mods_state.entries = vec![content_entry("Unknown mod", path)];
|
||||
ui.app.mods_state.list_state.selected = Some(0);
|
||||
let record = managed_mod_record("mods/unknown.jar", "known", false, Vec::new());
|
||||
let record = managed_mod_record(&minecraft, "mods/unknown.jar", "known", false, Vec::new());
|
||||
let project = record.resolved_project().unwrap().clone();
|
||||
ui.app.content_manifest = Some((
|
||||
"Unmatched".to_owned(),
|
||||
@@ -102,13 +118,13 @@ fn installed_popup_navigation_preserves_local_filters() {
|
||||
ui.add_instance("Popup");
|
||||
ui.app.focused = FocusedArea::Content;
|
||||
ui.app.content_tab = ContentTab::Mods;
|
||||
let path = ui
|
||||
.instance_path("Popup")
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join("mods/known.jar");
|
||||
let minecraft = crate::storage::InstancePaths::new(ui.instance_path("Popup")).minecraft();
|
||||
let path = minecraft.join("mods/known.jar");
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
std::fs::write(&path, b"known").unwrap();
|
||||
ui.app.mods_state.entries = vec![content_entry("Known mod", path)];
|
||||
ui.app.mods_state.list_state.selected = Some(0);
|
||||
let record = managed_mod_record("mods/known.jar", "known", false, Vec::new());
|
||||
let record = managed_mod_record(&minecraft, "mods/known.jar", "known", false, Vec::new());
|
||||
let project = record.resolved_project().unwrap().clone();
|
||||
ui.app.content_manifest = Some((
|
||||
"Popup".to_owned(),
|
||||
@@ -282,15 +298,16 @@ fn world_datapack_version_action_requires_selected_provider_match() {
|
||||
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 minecraft = crate::storage::InstancePaths::new(ui.instance_path("Datapacks")).minecraft();
|
||||
let world = minecraft.join("saves/World");
|
||||
let path = world.join("datapacks/unknown.zip");
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
std::fs::write(&path, b"pack").unwrap();
|
||||
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(
|
||||
&minecraft,
|
||||
"saves/World/datapacks/unknown.zip",
|
||||
"known",
|
||||
false,
|
||||
@@ -482,6 +499,7 @@ fn confirmed_screenshot_delete_removes_state_and_file() {
|
||||
}
|
||||
|
||||
fn managed_mod_record(
|
||||
minecraft: &Path,
|
||||
path: &str,
|
||||
project_id: &str,
|
||||
automatic_dependency: bool,
|
||||
@@ -491,11 +509,8 @@ fn managed_mod_record(
|
||||
relative_path: PathBuf::from(path),
|
||||
kind: ContentKind::Mod,
|
||||
enabled: true,
|
||||
fingerprint: FileFingerprint {
|
||||
size: 1,
|
||||
modified_ns: 1,
|
||||
hashes: Default::default(),
|
||||
},
|
||||
fingerprint: crate::instance::content::manifest::fingerprint(&minecraft.join(path))
|
||||
.unwrap(),
|
||||
resolution: Resolution::Resolved {
|
||||
project: ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
@@ -552,8 +567,8 @@ fn deleting_a_mod_offers_its_unused_dependency_chain() {
|
||||
ContentManifest {
|
||||
version: 1,
|
||||
files: vec![
|
||||
managed_mod_record("mods/root.jar", "root", false, vec![dependency]),
|
||||
managed_mod_record("mods/library.jar", "library", true, Vec::new()),
|
||||
managed_mod_record(&minecraft, "mods/root.jar", "root", false, vec![dependency]),
|
||||
managed_mod_record(&minecraft, "mods/library.jar", "library", true, Vec::new()),
|
||||
],
|
||||
}
|
||||
.save(&crate::storage::InstancePaths::new(ui.instance_path("Dependencies")).content_manifest())
|
||||
@@ -596,10 +611,12 @@ fn deleting_a_required_library_warns_but_can_continue() {
|
||||
let library_path = minecraft.join("mods/library.jar");
|
||||
std::fs::create_dir_all(library_path.parent().unwrap()).unwrap();
|
||||
std::fs::write(&library_path, b"l").unwrap();
|
||||
std::fs::write(minecraft.join("mods/root.jar"), b"r").unwrap();
|
||||
ContentManifest {
|
||||
version: 1,
|
||||
files: vec![
|
||||
managed_mod_record(
|
||||
&minecraft,
|
||||
"mods/root.jar",
|
||||
"root",
|
||||
false,
|
||||
@@ -609,7 +626,7 @@ fn deleting_a_required_library_warns_but_can_continue() {
|
||||
version_id: "library-version".to_owned(),
|
||||
}],
|
||||
),
|
||||
managed_mod_record("mods/library.jar", "library", true, Vec::new()),
|
||||
managed_mod_record(&minecraft, "mods/library.jar", "library", true, Vec::new()),
|
||||
],
|
||||
}
|
||||
.save(&crate::storage::InstancePaths::new(ui.instance_path("Required")).content_manifest())
|
||||
@@ -630,6 +647,58 @@ fn deleting_a_required_library_warns_but_can_continue() {
|
||||
assert!(!Path::new(&library_path).exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_delete_rejects_ownership_changed_after_confirmation_opened() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("ChangedOwner");
|
||||
let paths = crate::storage::InstancePaths::new(ui.instance_path("ChangedOwner"));
|
||||
let minecraft = paths.minecraft();
|
||||
let path = minecraft.join("mods/root.jar");
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
std::fs::write(&path, b"original").unwrap();
|
||||
let manifest = ContentManifest {
|
||||
version: 1,
|
||||
files: vec![managed_mod_record(
|
||||
&minecraft,
|
||||
"mods/root.jar",
|
||||
"root",
|
||||
false,
|
||||
Vec::new(),
|
||||
)],
|
||||
};
|
||||
manifest.save(&paths.content_manifest()).unwrap();
|
||||
ui.app.content_manifest = Some(("ChangedOwner".to_owned(), manifest));
|
||||
ui.app.mods_state.entries = vec![content_entry("Root", path.clone())];
|
||||
ui.app.mods_state.list_state.selected = Some(0);
|
||||
ui.app.focused = FocusedArea::Content;
|
||||
ui.app.content_tab = ContentTab::Mods;
|
||||
ui.key(KeyCode::Char('d'));
|
||||
|
||||
let new_owner = ProviderProject {
|
||||
provider: "curseforge".to_owned(),
|
||||
project_id: "new-owner".to_owned(),
|
||||
version_id: "new".to_owned(),
|
||||
};
|
||||
ContentManifest::update(&paths.content_manifest(), |manifest| {
|
||||
manifest.files[0].resolution = Resolution::Resolved {
|
||||
project: new_owner.clone(),
|
||||
};
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
assert_eq!(std::fs::read(&path).unwrap(), b"original");
|
||||
assert_eq!(ui.app.mods_state.entries[0].path, path);
|
||||
assert_eq!(
|
||||
ContentManifest::load(&paths.content_manifest())
|
||||
.unwrap()
|
||||
.files[0]
|
||||
.resolved_project(),
|
||||
Some(&new_owner)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confirmed_account_delete_updates_the_account_panel() {
|
||||
let mut ui = UiHarness::new();
|
||||
@@ -1164,6 +1233,7 @@ fn instance_launch_options_autosave_through_the_editor() {
|
||||
fn settings_panel_keeps_direct_profile_management() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("profile-test");
|
||||
std::fs::create_dir_all(ui.instance_path("profile-test").join("minecraft")).unwrap();
|
||||
ui.app.focused = FocusedArea::Settings;
|
||||
|
||||
ui.key(KeyCode::Char('a'));
|
||||
@@ -1249,6 +1319,11 @@ fn provider_conflict_selection_is_persisted() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("Conflict");
|
||||
let relative_path = std::path::PathBuf::from("mods/example.jar");
|
||||
let file = crate::storage::InstancePaths::new(ui.instance_path("Conflict"))
|
||||
.minecraft()
|
||||
.join(&relative_path);
|
||||
std::fs::create_dir_all(file.parent().unwrap()).unwrap();
|
||||
std::fs::write(&file, b"example").unwrap();
|
||||
let candidates = vec![
|
||||
ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
@@ -1267,11 +1342,7 @@ fn provider_conflict_selection_is_persisted() {
|
||||
relative_path: relative_path.clone(),
|
||||
kind: crate::instance::ContentKind::Mod,
|
||||
enabled: true,
|
||||
fingerprint: crate::instance::FileFingerprint {
|
||||
size: 1,
|
||||
modified_ns: 0,
|
||||
hashes: Default::default(),
|
||||
},
|
||||
fingerprint: crate::instance::content::manifest::fingerprint(&file).unwrap(),
|
||||
resolution: crate::instance::Resolution::Ambiguous {
|
||||
candidates: candidates.clone(),
|
||||
},
|
||||
@@ -1293,6 +1364,16 @@ fn provider_conflict_selection_is_persisted() {
|
||||
});
|
||||
|
||||
ui.key(KeyCode::Down);
|
||||
std::fs::write(&manifest_path, b"invalid").unwrap();
|
||||
ui.key(KeyCode::Enter);
|
||||
assert_eq!(ui.app.provider_conflict.as_ref().unwrap().selected, 1);
|
||||
ui.app
|
||||
.content_manifest
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.1
|
||||
.save(&manifest_path)
|
||||
.unwrap();
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
assert!(ui.app.provider_conflict.is_none());
|
||||
|
||||
+25
-13
@@ -3,7 +3,7 @@
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
|
||||
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
|
||||
use ratatui::{Terminal, backend::TestBackend};
|
||||
|
||||
use crate::auth::{Account, AccountStore, AccountType};
|
||||
@@ -94,7 +94,10 @@ impl UiHarness {
|
||||
},
|
||||
logs_state: widgets::logs_viewer::LogsState::default(),
|
||||
account_state,
|
||||
settings_state: widgets::settings::SettingsState::new(meta_dir),
|
||||
settings_state: widgets::settings::SettingsState::new(
|
||||
meta_dir,
|
||||
instance_manager.instances_dir.clone(),
|
||||
),
|
||||
instance_settings: None,
|
||||
pending_instance_settings_updates: Default::default(),
|
||||
global_settings: None,
|
||||
@@ -109,6 +112,7 @@ impl UiHarness {
|
||||
throbber_tick: 0,
|
||||
error_effects: HashMap::new(),
|
||||
pending_editor: None,
|
||||
edited_config_watches: Vec::new(),
|
||||
reconciliation_for: None,
|
||||
content_manifest: None,
|
||||
content_update_snapshot: None,
|
||||
@@ -164,15 +168,19 @@ impl UiHarness {
|
||||
}
|
||||
|
||||
pub fn add_account(&mut self, username: &str) {
|
||||
self.app.account_state.store.accounts.push(Account {
|
||||
uuid: username.to_owned(),
|
||||
username: username.to_owned(),
|
||||
account_type: AccountType::Microsoft,
|
||||
active: true,
|
||||
refresh_token: Some("refresh".to_owned()),
|
||||
cached_mc_token: None,
|
||||
cached_mc_token_expires_at: None,
|
||||
});
|
||||
self.app
|
||||
.account_state
|
||||
.store
|
||||
.add(Account {
|
||||
uuid: username.to_owned(),
|
||||
username: username.to_owned(),
|
||||
account_type: AccountType::Microsoft,
|
||||
active: true,
|
||||
refresh_token: Some("refresh".to_owned()),
|
||||
cached_mc_token: None,
|
||||
cached_mc_token_expires_at: None,
|
||||
})
|
||||
.expect("persist test account");
|
||||
self.app.account_state.list_state.selected = Some(0);
|
||||
}
|
||||
|
||||
@@ -185,10 +193,14 @@ impl UiHarness {
|
||||
}
|
||||
|
||||
pub fn key_with(&mut self, code: KeyCode, modifiers: KeyModifiers) {
|
||||
self.key_event(KeyEvent::new(code, modifiers));
|
||||
}
|
||||
|
||||
pub fn key_event(&mut self, key: KeyEvent) -> bool {
|
||||
let _runtime = self.runtime.enter();
|
||||
self.app
|
||||
.handle_key_event(KeyEvent::new(code, modifiers))
|
||||
.expect("handle key");
|
||||
.dispatch_event(Event::Key(key))
|
||||
.expect("handle key")
|
||||
}
|
||||
|
||||
pub fn mouse(&mut self, kind: MouseEventKind) {
|
||||
|
||||
@@ -2,6 +2,18 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn changing_loader_isolates_pending_filter_versions() {
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
let previous = state.filter_game_versions.clone();
|
||||
state.set_filter_loader(ModLoader::Fabric);
|
||||
*previous.lock().unwrap() = crate::tui::widgets::popups::LoadState::Error("stale".to_owned());
|
||||
assert!(matches!(
|
||||
*state.filter_game_versions.lock().unwrap(),
|
||||
crate::tui::widgets::popups::LoadState::Idle
|
||||
));
|
||||
}
|
||||
use crate::tests::TEST_LOCK;
|
||||
use chrono::Utc;
|
||||
use crossterm::event::KeyModifiers;
|
||||
@@ -1332,6 +1344,7 @@ fn dependency_resolution_opens_the_existing_confirmation() {
|
||||
title: "Project".to_owned(),
|
||||
version: root_version,
|
||||
installed_path: None,
|
||||
expected_record: None,
|
||||
kind: crate::instance::ContentKind::Mod,
|
||||
destination: std::path::PathBuf::from("mods"),
|
||||
provider_aliases: Vec::new(),
|
||||
@@ -1389,6 +1402,7 @@ fn confirming_state_with_plan() -> DiscoveryState {
|
||||
title: title.to_owned(),
|
||||
version,
|
||||
installed_path: None,
|
||||
expected_record: None,
|
||||
kind: crate::instance::ContentKind::Mod,
|
||||
destination: std::path::PathBuf::from("mods"),
|
||||
provider_aliases: Vec::new(),
|
||||
|
||||
@@ -8,6 +8,30 @@ use std::{
|
||||
};
|
||||
|
||||
use crate::instance::content::entry::{ContentEntry, WorldDetails, WorldGameMode};
|
||||
|
||||
#[tokio::test]
|
||||
async fn pending_version_metadata_does_not_queue_another_request_each_redraw() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let mut state = ContentListState {
|
||||
provider_icon_meta_dir: Some(temp.path().to_owned()),
|
||||
provider_icon_client: Some(crate::net::HttpClient::new()),
|
||||
local_game_version: "1.21".to_owned(),
|
||||
..ContentListState::default()
|
||||
};
|
||||
let mut entry = entry("project");
|
||||
entry.provider_project = Some(crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: "project".to_owned(),
|
||||
version_id: "version".to_owned(),
|
||||
});
|
||||
state.entries.push(entry);
|
||||
state.request_visible_provider_icons(&[0], 10);
|
||||
let pending = Arc::strong_count(&state.pending_provider_icons);
|
||||
for _ in 0..10 {
|
||||
state.request_visible_provider_icons(&[0], 10);
|
||||
}
|
||||
assert_eq!(Arc::strong_count(&state.pending_provider_icons), pending);
|
||||
}
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::Rect,
|
||||
|
||||
@@ -185,6 +185,7 @@ fn skipped_dependencies_render_as_skipped_in_confirmation() {
|
||||
title: title.to_owned(),
|
||||
version,
|
||||
installed_path: None,
|
||||
expected_record: None,
|
||||
kind: ContentKind::Mod,
|
||||
destination: std::path::PathBuf::from("mods"),
|
||||
provider_aliases: Vec::new(),
|
||||
|
||||
@@ -48,3 +48,58 @@ fn list_and_viewer_navigation_loads_and_scrolls_the_selected_log() {
|
||||
assert!(handle_key(&key(KeyCode::Esc), &mut state));
|
||||
assert!(!state.viewer_focused);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rescans_and_runtime_changes_keep_the_selected_log_and_viewer_in_sync() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let older = LogFileEntry {
|
||||
name: "older.log".to_owned(),
|
||||
path: temp.path().join("older.log"),
|
||||
};
|
||||
let newer = LogFileEntry {
|
||||
name: "newer.log".to_owned(),
|
||||
path: temp.path().join("newer.log"),
|
||||
};
|
||||
std::fs::write(&older.path, "older content").unwrap();
|
||||
std::fs::write(&newer.path, "newer content").unwrap();
|
||||
let name = "logs-rescan-identity";
|
||||
let mut state = LogsState {
|
||||
loaded_for: Some(name.to_owned()),
|
||||
entries: vec![older.clone()],
|
||||
..Default::default()
|
||||
};
|
||||
state.list_state.selected = Some(0);
|
||||
state.load_selected_content();
|
||||
*state.pending.lock().unwrap() = Some((name.to_owned(), vec![newer.clone(), older.clone()]));
|
||||
state.drain_pending();
|
||||
assert_eq!(state.list_state.selected, Some(1));
|
||||
assert_eq!(state.viewer_lines, ["older content"]);
|
||||
|
||||
crate::instance::runtime::set_state(name, crate::instance::runtime::RunState::Running);
|
||||
state.drain_pending();
|
||||
assert_eq!(state.list_state.selected, Some(2));
|
||||
state.search.query = "older".to_owned();
|
||||
state.list_state.selected = Some(0);
|
||||
state.load_selected_content();
|
||||
assert!(!state.is_live_selected());
|
||||
let mut terminal = ratatui::Terminal::new(ratatui::backend::TestBackend::new(60, 4)).unwrap();
|
||||
terminal
|
||||
.draw(|frame| render_viewer(frame, frame.area(), &mut state))
|
||||
.unwrap();
|
||||
let rendered = terminal
|
||||
.backend()
|
||||
.buffer()
|
||||
.content
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(rendered.contains("older content"));
|
||||
|
||||
state.search.query.clear();
|
||||
state.list_state.selected = Some(0);
|
||||
state.load_selected_content();
|
||||
crate::instance::runtime::remove(name);
|
||||
state.drain_pending();
|
||||
assert_eq!(state.viewer_lines, ["newer content"]);
|
||||
assert_eq!(state.selected_path, Some(newer.path));
|
||||
}
|
||||
@@ -435,6 +435,18 @@ fn emphasis_next_to_html_tag_boundaries_does_not_leak_markers() {
|
||||
assert!(!rendered.contains('*'), "{rendered}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_stars_and_code_operators_are_preserved() {
|
||||
let text = formatted_text("`*` and `2 ** 3` and \\*", 80);
|
||||
assert_eq!(
|
||||
text.lines
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<String>(),
|
||||
"* and 2 ** 3 and *"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fenced_code_blocks_are_rendered_without_fences() {
|
||||
let text = formatted_text("```json5\n{\n \"enabled\": true\n}\n```", 24);
|
||||
|
||||
@@ -16,6 +16,43 @@ fn key(code: KeyCode) -> KeyEvent {
|
||||
KeyEvent::new(code, KeyModifiers::NONE)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dispatch_repeats_import_version_search_but_not_import_confirmation() {
|
||||
use crate::tui::{app::FocusedArea, tests::harness::UiHarness};
|
||||
use crossterm::event::KeyEventKind;
|
||||
|
||||
let mut ui = UiHarness::new();
|
||||
ui.app.focused = FocusedArea::ImportPopup;
|
||||
ui.app.instances_state.show_import_popup = true;
|
||||
IMPORT_STATE.lock().unwrap().step = ImportStep::Version;
|
||||
IMPORT_STATE.lock().unwrap().version_search.activate();
|
||||
assert!(ui.key_event(KeyEvent::new_with_kind(
|
||||
KeyCode::Char('i'),
|
||||
KeyModifiers::NONE,
|
||||
KeyEventKind::Repeat
|
||||
)));
|
||||
assert_eq!(IMPORT_STATE.lock().unwrap().version_search.query, "i");
|
||||
assert!(!ui.key_event(KeyEvent::new_with_kind(
|
||||
KeyCode::Enter,
|
||||
KeyModifiers::NONE,
|
||||
KeyEventKind::Repeat
|
||||
)));
|
||||
{
|
||||
let mut state = IMPORT_STATE.lock().unwrap();
|
||||
state.step = ImportStep::Confirm;
|
||||
state.summary = Some(summary());
|
||||
}
|
||||
assert!(!ui.key_event(KeyEvent::new_with_kind(
|
||||
KeyCode::Enter,
|
||||
KeyModifiers::NONE,
|
||||
KeyEventKind::Repeat
|
||||
)));
|
||||
assert!(take_result().is_none());
|
||||
assert!(ui.app.instances_state.show_import_popup);
|
||||
ui.key(KeyCode::Enter);
|
||||
assert_eq!(take_result().unwrap().summary.name, "Test Pack");
|
||||
}
|
||||
|
||||
fn summary() -> ImportSummary {
|
||||
ImportSummary {
|
||||
name: "Test Pack".to_owned(),
|
||||
|
||||
@@ -11,6 +11,61 @@ fn key(code: KeyCode) -> KeyEvent {
|
||||
KeyEvent::new(code, KeyModifiers::NONE)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dispatch_repeats_version_search_but_not_snapshot_toggle_or_creation() {
|
||||
use crate::tui::{app::FocusedArea, tests::harness::UiHarness};
|
||||
use crossterm::event::KeyEventKind;
|
||||
|
||||
let mut ui = UiHarness::new();
|
||||
ui.app.focused = FocusedArea::Popup;
|
||||
ui.app.instances_state.show_popup = true;
|
||||
{
|
||||
let mut state = WIZARD_STATE.lock().unwrap();
|
||||
state.step = WizardStep::Version;
|
||||
state.versions = LoadState::Loaded(vec![GameVersion {
|
||||
id: "1.21.1".to_owned(),
|
||||
stable: true,
|
||||
}]);
|
||||
state.version_search.activate();
|
||||
}
|
||||
assert!(ui.key_event(KeyEvent::new_with_kind(
|
||||
KeyCode::Char('s'),
|
||||
KeyModifiers::NONE,
|
||||
KeyEventKind::Repeat
|
||||
)));
|
||||
{
|
||||
let state = WIZARD_STATE.lock().unwrap();
|
||||
assert_eq!(state.version_search.query, "s");
|
||||
assert!(!state.show_snapshots);
|
||||
}
|
||||
assert!(!ui.key_event(KeyEvent::new_with_kind(
|
||||
KeyCode::Enter,
|
||||
KeyModifiers::NONE,
|
||||
KeyEventKind::Repeat
|
||||
)));
|
||||
{
|
||||
let mut state = WIZARD_STATE.lock().unwrap();
|
||||
state.step = WizardStep::Confirm;
|
||||
state.name_state = TextState::new().with_value("Held Confirm");
|
||||
state.version_search.deactivate();
|
||||
}
|
||||
assert!(!ui.key_event(KeyEvent::new_with_kind(
|
||||
KeyCode::Enter,
|
||||
KeyModifiers::NONE,
|
||||
KeyEventKind::Repeat
|
||||
)));
|
||||
assert!(take_result().is_none());
|
||||
assert!(ui.app.instances_state.show_popup);
|
||||
ui.key(KeyCode::Enter);
|
||||
assert_eq!(take_result().unwrap().name, "Held Confirm");
|
||||
assert!(!ui.key_event(KeyEvent::new_with_kind(
|
||||
KeyCode::Enter,
|
||||
KeyModifiers::NONE,
|
||||
KeyEventKind::Repeat
|
||||
)));
|
||||
assert_eq!(ui.app.focused, FocusedArea::Instances);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filtered_vanilla_wizard_returns_the_displayed_version() {
|
||||
let _guard = TEST_LOCK.lock().unwrap_or_else(|error| error.into_inner());
|
||||
|
||||
@@ -53,6 +53,32 @@ fn highlight_spans_marks_each_case_insensitive_match() {
|
||||
assert!(spans[2].style.add_modifier.contains(Modifier::UNDERLINED));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn highlighting_maps_expanding_lowercase_back_to_the_original_character() {
|
||||
for (query, expected) in [("a", "a"), ("i", "İ"), ("\u{307}", "İ")] {
|
||||
let search = SearchState {
|
||||
query: query.to_owned(),
|
||||
..Default::default()
|
||||
};
|
||||
let spans = search.highlight_spans("İab", Style::default());
|
||||
assert_eq!(
|
||||
spans
|
||||
.iter()
|
||||
.map(|span| span.content.as_ref())
|
||||
.collect::<String>(),
|
||||
"İab"
|
||||
);
|
||||
assert_eq!(
|
||||
spans
|
||||
.iter()
|
||||
.filter(|span| span.style.add_modifier.contains(Modifier::UNDERLINED))
|
||||
.map(|span| span.content.as_ref())
|
||||
.collect::<String>(),
|
||||
expected
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ctrl_backspace_deletes_the_previous_word() {
|
||||
let mut search = SearchState {
|
||||
|
||||
@@ -6,13 +6,21 @@ use super::*;
|
||||
#[test]
|
||||
fn narrow_settings_shows_the_selected_pane() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let mut state = SettingsState::new(tmp.path().to_path_buf());
|
||||
let mut state = SettingsState::new(tmp.path().to_path_buf(), tmp.path().join("instances"));
|
||||
let instance: InstanceConfig = serde_json::from_value(serde_json::json!({
|
||||
"name": "Test", "game_version": "1.21", "loader": "vanilla",
|
||||
"loader_version": null, "created": "2026-01-01T00:00:00Z", "java_path": "test-java"
|
||||
}))
|
||||
.unwrap();
|
||||
state.java_key = Some("test-java".to_owned());
|
||||
let environment = crate::instance::java::merge_environment(
|
||||
&SETTINGS.read().defaults.environment,
|
||||
&instance.environment,
|
||||
);
|
||||
state.java_key = Some(java_path_key(
|
||||
"test-java",
|
||||
&state.instances_dir.join("Test/minecraft"),
|
||||
&environment,
|
||||
));
|
||||
state.java_label = "jdk17".to_owned();
|
||||
let mut terminal = ratatui::Terminal::new(ratatui::backend::TestBackend::new(35, 8)).unwrap();
|
||||
|
||||
@@ -62,7 +70,7 @@ fn narrow_settings_shows_the_selected_pane() {
|
||||
#[test]
|
||||
fn removing_selected_last_profile_clamps_selection() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let mut state = SettingsState::new(tmp.path().to_path_buf());
|
||||
let mut state = SettingsState::new(tmp.path().to_path_buf(), tmp.path().join("instances"));
|
||||
state.profiles = vec!["first".to_string(), "second".to_string()];
|
||||
state.active_profile = Some("second".to_string());
|
||||
state.list_state.selected = Some(2);
|
||||
@@ -77,7 +85,7 @@ fn removing_selected_last_profile_clamps_selection() {
|
||||
#[test]
|
||||
fn info_pane_does_not_bind_desktop_toggle() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let mut state = SettingsState::new(tmp.path().to_path_buf());
|
||||
let mut state = SettingsState::new(tmp.path().to_path_buf(), tmp.path().join("instances"));
|
||||
state.pane = SettingsPane::Info;
|
||||
|
||||
assert!(matches!(
|
||||
@@ -85,3 +93,45 @@ fn info_pane_does_not_bind_desktop_toggle() {
|
||||
SettingsAction::None
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn instance_java_labels_use_their_cwd_and_environment_and_discard_previous_results() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let _guard = crate::tests::TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner());
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let instances = temp.path().join("instances");
|
||||
let java = temp.path().join("selected-java");
|
||||
std::fs::write(&java, b"#!/bin/sh\nread -r expected < marker || exit 1\n[ \"$RMCL_TEST_JAVA_VERSION\" = \"$expected\" ] || exit 1\nprintf 'java.version = %s\\n' \"$expected\"\n").unwrap();
|
||||
std::fs::set_permissions(&java, std::fs::Permissions::from_mode(0o755)).unwrap();
|
||||
let mut state = SettingsState::new(temp.path().join("meta"), instances.clone());
|
||||
let instance = |name: &str, version: &str| -> InstanceConfig {
|
||||
let minecraft = instances.join(name).join("minecraft");
|
||||
std::fs::create_dir_all(&minecraft).unwrap();
|
||||
std::fs::write(minecraft.join("marker"), format!("{version}\n")).unwrap();
|
||||
serde_json::from_value(serde_json::json!({
|
||||
"name": name, "game_version": "1.21", "loader": "vanilla", "created": "2026-01-01T00:00:00Z",
|
||||
"java_path": java, "environment": {"RMCL_TEST_JAVA_VERSION": version}
|
||||
})).unwrap()
|
||||
};
|
||||
fn wait_for_label(state: &mut SettingsState, instance: &InstanceConfig, expected: &str) {
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
|
||||
while std::time::Instant::now() < deadline {
|
||||
state.update_for_instance(Some(instance));
|
||||
if state.java_label == expected {
|
||||
return;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
}
|
||||
panic!("Expected {expected}, found {}", state.java_label);
|
||||
}
|
||||
let first = instance("first", "21");
|
||||
wait_for_label(&mut state, &first, "jdk21");
|
||||
let old_pending = state.pending_java.clone();
|
||||
let second = instance("second", "25");
|
||||
state.update_for_instance(Some(&second));
|
||||
*old_pending.lock().unwrap() = Some("stale label".to_owned());
|
||||
wait_for_label(&mut state, &second, "jdk25");
|
||||
}
|
||||
Reference in new issue
Block a user