gpui-component's Input frame tracks its own focus handle, apart from the editor's: a click off the text line focused the frame and typing went nowhere. One app-side wrapper focuses the field's state instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
282 lines
11 KiB
Rust
282 lines
11 KiB
Rust
use super::banner_fixtures::banner;
|
|
use super::champ_select_fixtures::joueur_tracker;
|
|
use super::page_fixtures::{
|
|
RefreshHistory, assert_home_says, champions, draw, grid_names, open_page, open_page_in_season,
|
|
open_page_with_tracker, season, show, statistics, switch_tab,
|
|
};
|
|
use crate::champion_table::tests::row;
|
|
use crate::page::{Page, Tab};
|
|
use arena_tracker_core::{ChampionRow, ChampionState, Format, SeasonScope, StateFilter, Tracker};
|
|
use gpui_kit::{TestAppContext, VisualTestContext};
|
|
use std::path::Path;
|
|
|
|
#[gpui::test]
|
|
fn the_app_opens_on_the_challenge_with_all_champions_selected(cx: &mut TestAppContext) {
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
page.read_with(cx, |page, _| {
|
|
assert_eq!(page.tab, Tab::Challenge);
|
|
assert_eq!(page.home_filter, StateFilter::All);
|
|
assert_eq!(crate::page::home::FILTERS[0].0, "Tous");
|
|
assert_eq!(page.home_season.as_deref(), Some("Saison"));
|
|
});
|
|
}
|
|
|
|
#[gpui::test]
|
|
fn without_a_current_season_the_home_has_no_challenge(cx: &mut TestAppContext) {
|
|
let (page, cx) = open_page(cx);
|
|
let cx = &mut { cx };
|
|
show(&page, cx, statistics(1, 3, vec![row("Ahri")]));
|
|
cx.update(|window, cx| window.draw(cx).clear(cx));
|
|
page.read_with(cx, |page, cx| {
|
|
// « Toutes les Saisons », and no current Season to stand in.
|
|
assert_eq!(page.season, SeasonScope::AllSeasons);
|
|
assert_eq!(page.home_season, None);
|
|
assert!(page.home_statistics().is_none());
|
|
assert!(page.banner.title.text.is_empty());
|
|
assert!(page.home_grid.read(cx).names().is_empty());
|
|
});
|
|
}
|
|
|
|
#[gpui::test]
|
|
fn the_home_says_why_it_has_no_cards_until_the_statistics_arrive(cx: &mut TestAppContext) {
|
|
use crate::page::home::StatsNotice;
|
|
// A Season but no Account at all.
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
page.read_with(cx, |p, _| {
|
|
assert_eq!(p.stats_notice(), Some(StatsNotice::NoAccount));
|
|
assert_eq!(
|
|
p.anvil_line().as_deref(),
|
|
Some("Compte indisponible"),
|
|
"the champ select says it the same way"
|
|
);
|
|
});
|
|
assert_home_says(cx, StatsNotice::NoAccount);
|
|
|
|
// The statistics arrive: the heading and the grid show, and the notice goes.
|
|
show(&page, cx, statistics(0, 3, champions(3)));
|
|
draw(cx);
|
|
page.read_with(cx, |p, _| assert_eq!(p.stats_notice(), None));
|
|
assert!(cx.debug_bounds("home-notice").is_none());
|
|
assert!(cx.debug_bounds("home-tools").is_some());
|
|
assert!(cx.debug_bounds("card-1").is_some());
|
|
assert!(cx.debug_bounds("no-champion").is_none());
|
|
}
|
|
|
|
#[gpui::test]
|
|
async fn the_home_says_the_statistics_are_loading(cx: &mut TestAppContext) {
|
|
use crate::page::home::StatsNotice;
|
|
cx.executor().allow_parking();
|
|
let (page, mut window) = open_page_with_tracker(cx, joueur_tracker());
|
|
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
|
// The job of an Account is running: nothing is there yet.
|
|
window.update(|_, cx| {
|
|
page.update(cx, |p, cx| {
|
|
p.stats = None;
|
|
p.stats_error = None;
|
|
p.prepare_home_cards(cx);
|
|
cx.notify();
|
|
})
|
|
});
|
|
page.read_with(&window, |p, _| {
|
|
assert!(p.home_season.is_some());
|
|
assert_eq!(p.stats_notice(), Some(StatsNotice::Loading));
|
|
assert_eq!(
|
|
p.stats_notice().map(|n| n.label(None)).as_deref(),
|
|
Some("Chargement des statistiques…")
|
|
);
|
|
});
|
|
assert_home_says(&mut window, StatsNotice::Loading);
|
|
|
|
// Its error is the banner's alone.
|
|
window.update(|_, cx| {
|
|
page.update(cx, |p, cx| {
|
|
p.stats_error = Some("Statistiques indisponibles : disque plein".into());
|
|
cx.notify();
|
|
})
|
|
});
|
|
page.read_with(&window, |p, _| {
|
|
assert_eq!(p.stats_notice(), Some(StatsNotice::Error));
|
|
});
|
|
assert_home_says(&mut window, StatsNotice::Error);
|
|
}
|
|
|
|
#[gpui::test]
|
|
fn the_counter_keeps_its_total_while_a_search_and_a_filter_reduce_the_list(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
let champion = |name: &str, state| ChampionRow {
|
|
state: Some(state),
|
|
..row(name)
|
|
};
|
|
show(
|
|
&page,
|
|
cx,
|
|
statistics(
|
|
1,
|
|
4,
|
|
vec![
|
|
champion("Ahri", ChampionState::Completed),
|
|
champion("Annie", ChampionState::InProgress),
|
|
champion("Akali", ChampionState::NeverPlayed),
|
|
champion("Zed", ChampionState::NeverPlayed),
|
|
],
|
|
),
|
|
);
|
|
cx.update(|window, cx| window.draw(cx).clear(cx));
|
|
let (input, grid) = page.read_with(cx, |p, _| {
|
|
(p.home_search_input.clone(), p.home_grid.clone())
|
|
});
|
|
let names = |cx: &mut VisualTestContext| {
|
|
let mut names = grid_names(&grid, cx);
|
|
names.sort();
|
|
names
|
|
};
|
|
let counter =
|
|
|cx: &mut VisualTestContext| page.read_with(cx, |p, _| p.banner.title.text.to_string());
|
|
assert_eq!(names(cx), ["Ahri", "Akali", "Annie", "Zed"]);
|
|
assert_eq!(counter(cx), "1 / 4 champions validés");
|
|
|
|
// The home's search is its own: the Statistics tab's is untouched.
|
|
cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
|
|
cx.simulate_input("an");
|
|
assert_eq!(names(cx), ["Annie"]);
|
|
assert_eq!(counter(cx), "1 / 4 champions validés");
|
|
assert!(page.read_with(cx, |p, _| p.search.matches(&row("Zed").champion)));
|
|
|
|
cx.update(|window, cx| input.update(cx, |input, cx| input.clean(window, cx)));
|
|
page.update(cx, |p, cx| {
|
|
p.home_filter = StateFilter::Remaining;
|
|
p.refresh_home(cx);
|
|
});
|
|
assert_eq!(names(cx), ["Akali", "Annie", "Zed"]);
|
|
cx.simulate_input("a");
|
|
assert_eq!(names(cx), ["Akali", "Annie"]);
|
|
assert_eq!(counter(cx), "1 / 4 champions validés");
|
|
|
|
page.update(cx, |p, cx| {
|
|
p.home_filter = StateFilter::Completed;
|
|
p.refresh_home(cx);
|
|
});
|
|
assert_eq!(names(cx), ["Ahri"]);
|
|
assert_eq!(counter(cx), "1 / 4 champions validés");
|
|
}
|
|
|
|
#[gpui::test]
|
|
fn a_click_in_the_padding_of_the_search_field_gives_it_the_keyboard(cx: &mut TestAppContext) {
|
|
use gpui_kit::{Modifiers, point, px};
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
show(&page, cx, statistics(0, 3, champions(3)));
|
|
draw(cx);
|
|
let input = page.read_with(cx, |p, _| p.home_search_input.clone());
|
|
let field = cx.debug_bounds("home-search").unwrap();
|
|
let text = |cx: &mut VisualTestContext| input.read_with(cx, |i, _| i.value().to_string());
|
|
|
|
// Just inside the left border, above the text line: nothing but the frame is there.
|
|
cx.simulate_click(
|
|
point(field.left() + px(2.), field.top() + px(2.)),
|
|
Modifiers::none(),
|
|
);
|
|
cx.simulate_input("an");
|
|
assert_eq!(text(cx), "an");
|
|
|
|
// The text line still takes its own click, and the field keeps working.
|
|
cx.update(|window, cx| window.blur(cx));
|
|
cx.simulate_click(field.center(), Modifiers::none());
|
|
cx.simulate_input("x");
|
|
assert_eq!(text(cx), "anx");
|
|
}
|
|
|
|
#[gpui::test]
|
|
fn the_home_follows_the_season_of_the_statistics_but_not_their_format(cx: &mut TestAppContext) {
|
|
cx.executor().allow_parking();
|
|
let tracker = Tracker::open(Path::new(":memory:"), Box::new(RefreshHistory))
|
|
.unwrap()
|
|
.with_seasons(vec![season("Ancienne", 2020), season("Récente", 2026)]);
|
|
tracker.sync("Alice#EUW", &mut |_| {}).unwrap();
|
|
let (page, mut window) = open_page_with_tracker(cx, tracker);
|
|
let recompute = |window: &mut VisualTestContext, change: &dyn Fn(&mut Page)| {
|
|
window.update(|window, cx| {
|
|
page.update(cx, |page, cx| {
|
|
change(page);
|
|
page.recompute(window, cx);
|
|
})
|
|
});
|
|
};
|
|
let home = |cx: &mut VisualTestContext| {
|
|
page.read_with(cx, |page, _| {
|
|
(
|
|
page.home_season.clone(),
|
|
page.home_scope.is_some(),
|
|
page.home_statistics().cloned(),
|
|
)
|
|
})
|
|
};
|
|
|
|
// The current Season, with no Format: the home reads the Statistics tab's result.
|
|
let (season, apart, current) = home(&mut window);
|
|
assert_eq!(season.as_deref(), Some("Récente"));
|
|
assert!(!apart);
|
|
assert_eq!(banner(&page, &mut window).season.as_ref(), "RÉCENTE");
|
|
let current = current.unwrap();
|
|
assert_eq!(current.rows.iter().map(|r| r.matches).sum::<usize>(), 1);
|
|
|
|
// Another Format on the Statistics tab: the home keeps its Challenge.
|
|
recompute(&mut window, &|page| {
|
|
page.tab = Tab::Statistics;
|
|
page.shown_tab = Tab::Statistics;
|
|
page.format = Some(Format::Arena3x6);
|
|
});
|
|
let (season, apart, same) = home(&mut window);
|
|
assert_eq!(season.as_deref(), Some("Récente"));
|
|
assert!(apart);
|
|
assert_eq!(same.as_ref(), Some(¤t));
|
|
let text = banner(&page, &mut window);
|
|
assert_eq!(
|
|
(text.season.as_ref(), text.title.text.as_ref()),
|
|
("RÉCENTE", "0 / 1 champions validés")
|
|
);
|
|
|
|
// Another Season: the home follows.
|
|
recompute(&mut window, &|page| {
|
|
page.format = None;
|
|
page.season = SeasonScope::Season("Ancienne".into());
|
|
});
|
|
let (season, apart, other) = home(&mut window);
|
|
assert_eq!(season.as_deref(), Some("Ancienne"));
|
|
assert!(!apart);
|
|
assert_eq!(banner(&page, &mut window).season.as_ref(), "ANCIENNE");
|
|
let other = other.unwrap();
|
|
assert_ne!(other, current);
|
|
assert_eq!(other.rows.iter().map(|r| r.matches).sum::<usize>(), 0);
|
|
|
|
// « Toutes les Saisons » has no Challenge: the current Season stands in for the home.
|
|
recompute(&mut window, &|page| page.season = SeasonScope::AllSeasons);
|
|
let (season, apart, all) = home(&mut window);
|
|
assert_eq!(season.as_deref(), Some("Récente"));
|
|
assert!(apart);
|
|
assert_eq!(all.as_ref(), Some(¤t));
|
|
assert!(page.read_with(&window, |page, _| {
|
|
page.stats.as_ref().unwrap().challenge.is_none()
|
|
}));
|
|
}
|
|
|
|
// Guards the home's one rule of rule #1: it draws no chart (the cached row is not in its tree).
|
|
#[gpui::test]
|
|
fn the_home_does_not_render_the_charts(cx: &mut TestAppContext) {
|
|
let (page, cx) = open_page_in_season(cx);
|
|
let cx = &mut { cx };
|
|
show(&page, cx, statistics(0, 1, vec![row("Ahri")]));
|
|
let charts = page.read_with(cx, |page, _| page.charts.clone());
|
|
cx.update(|window, cx| window.draw(cx).clear(cx));
|
|
assert_eq!(charts.read_with(cx, |charts, _| charts.renders), 0);
|
|
|
|
switch_tab(&page, cx, Tab::Statistics);
|
|
cx.update(|window, cx| window.draw(cx).clear(cx));
|
|
assert!(charts.read_with(cx, |charts, _| charts.renders) > 0);
|
|
}
|