Show a missing-statistics notice once during a champ select (#75)

With the statistics missing, the Anvil area no longer repeats « Aucune Saison
en cours » when the header already says it, and « Autres champions » is not
offered since there is nothing to browse.

Test tidy-ups: the saved-portraits assertion message says what is checked,
main.rs tests use card_images' TestDir instead of their own TempDir, and the
test-only accessors of Page move after the last method so choose_sort reads
with its doc comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-21 02:26:14 +01:00
1 parent 28d86d48b7
commit 485d7b9065
4 files changed
+77 -47

No files matched your search

+3 -21
View File
@@ -376,6 +376,7 @@ mod tests {
};
use super::{INTER, KeyStore, RootView, Screen, Setup};
use crate::card_images::tests::TestDir;
use crate::title_bar::{BAR_HEIGHT, BUTTON_WIDTH};
use crate::worker::UpdateChecked;
@@ -486,25 +487,6 @@ mod tests {
assert!(root.read_with(cx, |root, _| root.screen == Screen::Settings));
}
/// A unique folder under the system's temporary one, removed when dropped.
struct TempDir(std::path::PathBuf);
impl TempDir {
fn new(name: &str) -> TempDir {
let dir =
std::env::temp_dir().join(format!("arena-tracker-{name}-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
TempDir(dir)
}
}
impl Drop for TempDir {
fn drop(&mut self) {
let _ = std::fs::remove_dir_all(&self.0);
}
}
/// The app opened on the config file at `path` (the file is read, or missing).
fn open_app(
cx: &mut TestAppContext,
@@ -535,8 +517,8 @@ mod tests {
fn the_chosen_sort_is_saved_with_the_preferences_and_found_again_at_the_next_launch(
cx: &mut TestAppContext,
) {
let dir = TempDir::new("sort-76");
let path = dir.0.join("config.toml");
let dir = TestDir::new("sort-76");
let path = dir.path().join("config.toml");
let (mut window, root) = open_app(cx, &path, Config::load_or_default);
let page = root.read_with(&window, |root, _| root.page.clone());
+47 -11
View File
@@ -921,16 +921,6 @@ impl Page {
self.order.iter().filter_map(move |&ix| rows.get(ix))
}
#[cfg(test)]
pub(crate) fn champion_sort(&self) -> Option<ChampionSort> {
self.champion_sort
}
#[cfg(test)]
pub(crate) fn home_filter(&self) -> StateFilter {
self.home_filter
}
/// The player chose a sort: the cards of every section follow it, and it is saved.
pub(crate) fn choose_sort(&mut self, sort: ChampionSort, cx: &mut Context<Self>) {
if self.champion_sort == Some(sort) {
@@ -970,7 +960,7 @@ impl Page {
self.champ_select_notice = match (&self.stats_error, self.stats.is_some()) {
(Some(error), _) => error.clone().into(),
(None, true) => SharedString::default(),
(None, false) if self.current_season.is_none() => "Aucune Saison en cours".into(),
(None, false) if self.current_season.is_none() => home::NO_SEASON.into(),
(None, false) if self.status.updating.is_none() => "Compte indisponible".into(),
(None, false) => "Chargement des statistiques…".into(),
};
@@ -1192,6 +1182,16 @@ impl Page {
.map(|alert| alert.small().into_any_element())
.collect()
}
#[cfg(test)]
pub(crate) fn champion_sort(&self) -> Option<ChampionSort> {
self.champion_sort
}
#[cfg(test)]
pub(crate) fn home_filter(&self) -> StateFilter {
self.home_filter
}
}
impl Render for Page {
@@ -2833,6 +2833,42 @@ mod tests {
}
}
#[gpui::test]
async fn missing_statistics_are_said_once_and_leave_nothing_to_browse(cx: &mut TestAppContext) {
cx.executor().allow_parking();
// No current Season: the header says so, and the Anvil area does not say it again.
let (page, mut window) = open_page(cx);
send(&page, &mut window, &frames()[0]);
draw(&mut window);
page.read_with(&window, |p, _| {
assert_eq!(p.champ_select_notice, "Aucune Saison en cours");
});
assert!(window.debug_bounds("no-season").is_some());
assert!(window.debug_bounds("anvil-notice").is_none());
assert!(window.debug_bounds("anvil-row").is_none());
assert!(window.debug_bounds("others-toggle").is_none());
// The statistics are on their way: the area says so, and there is nothing to browse yet.
let (page, mut window) = open_page_with_tracker(cx, joueur_tracker_with(true));
send(&page, &mut window, &frames()[0]);
draw(&mut window);
page.read_with(&window, |p, _| {
assert_eq!(
p.anvil_line().as_deref(),
Some("Chargement des statistiques…")
);
});
assert!(window.debug_bounds("no-season").is_none());
assert!(window.debug_bounds("anvil-notice").is_some());
assert!(window.debug_bounds("others-toggle").is_none());
// Once they are there, the section is offered.
cx.condition(&page, |p, _| p.stats.is_some()).await;
draw(&mut window);
assert!(window.debug_bounds("anvil-notice").is_none());
assert!(window.debug_bounds("others-toggle").is_some());
}
/// What the non-anvil champions of the capture are, in the home's order (A to Z by name).
const OTHERS_A_TO_Z: [u32; 4] = [103, 12, 25, 50];
+26 -14
View File
@@ -19,6 +19,10 @@ pub(super) const FILTERS: [(&str, StateFilter); 3] = [
("Validés", StateFilter::Completed),
];
/// What the header says when there is no current Season, and the champ select's notice for the
/// same cause.
pub(super) const NO_SEASON: &str = "Aucune Saison en cours";
impl Page {
/// Under the banners: the Season and its counter, then the heading with the filters and
/// search, and the cards. It holds no chart (#71): the cached charts row only belongs to the
@@ -42,7 +46,8 @@ impl Page {
if shown("anvil") {
column = column.child(self.anvil_area(cx));
}
if shown("others") {
// With the statistics missing there is nothing to browse: the notice stands alone.
if shown("others") && self.champ_select_notice.is_empty() {
column = column.child(self.others_area(cx));
}
return vec![
@@ -147,18 +152,24 @@ impl Page {
)
.child(self.sort_selector(cx)),
)
.child(match row {
Some(line) => div()
.text_sm()
.text_color(muted)
.debug_selector(|| "anvil-notice".into())
.child(line)
.into_any_element(),
None => div()
.w_full()
.debug_selector(|| "anvil-row".into())
.child(self.anvil_grid.clone())
.into_any_element(),
.children(match row {
// The header already says there is no Season: not twice.
Some(line) if self.home_season.is_none() && line == NO_SEASON => None,
Some(line) => Some(
div()
.text_sm()
.text_color(muted)
.debug_selector(|| "anvil-notice".into())
.child(line)
.into_any_element(),
),
None => Some(
div()
.w_full()
.debug_selector(|| "anvil-row".into())
.child(self.anvil_grid.clone())
.into_any_element(),
),
})
}
@@ -350,7 +361,8 @@ impl Page {
.text_sm()
.whitespace_nowrap()
.text_color(muted)
.child("Aucune Saison en cours")
.debug_selector(|| "no-season".into())
.child(NO_SEASON)
.into_any_element(),
),
};
+1 -1
View File
@@ -435,7 +435,7 @@ mod tests {
let start = Instant::now();
let at = |ms: u64| start + Duration::from_millis(ms);
let mut throttle = Throttle::new(Duration::from_secs(1));
assert!(throttle.saved(at(0)), "the first save waits");
assert!(throttle.saved(at(0)), "the first save is told at once");
assert!(!throttle.saved(at(300)));
assert!(!throttle.saved(at(999)));
assert!(throttle.saved(at(1000)));