fix: ignore stale TUI results and show narrow settings
This commit is contained in:
1 parent
0d1cafcb10
commit
75c74333c5
14 files changed
+268
-93
No files matched your search
@@ -200,11 +200,10 @@ fn structural_settings_update_repairs_runtime_before_persisting() {
|
||||
.mount(&server)
|
||||
.await;
|
||||
}
|
||||
let asset_index = serde_json::to_vec(&serde_json::json!({"objects": {}})).unwrap();
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/assets.json"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"objects": {}
|
||||
})))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_bytes(asset_index.clone()))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
@@ -252,7 +251,7 @@ fn structural_settings_update_repairs_runtime_before_persisting() {
|
||||
"assetIndex": {
|
||||
"id": "1.21.2",
|
||||
"url": format!("{}/assets.json", server.uri()),
|
||||
"sha1": "unused"
|
||||
"sha1": sha1(&asset_index)
|
||||
},
|
||||
"downloads": {
|
||||
"client": {
|
||||
@@ -364,6 +363,7 @@ 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"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -666,6 +666,43 @@ fn confirmed_account_delete_updates_the_account_panel() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typing_d_in_offline_account_name_does_not_open_delete_confirmation() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_account("MicrosoftPlayer");
|
||||
ui.app.focused = FocusedArea::Account;
|
||||
|
||||
ui.key(KeyCode::Char('a'));
|
||||
ui.key(KeyCode::Char('o'));
|
||||
ui.key(KeyCode::Char('d'));
|
||||
|
||||
assert_eq!(ui.app.focused, FocusedArea::Account);
|
||||
assert!(matches!(
|
||||
&ui.app.account_state.add_mode,
|
||||
crate::tui::widgets::account::AddMode::OfflineNameInput(name) if name == "d"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn switching_instances_discards_another_instances_update_review() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("A");
|
||||
ui.add_instance("B");
|
||||
let mut update = crate::tui::widgets::content::update::State::checking(
|
||||
"A".to_owned(),
|
||||
ContentKind::Mod,
|
||||
None,
|
||||
Vec::new(),
|
||||
);
|
||||
update.phase = crate::tui::widgets::content::update::Phase::Review;
|
||||
ui.app.content_update_popup = Some(update);
|
||||
ui.app.instances_state.list_state.selected = Some(1);
|
||||
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
assert!(ui.app.content_update_popup.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_panel_routes_legacy_edit_keys_to_tui_popups() {
|
||||
let mut ui = UiHarness::new();
|
||||
|
||||
@@ -967,7 +967,7 @@ fn streamed_entries_without_icons_are_visible_immediately() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn installed_icon_decode_survives_manifest_binding_and_cache_restore() {
|
||||
async fn installed_icon_decode_survives_manifest_binding() {
|
||||
let mut state = ContentListState::default();
|
||||
state.set_installed_options(
|
||||
&crate::tui::widgets::content::discovery::DiscoveryFilters::default(),
|
||||
@@ -1003,30 +1003,62 @@ async fn installed_icon_decode_survives_manifest_binding_and_cache_restore() {
|
||||
})
|
||||
.await
|
||||
.expect("installed icon decoded after manifest binding");
|
||||
}
|
||||
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
state.start_load(
|
||||
directory.path(),
|
||||
"other",
|
||||
crate::instance::content::mods::scan_one_mod,
|
||||
"jar",
|
||||
);
|
||||
state.start_load(
|
||||
directory.path(),
|
||||
"main",
|
||||
crate::instance::content::mods::scan_one_mod,
|
||||
"jar",
|
||||
);
|
||||
assert!(state.filtered_indices().is_empty());
|
||||
state.request_image_loads(&picker);
|
||||
#[tokio::test]
|
||||
async fn switching_back_rescans_content_changed_while_inactive() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let first = temp.path().join("first");
|
||||
let second = temp.path().join("second");
|
||||
std::fs::create_dir_all(&first).unwrap();
|
||||
std::fs::create_dir_all(&second).unwrap();
|
||||
std::fs::write(first.join("old.jar"), b"old").unwrap();
|
||||
let mut state = ContentListState::default();
|
||||
let scanner = crate::instance::content::mods::scan_one_mod;
|
||||
state.start_load(&first, "first", scanner, ".jar");
|
||||
tokio::time::timeout(std::time::Duration::from_secs(5), async {
|
||||
while state.filtered_indices().is_empty() {
|
||||
state.drain_image_loads(&picker);
|
||||
while state.loading {
|
||||
state.drain_pending();
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
})
|
||||
.await
|
||||
.expect("cached installed icon decoded");
|
||||
.unwrap();
|
||||
assert_eq!(state.entries.len(), 1);
|
||||
|
||||
state.start_load(&second, "second", scanner, ".jar");
|
||||
std::fs::remove_file(first.join("old.jar")).unwrap();
|
||||
std::fs::write(first.join("new.jar"), b"new").unwrap();
|
||||
state.start_load(&first, "first", scanner, ".jar");
|
||||
tokio::time::timeout(std::time::Duration::from_secs(5), async {
|
||||
while state.loading {
|
||||
state.drain_pending();
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(state.entries.len(), 1);
|
||||
assert_eq!(state.entries[0].path, first.join("new.jar"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn old_watcher_results_cannot_update_a_new_instance() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let mut state = ContentListState::default();
|
||||
let old_slot = state.watcher_diff.clone();
|
||||
state.watch_dir(temp.path().to_owned());
|
||||
*old_slot.lock().unwrap() = Some(super::WatcherDiff {
|
||||
toggled: vec![(
|
||||
"test".to_owned(),
|
||||
false,
|
||||
temp.path().join("test.jar.disabled"),
|
||||
)],
|
||||
removed: Vec::new(),
|
||||
added: Vec::new(),
|
||||
});
|
||||
|
||||
assert!(state.drain_watcher().toggles.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -74,6 +74,7 @@ fn snapshot() -> UpdateSnapshot {
|
||||
#[test]
|
||||
fn update_review_reuses_content_rows() {
|
||||
let mut state = State::checking(
|
||||
"Instance".to_owned(),
|
||||
ContentKind::Mod,
|
||||
None,
|
||||
vec![entry("Example Mod", "mods/example.jar")],
|
||||
@@ -101,6 +102,7 @@ fn update_conflicts_explain_why_the_item_was_not_updated() {
|
||||
.to_owned(),
|
||||
});
|
||||
let mut state = State::checking(
|
||||
"Instance".to_owned(),
|
||||
ContentKind::Mod,
|
||||
None,
|
||||
vec![entry("Example Mod", "mods/example.jar")],
|
||||
|
||||
@@ -3,6 +3,62 @@
|
||||
|
||||
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 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());
|
||||
state.java_label = "jdk17".to_owned();
|
||||
let mut terminal = ratatui::Terminal::new(ratatui::backend::TestBackend::new(35, 8)).unwrap();
|
||||
|
||||
terminal
|
||||
.draw(|frame| {
|
||||
render(
|
||||
frame,
|
||||
frame.area(),
|
||||
FocusedArea::Settings,
|
||||
&mut state,
|
||||
Some(&instance),
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
let text = terminal
|
||||
.backend()
|
||||
.buffer()
|
||||
.content()
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(text.contains(LOCAL_PROFILE_LABEL));
|
||||
|
||||
state.pane = SettingsPane::Info;
|
||||
terminal
|
||||
.draw(|frame| {
|
||||
render(
|
||||
frame,
|
||||
frame.area(),
|
||||
FocusedArea::Settings,
|
||||
&mut state,
|
||||
Some(&instance),
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
let text = terminal
|
||||
.backend()
|
||||
.buffer()
|
||||
.content()
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(text.contains("Memory"));
|
||||
assert!(text.contains("jdk17"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_selected_last_profile_clamps_selection() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in new issue
Block a user