Entering an Arena champ select adds the tab and shows it from anywhere; the Challenge and Statistics stay reachable during it, and coming back shows the hand at rest. Its end removes the tab and shows the Challenge, the hand leaving first when « Sélection » was in front. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
378 lines
16 KiB
Rust
378 lines
16 KiB
Rust
use super::banner_fixtures::{banner, splash};
|
|
use super::champ_select_fixtures::{
|
|
ANVIL, ANVIL_A_TO_Z, anvil_cards, bounds, capture, frames, ids, joueur_tracker,
|
|
joueur_tracker_with, leave, page_in_champ_select, places, read_champ_select, reasons, send,
|
|
with_bans_and_ally,
|
|
};
|
|
use super::page_fixtures::{center, draw, open_page, open_page_with_tracker, show};
|
|
use crate::card::{ASPECT, Reason};
|
|
use crate::card_images::tests::TestDir;
|
|
|
|
use crate::page::Tab;
|
|
use arena_tracker_core::{ChampSelectReader, StateFilter};
|
|
use gpui_kit::{Modifiers, TestAppContext, VisualTestContext, point, px};
|
|
|
|
#[gpui::test]
|
|
async fn the_champ_select_banner_follows_the_arena_capture(cx: &mut TestAppContext) {
|
|
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));
|
|
}
|
|
show(&page, &mut window, stats);
|
|
page.update(&mut window, |p, cx| {
|
|
p.home_season = Some("Saison 2 2026".into());
|
|
p.prepare_champ_select(cx);
|
|
});
|
|
// 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 · {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");
|
|
let places = places(&page, &mut window, &first, &ANVIL_A_TO_Z);
|
|
assert_eq!(bounds(&mut window), places, "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);
|
|
let places = places(&page, &mut window, &first, &[12, 233, 25, 16]);
|
|
assert_eq!(hand_bounds(&mut window), places, "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);
|
|
assert_eq!(
|
|
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]
|
|
async fn the_arena_capture_fills_the_anvil_row_in_the_homes_order(cx: &mut TestAppContext) {
|
|
cx.executor().allow_parking();
|
|
let (page, mut window) = open_page_with_tracker(cx, joueur_tracker());
|
|
// The home's own order, which the row follows.
|
|
let home_order: Vec<u32> = page.read_with(&window, |p, _| {
|
|
let rows = p.stats.as_ref().unwrap().rows.iter();
|
|
rows.map(|row| row.champion.id)
|
|
.filter(|id| ANVIL.contains(id))
|
|
.collect()
|
|
});
|
|
assert_eq!(home_order, ANVIL_A_TO_Z);
|
|
|
|
let frames = frames();
|
|
assert_eq!(frames.len(), 5);
|
|
send(&page, &mut window, &frames[0]);
|
|
// Until the statistics are there, the row is replaced by what is missing.
|
|
page.read_with(&window, |p, _| {
|
|
assert_eq!(p.anvil_line().as_deref(), Some("Compte indisponible"))
|
|
});
|
|
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
|
draw(&mut window);
|
|
let first = bounds(&mut window);
|
|
|
|
// Never greyed by the champ select: 233 and 16 are offered, the rest is not offered.
|
|
let baseline = [
|
|
(233, vec![]),
|
|
(64, vec![Reason::NotOffered]),
|
|
(68, vec![Reason::NotOffered]),
|
|
(16, vec![Reason::Completed]),
|
|
(5, vec![Reason::NotOffered]),
|
|
];
|
|
for (frame, pick) in frames.iter().enumerate() {
|
|
if frame > 0 {
|
|
send(&page, &mut window, pick);
|
|
}
|
|
draw(&mut window);
|
|
let cards = anvil_cards(&page, &mut window);
|
|
// 12 (banned), 25 (ally) and 50 (banned) are not Anvil champions: never in the row.
|
|
assert_eq!(ids(&cards), ANVIL_A_TO_Z, "frame {frame}");
|
|
for (id, expected) in &baseline {
|
|
assert_eq!(
|
|
&reasons(&cards, *id),
|
|
expected,
|
|
"frame {frame}, champion {id}"
|
|
);
|
|
}
|
|
// The cards keep their place.
|
|
let places = places(&page, &mut window, &first, &ANVIL_A_TO_Z);
|
|
assert_eq!(bounds(&mut window), places, "frame {frame}");
|
|
}
|
|
|
|
// The marks come with the Challenge of the signed-in Account.
|
|
let cards = anvil_cards(&page, &mut window);
|
|
let mark = |id| cards.iter().find(|c| c.id == id).unwrap().marks;
|
|
assert!(mark(16).completed && mark(16).won);
|
|
assert!(mark(233).played && !mark(233).completed);
|
|
assert!(!mark(64).played);
|
|
|
|
// Reasons add up: 16 is Completed and banned, 233 banned and confirmed by an ally. The
|
|
// labels change and the cards stay.
|
|
send(&page, &mut window, &with_bans_and_ally(&[16, 233, 12], 233));
|
|
draw(&mut window);
|
|
let cards = anvil_cards(&page, &mut window);
|
|
assert_eq!(ids(&cards), ANVIL_A_TO_Z);
|
|
assert_eq!(reasons(&cards, 16), [Reason::Completed, Reason::Banned]);
|
|
assert_eq!(reasons(&cards, 233), [Reason::Banned, Reason::TakenByAlly]);
|
|
assert_eq!(reasons(&cards, 64), [Reason::NotOffered]);
|
|
// Briar, taken by an ally, rests 8 px lower than the others, which do not move.
|
|
let mut lowered = first.clone();
|
|
lowered[0].origin.y += px(8.);
|
|
assert_eq!(bounds(&mut window), lowered);
|
|
|
|
// The cards are as big as the home's, on one row of six at 1280 px.
|
|
let (width, height) = (first[0].size.width.as_f32(), first[0].size.height.as_f32());
|
|
assert!((height - width / ASPECT).abs() < 1., "{width} x {height}");
|
|
assert_eq!(first[0].origin.y, first[1].origin.y);
|
|
let gap = (first[1].origin.x - first[0].origin.x).as_f32() - width;
|
|
assert!((gap - 14.).abs() < 1., "gap {gap}");
|
|
}
|
|
|
|
#[gpui::test]
|
|
async fn the_champ_select_takes_the_window_and_gives_the_home_back_as_it_was(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
use arena_tracker_core::SeasonScope;
|
|
cx.executor().allow_parking();
|
|
let (page, mut window) = open_page_with_tracker(cx, joueur_tracker());
|
|
let (input, home_grid) = page.read_with(&window, |p, _| {
|
|
(p.home_search_input.clone(), p.home_grid.clone())
|
|
});
|
|
window.update(|w, cx| {
|
|
page.update(cx, |p, cx| {
|
|
// Autre, on « Toutes les Saisons », with a filter and a search on the home.
|
|
p.set_tab(Tab::Statistics, w, cx);
|
|
p.pinned = Some("Autre".into());
|
|
p.season = SeasonScope::AllSeasons;
|
|
p.home_filter = StateFilter::Completed;
|
|
p.reload(w, cx);
|
|
});
|
|
input.update(cx, |input, cx| input.set_value("ah", w, cx));
|
|
});
|
|
page.read_with(&window, |p, _| {
|
|
assert_eq!(p.viewed().unwrap().puuid, "Autre");
|
|
assert_eq!(p.tab, Tab::Statistics);
|
|
});
|
|
draw(&mut window);
|
|
|
|
let frames = frames();
|
|
send(&page, &mut window, &frames[0]);
|
|
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
|
draw(&mut window);
|
|
page.read_with(&window, |p, _| {
|
|
// « Sélection », from « Statistiques »: the Challenge of the signed-in Account in the
|
|
// current Season, whatever « Statistiques » analyses.
|
|
assert_eq!(p.tab, Tab::ChampSelect);
|
|
assert_eq!(p.shown_tab, Tab::ChampSelect);
|
|
assert_eq!(p.season, SeasonScope::AllSeasons);
|
|
assert_eq!(p.viewed().unwrap().puuid, "Autre");
|
|
assert_eq!(p.displayed().unwrap().puuid, "Joueur");
|
|
assert_eq!(p.home_season.as_deref(), Some("Saison"));
|
|
assert_eq!(
|
|
p.champ_select_banner.season.as_ref(),
|
|
"SAISON · 1 / 9 validés"
|
|
);
|
|
assert_eq!(
|
|
p.champ_select_banner.title.text.as_ref(),
|
|
"Sélection des champions"
|
|
);
|
|
assert!(p.home_statistics().unwrap().challenge.is_some());
|
|
});
|
|
// The row is there; the grid, its filters and its search are on « Défi ».
|
|
assert!(window.debug_bounds("anvil-row").is_some());
|
|
assert!(window.debug_bounds("card-233").is_some());
|
|
assert!(window.debug_bounds("home-tools").is_none());
|
|
assert!(window.debug_bounds("card-103").is_none());
|
|
// Its banner is about the champ select only: no link to « Statistiques ».
|
|
assert!(window.debug_bounds("statistics-link").is_none());
|
|
|
|
// Bans and ally picks are the champ select's.
|
|
send(&page, &mut window, &with_bans_and_ally(&[16, 233], 233));
|
|
let cards = anvil_cards(&page, &mut window);
|
|
assert_eq!(reasons(&cards, 233), [Reason::Banned, Reason::TakenByAlly]);
|
|
|
|
leave(&page, &mut window);
|
|
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
|
draw(&mut window);
|
|
page.read_with(&window, |p, cx| {
|
|
// As before the champ select, with « Tous » and no search on the home.
|
|
assert_eq!(p.viewed().unwrap().puuid, "Autre");
|
|
assert_eq!(p.season, SeasonScope::AllSeasons);
|
|
assert_eq!(p.tab, Tab::Challenge);
|
|
assert_eq!(p.home_filter, StateFilter::All);
|
|
assert!(p.home_search_input.read(cx).value().is_empty());
|
|
assert_eq!(p.home_shown_count.as_ref(), "9");
|
|
assert_eq!(p.home_grid.read(cx).names().len(), 9);
|
|
assert_eq!(p.banner.title.text.as_ref(), "0 / 9 champions validés");
|
|
assert!(p.anvil_grid.read(cx).names().is_empty());
|
|
});
|
|
assert_eq!(
|
|
home_grid.read_with(&window, |grid, _| grid.names().len()),
|
|
9
|
|
);
|
|
assert!(window.debug_bounds("home-tools").is_some());
|
|
assert!(window.debug_bounds("card-103").is_some());
|
|
assert!(window.debug_bounds("anvil-row").is_none());
|
|
|
|
// Another champ select starts clean.
|
|
send(&page, &mut window, &frames[0]);
|
|
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
|
let cards = anvil_cards(&page, &mut window);
|
|
assert_eq!(reasons(&cards, 16), [Reason::Completed]);
|
|
assert_eq!(reasons(&cards, 233), []);
|
|
assert_eq!(ids(&cards), ANVIL_A_TO_Z);
|
|
}
|
|
|
|
#[gpui::test]
|
|
async fn an_unknown_or_empty_anvil_list_is_said_soberly(cx: &mut TestAppContext) {
|
|
cx.executor().allow_parking();
|
|
for (anvil, line) in [
|
|
(None, "Champions de l'Enclume non communiqués par le client"),
|
|
(
|
|
Some("[]"),
|
|
"Aucun Champion de l'Enclume dans cette sélection",
|
|
),
|
|
] {
|
|
let (page, mut window) = open_page_with_tracker(cx, joueur_tracker());
|
|
let session = capture()["sessions"][0].clone();
|
|
let pick = read_champ_select(
|
|
&ChampSelectReader::default(),
|
|
session,
|
|
anvil.map(str::to_string),
|
|
);
|
|
send(&page, &mut window, &pick);
|
|
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
|
draw(&mut window);
|
|
page.read_with(&window, |p, _| {
|
|
assert_eq!(p.anvil_line().as_deref(), Some(line))
|
|
});
|
|
// No row, and no champion is presented as without an anvil.
|
|
assert!(anvil_cards(&page, &mut window).is_empty());
|
|
assert_eq!(
|
|
window.debug_bounds("anvil-notice").is_some(),
|
|
anvil.is_some()
|
|
);
|
|
assert!(window.debug_bounds("anvil-row").is_none());
|
|
assert!(window.debug_bounds("card-103").is_none());
|
|
assert!(window.debug_bounds("card-16").is_none());
|
|
}
|
|
}
|
|
|
|
#[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.stats_notice(),
|
|
Some(crate::page::home::StatsNotice::NoSeason)
|
|
);
|
|
});
|
|
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());
|
|
}
|