Files
arena-tracker/crates/app/src/settings/tests.rs
T
nessarandClaude Opus 5.5 1eebb86902 Call Riot through the relay, without a key (#149)
Every Riot call goes to {relay}/{routing value}{Riot path} and sends no
key. The relay's address is built in (arena-tracker.nessar.fr);
relay_url in config.toml replaces it for development. A riot_api_key
left by an older version is never read, and is written back on save.

The personal keys' local pacing is gone. An import waits out each
Retry-After as often as it comes (at least a second each time), and so
do Mastery requests. A 5xx is the service unavailable, with its own
banner; a 401/403 is a refusal, which for a timeline the Match itself
confirms before it is stored, so a key failing on the relay's side
stores no refused Death Recap.

The first-launch key prompt, the key field in « Paramètres » and the
Friend refusal's « Paramètres » button are removed; the follower starts
with the app. KeyForm, KeyStore and KeyEvent become SettingsForm,
SettingsStore and SettingsEvent. README, user guide and interface spec
no longer ask for a key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 13:44:58 +01:00

308 lines
12 KiB
Rust

use std::sync::Arc;
use arena_tracker_core::{Config, Preferences, RiotApi, ThemePreference, Tracker, UpdateChannel};
use gpui_kit::component::ThemeMode;
use gpui_kit::{
AppContext as _, ScrollDelta, ScrollEvent, TestAppContext, VisualTestContext, WindowOptions,
point, px,
};
use super::{SettingsForm, SettingsStore, theme_mode};
use crate::logon::tests::Scratch;
use crate::title_bar::MIN_WINDOW_SIZE;
use crate::worker::UpdateChecked;
/// The settings' Accounts: none stored.
fn tracker() -> Arc<Tracker> {
let api = RiotApi::new("", "europe");
Arc::new(Tracker::open(std::path::Path::new(":memory:"), Box::new(api)).unwrap())
}
#[gpui::test]
fn the_chosen_channel_is_saved_and_only_its_check_offers_a_restart(cx: &mut TestAppContext) {
cx.update(gpui_kit::init);
let dir = std::env::temp_dir().join(format!("arena-channel-{}", std::process::id()));
let path = dir.join("config.toml");
let _ = std::fs::remove_dir_all(&dir);
let (window, form) = cx.update(|cx| {
let config = Config::load_or_default(&path).unwrap();
let store = SettingsStore::new(path.clone(), config);
gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {
cx.new(|cx| SettingsForm::new(store, tracker(), window, cx))
})
.unwrap()
});
let cx = &mut VisualTestContext::from_window(window, cx);
let choose = |channel, cx: &mut VisualTestContext| {
cx.update(|window, cx| {
form.update(cx, |form, cx| {
let preferences = Preferences {
update_channel: Some(channel),
..form.store.preferences()
};
form.set_preferences(preferences, window, cx);
})
})
};
let saved = |channel| Preferences {
update_channel: Some(channel),
..Preferences::default()
};
choose(UpdateChannel::Beta, cx);
let loaded = Config::load(&path).unwrap().preferences;
assert_eq!(loaded, saved(UpdateChannel::Beta));
form.update(cx, |form, cx| {
// A stable check that ends after the change to Bêta stays out of sight.
let late = UpdateChecked {
channel: UpdateChannel::Stable,
result: Ok(Some("1.0.1".into())),
};
form.update_checked(late, cx);
assert!(!form.update_ready());
assert_eq!(form.update_status(), None);
let checked = UpdateChecked {
channel: UpdateChannel::Beta,
result: Ok(Some("1.1.0-beta.3".into())),
};
form.update_checked(checked, cx);
assert!(form.update_ready());
assert_eq!(
form.update_status().as_deref(),
Some("Mise à jour prête : version 1.1.0-beta.3")
);
});
cx.update(|window, cx| window.draw(cx).clear(cx));
form.update(cx, |form, cx| {
// A development build has no installer: « Redémarrer » says so and the app stays.
form.restart(cx);
assert!(!form.update_ready());
let error = form.preference_error.as_deref();
assert_eq!(error, Some("Cette version ne se met pas à jour."));
});
form.update(cx, |form, cx| {
let checked = UpdateChecked {
channel: UpdateChannel::Beta,
result: Ok(None),
};
form.update_checked(checked, cx);
assert!(form.check_status().is_some());
});
choose(UpdateChannel::Stable, cx);
assert_eq!(form.read_with(cx, |form, _| form.check_status()), None);
assert!(!form.read_with(cx, |form, _| form.update_ready()));
let loaded = Config::load(&path).unwrap().preferences;
assert_eq!(loaded, saved(UpdateChannel::Stable));
std::fs::remove_dir_all(&dir).unwrap();
}
#[gpui::test]
fn the_last_check_is_told_until_the_settings_are_shown_again(cx: &mut TestAppContext) {
cx.update(gpui_kit::init);
let (window, form) = cx.update(|cx| {
let config = Config::load_or_default(std::path::Path::new(":memory:")).unwrap();
let store = SettingsStore::new("unused.toml".into(), config);
gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {
cx.new(|cx| SettingsForm::new(store, tracker(), window, cx))
})
.unwrap()
});
let cx = &mut VisualTestContext::from_window(window, cx);
let checked = |result| UpdateChecked {
channel: UpdateChannel::Stable,
result,
};
form.update(cx, |form, cx| {
assert_eq!(form.check_status(), None);
assert!(form.update_checks.request());
assert_eq!(form.check_status().as_deref(), Some("Recherche en cours…"));
form.update_checked(checked(Ok(Some("1.0.1".into()))), cx);
assert!(form.update_ready());
assert_eq!(form.check_status(), None);
// A failed check leaves the kept package ready and says why.
form.update_checked(checked(Err("réseau".into())), cx);
assert!(form.update_ready());
assert_eq!(
form.check_status().as_deref(),
Some("Impossible de vérifier les mises à jour : réseau")
);
// A check of the other channel that ends late says nothing about this one.
let other = UpdateChecked {
channel: UpdateChannel::Beta,
result: Err("autre canal".into()),
};
form.update_checked(other, cx);
assert!(form.check_status().as_deref().unwrap().ends_with("réseau"));
// Nothing newer: the kept package is gone and the settings say so.
form.update_checked(checked(Ok(None)), cx);
assert!(!form.update_ready());
assert_eq!(
form.check_status().as_deref(),
Some("Vous avez la dernière version")
);
});
form.update(cx, |form, cx| {
form.reset(cx);
assert_eq!(form.check_status(), None);
});
}
#[gpui::test]
fn the_logon_switch_shows_what_windows_holds(cx: &mut TestAppContext) {
cx.update(gpui_kit::init);
let (window, form) = cx.update(|cx| {
let config = Config::load_or_default(std::path::Path::new(":memory:")).unwrap();
let store = SettingsStore::new("unused.toml".into(), config);
gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {
cx.new(|cx| SettingsForm::new(store, tracker(), window, cx))
})
.unwrap()
});
let cx = &mut VisualTestContext::from_window(window, cx);
let (scratch, installed) = Scratch::launch("settings", true);
let (_dev_scratch, development) = Scratch::launch("settings-dev", false);
form.update(cx, |form, cx| {
form.logon_launch = installed;
form.read_logon_launch();
assert!(
!form.launches_at_logon,
"a first installation starts disabled"
);
form.set_logon_launch(true, cx);
assert!(form.launches_at_logon);
assert_eq!(form.preference_error, None);
});
cx.update(|window, cx| window.draw(cx).clear(cx));
// Disabled in the Task Manager while the settings were closed, then opened again.
scratch.disable_in_task_manager();
form.update(cx, |form, cx| {
form.read_logon_launch();
assert!(!form.launches_at_logon);
form.set_logon_launch(true, cx);
assert!(form.launches_at_logon, "switching it on approves it again");
form.set_logon_launch(false, cx);
assert!(!form.launches_at_logon);
});
// Windows refuses: the switch shows what it holds, and the settings say so.
form.update(cx, |form, cx| {
form.logon_launch = development;
form.set_logon_launch(true, cx);
assert!(!form.launches_at_logon);
assert_eq!(form.preference_error.as_deref(), Some(super::LOGON_ERROR));
});
cx.update(|window, cx| window.draw(cx).clear(cx));
}
#[gpui::test]
fn the_riot_notice_is_drawn_inside_the_window_at_its_minimum_size(cx: &mut TestAppContext) {
cx.update(gpui_kit::init);
let (window, _form) = cx.update(|cx| {
let config = Config::load_or_default(std::path::Path::new(":memory:")).unwrap();
let store = SettingsStore::new("unused.toml".into(), config);
gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {
cx.new(|cx| SettingsForm::new(store, tracker(), window, cx))
})
.unwrap()
});
let cx = &mut VisualTestContext::from_window(window, cx);
cx.simulate_resize(MIN_WINDOW_SIZE);
cx.update(|window, cx| window.draw(cx).clear(cx));
// Debug bounds are recorded even for clipped elements: the title must start on screen, and
// after scrolling down the notice must end on screen.
let title = cx
.debug_bounds("settings-title")
.expect("the title is drawn");
assert!(title.top() >= px(0.), "{title:?}");
cx.simulate_event(ScrollEvent {
position: point(px(100.), px(100.)),
delta: ScrollDelta::Pixels(point(px(0.), px(-2000.))),
..Default::default()
});
cx.update(|window, cx| window.draw(cx).clear(cx));
let notice = cx.debug_bounds("riot-notice").expect("the notice is drawn");
assert!(notice.right() <= MIN_WINDOW_SIZE.width, "{notice:?}");
assert!(notice.top() >= px(0.), "{notice:?}");
assert!(notice.bottom() <= MIN_WINDOW_SIZE.height, "{notice:?}");
}
#[test]
fn system_tracks_the_current_appearance_and_manual_choices_override_it() {
for system in [ThemeMode::Light, ThemeMode::Dark] {
assert_eq!(theme_mode(ThemePreference::System, system), system);
assert_eq!(theme_mode(ThemePreference::Light, system), ThemeMode::Light);
assert_eq!(theme_mode(ThemePreference::Dark, system), ThemeMode::Dark);
}
}
static OPENED: std::sync::Mutex<Vec<std::path::PathBuf>> = std::sync::Mutex::new(Vec::new());
#[gpui::test]
fn the_logs_button_opens_the_logs_folder_beside_the_configuration(cx: &mut TestAppContext) {
cx.update(gpui_kit::init);
let dir = std::env::temp_dir().join(format!("arena-logs-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
let (window, form) = cx.update(|cx| {
let config = Config::load_or_default(std::path::Path::new(":memory:")).unwrap();
let store = SettingsStore::new(dir.join("config.toml"), config);
gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {
cx.new(|cx| SettingsForm::new(store, tracker(), window, cx))
})
.unwrap()
});
let cx = &mut VisualTestContext::from_window(window, cx);
form.update(cx, |form, _| {
form.open_folder = |dir| {
OPENED.lock().unwrap().push(dir.to_path_buf());
Ok(())
};
});
cx.update(|window, cx| window.draw(cx).clear(cx));
let button = cx.debug_bounds("open-logs").unwrap().center();
cx.simulate_click(button, gpui_kit::Modifiers::none());
assert_eq!(*OPENED.lock().unwrap(), [dir.join("logs")]);
assert!(dir.join("logs").is_dir());
form.update(cx, |form, _| {
assert_eq!(form.preference_error, None);
// An unrelated error is not wiped by opening the folder.
form.preference_error = Some("autre erreur".into());
});
cx.update(|window, cx| window.draw(cx).clear(cx));
let button = cx.debug_bounds("open-logs").unwrap().center();
cx.simulate_click(button, gpui_kit::Modifiers::none());
form.update(cx, |form, _| {
assert_eq!(form.preference_error.as_deref(), Some("autre erreur"));
form.preference_error = None;
});
assert_eq!(OPENED.lock().unwrap().len(), 2);
cx.update(|window, cx| window.draw(cx).clear(cx));
let button = cx.debug_bounds("open-logs").unwrap().center();
// The explorer cannot be started: the settings say so.
form.update(cx, |form, _| {
form.open_folder = |_| Err(std::io::Error::other("refused"));
});
cx.simulate_click(button, gpui_kit::Modifiers::none());
form.update(cx, |form, _| {
assert_eq!(
form.preference_error.as_deref(),
Some(super::logs::LOGS_ERROR)
);
form.open_folder = |_| Ok(());
});
cx.update(|window, cx| window.draw(cx).clear(cx));
let button = cx.debug_bounds("open-logs").unwrap().center();
// Its own error goes away once the folder opens.
cx.simulate_click(button, gpui_kit::Modifiers::none());
form.update(cx, |form, _| assert_eq!(form.preference_error, None));
let _ = std::fs::remove_dir_all(&dir);
}