Show the champion's sheet on hover and keyboard focus (#73)

The sheet covers the card with the Season's Matches, Wins, best Placement
and Attempts, and the date of the first top 1 for a Completed champion. Its
lines are prepared in Card::from_row; only the shown cards build it. The
grid keeps the hovered card and one focus handle per card id, and handles
Tab and Shift-Tab itself, scrolling the next card's row into view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-20 21:30:50 +01:00
1 parent bd9f1c7c98
commit 796fae11b7
5 files changed
+520 -8

No files matched your search

+200
View File
@@ -1166,6 +1166,7 @@ mod tests {
tracker: Tracker,
) -> (Entity<Page>, VisualTestContext) {
cx.update(gpui_kit::init);
cx.update(crate::card_grid::init);
let tracker = Arc::new(tracker);
let (window, page) = cx.update(|cx| {
let (tx, rx) = unbounded();
@@ -1957,6 +1958,205 @@ mod tests {
cx.debug_bounds(id).unwrap().center()
}
/// `champions`, the first one Completed (first top 1 on 2 March 2026) and the second one
/// remaining with a 2nd place.
fn sheet_champions(count: u32) -> Vec<ChampionRow> {
let mut rows = champions(count);
rows[0].state = Some(ChampionState::Completed);
rows[0].attempts = Some(3);
rows[0].challenge = Some(ChampionChallenge {
matches: 4,
wins: 2,
best_placement: Some(1),
completed_on: Some(Date {
year: 2026,
month: 3,
day: 2,
}),
});
rows[1].state = Some(ChampionState::InProgress);
rows[1].attempts = Some(2);
rows[1].challenge = Some(ChampionChallenge {
matches: 2,
wins: 1,
best_placement: Some(2),
completed_on: None,
});
rows
}
const DATE: &str = "Premier top 1";
/// Whether the card's sheet was built in the last draw, and then whether it has the date.
fn sheet(cx: &mut VisualTestContext, id: u32) -> Option<bool> {
cx.debug_bounds(Box::leak(format!("sheet-{id}").into_boxed_str()))?;
Some(
cx.debug_bounds(Box::leak(format!("sheet-{id}-{DATE}").into_boxed_str()))
.is_some(),
)
}
fn sheet_ids(cx: &mut VisualTestContext, count: u32) -> Vec<u32> {
(1..=count).filter(|&id| sheet(cx, id).is_some()).collect()
}
#[gpui::test]
fn the_sheet_shows_on_hover_with_the_date_of_a_completed_champion_only(
cx: &mut TestAppContext,
) {
let (page, cx) = open_page_in_season(cx);
let cx = &mut { cx };
show(&page, cx, statistics(1, 12, sheet_champions(12)));
draw(cx);
assert!(sheet_ids(cx, 12).is_empty(), "a sheet is built at rest");
let completed = center(cx, "card-1");
cx.simulate_mouse_move(completed, None, Modifiers::none());
draw(cx);
assert_eq!(sheet_ids(cx, 12), [1]);
assert_eq!(sheet(cx, 1), Some(true));
let remaining = center(cx, "card-2");
cx.simulate_mouse_move(remaining, None, Modifiers::none());
draw(cx);
assert_eq!(sheet_ids(cx, 12), [2]);
assert_eq!(sheet(cx, 2), Some(false));
cx.simulate_mouse_move(point(px(5.), px(5.)), None, Modifiers::none());
draw(cx);
assert!(
sheet_ids(cx, 12).is_empty(),
"the sheet stays after the pointer left"
);
}
fn press(cx: &mut VisualTestContext, keys: &str) {
cx.simulate_keystrokes(keys);
draw(cx);
}
#[gpui::test]
fn the_sheet_shows_on_keyboard_focus_and_follows_tab(cx: &mut TestAppContext) {
let (page, cx) = open_page_in_season(cx);
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)));
draw(cx);
assert!(sheet_ids(cx, 40).is_empty());
// From the search field, 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));
// The next card: the previous sheet goes, the remaining champion has no date.
press(cx, "tab");
assert_eq!(sheet_ids(cx, 40), [2]);
assert_eq!(sheet(cx, 2), Some(false));
press(cx, "tab");
assert_eq!(sheet_ids(cx, 40), [3]);
// Shift-Tab goes back.
press(cx, "shift-tab");
press(cx, "shift-tab");
assert_eq!(sheet_ids(cx, 40), [1]);
assert_eq!(sheet(cx, 1), Some(true));
}
#[gpui::test]
fn tab_scrolls_the_row_of_the_next_card_into_view(cx: &mut TestAppContext) {
let (page, cx) = open_page_in_season(cx);
let cx = &mut { cx };
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)));
draw(cx);
assert!(
cx.debug_bounds("card-25").is_none(),
"card 25 is already built"
);
assert_eq!(grid.read_with(cx, |grid, _| grid.scrolled()), px(0.));
// Rows of 6: the 25th card opens the 5th row, below what 860 px shows.
for _ in 0..25 {
press(cx, "tab");
}
assert_eq!(sheet_ids(cx, 170), [25]);
assert!(grid.read_with(cx, |grid, _| grid.scrolled()) > px(0.));
let bounds = cx.debug_bounds("card-25").expect("the row was not built");
assert!(bounds.bottom() <= px(860.), "{bounds:?}");
// Back across the row boundary, upwards.
for _ in 0..6 {
press(cx, "shift-tab");
}
assert_eq!(sheet_ids(cx, 170), [19]);
let bounds = cx.debug_bounds("card-19").expect("the row was not built");
assert!(bounds.origin.y >= px(0.), "{bounds:?}");
}
#[gpui::test]
fn tab_leaves_the_grid_after_its_last_card(cx: &mut TestAppContext) {
let (page, cx) = open_page_in_season(cx);
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)));
for _ in 0..3 {
press(cx, "tab");
}
assert_eq!(sheet_ids(cx, 3), [3]);
press(cx, "tab");
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.
#[gpui::test]
fn showing_a_sheet_does_not_rebuild_the_cards_nor_recompute_the_statistics(
cx: &mut TestAppContext,
) {
let (page, cx) = open_page_in_season(cx);
let cx = &mut { cx };
show(&page, cx, statistics(1, 170, sheet_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);
for id in ["card-1", "card-2", "card-1"] {
let card = center(cx, id);
cx.simulate_mouse_move(card, None, Modifiers::none());
draw(cx);
}
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)));
for _ in 0..10 {
press(cx, "tab");
}
assert!(grid.read_with(cx, |grid, _| grid.renders) > hovered_renders);
// The key presses ended the pointer's hover: the focused card alone shows its sheet.
assert_eq!(sheet_ids(cx, 170), [10]);
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()));
}
#[gpui::test]
fn the_navigation_switches_tabs_with_the_mouse(cx: &mut TestAppContext) {
let (page, cx) = open_page(cx);