From bd4de1ec051b638d211947c88e383126c63ea825 Mon Sep 17 00:00:00 2001
From: TO
Date: Fri, 20 Nov 2026 21:08:30 +0100
Subject: [PATCH] Tell why a champ select makes a champion unavailable (#74)
Split the excluded set into banned and taken_by_ally, add
ChampSelect::unavailability (banned, taken_by_ally, not_offered; never for
the player's own pick) and make the anvil list an Option so an unreadable
list is not read as an empty one.
Co-Authored-By: Claude Opus 5.5
---
crates/app/src/page.rs | 7 +-
crates/core/src/champ_select.rs | 262 ++++++++++++++++++++++++++-----
crates/core/src/league_client.rs | 6 +-
crates/core/src/lib.rs | 2 +-
crates/core/tests/common/mod.rs | 5 +-
crates/core/tests/follow.rs | 79 ++++++++--
6 files changed, 302 insertions(+), 59 deletions(-)
diff --git a/crates/app/src/page.rs b/crates/app/src/page.rs
index 1862f45..c67c9d4 100644
--- a/crates/app/src/page.rs
+++ b/crates/app/src/page.rs
@@ -797,6 +797,7 @@ impl Page {
.map(|s| {
s.anvil_champions
.iter()
+ .flatten()
.map(|id| {
let row = rows.iter().find(|r| r.champion.id == *id);
let mut label = champion_label(row, *id);
@@ -1254,7 +1255,7 @@ mod tests {
tracker.sync("Bob#EUW", &mut |_| {}).unwrap();
tracker.follow_client(0, Some("Alice#EUW"), &mut |_| {});
let (page, mut window) = open_page_with_tracker(cx, tracker);
- let pick = ChampSelect::new(Some(39), [39].into(), vec![39]);
+ let pick = ChampSelect::new(Some(39), [39].into(), Some(vec![39]));
window.update(|w, cx| {
page.update(cx, |p, cx| {
// The table that follows the champ select pool back is the Statistics one.
@@ -1282,7 +1283,7 @@ mod tests {
});
// A hover change touches neither the Account nor the pool: the panel must still update.
- let next = ChampSelect::new(None, [39].into(), vec![39]);
+ let next = ChampSelect::new(None, [39].into(), Some(vec![39]));
window.update(|w, cx| {
page.update(cx, |p, cx| {
p.apply(Msg::ChampSelect(Some(("Alice#EUW".into(), next))), w, cx);
@@ -1323,7 +1324,7 @@ mod tests {
},
)
});
- let hovered = |current| ChampSelect::new(current, [39].into(), vec![39]);
+ let hovered = |current| ChampSelect::new(current, [39].into(), Some(vec![39]));
for champ_select in [
None,
Some(("Alice#EUW".into(), hovered(Some(39)))),
diff --git a/crates/core/src/champ_select.rs b/crates/core/src/champ_select.rs
index 179c740..89912e2 100644
--- a/crates/core/src/champ_select.rs
+++ b/crates/core/src/champ_select.rs
@@ -17,14 +17,31 @@ pub(crate) const ANVIL_EVENT: &str =
#[derive(Clone, Debug)]
pub struct ChampSelect {
pub current: Option,
- /// The five anvil champions; empty when the client reports none. The client calls them
- /// crowd favorites.
- pub anvil_champions: Vec,
+ /// The five anvil champions, in the order the client gives them; the client calls them
+ /// crowd favorites. `None` when the client gave no readable list for this champ select,
+ /// `Some` of an empty list when it said there are none: its list request fails (HTTP
+ /// error, unreadable body) when the list is absent, answers `[]` for a known empty list,
+ /// and its Update events carry a list while a Delete carries `null`.
+ pub anvil_champions: Option>,
/// The champions the champ select offers, before its bans and the other players' picks.
/// Shared with the client's cache instead of cloned on every session event.
pickable: Arc>,
- /// Banned or taken by another player in this champ select.
- excluded: HashSet,
+ /// Banned in this champ select: the completed ban actions and both teams' ban lists.
+ banned: HashSet,
+ /// Confirmed by another player of the local team in this champ select. A pre-pick (the
+ /// client's pick intent) is not part of it.
+ taken_by_ally: HashSet,
+}
+
+/// Why the champ select does not let the local player pick a champion. Reasons add up; a
+/// champion available to pick has none. Whether the champion is Completed is not part of it.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub struct Unavailability {
+ pub banned: bool,
+ pub taken_by_ally: bool,
+ /// The client does not offer the champion (not pickable, or disabled), and neither a ban
+ /// nor an ally explains it.
+ pub not_offered: bool,
}
impl PartialEq for ChampSelect {
@@ -62,19 +79,24 @@ fn ids_in(value: &Value) -> Option> {
impl ChampSelect {
/// A champ select with nothing banned or taken, for callers with a ready pool.
- pub fn new(current: Option, pickable: HashSet, anvil_champions: Vec) -> Self {
+ pub fn new(
+ current: Option,
+ pickable: HashSet,
+ anvil_champions: Option>,
+ ) -> Self {
Self {
current,
anvil_champions,
pickable: Arc::new(pickable),
- excluded: HashSet::new(),
+ banned: HashSet::new(),
+ taken_by_ally: HashSet::new(),
}
}
fn from_session(
session: &Value,
pickable: Arc>,
- anvil_champions: Vec,
+ anvil_champions: Option>,
) -> Result {
let local = session["localPlayerCellId"]
.as_i64()
@@ -86,13 +108,14 @@ impl ChampSelect {
.ok_or(ClientError::Absent)?;
let current =
champion_id(&me["championId"]).or_else(|| champion_id(&me["championPickIntent"]));
- let mut excluded = HashSet::new();
+ let mut taken_by_ally = HashSet::new();
+ let mut banned = HashSet::new();
for player in team
.iter()
.filter(|p| p["cellId"] != local && p["team"] == me["team"])
{
if let Some(id) = champion_id(&player["championId"]) {
- excluded.insert(id);
+ taken_by_ally.insert(id);
}
}
// In Arena the confirmed bans were in actions while both team ban lists were empty.
@@ -102,20 +125,21 @@ impl ChampSelect {
&& action["completed"] == true
&& let Some(id) = champion_id(&action["championId"])
{
- excluded.insert(id);
+ banned.insert(id);
}
}
}
for key in ["myTeamBans", "theirTeamBans"] {
if let Some(bans) = session["bans"][key].as_array() {
- excluded.extend(bans.iter().filter_map(champion_id));
+ banned.extend(bans.iter().filter_map(champion_id));
}
}
Ok(Self {
current,
anvil_champions,
pickable,
- excluded,
+ banned,
+ taken_by_ally,
})
}
@@ -127,14 +151,33 @@ impl ChampSelect {
/// Whether the local player can still pick this champion. Their own pick always stays
/// pickable.
pub fn can_pick(&self, id: u32) -> bool {
- self.current == Some(id) || (self.pickable.contains(&id) && !self.excluded.contains(&id))
+ self.current == Some(id)
+ || (self.pickable.contains(&id)
+ && !self.banned.contains(&id)
+ && !self.taken_by_ally.contains(&id))
+ }
+
+ /// Why the local player cannot pick this champion. The player's own pick, hovered or
+ /// locked, is never unavailable.
+ pub fn unavailability(&self, id: u32) -> Unavailability {
+ if self.current == Some(id) {
+ return Unavailability::default();
+ }
+ let banned = self.banned.contains(&id);
+ let taken_by_ally = self.taken_by_ally.contains(&id);
+ Unavailability {
+ banned,
+ taken_by_ally,
+ not_offered: !banned && !taken_by_ally && !self.pickable.contains(&id),
+ }
}
/// Whether both champ selects offer the same champions, whatever the current pick. The
/// shared set makes the common case a pointer comparison.
pub fn same_pickable(&self, other: &Self) -> bool {
(Arc::ptr_eq(&self.pickable, &other.pickable) || self.pickable == other.pickable)
- && self.excluded == other.excluded
+ && self.banned == other.banned
+ && self.taken_by_ally == other.taken_by_ally
}
/// A champion still to complete in the Challenge and pickable in this champ select. The
@@ -196,7 +239,11 @@ impl ChampSelectReader {
}
let lists = lock(&self.lists);
let lists = lists.as_ref().expect("set just above");
- ChampSelect::from_session(&session, lists.pickable(), lists.anvil().to_vec())
+ ChampSelect::from_session(
+ &session,
+ lists.pickable(),
+ lists.anvil().map(<[u32]>::to_vec),
+ )
}
/// Applies the client's pickable list event.
@@ -227,7 +274,8 @@ pub(crate) struct ChampSelectLists {
/// The client's pickable list, before the disabled champions are removed.
offered: HashSet,
disabled: HashSet,
- anvil: Vec,
+ /// `None` until the client gives a readable list.
+ anvil: Option>,
/// `offered` minus `disabled`, rebuilt only when either list changes.
pickable: Arc>,
}
@@ -243,12 +291,10 @@ impl ChampSelectLists {
disabled: ids(disabled)?,
..Self::default()
};
- if let Some(body) = anvil
- && let Ok(value) = parse(body)
- && let Some(ids) = ids_in(&value)
- {
- lists.anvil = ids;
- }
+ // A missing or unreadable body leaves the list unknown; `[]` is a known empty list.
+ lists.anvil = anvil
+ .and_then(|body| parse(body).ok())
+ .and_then(|value| ids_in(&value));
lists.rebuild();
Ok(lists)
}
@@ -261,8 +307,8 @@ impl ChampSelectLists {
self.pickable.clone()
}
- pub(crate) fn anvil(&self) -> &[u32] {
- &self.anvil
+ pub(crate) fn anvil(&self) -> Option<&[u32]> {
+ self.anvil.as_deref()
}
fn set_pickable(&mut self, data: &Value) {
@@ -281,7 +327,7 @@ impl ChampSelectLists {
fn set_anvil(&mut self, data: &Value) {
if let Some(ids) = ids_in(data) {
- self.anvil = ids;
+ self.anvil = Some(ids);
}
}
}
@@ -295,43 +341,177 @@ mod tests {
fn the_lists_change_only_for_the_events_that_concern_them() {
let mut lists = ChampSelectLists::from_bodies("[1,2,3]", "[3]", Some("[9,8]")).unwrap();
assert_eq!(&*lists.pickable(), &HashSet::from([1, 2]));
- assert_eq!(lists.anvil(), [9, 8]);
+ assert_eq!(lists.anvil(), Some(&[9, 8][..]));
// A Delete carries no data: it changes nothing.
lists.set_pickable(&Value::Null);
lists.set_anvil(&Value::Null);
assert_eq!(&*lists.pickable(), &HashSet::from([1, 2]));
- assert_eq!(lists.anvil(), [9, 8]);
+ assert_eq!(lists.anvil(), Some(&[9, 8][..]));
lists.set_pickable(&json!([1, 4]));
assert_eq!(&*lists.pickable(), &HashSet::from([1, 4]));
- assert_eq!(lists.anvil(), [9, 8]);
+ assert_eq!(lists.anvil(), Some(&[9, 8][..]));
lists.set_disabled(&json!([1]));
assert_eq!(&*lists.pickable(), &HashSet::from([4]));
lists.set_anvil(&json!([5, 6]));
- assert_eq!(lists.anvil(), [5, 6]);
+ assert_eq!(lists.anvil(), Some(&[5, 6][..]));
}
#[test]
fn the_anvil_champions_are_read_once_when_the_champ_select_starts() {
- assert!(
- ChampSelectLists::from_bodies("[]", "[]", None)
+ let anvil = |body| {
+ ChampSelectLists::from_bodies("[]", "[]", body)
.unwrap()
.anvil()
- .is_empty()
- );
- assert_eq!(
- ChampSelectLists::from_bodies("[]", "[]", Some("[1,2]"))
- .unwrap()
- .anvil(),
- [1, 2]
- );
+ .map(<[u32]>::to_vec)
+ };
+ // No answer, or one that is not a list: the client gave no list.
+ assert_eq!(anvil(None), None);
+ assert_eq!(anvil(Some("not json")), None);
+ assert_eq!(anvil(Some(r#"{"error":"x"}"#)), None);
+ // An empty list is a list: the client says there are none.
+ assert_eq!(anvil(Some("[]")), Some(vec![]));
+ assert_eq!(anvil(Some("[1,2]")), Some(vec![1, 2]));
+ // The client's order is kept.
+ assert_eq!(anvil(Some("[9,1,5]")), Some(vec![9, 1, 5]));
// A malformed anvil answer only loses the anvil list, not the pickable one.
let lists = ChampSelectLists::from_bodies("[7]", "[]", Some("not json")).unwrap();
assert_eq!(&*lists.pickable(), &HashSet::from([7]));
- assert!(lists.anvil().is_empty());
+ assert_eq!(lists.anvil(), None);
+ }
+
+ #[test]
+ fn an_anvil_event_gives_a_list_from_unknown_and_a_delete_keeps_the_value() {
+ let mut lists = ChampSelectLists::from_bodies("[]", "[]", None).unwrap();
+ lists.set_anvil(&Value::Null);
+ assert_eq!(lists.anvil(), None);
+ lists.set_anvil(&json!([4, 2]));
+ assert_eq!(lists.anvil(), Some(&[4, 2][..]));
+ lists.set_anvil(&Value::Null);
+ assert_eq!(lists.anvil(), Some(&[4, 2][..]));
+ // An empty list from an event is a known empty list.
+ lists.set_anvil(&json!([]));
+ assert_eq!(lists.anvil(), Some(&[][..]));
+ }
+
+ fn session(
+ local_intent: u32,
+ ally_id: u32,
+ ally_intent: u32,
+ actions: Value,
+ bans: Value,
+ ) -> Value {
+ json!({
+ "localPlayerCellId": 16,
+ "myTeam": [
+ {"cellId": 16, "team": 1, "championId": 0, "championPickIntent": local_intent},
+ {"cellId": 17, "team": 1, "championId": ally_id, "championPickIntent": ally_intent},
+ {"cellId": 18, "team": 2, "championId": 77, "championPickIntent": 0},
+ ],
+ "actions": actions,
+ "bans": bans,
+ })
+ }
+
+ fn champ_select(current_session: Value) -> ChampSelect {
+ ChampSelect::from_session(
+ ¤t_session,
+ Arc::new(HashSet::from([1, 2, 3, 4, 5, 6])),
+ Some(vec![1, 2]),
+ )
+ .unwrap()
+ }
+
+ fn reasons(banned: bool, taken_by_ally: bool, not_offered: bool) -> Unavailability {
+ Unavailability {
+ banned,
+ taken_by_ally,
+ not_offered,
+ }
+ }
+
+ #[test]
+ fn every_reason_that_applies_is_given() {
+ let pick = champ_select(session(
+ 0,
+ 2,
+ 0,
+ json!([[
+ {"type": "ban", "championId": 1, "completed": true},
+ {"type": "ban", "championId": 3, "completed": false},
+ {"type": "pick", "championId": 4, "completed": true},
+ ]]),
+ json!({"myTeamBans": [5], "theirTeamBans": [2]}),
+ ));
+ // A completed ban, either team's ban list.
+ assert_eq!(pick.unavailability(1), reasons(true, false, false));
+ assert_eq!(pick.unavailability(5), reasons(true, false, false));
+ // Banned and taken by an ally add up; a ban in progress or a pick action count for
+ // nothing; a player of the other team is not an ally.
+ assert_eq!(pick.unavailability(2), reasons(true, true, false));
+ assert_eq!(pick.unavailability(3), Unavailability::default());
+ assert_eq!(pick.unavailability(4), Unavailability::default());
+ assert_eq!(pick.unavailability(77), reasons(false, false, true));
+ // Not in the client's pickable list.
+ assert_eq!(pick.unavailability(99), reasons(false, false, true));
+ assert_eq!(pick.unavailability(6), Unavailability::default());
+ // `can_pick` agrees with the reasons.
+ for id in [1, 2, 3, 4, 5, 6, 77, 99] {
+ assert_eq!(
+ pick.can_pick(id),
+ pick.unavailability(id) == Unavailability::default(),
+ "champion {id}"
+ );
+ }
+ }
+
+ #[test]
+ fn an_ally_pre_pick_takes_nothing_but_the_confirmed_pick_does() {
+ let hover = champ_select(session(0, 0, 3, json!([]), json!({})));
+ assert_eq!(hover.unavailability(3), Unavailability::default());
+ let locked = champ_select(session(0, 3, 3, json!([]), json!({})));
+ assert_eq!(locked.unavailability(3), reasons(false, true, false));
+ }
+
+ #[test]
+ fn a_disabled_champion_is_not_offered() {
+ let lists = ChampSelectLists::from_bodies("[1,2,3]", "[3]", None).unwrap();
+ let pick = ChampSelect::from_session(
+ &session(0, 0, 0, json!([]), json!({})),
+ lists.pickable(),
+ None,
+ )
+ .unwrap();
+ assert_eq!(pick.unavailability(3), reasons(false, false, true));
+ assert_eq!(pick.unavailability(1), Unavailability::default());
+ }
+
+ #[test]
+ fn the_players_own_pick_is_never_greyed() {
+ // Hovered then locked, though the data also bans it, takes it and does not offer it.
+ let banned = json!([[{"type": "ban", "championId": 99, "completed": true}]]);
+ let intent = champ_select(session(99, 99, 0, banned.clone(), json!({})));
+ assert_eq!(intent.current, Some(99));
+ assert_eq!(intent.unavailability(99), Unavailability::default());
+ let mut locked = session(0, 99, 0, banned, json!({"myTeamBans": [99]}));
+ locked["myTeam"][0]["championId"] = json!(99);
+ let locked = champ_select(locked);
+ assert_eq!(locked.unavailability(99), Unavailability::default());
+ assert!(locked.can_pick(99));
+ }
+
+ #[test]
+ fn two_champ_selects_differ_by_their_bans_and_ally_picks() {
+ let plain = champ_select(session(0, 0, 0, json!([]), json!({})));
+ let banned = champ_select(session(0, 0, 0, json!([]), json!({"myTeamBans": [3]})));
+ let taken = champ_select(session(0, 3, 0, json!([]), json!({})));
+ assert!(!plain.same_pickable(&banned));
+ assert!(!plain.same_pickable(&taken));
+ assert!(!banned.same_pickable(&taken));
+ assert_ne!(plain, banned);
}
#[test]
diff --git a/crates/core/src/league_client.rs b/crates/core/src/league_client.rs
index c87e33f..7fcfc4c 100644
--- a/crates/core/src/league_client.rs
+++ b/crates/core/src/league_client.rs
@@ -179,7 +179,7 @@ impl GameClientSource for LeagueClient {
|| {
let pickable = self.get_ok(PICKABLE)?;
let disabled = self.get_ok(DISABLED)?;
- // The anvil list is a bonus: a failed read leaves it empty until an event
+ // The anvil list is a bonus: a failed read leaves it unknown until an event
// delivers it.
let anvil = self.get_ok(ANVIL_CHAMPIONS).ok();
Ok((pickable, disabled, anvil))
@@ -710,7 +710,7 @@ mod tests {
)
.unwrap();
assert_eq!(pick.current, Some(16));
- assert_eq!(pick.anvil_champions, [9, 8]);
+ assert_eq!(pick.anvil_champions, Some(vec![9, 8]));
assert!(!pick.can_pick(1));
assert!(pick.can_pick(2));
}
@@ -755,7 +755,7 @@ mod tests {
.unwrap()
};
let pick = read();
- assert_eq!(pick.anvil_champions, [9]);
+ assert_eq!(pick.anvil_champions, Some(vec![9]));
assert!(pick.can_pick(1));
assert!(!pick.can_pick(2));
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
index 55fb112..02653a5 100644
--- a/crates/core/src/lib.rs
+++ b/crates/core/src/lib.rs
@@ -14,7 +14,7 @@ mod statistics;
mod tracker;
mod update_package;
-pub use champ_select::{ChampSelect, ChampSelectReader};
+pub use champ_select::{ChampSelect, ChampSelectReader, Unavailability};
pub use champion_search::ChampionSearch;
pub use champions::{Champion, ChampionCatalog, ChampionSource, DataDragon};
pub use client::{ClientError, ClientEvent, ClientSnapshot, GameClientSource, GamePhase, Gameflow};
diff --git a/crates/core/tests/common/mod.rs b/crates/core/tests/common/mod.rs
index 688891a..0e3a944 100644
--- a/crates/core/tests/common/mod.rs
+++ b/crates/core/tests/common/mod.rs
@@ -684,7 +684,8 @@ struct ClientState {
pub struct RawChampSelect {
pub pickable: String,
pub disabled: String,
- pub anvil: String,
+ /// `None` when the client's anvil list request fails.
+ pub anvil: Option,
pub session: String,
}
@@ -837,7 +838,7 @@ impl GameClientSource for FakeClient {
Ok((
raw.pickable.clone(),
raw.disabled.clone(),
- Some(raw.anvil.clone()),
+ raw.anvil.clone(),
))
},
)
diff --git a/crates/core/tests/follow.rs b/crates/core/tests/follow.rs
index 03f4349..b6730f1 100644
--- a/crates/core/tests/follow.rs
+++ b/crates/core/tests/follow.rs
@@ -9,7 +9,7 @@ use std::time::{Duration, Instant};
use arena_tracker_core::{
Account, ChampSelect, ChampionRow, ChampionState, ClientError, ClientEvent, Format,
MATCH_RETRIES, ProgressCheck, RETRY_EVERY_MS, Scope, SeasonScope, SourceError, Tracker,
- UpdateProblem,
+ Unavailability, UpdateProblem,
};
use common::{
FakeClient, FakeHistory, PlayedMatch, RawChampSelect, S2, S2_TRACK, SELF_PUUID, at, date,
@@ -1040,7 +1040,7 @@ fn arena_champ_select_replays_bans_hovers_and_lock_in_for_the_current_challenge(
current: Option<(u32, ChampionState)>,
remaining: &[u32],
) {
- assert_eq!(pick.anvil_champions, [233, 64, 5, 16, 68]);
+ assert_eq!(pick.anvil_champions, Some(vec![233, 64, 5, 16, 68]));
assert_eq!(
pick.current_row(rows)
.map(|r| (r.champion.id, r.attempts, r.state)),
@@ -1055,6 +1055,24 @@ fn arena_champ_select_replays_bans_hovers_and_lock_in_for_the_current_challenge(
assert_eq!(ids, remaining);
}
+ // The reasons the champ select gives for the champions of the capture. The anvil champions
+ // 64, 5 and 68 are not in the client's pickable list. The player's own pick is never
+ // unavailable, whatever the bans and allies say.
+ fn assert_reasons(pick: &ChampSelect, banned: &[u32], taken: &[u32]) {
+ for id in [12, 16, 25, 50, 64, 5, 68, 103, 233] {
+ let expected = if pick.current == Some(id) {
+ Unavailability::default()
+ } else {
+ Unavailability {
+ banned: banned.contains(&id),
+ taken_by_ally: taken.contains(&id),
+ not_offered: [64, 5, 68].contains(&id),
+ }
+ };
+ assert_eq!(pick.unavailability(id), expected, "champion {id}");
+ }
+ }
+
let capture: Value =
serde_json::from_str(include_str!("fixtures/client/arena_champ_select.json")).unwrap();
let world = World::new(
@@ -1066,7 +1084,7 @@ fn arena_champ_select_replays_bans_hovers_and_lock_in_for_the_current_challenge(
world.client.set_champ_select(RawChampSelect {
pickable: capture["pickableChampionIds"].to_string(),
disabled: capture["disabledChampionIds"].to_string(),
- anvil: capture["crowdFavoriteChampionIds"].to_string(),
+ anvil: Some(capture["crowdFavoriteChampionIds"].to_string()),
session: capture["sessions"][frame].to_string(),
});
};
@@ -1091,19 +1109,36 @@ fn arena_champ_select_replays_bans_hovers_and_lock_in_for_the_current_challenge(
let (account, pick) = shown(&tracker).unwrap().unwrap();
assert_eq!(account, "Joueur#EUW");
assert_pick(&pick, &rows, None, &[12, 25, 50, 103, 233]);
+ assert_reasons(&pick, &[], &[]);
assert_eq!(world.client.champ_select_reads(), (1, 1));
// Every later change arrives as the client's session event: neither the session nor the
// lists are read again.
- for (frame, current, remaining) in [
- (1, None, vec![25, 50, 103, 233]),
+ // The ban of 12 is completed in frame 1 and the ban of 50 in frame 2. The ally's pre-pick of
+ // 25 (frame 1) leaves it as it is; the confirmed pick (frame 3) takes it.
+ for (frame, current, remaining, banned, taken) in [
+ (1, None, vec![25, 50, 103, 233], vec![12], vec![]),
(
2,
Some((233, ChampionState::InProgress)),
vec![25, 103, 233],
+ vec![12, 50],
+ vec![],
+ ),
+ (
+ 3,
+ Some((16, ChampionState::Completed)),
+ vec![103, 233],
+ vec![12, 50],
+ vec![25],
+ ),
+ (
+ 4,
+ Some((16, ChampionState::Completed)),
+ vec![103, 233],
+ vec![12, 50],
+ vec![25],
),
- (3, Some((16, ChampionState::Completed)), vec![103, 233]),
- (4, Some((16, ChampionState::Completed)), vec![103, 233]),
] {
world
.client
@@ -1111,6 +1146,7 @@ fn arena_champ_select_replays_bans_hovers_and_lock_in_for_the_current_challenge(
assert_eq!(tracker.wait_for_client(), ClientEvent::ChampSelect);
let (_, pick) = shown(&tracker).unwrap().unwrap();
assert_pick(&pick, &rows, current, &remaining);
+ assert_reasons(&pick, &banned, &taken);
assert_eq!(world.client.champ_select_reads(), (1, 1));
}
@@ -1119,10 +1155,35 @@ fn arena_champ_select_replays_bans_hovers_and_lock_in_for_the_current_challenge(
assert_eq!(shown(&tracker), Ok(None));
set_frame(0);
world.client.set_gameflow(&capture["gameflow"].to_string());
- assert!(shown(&tracker).unwrap().is_some());
+ // Bans and ally picks expired with the first champ select.
+ let (_, pick) = shown(&tracker).unwrap().unwrap();
+ assert_reasons(&pick, &[], &[]);
assert_eq!(world.client.champ_select_reads(), (2, 2));
}
+#[test]
+fn the_anvil_list_is_unknown_when_the_client_fails_to_give_it_and_empty_when_it_says_so() {
+ use serde_json::Value;
+ let capture: Value =
+ serde_json::from_str(include_str!("fixtures/client/arena_champ_select.json")).unwrap();
+ let anvil_champions = |anvil: Option<&str>| {
+ let world = World::new(&[]);
+ let tracker = world.tracker();
+ world.client.set_champ_select(RawChampSelect {
+ pickable: capture["pickableChampionIds"].to_string(),
+ disabled: capture["disabledChampionIds"].to_string(),
+ anvil: anvil.map(str::to_string),
+ session: capture["sessions"][0].to_string(),
+ });
+ world.client.set_gameflow(&capture["gameflow"].to_string());
+ shown(&tracker).unwrap().unwrap().1.anvil_champions
+ };
+ assert_eq!(anvil_champions(None), None);
+ assert_eq!(anvil_champions(Some("not json")), None);
+ assert_eq!(anvil_champions(Some("[]")), Some(vec![]));
+ assert_eq!(anvil_champions(Some("[3,1,2]")), Some(vec![3, 1, 2]));
+}
+
#[test]
fn a_failed_champ_select_read_keeps_the_pick_until_the_champ_select_really_ends() {
use serde_json::Value;
@@ -1133,7 +1194,7 @@ fn a_failed_champ_select_read_keeps_the_pick_until_the_champ_select_really_ends(
world.client.set_champ_select(RawChampSelect {
pickable: capture["pickableChampionIds"].to_string(),
disabled: capture["disabledChampionIds"].to_string(),
- anvil: capture["crowdFavoriteChampionIds"].to_string(),
+ anvil: Some(capture["crowdFavoriteChampionIds"].to_string()),
session: capture["sessions"][0].to_string(),
});
world.client.set_gameflow(&capture["gameflow"].to_string());