Keep the ring lit without a list and test the banner on the real capture (#85)
CI / core (pull_request) Successful in 1m35s
CI / core (push) Successful in 1m37s

A champ select whose Anvil list the client did not send no longer dims every
tick of the ring. k takes the singular at 0 and 1, and the line uses the same
apostrophe as the row and its fallback message. Both banners write a default
split Season as « SAISON 2 · 2026 ».

The replay test now checks the capture's own hand (k stays at 1 across the
ally's confirmation), the default and hovered illustrations, the cards'
places and the ring's Anvil list. A unit test checks which ticks stay bright.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #95.
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-21 18:37:06 +01:00
1 parent d74da1bee1
commit 0f860fda15
3 files changed
+177 -32

No files matched your search

+92 -12
View File
@@ -1135,8 +1135,8 @@ impl Page {
self.ordered_rows()
.filter(|row| ids.contains(&row.champion.id)),
);
self.ring
.update(cx, |ring, cx| ring.set_anvil(champ_select.map(|_| ids), cx));
// A list the client did not send dims no tick: the ring would look empty.
self.ring.update(cx, |ring, cx| ring.set_anvil(anvil, cx));
if champ_select.is_some() {
let remaining_pickable = cards.iter().filter(|card| !card.greyed());
let first = remaining_pickable.clone().next().or_else(|| cards.first());
@@ -2938,27 +2938,104 @@ mod tests {
#[gpui::test]
async fn the_champ_select_banner_follows_the_arena_capture(cx: &mut TestAppContext) {
let mut picks = frames();
// Put the capture's banned Alistar and the ally's Morgana in the hand.
for pick in &mut picks {
pick.anvil_champions = Some(vec![12, 16, 25, 233]);
let dir = TestDir::new("champ-select-banner");
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
let mut stats = page.read_with(&window, |p, _| p.home_statistics().unwrap().clone());
for row in &mut stats.rows {
row.splash = Some(splash(dir.path(), &row.champion.key));
}
let (page, mut window) = page_in_champ_select(cx, &picks[0]).await;
show(&page, &mut window, stats);
page.update(&mut window, |p, cx| {
p.home_season = Some("Saison 2 2026".into());
p.prepare_champ_select(cx);
});
for (pick, available) in picks.iter().zip([3, 2, 2, 1, 1]) {
send(&page, &mut window, pick);
let text = banner(&page, &mut window);
assert_eq!(text.season.as_ref(), "SAISON 2 · 2026 · 1 / 9 validés");
// The splash the banner shows, or fades to.
let art = |window: &mut VisualTestContext| {
page.read_with(window, |p, cx| {
let target = p.banner_art.read(cx).target.clone()?;
Some(target.path.file_name()?.to_string_lossy().into_owned())
})
};
let ring_anvil = |window: &mut VisualTestContext| {
page.read_with(window, |p, cx| p.ring.read(cx).anvil().map(<[u32]>::to_vec))
};
let check = |window: &mut VisualTestContext, frame: usize, k: usize, splash: &str| {
let text = banner(&page, window);
assert_eq!(
text.season.as_ref(),
"SAISON 2 · 2026 · 1 / 9 validés",
"frame {frame}"
);
assert_eq!(text.title.text.as_ref(), "Sélection des champions");
let plural = if k > 1 { "s" } else { "" };
assert_eq!(
text.detail.text.as_ref(),
format!("Champions de l’Enclume · {available} à valider et disponibles")
format!("Champions de l'Enclume · {k} à valider et disponible{plural}"),
"frame {frame}"
);
assert!(text.last_match.is_none());
assert_eq!(
art(window).as_deref(),
Some(format!("{splash}.50.30.jpg").as_str()),
"frame {frame}"
);
};
// The capture's own hand: Soraka is validated, Lee Sin, Rumble and Xin Zhao are not
// offered, so only Briar is left. The bans (Alistar, Swain) and the ally's Morgana are
// not in the hand: k stays at 1, before and after the ally's confirmation.
draw(&mut window);
let first = bounds(&mut window);
for (frame, pick) in frames().iter().enumerate() {
send(&page, &mut window, pick);
draw(&mut window);
check(&mut window, frame, 1, "Briar");
assert_eq!(bounds(&mut window), first, "frame {frame}");
assert_eq!(ring_anvil(&mut window), Some(ANVIL.to_vec()));
}
// A hovered card supplies the illustration; without one, the default comes back.
let at = center(&mut window, "card-64");
window.simulate_mouse_move(at, None, Modifiers::none());
draw(&mut window);
assert_eq!(art(&mut window).as_deref(), Some("LeeSin.50.30.jpg"));
window.simulate_mouse_move(point(px(5.), px(5.)), None, Modifiers::none());
draw(&mut window);
assert_eq!(art(&mut window).as_deref(), Some("Briar.50.30.jpg"));
// The same frames with the banned Alistar and the ally's Morgana in the hand (A to Z:
// Alistar, Briar, Morgana, Soraka): Alistar's ban, then Morgana's confirmation, lower k
// and move the default illustration on. The cards stay.
let hand = [12, 16, 25, 233];
let cards = ["card-12", "card-233", "card-25", "card-16"];
let mut picks = frames();
for pick in &mut picks {
pick.anvil_champions = Some(hand.to_vec());
}
let hand_bounds = |window: &mut VisualTestContext| -> Vec<_> {
cards
.iter()
.map(|id| window.debug_bounds(id).expect("the card is not drawn"))
.collect()
};
send(&page, &mut window, &picks[0]);
draw(&mut window);
let first = hand_bounds(&mut window);
let expected = [
(3, "Alistar"),
(2, "Briar"),
(2, "Briar"),
(1, "Briar"),
(1, "Briar"),
];
for (frame, (pick, (k, splash))) in picks.iter().zip(expected).enumerate() {
send(&page, &mut window, pick);
draw(&mut window);
check(&mut window, frame, k, splash);
assert_eq!(hand_bounds(&mut window), first, "frame {frame}");
assert_eq!(ring_anvil(&mut window), Some(hand.to_vec()));
}
// A list the client does not send: #74's message, and no tick dimmed.
let mut unknown = picks[4].clone();
unknown.anvil_champions = None;
send(&page, &mut window, &unknown);
@@ -2966,6 +3043,9 @@ mod tests {
banner(&page, &mut window).detail.text.as_ref(),
"Champions de l'Enclume non communiqués par le client"
);
assert_eq!(ring_anvil(&mut window), None);
leave(&page, &mut window);
assert_eq!(ring_anvil(&mut window), None);
}
#[gpui::test]
+29 -18
View File
@@ -661,6 +661,22 @@ impl Line {
}
}
/// The Season as both banners' overline writes it: upper case, and a default split Season, named
/// « Saison 2 2026 » in the stored data, as « SAISON 2 · 2026 ».
fn overline(season: &SharedString) -> String {
let season = season.to_uppercase();
if let Some((split, year)) = season.rsplit_once(' ')
&& year.len() == 4
&& year.bytes().all(|b| b.is_ascii_digit())
&& split
.strip_prefix("SAISON ")
.is_some_and(|n| n.parse::<u32>().is_ok())
{
return format!("{split} · {year}");
}
season
}
/// What the banner shows, prepared when the home statistics change: it follows the home's Season,
/// never the Format, the filter nor the search.
#[derive(Clone, Debug, Default, PartialEq)]
@@ -685,22 +701,15 @@ impl BannerContent {
count: usize,
splash: Option<Rc<Splash>>,
) -> Self {
let mut season = season.map(|name| name.to_uppercase()).unwrap_or_default();
// Default split Seasons are named « Saison 2 2026 » in the stored data.
if let Some((split, year)) = season.rsplit_once(' ')
&& year.len() == 4
&& year.bytes().all(|b| b.is_ascii_digit())
&& split
.strip_prefix("SAISON ")
.is_some_and(|n| n.parse::<u32>().is_ok())
{
season = format!("{split} · {year}");
}
let mut season = season.map(overline).unwrap_or_default();
if let Some(challenge) = stats.and_then(|s| s.challenge.as_ref()) {
use std::fmt::Write;
if !season.is_empty() {
season.push_str(" · ");
}
write!(
season,
" · {} / {} validés",
"{} / {} validés",
challenge.completed, challenge.total
)
.unwrap();
@@ -708,11 +717,13 @@ impl BannerContent {
let detail = if !known {
Line::plain(UNKNOWN_ANVIL)
} else if stats.is_some() {
Line::new(
"Champions de l’Enclume · ",
&count.to_string(),
" à valider et disponibles",
)
// 0 and 1 take the singular in French.
let available = if count > 1 {
" à valider et disponibles"
} else {
" à valider et disponible"
};
Line::new("Champions de l'Enclume · ", &count.to_string(), available)
} else {
Line::default()
};
@@ -726,7 +737,7 @@ impl BannerContent {
}
pub(super) fn new(season: Option<&SharedString>, stats: Option<&Statistics>) -> BannerContent {
let season = season.map_or_else(SharedString::default, |name| name.to_uppercase().into());
let season = season.map_or_else(SharedString::default, |name| overline(name).into());
let Some((stats, challenge)) = stats.and_then(|s| Some((s, s.challenge.as_ref()?))) else {
return BannerContent {
season,
+56 -2
View File
@@ -135,7 +135,7 @@ struct Geometry {
/// The size it was made for: it is made at the origin, and moved where the ring is painted,
/// so a scroll that moves the ring does not make it again.
size: Size<Pixels>,
/// One path per state of tick.
/// One path per state of tick, bright or dimmed (`true`) during a champ select.
ticks: Vec<(ChampionState, bool, Path<Pixels>)>,
crown: Option<Path<Pixels>>,
}
@@ -244,6 +244,8 @@ impl Ring {
}
}
/// During a champ select whose Anvil list is known: only these champions' ticks stay bright,
/// the others are dimmed. None dims no tick.
pub fn set_anvil(&mut self, ids: Option<&[u32]>, cx: &mut Context<Self>) {
if self.anvil.as_deref() != ids {
self.anvil = ids.map(Rc::from);
@@ -265,6 +267,11 @@ impl Ring {
&self.ticks
}
#[cfg(test)]
pub(crate) fn anvil(&self) -> Option<&[u32]> {
self.anvil.as_deref()
}
pub(crate) fn lit(&self) -> Option<u32> {
self.lit
}
@@ -356,7 +363,9 @@ impl Render for Ring {
mod tests {
use arena_tracker_core::{Champion, ChampionRow, ChampionState};
use super::{Tick, ticks};
use gpui_kit::{px, size};
use super::{Geometry, Tick, ticks};
use crate::champion_table::tests::row;
fn champion(id: u32, name: &str, state: ChampionState, points: Option<u64>) -> ChampionRow {
@@ -419,4 +428,49 @@ mod tests {
]
);
}
/// Which shapes the ring paints: per state, bright or dimmed.
fn painted(ticks: &[Tick], anvil: Option<&[u32]>) -> Vec<(ChampionState, bool)> {
Geometry::new(size(px(200.), px(200.)), ticks, anvil)
.ticks
.iter()
.map(|(state, dim, _)| (*state, *dim))
.collect()
}
#[test]
fn only_the_anvil_champions_ticks_stay_bright() {
use ChampionState::*;
let tick = |id, state| Tick { id, state };
let ring = [
tick(1, Completed),
tick(2, Completed),
tick(3, InProgress),
tick(4, NeverPlayed),
];
// At home, and in a champ select whose list the client did not send: nothing dimmed.
assert_eq!(
painted(&ring, None),
[
(Completed, false),
(InProgress, false),
(NeverPlayed, false)
]
);
// The hand is 1 and 4: 2 and 3 fade.
assert_eq!(
painted(&ring, Some(&[1, 4])),
[
(Completed, false),
(Completed, true),
(InProgress, true),
(NeverPlayed, false),
]
);
// An empty hand: every tick fades.
assert_eq!(
painted(&ring, Some(&[])),
[(Completed, true), (InProgress, true), (NeverPlayed, true)]
);
}
}