From 45adf219d72385de4ccd070ac24259d917ba016c Mon Sep 17 00:00:00 2001 From: Nessar Date: Fri, 27 Nov 2026 11:50:45 +0100 Subject: [PATCH] =?UTF-8?q?Drop=20the=20official=20count=20note=20from=20t?= =?UTF-8?q?he=20=C2=AB=20Statistiques=20=C2=BB=20tiles=20(#143)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tiles are now all built the same way; the mismatch alert stays the only signal of an incomplete history. Co-Authored-By: Claude Opus 5.5 --- crates/app/src/page/display.rs | 35 +++++---- crates/app/src/page/statistics.rs | 45 +++-------- crates/app/src/page/tests.rs | 1 + crates/app/src/page/tests/statistics_tiles.rs | 74 +++++++++++++++++++ crates/app/src/text.rs | 6 -- 5 files changed, 106 insertions(+), 55 deletions(-) create mode 100644 crates/app/src/page/tests/statistics_tiles.rs diff --git a/crates/app/src/page/display.rs b/crates/app/src/page/display.rs index ac09b72..da7d870 100644 --- a/crates/app/src/page/display.rs +++ b/crates/app/src/page/display.rs @@ -16,34 +16,43 @@ impl Page { let mut banners = Vec::new(); if let Some(problem) = &self.status.problem { let message = problem.message(); - banners.push(match problem { - UpdateProblem::MatchPending - | UpdateProblem::RateLimited - | UpdateProblem::NoAccount => Alert::warning("problem", message), - _ => Alert::error("problem", message), - }); + banners.push(( + "problem", + match problem { + UpdateProblem::MatchPending + | UpdateProblem::RateLimited + | UpdateProblem::NoAccount => Alert::warning("problem", message), + _ => Alert::error("problem", message), + }, + )); } if let Some(error) = self.friend_error() { - banners.push(Alert::error("friend", error.clone())); + banners.push(("friend", Alert::error("friend", error.clone()))); } if let Some(ProgressCheck::Differs { app, official }) = self.official() { - banners.push(Alert::warning( + banners.push(( "official", - official_differs(*app, *official), + Alert::warning("official", official_differs(*app, *official)), )); } if !self.pending_round && !self.status.client_running { - banners.push(Alert::info("client", CLIENT_ABSENT)); + banners.push(("client", Alert::info("client", CLIENT_ABSENT))); } if let Some(notice) = &self.notice { - banners.push(Alert::warning("notice", notice.clone())); + banners.push(("notice", Alert::warning("notice", notice.clone()))); } if let Some(error) = self.error() { - banners.push(Alert::error("stats", error.clone())); + banners.push(("stats", Alert::error("stats", error.clone()))); } banners .into_iter() - .map(|alert| alert.small().into_any_element()) + .map(|(id, alert)| { + // The selector lets the tests find the alert; it costs nothing in a release build. + div() + .debug_selector(move || id.into()) + .child(alert.small()) + .into_any_element() + }) .collect() } diff --git a/crates/app/src/page/statistics.rs b/crates/app/src/page/statistics.rs index fb08b0b..70724ae 100644 --- a/crates/app/src/page/statistics.rs +++ b/crates/app/src/page/statistics.rs @@ -3,7 +3,7 @@ mod data; -use arena_tracker_core::{ChallengeSummary, Charts, ProgressCheck, StateFilter}; +use arena_tracker_core::{ChallengeSummary, Charts, StateFilter}; use gpui_kit::component::chart::{AreaChart, BarChart}; use gpui_kit::component::input::Input; use gpui_kit::component::select::Select; @@ -13,7 +13,7 @@ use gpui_kit::prelude::FluentBuilder as _; use gpui_kit::*; use super::{Page, Tab as Screen, shown}; -use crate::text::{decimal, official_note}; +use crate::text::decimal; use crate::theme::{heading, surface}; const NO_MATCH: &str = "Aucune Partie"; @@ -37,13 +37,9 @@ fn filters(in_season: bool) -> &'static [(&'static str, StateFilter)] { } } -fn tile( - label: &'static str, - value: String, - note: Option, - theme: &Theme, -) -> impl IntoElement { +fn tile(label: &'static str, value: String, theme: &Theme) -> impl IntoElement { div() + .debug_selector(move || format!("tile-{label}")) .v_flex() .flex_1() .gap_1() @@ -64,44 +60,21 @@ fn tile( .font_weight(FontWeight::SEMIBOLD) .child(value), ) - .children(note.map(|note| { - div() - .text_xs() - .text_color(theme.muted_foreground) - .child(note) - })) } -fn challenge_tiles( - c: &ChallengeSummary, - official: Option<&ProgressCheck>, - theme: &Theme, -) -> impl IntoElement { +fn challenge_tiles(c: &ChallengeSummary, theme: &Theme) -> impl IntoElement { let average = c.average_attempts.map_or("-".into(), |a| decimal(a, 2)); - // Next to the count whether the app agrees or not; the banner covers the difference. - let note = match official { - Some(ProgressCheck::Agrees(n)) | Some(ProgressCheck::Differs { official: n, .. }) => { - Some(official_note(*n)) - } - _ => None, - }; div() .h_flex() .gap_3() .child(tile( "Champions validés", format!("{} / {}", c.completed, c.total), - note, - theme, - )) - .child(tile("Tentatives", c.attempts.to_string(), None, theme)) - .child(tile("Tentatives par champion validé", average, None, theme)) - .child(tile( - "Du premier coup", - c.first_tries.to_string(), - None, theme, )) + .child(tile("Tentatives", c.attempts.to_string(), theme)) + .child(tile("Tentatives par champion validé", average, theme)) + .child(tile("Du premier coup", c.first_tries.to_string(), theme)) } /// A titled card holding a chart, or `empty` in its place. @@ -353,7 +326,7 @@ impl Page { if shown("tiles") && let Some(c) = challenge { - content.push(challenge_tiles(c, self.official(), cx.theme()).into_any_element()); + content.push(challenge_tiles(c, cx.theme()).into_any_element()); } content.push( self.charts diff --git a/crates/app/src/page/tests.rs b/crates/app/src/page/tests.rs index 1ff1b56..1ff2a9b 100644 --- a/crates/app/src/page/tests.rs +++ b/crates/app/src/page/tests.rs @@ -42,3 +42,4 @@ mod portraits; mod ring_hover; mod sorting; mod sorting_fixtures; +mod statistics_tiles; diff --git a/crates/app/src/page/tests/statistics_tiles.rs b/crates/app/src/page/tests/statistics_tiles.rs new file mode 100644 index 0000000..4679627 --- /dev/null +++ b/crates/app/src/page/tests/statistics_tiles.rs @@ -0,0 +1,74 @@ +//! The « Statistiques » tiles never carry the official count (#143): only the mismatch alert +//! shows what the game counts. + +use super::page_fixtures::{draw, open_page_in_season, show, statistics, switch_tab}; +use crate::page::{Page, Tab}; +use crate::worker::Msg; +use arena_tracker_core::{Account, ProgressCheck, Status}; +use gpui_kit::{Entity, TestAppContext, VisualTestContext}; + +/// The page on Alice's Challenge in the current Season, with `official` as the game's count. +fn with_official(page: &Entity, cx: &mut VisualTestContext, official: ProgressCheck) { + cx.update(|window, cx| { + page.update(cx, |page, cx| { + let status = Status { + updating: Some(Account { + puuid: "p".into(), + game_name: "Alice".into(), + tag_line: "EUW".into(), + }), + official_progress: official, + ..page.status.clone() + }; + page.apply( + Msg::Round { + status, + reload: false, + matches: Vec::new(), + game_end: None, + }, + window, + cx, + ) + }) + }); +} + +/// The drawn height of the tile `label`, once the page is drawn again. +fn tile_height(window: &mut VisualTestContext, label: &'static str) -> f32 { + draw(window); + let bounds = window.debug_bounds(label).expect("the tile is drawn"); + bounds.size.height.into() +} + +#[gpui::test] +async fn the_tiles_stay_without_the_official_count(cx: &mut TestAppContext) { + cx.executor().allow_parking(); + let (page, mut window) = open_page_in_season(cx); + cx.condition(&page, |p, _| !p.busy()).await; + show(&page, &mut window, statistics(52, 100, Vec::new())); + switch_tab(&page, &mut window, Tab::Statistics); + // Without the game's count, the row of tiles has its own height. The row stretches to its + // tallest tile, so a note under the first tile would make every tile taller. + let plain = tile_height(&mut window, "tile-Champions validés"); + assert_eq!(tile_height(&mut window, "tile-Tentatives"), plain); + + // The game agrees: no alert, and the tiles are as tall as without the count. + with_official(&page, &mut window, ProgressCheck::Agrees(52)); + assert_eq!(tile_height(&mut window, "tile-Champions validés"), plain); + assert_eq!(tile_height(&mut window, "tile-Tentatives"), plain); + assert!(window.debug_bounds("official").is_none()); + + // The game differs: the alert still shows, and the tiles are as tall as before. + with_official( + &page, + &mut window, + ProgressCheck::Differs { + app: 50, + official: 52, + }, + ); + assert_eq!(tile_height(&mut window, "tile-Champions validés"), plain); + assert_eq!(tile_height(&mut window, "tile-Tentatives"), plain); + assert!(window.debug_bounds("official").is_some()); +} diff --git a/crates/app/src/text.rs b/crates/app/src/text.rs index 9f4b7ab..c64b0ff 100644 --- a/crates/app/src/text.rs +++ b/crates/app/src/text.rs @@ -98,11 +98,6 @@ pub const CLIENT_ABSENT: &str = "Client League of Legends non détecté : affichage des données enregistrées."; const INTERNAL_ERROR: &str = "Mise à jour impossible : erreur interne."; -/// The discreet line under the Challenge tile. -pub fn official_note(official: u32) -> String { - format!("Progression officielle : {official}") -} - pub fn official_differs(app: usize, official: u32) -> String { format!( "La Progression officielle du jeu indique {official} champions validés, l'application en compte {app} : des Parties manquent peut-être." @@ -220,7 +215,6 @@ mod tests { #[test] fn official_progress_texts() { - assert_eq!(official_note(52), "Progression officielle : 52"); assert_eq!( official_differs(50, 52), "La Progression officielle du jeu indique 52 champions validés, l'application en compte 50 : des Parties manquent peut-être."