Keep a whole row in "Autres champions" and tidy the cards code (#75)
- "Autres champions" grid is never shorter than one card row. - A Format change keeps the home's statistics (#71); the home cards are built when "Defi" is shown again; hidden grids give back their decoded portraits; the card holds its portrait as Arc<Path>. - Unavailability becomes Unpickable (glossary), "selection" becomes "champ select" in comments (#74); the statistics error is shown by the banner only during a champ select. - Column breakpoints follow the mockup's max-width rules, the home tools row is search, filters, sort; stale comments fixed. - Tests: whole row, hidden grids, stats scopes, error shown once, and the capture's reasons end to end in the open section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2cd8b2c545
commit
4612d89a3d
8 files changed
+535
-159
No files matched your search
+388
-72
@@ -1,5 +1,6 @@
|
||||
//! The page and its two tabs: the shared state, the header row with its navigation, the banners and
|
||||
//! the champ select view. `home` and `statistics` render what is under the banners.
|
||||
//! The page and its two tabs: the shared state, the header row with its navigation and the
|
||||
//! banners. `home` (which also holds the champ select's sections) and `statistics` render what
|
||||
//! is under the banners.
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
@@ -172,6 +173,9 @@ pub struct Page {
|
||||
/// Only for a `home_scope`.
|
||||
home_stats: Option<Statistics>,
|
||||
home_error: Option<String>,
|
||||
/// The Account and scope `home_stats` or `home_error` were computed for: the home does not
|
||||
/// depend on the Format, so a change of Format keeps them.
|
||||
home_computed: Option<(String, Scope)>,
|
||||
/// « N / total », prepared when the statistics change.
|
||||
home_count: SharedString,
|
||||
/// Completed over total, for the progress line.
|
||||
@@ -200,6 +204,8 @@ pub struct Page {
|
||||
table: Entity<ChampionTable>,
|
||||
/// The home's champions, one card each.
|
||||
home_grid: Entity<CardGrid>,
|
||||
/// The home's cards were not rebuilt for the latest statistics, as the home was not shown.
|
||||
home_cards_stale: bool,
|
||||
/// How many cards the grid shows, prepared when the filter or search change.
|
||||
home_shown_count: SharedString,
|
||||
/// The Anvil champions of the champ select, one card each in the home grid's order, with
|
||||
@@ -207,9 +213,9 @@ pub struct Page {
|
||||
anvil_grid: Entity<CardGrid>,
|
||||
/// How many Anvil champions the row shows, prepared with the cards.
|
||||
anvil_count: SharedString,
|
||||
/// « Autres champions »: folded at each new selection. While it is, it holds no card.
|
||||
/// « Autres champions »: folded at each new champ select. While it is, it holds no card.
|
||||
others_open: bool,
|
||||
/// Filters this section only; emptied with each new selection.
|
||||
/// Filters this section only; emptied with each new champ select.
|
||||
others_search: ChampionSearch,
|
||||
others_search_input: Entity<InputState>,
|
||||
/// The champions without an Anvil (all of them when the list is unknown), only built while
|
||||
@@ -400,6 +406,7 @@ impl Page {
|
||||
home_scope: None,
|
||||
home_stats: None,
|
||||
home_error: None,
|
||||
home_computed: None,
|
||||
home_count: SharedString::default(),
|
||||
home_fraction: 0.,
|
||||
home_filter: StateFilter::All,
|
||||
@@ -419,6 +426,7 @@ impl Page {
|
||||
charts,
|
||||
table,
|
||||
home_grid,
|
||||
home_cards_stale: false,
|
||||
home_shown_count: SharedString::default(),
|
||||
anvil_grid,
|
||||
anvil_count: SharedString::default(),
|
||||
@@ -519,15 +527,24 @@ impl Page {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_tab(&mut self, tab: Tab, cx: &mut Context<Self>) {
|
||||
// The selection takes the window: the Statistics tab waits for its end.
|
||||
fn set_tab(&mut self, tab: Tab, window: &mut Window, cx: &mut Context<Self>) {
|
||||
// The champ select takes the window: the Statistics tab waits for its end.
|
||||
if tab == Tab::Statistics && self.in_champ_select() {
|
||||
return;
|
||||
}
|
||||
if self.tab != tab {
|
||||
self.tab = tab;
|
||||
if tab == Tab::Statistics {
|
||||
// The home grid is not shown: its portraits are given back, and come back
|
||||
// with the grid.
|
||||
self.home_grid
|
||||
.update(cx, |grid, cx| grid.release_images(window, cx));
|
||||
}
|
||||
// The tab left was not kept up to date.
|
||||
self.refresh_table(cx);
|
||||
if self.home_cards_stale {
|
||||
self.prepare_home_cards(cx);
|
||||
}
|
||||
self.refresh_home(cx);
|
||||
cx.notify();
|
||||
}
|
||||
@@ -553,10 +570,15 @@ impl Page {
|
||||
self.champ_select = champ_select;
|
||||
if changed_page {
|
||||
if self.in_champ_select() {
|
||||
// The selection is about the Challenge, whatever tab was open.
|
||||
// The champ select is about the Challenge, whatever tab was open.
|
||||
self.tab = Tab::Challenge;
|
||||
// The home grid gives way to the champ select's sections.
|
||||
self.home_grid
|
||||
.update(cx, |grid, cx| grid.release_images(window, cx));
|
||||
} else {
|
||||
self.reset_home_view(window, cx);
|
||||
self.anvil_grid
|
||||
.update(cx, |grid, cx| grid.release_images(window, cx));
|
||||
}
|
||||
}
|
||||
if switch {
|
||||
@@ -566,11 +588,10 @@ impl Page {
|
||||
self.stats_generation += 1;
|
||||
self.stats = None;
|
||||
self.stats_error = None;
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.forget_home();
|
||||
self.stored = None;
|
||||
self.reorder();
|
||||
// A new selection starts with « Autres champions » folded and searchless.
|
||||
// A new champ select starts with « Autres champions » folded and searchless.
|
||||
self.fold_others(window, cx);
|
||||
self.reload_in_background(window, cx);
|
||||
}
|
||||
@@ -714,7 +735,7 @@ impl Page {
|
||||
self.stats_generation += 1;
|
||||
}
|
||||
// The home is the champ select's: its Challenge is the current Season's, which is
|
||||
// the Statistics scope for the whole selection.
|
||||
// the Statistics scope for the whole champ select.
|
||||
self.home_scope = None;
|
||||
self.current_season = self.tracker.current_season(now_ms()).map(|s| s.name);
|
||||
self.home_season = self.current_season.clone().map(Into::into);
|
||||
@@ -759,8 +780,11 @@ impl Page {
|
||||
self.home_scope = home.filter(|home| *home != self.statistics_scope());
|
||||
}
|
||||
|
||||
/// Keeps what the job computed for the home's own scope, if it had one.
|
||||
/// Keeps what was computed for the home's own scope, if it had one, and for which Account.
|
||||
fn set_home_result(&mut self, home: Option<Box<Result<Statistics, String>>>) {
|
||||
self.home_computed = home
|
||||
.as_ref()
|
||||
.and_then(|_| self.shown.clone().zip(self.home_scope.clone()));
|
||||
(self.home_stats, self.home_error) = match home.map(|result| *result) {
|
||||
Some(Ok(stats)) => (Some(stats), None),
|
||||
Some(Err(error)) => (None, Some(error)),
|
||||
@@ -768,6 +792,22 @@ impl Page {
|
||||
};
|
||||
}
|
||||
|
||||
fn forget_home(&mut self) {
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.home_computed = None;
|
||||
}
|
||||
|
||||
/// Whether the home's own statistics were computed for the Account and scope it has now.
|
||||
fn home_is_current(&self) -> bool {
|
||||
match (&self.shown, &self.home_scope, &self.home_computed) {
|
||||
(Some(puuid), Some(scope), Some((computed_puuid, computed_scope))) => {
|
||||
puuid == computed_puuid && scope == computed_scope
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The Account of the live champ select. Resolved when the signed-in Riot ID changes (or the
|
||||
/// Accounts do), so preparing statistics builds no Riot ID per Account every time.
|
||||
fn champ_select_account(&mut self) -> Option<String> {
|
||||
@@ -826,30 +866,35 @@ impl Page {
|
||||
}
|
||||
self.stats = None;
|
||||
self.stats_error = None;
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.forget_home();
|
||||
self.stored = None;
|
||||
self.show_statistics(window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
/// Recomputes the statistics for the current scope; never called while rendering.
|
||||
/// Recomputes the statistics for the current scope; never called while rendering. The home's
|
||||
/// own statistics are kept when they were computed for the same Account and scope (a change
|
||||
/// of Format leaves them as they are).
|
||||
fn recompute(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let viewed = self.prepare_statistics(true, window, cx);
|
||||
self.stats = None;
|
||||
self.stats_error = None;
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.stored = None;
|
||||
let keep_home = viewed.is_some() && self.home_is_current();
|
||||
if !keep_home {
|
||||
self.forget_home();
|
||||
}
|
||||
if let Some(puuid) = &viewed {
|
||||
let scope = self.statistics_scope();
|
||||
match compute_statistics(&self.tracker, puuid, &scope) {
|
||||
Ok(stats) => self.stats = Some(stats),
|
||||
Err(error) => self.stats_error = Some(error),
|
||||
}
|
||||
let home = (self.home_scope.clone())
|
||||
.map(|home| Box::new(compute_statistics(&self.tracker, puuid, &home)));
|
||||
self.set_home_result(home);
|
||||
if !keep_home {
|
||||
let home = (self.home_scope.clone())
|
||||
.map(|home| Box::new(compute_statistics(&self.tracker, puuid, &home)));
|
||||
self.set_home_result(home);
|
||||
}
|
||||
self.stored = self.tracker.match_count(puuid).ok();
|
||||
}
|
||||
self.show_statistics(window, cx);
|
||||
@@ -859,7 +904,7 @@ impl Page {
|
||||
fn show_statistics(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.reorder();
|
||||
if self.in_champ_select() {
|
||||
// Neither the charts, the table nor the home grid are shown during a selection.
|
||||
// Neither the charts, the table nor the home grid are shown during a champ select.
|
||||
self.prepare_home_labels();
|
||||
self.prepare_champ_select(cx);
|
||||
cx.notify();
|
||||
@@ -899,7 +944,7 @@ impl Page {
|
||||
}
|
||||
|
||||
/// Computes the cards' order again: for when the home statistics (the champ select's during
|
||||
/// a selection) or the sort change, and for nothing else.
|
||||
/// a champ select) or the sort change, and for nothing else.
|
||||
fn reorder(&mut self) {
|
||||
let sort = self.champion_sort.unwrap_or(ChampionSort::Mastery);
|
||||
let rows = self
|
||||
@@ -939,7 +984,13 @@ impl Page {
|
||||
}
|
||||
|
||||
/// One card per champion, in the cards' order, for when the statistics or the sort change.
|
||||
/// While the home is not shown the next switch to it does (`home_cards_stale`).
|
||||
fn prepare_home_cards(&mut self, cx: &mut Context<Self>) {
|
||||
if self.tab != Tab::Challenge {
|
||||
self.home_cards_stale = true;
|
||||
return;
|
||||
}
|
||||
self.home_cards_stale = false;
|
||||
let cards: Rc<[Card]> = self.ordered_rows().map(Card::from_row).collect();
|
||||
self.home_grid
|
||||
.update(cx, |grid, cx| grid.set_cards(cards, cx));
|
||||
@@ -973,8 +1024,7 @@ impl Page {
|
||||
self.ordered_rows()
|
||||
.filter(|row| anvil.contains(&row.champion.id))
|
||||
.map(|row| {
|
||||
Card::from_row(row)
|
||||
.with_unavailability(pick.unavailability(row.champion.id))
|
||||
Card::from_row(row).with_unpickable(pick.unpickable(row.champion.id))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -1008,9 +1058,7 @@ impl Page {
|
||||
let cards: Rc<[Card]> = match self.live_champ_select() {
|
||||
Some(pick) => self
|
||||
.other_rows()
|
||||
.map(|row| {
|
||||
Card::from_row(row).with_unavailability(pick.unavailability(row.champion.id))
|
||||
})
|
||||
.map(|row| Card::from_row(row).with_unpickable(pick.unpickable(row.champion.id)))
|
||||
.collect(),
|
||||
None => Rc::new([]),
|
||||
};
|
||||
@@ -1046,7 +1094,7 @@ impl Page {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Folds « Autres champions » and empties its search, for a new selection.
|
||||
/// Folds « Autres champions » and empties its search, for a new champ select.
|
||||
fn fold_others(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if self.others_open {
|
||||
self.others_open = false;
|
||||
@@ -1124,7 +1172,7 @@ impl Page {
|
||||
.flex_shrink_0()
|
||||
.children(tabs.map(|(id, label, tab)| {
|
||||
let current = self.tab == tab;
|
||||
// The selection takes the window: « Statistiques » waits for its end.
|
||||
// The champ select takes the window: « Statistiques » waits for its end.
|
||||
let disabled = tab == Tab::Statistics && self.in_champ_select();
|
||||
BaseButton::new(id)
|
||||
.disabled(disabled)
|
||||
@@ -1146,7 +1194,7 @@ impl Page {
|
||||
.accessibility_label(label)
|
||||
.debug_selector(|| id.into())
|
||||
.child(label)
|
||||
.on_click(cx.listener(move |this, _, _, cx| this.set_tab(tab, cx)))
|
||||
.on_click(cx.listener(move |this, _, window, cx| this.set_tab(tab, window, cx)))
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1195,7 +1243,7 @@ impl Page {
|
||||
}
|
||||
|
||||
impl Render for Page {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let muted = cx.theme().muted_foreground;
|
||||
let busy = self.busy();
|
||||
let status_line = sync_line(busy, self.progress, self.crashed, self.stored);
|
||||
@@ -1227,7 +1275,7 @@ impl Render for Page {
|
||||
Select::new(&self.account_select)
|
||||
.id("account")
|
||||
.placeholder("Aucun Compte")
|
||||
// The selection is about the signed-in Account.
|
||||
// The champ select is about the signed-in Account.
|
||||
.disabled(self.in_champ_select())
|
||||
.w(px(260.))
|
||||
.min_w(px(150.)),
|
||||
@@ -1259,7 +1307,7 @@ impl Render for Page {
|
||||
page.child(div().v_flex().gap_1().children(self.banners()))
|
||||
})
|
||||
.children(match self.tab {
|
||||
Tab::Challenge => self.home_content(cx),
|
||||
Tab::Challenge => self.home_content(window, cx),
|
||||
Tab::Statistics => self.statistics_content(cx),
|
||||
})
|
||||
}
|
||||
@@ -1279,16 +1327,20 @@ mod tests {
|
||||
};
|
||||
use gpui_kit::base::async_util::unbounded;
|
||||
use gpui_kit::{
|
||||
AppContext as _, Bounds, Entity, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers,
|
||||
ScrollDelta, ScrollEvent, TestAppContext, VisualTestContext, WindowBounds, WindowOptions,
|
||||
point, px, size,
|
||||
AppContext as _, Bounds, Entity, Focusable as _, KeyDownEvent, KeyUpEvent, Keystroke,
|
||||
Modifiers, ScrollDelta, ScrollEvent, TestAppContext, VisualTestContext, WindowBounds,
|
||||
WindowOptions, point, px, size,
|
||||
};
|
||||
|
||||
use super::{ChampionSortChosen, Page, SelectEvent, Tab};
|
||||
use crate::card::ASPECT;
|
||||
use crate::card_grid::CardGrid;
|
||||
use crate::card_grid::{CardGrid, row_height};
|
||||
use crate::champion_table::tests::row;
|
||||
|
||||
fn switch_tab(page: &Entity<Page>, cx: &mut VisualTestContext, tab: Tab) {
|
||||
cx.update(|window, cx| page.update(cx, |page, cx| page.set_tab(tab, window, cx)));
|
||||
}
|
||||
|
||||
fn open_page(cx: &mut TestAppContext) -> (Entity<Page>, VisualTestContext) {
|
||||
open_page_with_tracker(
|
||||
cx,
|
||||
@@ -1446,7 +1498,7 @@ mod tests {
|
||||
let pick = ChampSelect::new(Some(39), [39].into(), Some(vec![39]));
|
||||
window.update(|w, cx| {
|
||||
page.update(cx, |p, cx| {
|
||||
p.set_tab(Tab::Statistics, cx);
|
||||
p.set_tab(Tab::Statistics, w, cx);
|
||||
p.pinned = Some("Bob".into());
|
||||
p.season = SeasonScope::AllSeasons;
|
||||
p.filter = StateFilter::NeverPlayed;
|
||||
@@ -1457,7 +1509,7 @@ mod tests {
|
||||
});
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
page.read_with(cx, |p, cx| {
|
||||
// The selection takes the home, about the signed-in Account's current Season.
|
||||
// The champ select takes the home, about the signed-in Account's current Season.
|
||||
assert_eq!(p.tab, Tab::Challenge);
|
||||
assert_eq!(p.displayed().unwrap().puuid, "Alice");
|
||||
assert_eq!(p.home_season, p.current_season.clone().map(Into::into));
|
||||
@@ -1561,7 +1613,7 @@ mod tests {
|
||||
});
|
||||
});
|
||||
// The search field of the Statistics tab is only there on that tab.
|
||||
page.update(cx, |page, cx| page.set_tab(Tab::Statistics, cx));
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
let (input, table) = page.read_with(cx, |p, _| (p.search_input.clone(), p.table.clone()));
|
||||
let names = |cx: &mut VisualTestContext| table.read_with(cx, |table, _| table.names());
|
||||
@@ -1602,7 +1654,7 @@ mod tests {
|
||||
let (page, cx) = open_page(cx);
|
||||
let cx = &mut { cx };
|
||||
// The table hovered is the Statistics tab's: the app opens on the Challenge.
|
||||
page.update(cx, |page, cx| page.set_tab(Tab::Statistics, cx));
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
let (table, charts) =
|
||||
page.read_with(cx, |page, _| (page.table.clone(), page.charts.clone()));
|
||||
// Enough rows to fill the table, under the points hovered below.
|
||||
@@ -1859,7 +1911,7 @@ mod tests {
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
assert_eq!(charts.read_with(cx, |charts, _| charts.renders), 0);
|
||||
|
||||
page.update(cx, |page, cx| page.set_tab(Tab::Statistics, cx));
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
assert!(charts.read_with(cx, |charts, _| charts.renders) > 0);
|
||||
}
|
||||
@@ -1984,7 +2036,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_card_is_as_wide_as_the_mockups_and_a_card_without_a_portrait_renders(
|
||||
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);
|
||||
@@ -2035,6 +2087,33 @@ mod tests {
|
||||
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]
|
||||
@@ -2063,8 +2142,10 @@ mod tests {
|
||||
assert_eq!(grid.read_with(cx, |grid, _| grid.renders), renders + 1);
|
||||
}
|
||||
|
||||
// Hovering a card or scrolling the grid draws the grid, and nothing upstream: the cards are
|
||||
// not built again and no statistics are computed.
|
||||
// Hovering a card or scrolling the grid notifies the grid view, which GPUI draws again along
|
||||
// with its parent, the page (it is not a cached view). What the test proves is that this
|
||||
// costs no statistics and no cards: the statistics are not computed again and the cards are
|
||||
// not built 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);
|
||||
@@ -2209,6 +2290,16 @@ mod tests {
|
||||
assert!(sheet_ids(cx, 170).is_empty(), "the sheet stuck to its card");
|
||||
}
|
||||
|
||||
/// The focus on the sort selector, the last stop of the home's tools before the cards.
|
||||
fn focus_sort(page: &Entity<Page>, cx: &mut VisualTestContext) {
|
||||
let select = page.read_with(cx, |p, _| p.sort_select.clone());
|
||||
cx.update(|window, cx| {
|
||||
let handle = select.read(cx).focus_handle(cx);
|
||||
window.focus(&handle, cx)
|
||||
});
|
||||
draw(cx);
|
||||
}
|
||||
|
||||
fn press(cx: &mut VisualTestContext, keys: &str) {
|
||||
cx.simulate_keystrokes(keys);
|
||||
draw(cx);
|
||||
@@ -2220,12 +2311,11 @@ mod tests {
|
||||
let cx = &mut { cx };
|
||||
show(&page, cx, statistics(1, 40, sheet_champions(40)));
|
||||
draw(cx);
|
||||
let input = page.read_with(cx, |p, _| p.home_search_input.clone());
|
||||
cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
|
||||
focus_sort(&page, cx);
|
||||
draw(cx);
|
||||
assert!(sheet_ids(cx, 40).is_empty());
|
||||
|
||||
// From the search field, Tab reaches the first card, the Completed one.
|
||||
// From the sort selector, the last stop before the cards, Tab reaches the first card, the Completed one.
|
||||
press(cx, "tab");
|
||||
assert_eq!(sheet_ids(cx, 40), [1]);
|
||||
assert_eq!(sheet(cx, 1), Some(true));
|
||||
@@ -2249,8 +2339,7 @@ mod tests {
|
||||
show(&page, cx, statistics(1, 170, sheet_champions(170)));
|
||||
draw(cx);
|
||||
let grid = page.read_with(cx, |page, _| page.home_grid.clone());
|
||||
let input = page.read_with(cx, |p, _| p.home_search_input.clone());
|
||||
cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
|
||||
focus_sort(&page, cx);
|
||||
draw(cx);
|
||||
assert!(
|
||||
cx.debug_bounds("card-25").is_none(),
|
||||
@@ -2282,8 +2371,7 @@ mod tests {
|
||||
let cx = &mut { cx };
|
||||
show(&page, cx, statistics(1, 3, sheet_champions(3)));
|
||||
draw(cx);
|
||||
let input = page.read_with(cx, |p, _| p.home_search_input.clone());
|
||||
cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
|
||||
focus_sort(&page, cx);
|
||||
for _ in 0..3 {
|
||||
press(cx, "tab");
|
||||
}
|
||||
@@ -2292,8 +2380,8 @@ mod tests {
|
||||
assert!(sheet_ids(cx, 3).is_empty(), "the focus stayed in the grid");
|
||||
}
|
||||
|
||||
// Hovering or tabbing over the cards draws the grid and nothing upstream: the cards are not
|
||||
// built again and no statistics are computed.
|
||||
// Hovering or tabbing over the cards notifies the grid view (GPUI draws its parent page again
|
||||
// too): the cards are not built again and no statistics are computed.
|
||||
#[gpui::test]
|
||||
fn showing_a_sheet_does_not_rebuild_the_cards_nor_recompute_the_statistics(
|
||||
cx: &mut TestAppContext,
|
||||
@@ -2315,8 +2403,7 @@ mod tests {
|
||||
let hovered_renders = grid.read_with(cx, |grid, _| grid.renders);
|
||||
assert!(hovered_renders > renders, "the grid was not drawn");
|
||||
|
||||
let input = page.read_with(cx, |p, _| p.home_search_input.clone());
|
||||
cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
|
||||
focus_sort(&page, cx);
|
||||
for _ in 0..10 {
|
||||
press(cx, "tab");
|
||||
}
|
||||
@@ -2659,7 +2746,7 @@ mod tests {
|
||||
draw(&mut window);
|
||||
let first = bounds(&mut window);
|
||||
|
||||
// Never greyed by the selection: 233 and 16 are offered, the rest is not offered.
|
||||
// Never greyed by the champ select: 233 and 16 are offered, the rest is not offered.
|
||||
let baseline = [
|
||||
(233, vec![]),
|
||||
(64, vec![Reason::NotOffered]),
|
||||
@@ -2713,7 +2800,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_selection_takes_the_home_and_gives_it_back_as_it_was(cx: &mut TestAppContext) {
|
||||
async fn the_champ_select_takes_the_home_and_gives_it_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());
|
||||
@@ -2723,7 +2810,7 @@ mod tests {
|
||||
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, cx);
|
||||
p.set_tab(Tab::Statistics, w, cx);
|
||||
p.pinned = Some("Autre".into());
|
||||
p.season = SeasonScope::AllSeasons;
|
||||
p.home_filter = StateFilter::Completed;
|
||||
@@ -2758,13 +2845,13 @@ mod tests {
|
||||
assert!(window.debug_bounds("home-tools").is_none());
|
||||
assert!(window.debug_bounds("card-103").is_none());
|
||||
|
||||
// « Statistiques » is out of reach during the selection.
|
||||
// « Statistiques » is out of reach during the champ select.
|
||||
let statistics = center(&mut window, "tab-statistics");
|
||||
window.simulate_click(statistics, Modifiers::none());
|
||||
page.update(&mut window, |p, cx| p.set_tab(Tab::Statistics, cx));
|
||||
switch_tab(&page, &mut window, Tab::Statistics);
|
||||
assert_eq!(page.read_with(&window, |p, _| p.tab), Tab::Challenge);
|
||||
|
||||
// Bans and ally picks are the selection's.
|
||||
// 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]);
|
||||
@@ -2773,7 +2860,7 @@ mod tests {
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
draw(&mut window);
|
||||
page.read_with(&window, |p, cx| {
|
||||
// As before the selection, with « Tous » and no search on the home.
|
||||
// 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);
|
||||
@@ -2792,7 +2879,7 @@ mod tests {
|
||||
assert!(window.debug_bounds("card-103").is_some());
|
||||
assert!(window.debug_bounds("anvil-row").is_none());
|
||||
|
||||
// Another selection starts clean.
|
||||
// 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);
|
||||
@@ -3000,7 +3087,7 @@ mod tests {
|
||||
activate(&mut window, "enter");
|
||||
assert!(others_open(&page, &mut window));
|
||||
|
||||
// The lock-ins of the selection reach the open section, which keeps its place.
|
||||
// The lock-ins of the champ select reach the open section, which keeps its place.
|
||||
send(&page, &mut window, &with_bans_and_ally(&[103], 25));
|
||||
draw(&mut window);
|
||||
let cards = others_cards(&page, &mut window);
|
||||
@@ -3052,7 +3139,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn a_new_selection_folds_others_and_empties_its_search(cx: &mut TestAppContext) {
|
||||
async fn a_new_champ_select_folds_others_and_empties_its_search(cx: &mut TestAppContext) {
|
||||
let frames = frames();
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames[0]).await;
|
||||
let fresh = |window: &mut VisualTestContext| {
|
||||
@@ -3064,7 +3151,7 @@ mod tests {
|
||||
})
|
||||
};
|
||||
|
||||
// The frames of the same selection keep it open, with its search.
|
||||
// The frames of the same champ select keep it open, with its search.
|
||||
click_others(&mut window);
|
||||
search_others(&page, &mut window, "ahr");
|
||||
send(&page, &mut window, &frames[1]);
|
||||
@@ -3085,7 +3172,7 @@ mod tests {
|
||||
assert!(window.debug_bounds("others-toggle").is_some());
|
||||
assert!(window.debug_bounds("card-103").is_none());
|
||||
|
||||
// The selection of another Riot ID.
|
||||
// The champ select of another Riot ID.
|
||||
click_others(&mut window);
|
||||
search_others(&page, &mut window, "cow");
|
||||
let live = Some(("Autre#EUW".to_string(), frames[0].clone()));
|
||||
@@ -3228,7 +3315,7 @@ mod tests {
|
||||
let cards = grid.shown_cards().into_iter();
|
||||
cards
|
||||
.filter(|card| card.id == 103)
|
||||
.map(|card| card.portrait)
|
||||
.map(|card| card.portrait.map(|path| path.to_path_buf()))
|
||||
.next()
|
||||
};
|
||||
assert_eq!(grid.read_with(&window, |grid, _| ahri(grid)), Some(None));
|
||||
@@ -3325,6 +3412,238 @@ mod tests {
|
||||
assert_eq!(in_atlas(&mut window), 0);
|
||||
}
|
||||
|
||||
// A grid that is not shown gives its portraits back, on the GPU too, and loads them again
|
||||
// when it is shown.
|
||||
#[gpui::test]
|
||||
async fn a_grid_that_is_not_shown_gives_its_portraits_back(cx: &mut TestAppContext) {
|
||||
cx.executor().allow_parking();
|
||||
let dir = TestDir::new("hidden-portraits");
|
||||
let keys = [
|
||||
"Ahri", "Alistar", "Briar", "LeeSin", "Morgana", "Rumble", "Soraka", "Swain", "XinZhao",
|
||||
];
|
||||
let (page, mut window) =
|
||||
open_page_with_tracker(cx, tracker_with_portraits(dir.path(), &keys));
|
||||
let load = |window: &mut VisualTestContext| {
|
||||
draw(window);
|
||||
window.run_until_parked();
|
||||
draw(window);
|
||||
};
|
||||
let held = |grid: &Entity<CardGrid>, window: &mut VisualTestContext| {
|
||||
let images = grid.read_with(window, |grid, _| grid.images().cloned());
|
||||
let images = images.expect("the grid was never drawn");
|
||||
images.read_with(window, |images, _| images.held().len())
|
||||
};
|
||||
let home = page.read_with(&window, |p, _| p.home_grid.clone());
|
||||
load(&mut window);
|
||||
assert_eq!(held(&home, &mut window), keys.len());
|
||||
let images = home.read_with(&window, |grid, _| grid.images().cloned().unwrap());
|
||||
let loaded = images.read_with(&window, |i, _| i.loaded());
|
||||
assert_eq!(loaded.len(), keys.len());
|
||||
let in_atlas = |window: &mut VisualTestContext| {
|
||||
window.update(|w, _| {
|
||||
(loaded.iter())
|
||||
.filter(|image| w.has_image_atlas_entry(image))
|
||||
.count()
|
||||
})
|
||||
};
|
||||
assert_eq!(in_atlas(&mut window), keys.len());
|
||||
|
||||
// « Statistiques » shows no card.
|
||||
switch_tab(&page, &mut window, Tab::Statistics);
|
||||
draw(&mut window);
|
||||
assert_eq!(held(&home, &mut window), 0);
|
||||
assert!(images.read_with(&window, |i, _| i.loaded()).is_empty());
|
||||
assert_eq!(in_atlas(&mut window), 0);
|
||||
|
||||
// Back on « Défi » they load again.
|
||||
switch_tab(&page, &mut window, Tab::Challenge);
|
||||
load(&mut window);
|
||||
assert_eq!(held(&home, &mut window), keys.len());
|
||||
assert_eq!(
|
||||
images.read_with(&window, |i, _| i.loaded()).len(),
|
||||
keys.len()
|
||||
);
|
||||
|
||||
// A champ select takes the home's place with its own sections.
|
||||
send(&page, &mut window, &frames()[0]);
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
load(&mut window);
|
||||
assert_eq!(held(&home, &mut window), 0);
|
||||
let anvil = page.read_with(&window, |p, _| p.anvil_grid.clone());
|
||||
assert_eq!(held(&anvil, &mut window), ANVIL.len());
|
||||
|
||||
// And gives the Anvil row up when it ends.
|
||||
leave(&page, &mut window);
|
||||
assert_eq!(held(&anvil, &mut window), 0);
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
load(&mut window);
|
||||
assert_eq!(held(&home, &mut window), keys.len());
|
||||
assert_eq!(held(&anvil, &mut window), 0);
|
||||
}
|
||||
|
||||
// « Autres champions » is open in a column that also scrolls: its grid keeps at least a
|
||||
// whole row, not the sliver the Anvil row leaves it in a 860 px window.
|
||||
#[gpui::test]
|
||||
async fn the_open_others_grid_shows_a_whole_row(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
|
||||
click_others(&mut window);
|
||||
draw(&mut window);
|
||||
let list = window
|
||||
.debug_bounds("card-list")
|
||||
.expect("the open section's grid is not drawn");
|
||||
let row = row_height(px(1280.));
|
||||
assert!(
|
||||
list.size.height >= row,
|
||||
"{:?} tall for a row of {row:?}",
|
||||
list.size.height
|
||||
);
|
||||
assert!(window.debug_bounds("card-103").is_some());
|
||||
assert!(others_open(&page, &mut window));
|
||||
}
|
||||
|
||||
/// The statistics' error is the banner's alone during a champ select: the Anvil area does
|
||||
/// not repeat it, and nothing is left to browse.
|
||||
#[gpui::test]
|
||||
async fn a_statistics_error_is_said_once_during_a_champ_select(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
|
||||
let error = "Statistiques indisponibles : disque plein";
|
||||
window.update(|_, cx| {
|
||||
page.update(cx, |p, cx| {
|
||||
p.stats = None;
|
||||
p.stats_error = Some(error.into());
|
||||
p.prepare_champ_select(cx);
|
||||
cx.notify();
|
||||
})
|
||||
});
|
||||
draw(&mut window);
|
||||
page.read_with(&window, |p, _| {
|
||||
assert_eq!(p.champ_select_notice, error);
|
||||
assert_eq!(p.error().map(String::as_str), Some(error));
|
||||
});
|
||||
// The banner says it; the area says nothing and offers nothing to browse.
|
||||
assert!(window.debug_bounds("anvil-notice").is_none());
|
||||
assert!(window.debug_bounds("anvil-row").is_none());
|
||||
assert!(window.debug_bounds("others-toggle").is_none());
|
||||
assert!(window.debug_bounds("no-season").is_none());
|
||||
}
|
||||
|
||||
// The Season's statistics are computed once while the Format changes: it does not apply to
|
||||
// the home.
|
||||
#[gpui::test]
|
||||
async fn changing_the_format_recomputes_only_the_statistics_scope(cx: &mut TestAppContext) {
|
||||
use crate::worker::COMPUTED;
|
||||
use arena_tracker_core::Scope;
|
||||
let (page, mut window) = open_page_with_tracker(cx, joueur_tracker());
|
||||
let scope = |season: SeasonScope, format| Scope { season, format };
|
||||
let saison = || SeasonScope::Season("Saison".into());
|
||||
let computed = |window: &mut VisualTestContext, change: &dyn Fn(&mut Page)| {
|
||||
COMPUTED.with(|computed| computed.borrow_mut().clear());
|
||||
window.update(|w, cx| {
|
||||
page.update(cx, |p, cx| {
|
||||
change(p);
|
||||
p.recompute(w, cx)
|
||||
})
|
||||
});
|
||||
COMPUTED.with(|computed| computed.borrow().clone())
|
||||
};
|
||||
|
||||
// A Format: the statistics for it, and the home's, which were read from the former.
|
||||
let first = computed(&mut window, &|p| p.format = Some(Format::Arena3x6));
|
||||
assert_eq!(
|
||||
first,
|
||||
[
|
||||
scope(saison(), Some(Format::Arena3x6)),
|
||||
scope(saison(), None)
|
||||
]
|
||||
);
|
||||
// Another Format: the home's statistics are kept.
|
||||
let kept = page.read_with(&window, |p, _| p.home_stats.clone());
|
||||
let second = computed(&mut window, &|p| p.format = Some(Format::BraveryArena));
|
||||
assert_eq!(second, [scope(saison(), Some(Format::BraveryArena))]);
|
||||
page.read_with(&window, |p, _| {
|
||||
assert!(p.home_stats.is_some() && p.home_stats == kept);
|
||||
});
|
||||
// All the Seasons while the current one is the home's: same scope, kept.
|
||||
let third = computed(&mut window, &|p| p.season = SeasonScope::AllSeasons);
|
||||
assert_eq!(
|
||||
third,
|
||||
[scope(SeasonScope::AllSeasons, Some(Format::BraveryArena))]
|
||||
);
|
||||
// Back to « Tous les Formats » on the current Season: the statistics are the home's.
|
||||
let fourth = computed(&mut window, &|p| {
|
||||
p.season = saison();
|
||||
p.format = None;
|
||||
});
|
||||
assert_eq!(fourth, [scope(saison(), None)]);
|
||||
page.read_with(&window, |p, _| assert!(p.home_stats.is_none()));
|
||||
// A Format again: the home's statistics were the Statistics tab's, and are computed.
|
||||
let fifth = computed(&mut window, &|p| {
|
||||
p.format = Some(Format::Arena3x6);
|
||||
});
|
||||
assert_eq!(
|
||||
fifth,
|
||||
[
|
||||
scope(saison(), Some(Format::Arena3x6)),
|
||||
scope(saison(), None)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/// The reasons of the capture on the cards of « Autres champions », drawn end to end.
|
||||
#[gpui::test]
|
||||
async fn a_reason_appearing_on_a_card_of_others_is_drawn_without_moving_it(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let frames = frames();
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames[0]).await;
|
||||
click_others(&mut window);
|
||||
let name = |prefix: &str, id: u32, label: &str| -> &'static str {
|
||||
Box::leak(format!("{prefix}-{id}{label}").into_boxed_str())
|
||||
};
|
||||
let badge = |window: &mut VisualTestContext, id: u32, label: &str| {
|
||||
window
|
||||
.debug_bounds(name("reason", id, &format!("-{label}")))
|
||||
.is_some()
|
||||
};
|
||||
let places = |window: &mut VisualTestContext| {
|
||||
OTHERS_A_TO_Z.map(|id| {
|
||||
window
|
||||
.debug_bounds(name("card", id, ""))
|
||||
.expect("not drawn")
|
||||
})
|
||||
};
|
||||
let first = places(&mut window);
|
||||
for id in OTHERS_A_TO_Z {
|
||||
assert!(!badge(&mut window, id, "Banni"), "frame 0, {id}");
|
||||
}
|
||||
|
||||
// Frame 1: 12 is banned; 25 is only an ally's pre-pick, which leaves it as it is.
|
||||
send(&page, &mut window, &frames[1]);
|
||||
draw(&mut window);
|
||||
assert!(badge(&mut window, 12, "Banni"));
|
||||
assert!(!badge(&mut window, 25, "Pris par un allié"));
|
||||
assert!(!badge(&mut window, 25, "Banni"));
|
||||
assert!(!badge(&mut window, 50, "Banni"));
|
||||
assert_eq!(places(&mut window), first);
|
||||
|
||||
// Frame 2: 50 too.
|
||||
send(&page, &mut window, &frames[2]);
|
||||
draw(&mut window);
|
||||
assert!(badge(&mut window, 12, "Banni") && badge(&mut window, 50, "Banni"));
|
||||
assert!(!badge(&mut window, 25, "Pris par un allié"));
|
||||
assert_eq!(places(&mut window), first);
|
||||
|
||||
// Frame 3: the ally confirms 25.
|
||||
for frame in [&frames[3], &frames[4]] {
|
||||
send(&page, &mut window, frame);
|
||||
draw(&mut window);
|
||||
assert!(badge(&mut window, 25, "Pris par un allié"));
|
||||
assert!(badge(&mut window, 12, "Banni") && badge(&mut window, 50, "Banni"));
|
||||
assert!(!badge(&mut window, 103, "Banni"));
|
||||
assert_eq!(places(&mut window), first);
|
||||
}
|
||||
}
|
||||
|
||||
// The sort of the cards (#76).
|
||||
|
||||
/// A row with a name, an id and its Mastery Points.
|
||||
@@ -3577,9 +3896,6 @@ mod tests {
|
||||
// Entering a champ select: the Anvil row follows the sort, so does « Autres champions »,
|
||||
// and the selector stays.
|
||||
send(&page, &mut window, &frames()[0]);
|
||||
window.update(|w, cx| {
|
||||
page.update(cx, |p, cx| p.reload_in_background(w, cx));
|
||||
});
|
||||
cx.condition(&page, |p, _| {
|
||||
p.stats.as_ref().is_some_and(|s| s.rows.len() == 9)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user