Hovering the icon leaves the cached ring unrendered (asserted in the grid test). performance.md opens « Statistiques » by the chart icon, and interface.md no longer claims the icon leaves the text untouched in a narrow window. The chart icon comes from gpui_kit::assets::icon_assets!, so the vendored SVG and Lucide license are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
260 lines
9.5 KiB
Rust
260 lines
9.5 KiB
Rust
use super::banner_fixtures::ring_renders;
|
|
use super::page_fixtures::{
|
|
center, champions, count_hovers, draw, grid_names, open_page_in_season, settle, show,
|
|
statistics, switch_tab,
|
|
};
|
|
use crate::card::ASPECT;
|
|
use crate::champion_table::tests::row;
|
|
use crate::page::Tab;
|
|
use arena_tracker_core::{
|
|
Champion, ChampionChallenge, ChampionRow, ChampionState, Date, StateFilter,
|
|
};
|
|
use gpui_kit::{Modifiers, ScrollDelta, ScrollEvent, TestAppContext, VisualTestContext, point, px};
|
|
|
|
#[gpui::test]
|
|
fn the_grid_follows_the_alias_search_and_the_filters(cx: &mut TestAppContext) {
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
let champion = |id, key: &str, name: &str, state, matches, completed: bool| ChampionRow {
|
|
champion: Champion {
|
|
id,
|
|
key: key.into(),
|
|
name: name.into(),
|
|
},
|
|
state: Some(state),
|
|
matches,
|
|
challenge: Some(ChampionChallenge {
|
|
matches,
|
|
completed_on: completed.then_some(Date {
|
|
year: 2026,
|
|
month: 3,
|
|
day: 2,
|
|
}),
|
|
..Default::default()
|
|
}),
|
|
..row(name)
|
|
};
|
|
// As the statistics give them: A to Z, the accented name where French collation puts it.
|
|
show(
|
|
&page,
|
|
cx,
|
|
statistics(
|
|
1,
|
|
4,
|
|
vec![
|
|
champion(86, "Garen", "Garen", ChampionState::NeverPlayed, 0, false),
|
|
champion(107, "Rengar", "Rengar", ChampionState::InProgress, 5, false),
|
|
champion(
|
|
4,
|
|
"TwistedFate",
|
|
"Twisted Fate",
|
|
ChampionState::Completed,
|
|
3,
|
|
true,
|
|
),
|
|
champion(238, "Zed", "Éd", ChampionState::NeverPlayed, 0, false),
|
|
],
|
|
),
|
|
);
|
|
draw(cx);
|
|
let (input, grid) = page.read_with(cx, |p, _| {
|
|
(p.home_search_input.clone(), p.home_grid.clone())
|
|
});
|
|
let shown_count =
|
|
|cx: &mut VisualTestContext| page.read_with(cx, |p, _| p.home_shown_count.to_string());
|
|
// « Tous »: everything, never played and completed ones included, in the given order.
|
|
assert_eq!(
|
|
grid_names(&grid, cx),
|
|
["Garen", "Rengar", "Twisted Fate", "Éd"]
|
|
);
|
|
assert_eq!(shown_count(cx), "4");
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("no-champion").is_none());
|
|
|
|
cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
|
|
cx.simulate_input("TF");
|
|
assert_eq!(grid_names(&grid, cx), ["Twisted Fate"]);
|
|
assert_eq!(shown_count(cx), "1");
|
|
|
|
cx.update(|window, cx| input.update(cx, |input, cx| input.clean(window, cx)));
|
|
assert_eq!(grid_names(&grid, cx).len(), 4);
|
|
cx.simulate_input("ren");
|
|
page.update(cx, |p, cx| {
|
|
p.home_filter = StateFilter::Remaining;
|
|
p.refresh_home(cx);
|
|
});
|
|
assert_eq!(grid_names(&grid, cx), ["Garen", "Rengar"]);
|
|
|
|
// Nothing completed matches: the grid says so.
|
|
page.update(cx, |p, cx| {
|
|
p.home_filter = StateFilter::Completed;
|
|
p.refresh_home(cx);
|
|
});
|
|
assert!(grid_names(&grid, cx).is_empty());
|
|
assert_eq!(shown_count(cx), "0");
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("no-champion").is_some());
|
|
assert!(cx.debug_bounds("card-4").is_none());
|
|
|
|
// « Validés » alone brings the completed card back.
|
|
cx.update(|window, cx| input.update(cx, |input, cx| input.clean(window, cx)));
|
|
assert_eq!(grid_names(&grid, cx), ["Twisted Fate"]);
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("card-4").is_some());
|
|
assert!(cx.debug_bounds("no-champion").is_none());
|
|
}
|
|
|
|
#[gpui::test]
|
|
fn the_cards_keep_the_aspect_and_the_rows_their_pitch_and_a_card_without_a_portrait_renders(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
show(&page, cx, statistics(0, 30, champions(30)));
|
|
draw(cx);
|
|
let first = cx
|
|
.debug_bounds("card-1")
|
|
.expect("the first card is not drawn");
|
|
let second = cx.debug_bounds("card-2").unwrap();
|
|
let next_row = cx.debug_bounds("card-7").unwrap();
|
|
// 6 columns at 1280 px, as tall as the aspect says.
|
|
assert_eq!(first.origin.y, second.origin.y);
|
|
assert!(next_row.origin.x == first.origin.x);
|
|
let (width, height) = (first.size.width.as_f32(), first.size.height.as_f32());
|
|
assert!((height - width / ASPECT).abs() < 1., "{width} x {height}");
|
|
// The first-row measure sizes every row: the next one starts a card and a gap lower.
|
|
let step = (next_row.origin.y - first.origin.y).as_f32();
|
|
assert!(
|
|
(step - (height + 14.)).abs() < 1.,
|
|
"step {step}, card {height}"
|
|
);
|
|
assert!(
|
|
((second.origin.x - first.origin.x).as_f32() - width - 14.).abs() < 1.,
|
|
"gap between columns"
|
|
);
|
|
// None of these cards has a portrait.
|
|
page.read_with(cx, |page, cx| {
|
|
assert!(
|
|
page.home_grid
|
|
.read(cx)
|
|
.names()
|
|
.contains(&"Champion 001".into())
|
|
);
|
|
});
|
|
}
|
|
|
|
#[gpui::test]
|
|
fn only_the_visible_cards_are_built(cx: &mut TestAppContext) {
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
show(&page, cx, statistics(0, 170, champions(170)));
|
|
draw(cx);
|
|
let grid = page.read_with(cx, |page, _| page.home_grid.clone());
|
|
let built = grid.read_with(cx, |grid, _| grid.card_builds);
|
|
// A few rows of 6 under 860 px, the first measured again: far from the 170 cards.
|
|
assert!(built > 0);
|
|
assert!(built <= 8 * 6, "{built} cards built for 170");
|
|
}
|
|
|
|
// While « Statistiques » is shown the home is not: its cards wait for the next switch to it.
|
|
#[gpui::test]
|
|
fn the_home_cards_are_not_built_while_statistiques_is_shown(cx: &mut TestAppContext) {
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
show(&page, cx, statistics(0, 5, champions(5)));
|
|
draw(cx);
|
|
let grid = page.read_with(cx, |page, _| page.home_grid.clone());
|
|
let built = |cx: &mut VisualTestContext| grid.read_with(cx, |grid, _| grid.set_cards_calls);
|
|
let calls = built(cx);
|
|
assert!(calls > 0);
|
|
|
|
switch_tab(&page, cx, Tab::Statistics);
|
|
show(&page, cx, statistics(0, 8, champions(8)));
|
|
assert_eq!(built(cx), calls, "the cards were built while hidden");
|
|
assert!(page.read_with(cx, |page, _| page.home_cards_stale));
|
|
|
|
switch_tab(&page, cx, Tab::Challenge);
|
|
assert_eq!(built(cx), calls + 1);
|
|
assert!(!page.read_with(cx, |page, _| page.home_cards_stale));
|
|
assert_eq!(grid_names(&grid, cx).len(), 8);
|
|
// Nothing changed meanwhile: coming back builds nothing more.
|
|
switch_tab(&page, cx, Tab::Statistics);
|
|
switch_tab(&page, cx, Tab::Challenge);
|
|
assert_eq!(built(cx), calls + 1);
|
|
}
|
|
|
|
// Hovering outside the grid draws the page again, not the cards: the grid is a cached view
|
|
// (rule #1), like the charts row.
|
|
#[gpui::test]
|
|
fn hovering_outside_the_grid_does_not_render_the_cards(cx: &mut TestAppContext) {
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
show(&page, cx, statistics(0, 170, champions(170)));
|
|
draw(cx);
|
|
let grid = page.read_with(cx, |page, _| page.home_grid.clone());
|
|
let renders = grid.read_with(cx, |grid, _| grid.renders);
|
|
assert!(renders > 0);
|
|
let ring = ring_renders(&page, cx);
|
|
|
|
// A navigation button's hover style redraws the window (the icon from where no tick is lit).
|
|
for _ in 0..2 {
|
|
let button = center(cx, "statistics-link");
|
|
cx.simulate_mouse_move(button, None, Modifiers::none());
|
|
draw(cx);
|
|
cx.simulate_mouse_move(point(px(5.), px(5.)), None, Modifiers::none());
|
|
draw(cx);
|
|
}
|
|
assert_eq!(grid.read_with(cx, |grid, _| grid.renders), renders);
|
|
assert_eq!(ring_renders(&page, cx), ring);
|
|
|
|
// The count does move when the grid changes.
|
|
grid.update(cx, |_, cx| cx.notify());
|
|
draw(cx);
|
|
assert_eq!(grid.read_with(cx, |grid, _| grid.renders), renders + 1);
|
|
}
|
|
|
|
// Hovering a card draws it lifted over the grid, which is not drawn again; scrolling the grid
|
|
// draws it again. Neither computes the statistics again nor builds the cards again.
|
|
#[gpui::test]
|
|
fn scrolling_or_hovering_the_grid_does_not_recompute_the_statistics(cx: &mut TestAppContext) {
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
show(&page, cx, statistics(0, 170, champions(170)));
|
|
draw(cx);
|
|
let grid = page.read_with(cx, |page, _| page.home_grid.clone());
|
|
let generation = page.read_with(cx, |page, _| page.stats_generation);
|
|
let set_cards = grid.read_with(cx, |grid, _| grid.set_cards_calls);
|
|
let renders = grid.read_with(cx, |grid, _| grid.renders);
|
|
assert!(set_cards > 0);
|
|
|
|
let hovers = count_hovers(&grid, cx);
|
|
for id in ["card-1", "card-2"] {
|
|
let card = center(cx, id);
|
|
cx.simulate_mouse_move(card, None, Modifiers::none());
|
|
draw(cx);
|
|
}
|
|
settle(cx);
|
|
assert!(hovers.get() > 0, "no card was hovered");
|
|
assert_eq!(grid.read_with(cx, |grid, _| grid.renders), renders);
|
|
|
|
let over = center(cx, "card-1");
|
|
cx.simulate_event(ScrollEvent {
|
|
position: over,
|
|
delta: ScrollDelta::Pixels(point(px(0.), px(-400.))),
|
|
..Default::default()
|
|
});
|
|
draw(cx);
|
|
assert!(grid.read_with(cx, |grid, _| grid.scrolled()) > px(0.));
|
|
|
|
assert_eq!(
|
|
grid.read_with(cx, |grid, _| grid.set_cards_calls),
|
|
set_cards,
|
|
"the cards were built again"
|
|
);
|
|
assert_eq!(
|
|
page.read_with(cx, |page, _| page.stats_generation),
|
|
generation
|
|
);
|
|
assert!(!page.read_with(cx, |page, _| page.stats_job.running()));
|
|
}
|