Unfold a player's details in the Match Recap (#125)
Damage dealt and taken by type, mitigation, heals and shields on allies, gold and crowd control, as the source gives them, built once per recap and only drawn for the player unfolded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
beb5e5037b
commit
a4f2069f87
12 files changed
+501
-41
No files matched your search
@@ -3,6 +3,7 @@
|
||||
//! stored Matches change while it does), and only the Match chosen is decoded, on a worker too:
|
||||
//! nothing runs while the screen is hidden but marking the list stale (rule #1).
|
||||
|
||||
mod details;
|
||||
mod list;
|
||||
mod recap;
|
||||
mod screen;
|
||||
@@ -36,6 +37,9 @@ pub(in crate::page) enum Recap {
|
||||
Ready {
|
||||
recap: Box<MatchRecap>,
|
||||
shown: Box<ShownRecap>,
|
||||
/// The player whose details are unfolded (their index in the recap, teams in order).
|
||||
/// Kept while the same Match is decoded again, gone with the recap otherwise.
|
||||
open: Option<usize>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -319,9 +323,16 @@ impl Page {
|
||||
Ok(Some(recap)) => {
|
||||
let champions = self.champions();
|
||||
let shown = ShownRecap::new(&recap, self.chosen_champion(), &champions);
|
||||
let open = match &self.matches.recap {
|
||||
Recap::Ready {
|
||||
recap: old, open, ..
|
||||
} if old.match_id == recap.match_id => *open,
|
||||
_ => None,
|
||||
};
|
||||
Recap::Ready {
|
||||
recap: Box::new(recap),
|
||||
shown: Box::new(shown),
|
||||
open,
|
||||
}
|
||||
}
|
||||
Ok(None) => Recap::Missing,
|
||||
@@ -334,6 +345,15 @@ impl Page {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// A click or a key on a player's line: unfolds their details, folding the previous
|
||||
/// player's, or folds them.
|
||||
fn toggle_player(&mut self, index: usize, cx: &mut Context<Self>) {
|
||||
if let Recap::Ready { open, .. } = &mut self.matches.recap {
|
||||
*open = (*open != Some(index)).then_some(index);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/// The champions' names and portraits, as the statistics have them.
|
||||
fn champions(&self) -> Champions {
|
||||
Champions::of(self.home_statistics().or(self.stats.as_ref()))
|
||||
@@ -370,7 +390,7 @@ impl Page {
|
||||
.update(cx, |list, cx| list.set_rows(rows, selected.as_deref(), cx));
|
||||
let champion = self.chosen_champion();
|
||||
let champion = (champion.0, champion.1.to_string());
|
||||
if let Recap::Ready { recap, shown } = &mut self.matches.recap {
|
||||
if let Recap::Ready { recap, shown, .. } = &mut self.matches.recap {
|
||||
**shown = ShownRecap::new(recap, (champion.0, &champion.1), &champions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
//! The details of a player in the recap, written once with the rest of the recap: what
|
||||
//! Match-V5 gives of their Match, each measure named with its scope and, off points, its unit.
|
||||
//! Totals are kept as published: no value is the sum of others. A folded player builds none of
|
||||
//! it on screen (rule #1).
|
||||
|
||||
use arena_tracker_core::{DamageByType, RecapPlayer};
|
||||
|
||||
use super::shown::Value;
|
||||
use crate::text::{seconds, thousands};
|
||||
|
||||
/// One measure and its value.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(in crate::page) struct Measure {
|
||||
pub(in crate::page) caption: &'static str,
|
||||
pub(in crate::page) value: Value,
|
||||
}
|
||||
|
||||
/// Measures that go together, on one row.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(in crate::page) struct Group {
|
||||
pub(in crate::page) title: &'static str,
|
||||
pub(in crate::page) measures: Vec<Measure>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(in crate::page) struct Details(pub(in crate::page) Vec<Group>);
|
||||
|
||||
impl Details {
|
||||
/// `missing`: the word for a value the source does not give.
|
||||
pub(super) fn of(p: &RecapPlayer, missing: &'static str) -> Details {
|
||||
let points = |value: Option<u64>| Value::of(value, missing, thousands);
|
||||
let gold =
|
||||
|value: Option<u64>| Value::of(value, missing, |v| format!("{} or", thousands(v)));
|
||||
let time = |value: Option<u64>| Value::of(value, missing, seconds);
|
||||
let by_type = |title, damage: &DamageByType| Group {
|
||||
title,
|
||||
measures: vec![
|
||||
measure("Total", points(damage.total)),
|
||||
measure("Physiques", points(damage.physical)),
|
||||
measure("Magiques", points(damage.magic)),
|
||||
measure("Bruts", points(damage.true_damage)),
|
||||
],
|
||||
};
|
||||
Details(vec![
|
||||
by_type("Dégâts aux champions", &p.damage_to_champions),
|
||||
by_type("Dégâts reçus", &p.damage_taken),
|
||||
Group {
|
||||
title: "Protection",
|
||||
measures: vec![
|
||||
measure("Dégâts atténués", points(p.self_mitigated)),
|
||||
measure("Soins aux alliés", points(p.heals_on_teammates)),
|
||||
measure("Boucliers sur les alliés", points(p.shields_on_teammates)),
|
||||
],
|
||||
},
|
||||
Group {
|
||||
title: "Or",
|
||||
measures: vec![
|
||||
measure("Or gagné", gold(p.gold_earned)),
|
||||
measure("Or dépensé", gold(p.gold_spent)),
|
||||
],
|
||||
},
|
||||
Group {
|
||||
title: "Contrôle",
|
||||
measures: vec![
|
||||
measure("Contrôle infligé", time(p.total_time_cc_dealt_s)),
|
||||
measure("Score de contrôle", points(p.time_ccing_others_s)),
|
||||
],
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
/// The value of a measure of a group, as the tests ask for it.
|
||||
#[cfg(test)]
|
||||
pub(in crate::page) fn get(&self, title: &str, caption: &str) -> Option<&Value> {
|
||||
let group = self.0.iter().find(|group| group.title == title)?;
|
||||
(group.measures.iter())
|
||||
.find(|measure| measure.caption == caption)
|
||||
.map(|measure| &measure.value)
|
||||
}
|
||||
}
|
||||
|
||||
fn measure(caption: &'static str, value: Value) -> Measure {
|
||||
Measure { caption, value }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::page::matches::shown::{PENDING, UNAVAILABLE};
|
||||
|
||||
fn text(details: &Details, title: &str, caption: &str) -> (String, bool) {
|
||||
let value = details.get(title, caption).unwrap();
|
||||
(value.text.to_string(), value.missing)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_value_is_kept_as_the_source_gives_it() {
|
||||
let p = RecapPlayer {
|
||||
damage_to_champions: DamageByType {
|
||||
total: Some(30_000),
|
||||
physical: Some(12_000),
|
||||
magic: Some(17_000),
|
||||
// 0 is given: shown as 0. The types do not add up to the total: kept so.
|
||||
true_damage: Some(0),
|
||||
},
|
||||
gold_earned: Some(15_000),
|
||||
gold_spent: Some(0),
|
||||
total_time_cc_dealt_s: Some(83),
|
||||
time_ccing_others_s: Some(20),
|
||||
..RecapPlayer::default()
|
||||
};
|
||||
let details = Details::of(&p, UNAVAILABLE);
|
||||
let at = |title, caption| text(&details, title, caption);
|
||||
let dealt = "Dégâts aux champions";
|
||||
assert_eq!(at(dealt, "Total"), ("30\u{202f}000".into(), false));
|
||||
assert_eq!(at(dealt, "Magiques"), ("17\u{202f}000".into(), false));
|
||||
assert_eq!(at(dealt, "Bruts"), ("0".into(), false));
|
||||
assert_eq!(at("Or", "Or gagné"), ("15\u{202f}000 or".into(), false));
|
||||
assert_eq!(at("Or", "Or dépensé"), ("0 or".into(), false));
|
||||
assert_eq!(at("Contrôle", "Contrôle infligé").0, "1 min 23 s");
|
||||
assert_eq!(at("Contrôle", "Score de contrôle").0, "20");
|
||||
// Absent: the word, never 0.
|
||||
assert_eq!(at("Dégâts reçus", "Total"), (UNAVAILABLE.into(), true));
|
||||
assert_eq!(
|
||||
at("Protection", "Soins aux alliés"),
|
||||
(UNAVAILABLE.into(), true)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_provisional_match_waits_for_its_details() {
|
||||
let details = Details::of(&RecapPlayer::default(), PENDING);
|
||||
assert!(
|
||||
details
|
||||
.0
|
||||
.iter()
|
||||
.flat_map(|g| &g.measures)
|
||||
.all(|m| { m.value.missing && m.value.text == PENDING })
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
//! The recap of « Parties », drawn as functions of the page's render: the Match Recap of the
|
||||
//! Match chosen, already written (`ShownRecap`), its teams by Placement and one line per
|
||||
//! player, the Account's in gold.
|
||||
//! player, the Account's in gold. A click or a key on a line unfolds the details of the player.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -9,7 +9,11 @@ use gpui_kit::component::{ActiveTheme as _, Icon, IconName, Sizable as _, Styled
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use gpui_kit::base::Button as BaseButton;
|
||||
|
||||
use super::details::Details;
|
||||
use super::shown::{ShownPlayer, ShownRecap, ShownTeam, Slot, Value};
|
||||
use crate::page::Page;
|
||||
use crate::theme::{gold_ink, heading, surface};
|
||||
|
||||
const PORTRAIT: f32 = 32.;
|
||||
@@ -96,8 +100,12 @@ pub(in crate::page) fn provisional_badge(theme: &Theme) -> impl IntoElement {
|
||||
.child("Provisoire")
|
||||
}
|
||||
|
||||
/// The teams by Placement, the Account's highlighted.
|
||||
pub(in crate::page) fn teams(recap: &ShownRecap, cx: &App) -> impl IntoElement {
|
||||
/// The teams by Placement, the Account's highlighted; `open`: the player unfolded.
|
||||
pub(in crate::page) fn teams(
|
||||
recap: &ShownRecap,
|
||||
open: Option<usize>,
|
||||
cx: &Context<Page>,
|
||||
) -> impl IntoElement {
|
||||
let mut index = 0;
|
||||
div()
|
||||
.v_flex()
|
||||
@@ -105,12 +113,17 @@ pub(in crate::page) fn teams(recap: &ShownRecap, cx: &App) -> impl IntoElement {
|
||||
.children(recap.teams.iter().map(|shown| {
|
||||
let first = index;
|
||||
index += shown.players.len();
|
||||
team(shown, first, cx)
|
||||
team(shown, first, open, cx)
|
||||
}))
|
||||
}
|
||||
|
||||
/// `first`: the index of its first player in the recap, which names their item slots.
|
||||
fn team(shown: &ShownTeam, first: usize, cx: &App) -> impl IntoElement {
|
||||
fn team(
|
||||
shown: &ShownTeam,
|
||||
first: usize,
|
||||
open: Option<usize>,
|
||||
cx: &Context<Page>,
|
||||
) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
div()
|
||||
.v_flex()
|
||||
@@ -126,14 +139,16 @@ fn team(shown: &ShownTeam, first: usize, cx: &App) -> impl IntoElement {
|
||||
.children(
|
||||
(shown.players.iter())
|
||||
.enumerate()
|
||||
.map(|(ix, shown)| player(shown, first + ix, theme)),
|
||||
.map(|(ix, shown)| player(shown, first + ix, open == Some(first + ix), cx)),
|
||||
)
|
||||
}
|
||||
|
||||
/// One line per player: who, their level, K/D/A and damage to champions, then their items and
|
||||
/// augments under their name.
|
||||
fn player(shown: &ShownPlayer, ix: usize, theme: &Theme) -> impl IntoElement {
|
||||
/// augments under their name. The line is a button: it unfolds the details, built only then.
|
||||
fn player(shown: &ShownPlayer, ix: usize, open: bool, cx: &Context<Page>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let gold = gold_ink(theme);
|
||||
let (ring, hover, hover_foreground) = (theme.ring, theme.accent, theme.accent_foreground);
|
||||
let identity = div()
|
||||
.v_flex()
|
||||
.flex_1()
|
||||
@@ -147,22 +162,20 @@ fn player(shown: &ShownPlayer, ix: usize, theme: &Theme) -> impl IntoElement {
|
||||
.child(shown.champion.clone()),
|
||||
)
|
||||
.child(value(&shown.riot_id, theme).text_xs());
|
||||
div()
|
||||
let line = BaseButton::new(("recap-player", ix))
|
||||
.v_flex()
|
||||
.items_stretch()
|
||||
.w_full()
|
||||
.gap_1()
|
||||
.px_2()
|
||||
.py_1()
|
||||
.rounded_md()
|
||||
.border_1()
|
||||
.map(|line| {
|
||||
if shown.is_account {
|
||||
line.border_color(gold)
|
||||
.bg(gold.opacity(0.08))
|
||||
.debug_selector(|| "recap-account".into())
|
||||
} else {
|
||||
line.border_color(transparent_black())
|
||||
}
|
||||
})
|
||||
.border_color(transparent_black())
|
||||
.focus_visible(|style| style.border_color(ring))
|
||||
.hover(|style| style.bg(hover).text_color(hover_foreground))
|
||||
.accessibility_label(format!("Détails de {}", shown.champion))
|
||||
.debug_selector(move || format!("recap-player-{ix}"))
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
@@ -172,7 +185,16 @@ fn player(shown: &ShownPlayer, ix: usize, theme: &Theme) -> impl IntoElement {
|
||||
.child(identity)
|
||||
.child(stat("Niveau", &shown.level, 72., theme))
|
||||
.child(stat("K/D/A", &shown.kda, 120., theme))
|
||||
.child(stat("Dégâts aux champions", &shown.damage, 140., theme)),
|
||||
.child(stat("Dégâts aux champions", &shown.damage, 140., theme))
|
||||
.child(
|
||||
Icon::new(if open {
|
||||
IconName::ChevronDown
|
||||
} else {
|
||||
IconName::ChevronRight
|
||||
})
|
||||
.small()
|
||||
.text_color(theme.muted_foreground),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
@@ -184,6 +206,54 @@ fn player(shown: &ShownPlayer, ix: usize, theme: &Theme) -> impl IntoElement {
|
||||
.child(items(&shown.items, ix, theme))
|
||||
.child(augments(&shown.augments, theme)),
|
||||
)
|
||||
.on_click(cx.listener(move |page, _, _, cx| page.toggle_player(ix, cx)));
|
||||
div()
|
||||
.v_flex()
|
||||
.rounded_md()
|
||||
.border_1()
|
||||
.map(|card| {
|
||||
if shown.is_account {
|
||||
card.border_color(gold)
|
||||
.bg(gold.opacity(0.08))
|
||||
.debug_selector(|| "recap-account".into())
|
||||
} else {
|
||||
card.border_color(transparent_black())
|
||||
}
|
||||
})
|
||||
.child(line)
|
||||
.when(open, |card| card.child(details(&shown.details, theme)))
|
||||
}
|
||||
|
||||
/// The measures of a player, a row per group: its title, then each measure under its caption.
|
||||
/// Built for the player unfolded only.
|
||||
fn details(details: &Details, theme: &Theme) -> impl IntoElement {
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_2()
|
||||
.px_2()
|
||||
.pb_2()
|
||||
.pl(px(PORTRAIT + 24.))
|
||||
.debug_selector(|| "recap-details".into())
|
||||
.children(details.0.iter().map(|group| {
|
||||
div()
|
||||
.h_flex()
|
||||
.flex_wrap()
|
||||
.items_start()
|
||||
.gap_x_3()
|
||||
.gap_y_1()
|
||||
.child(
|
||||
div()
|
||||
.w(px(150.))
|
||||
.flex_shrink_0()
|
||||
.text_sm()
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
.child(group.title),
|
||||
)
|
||||
.children(
|
||||
(group.measures.iter())
|
||||
.map(|measure| stat(measure.caption, &measure.value, 150., theme)),
|
||||
)
|
||||
}))
|
||||
}
|
||||
|
||||
/// What stands for items or augments the source does not give: « Objets : Indisponible ».
|
||||
|
||||
@@ -198,9 +198,9 @@ impl Page {
|
||||
.child(error.clone())
|
||||
.into_any_element(),
|
||||
],
|
||||
Recap::Ready { shown, .. } => vec![
|
||||
Recap::Ready { shown, open, .. } => vec![
|
||||
recap::header(shown, cx).into_any_element(),
|
||||
recap::teams(shown, cx).into_any_element(),
|
||||
recap::teams(shown, *open, cx).into_any_element(),
|
||||
],
|
||||
};
|
||||
card_images::provide(div(), images)
|
||||
|
||||
@@ -7,6 +7,7 @@ use std::path::PathBuf;
|
||||
use arena_tracker_core::{MatchRecap, RecapPlayer, Statistics};
|
||||
use gpui_kit::SharedString;
|
||||
|
||||
use super::details::Details;
|
||||
use crate::local_time::local_time;
|
||||
use crate::text::{duration, match_time, ordinal, thousands};
|
||||
|
||||
@@ -52,7 +53,11 @@ pub(in crate::page) struct Value {
|
||||
}
|
||||
|
||||
impl Value {
|
||||
fn of<T>(value: Option<T>, missing: &'static str, show: impl FnOnce(T) -> String) -> Value {
|
||||
pub(super) fn of<T>(
|
||||
value: Option<T>,
|
||||
missing: &'static str,
|
||||
show: impl FnOnce(T) -> String,
|
||||
) -> Value {
|
||||
match value {
|
||||
Some(value) => Value {
|
||||
text: show(value).into(),
|
||||
@@ -91,6 +96,8 @@ pub(in crate::page) struct ShownPlayer {
|
||||
/// field.
|
||||
pub(in crate::page) augments: Result<Vec<SharedString>, Value>,
|
||||
pub(in crate::page) damage: Value,
|
||||
/// What unfolds under their line.
|
||||
pub(in crate::page) details: Details,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -190,6 +197,7 @@ fn player(p: &RecapPlayer, missing: &'static str, champions: &Champions) -> Show
|
||||
})
|
||||
.ok_or_else(absent),
|
||||
damage: Value::of(p.damage_to_champions.total, missing, thousands),
|
||||
details: Details::of(p, missing),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,10 @@ mod champ_select_scroll;
|
||||
mod champ_select_tab;
|
||||
mod grid;
|
||||
mod home;
|
||||
mod key_fixtures;
|
||||
mod match_animation;
|
||||
mod matches;
|
||||
mod matches_details;
|
||||
mod matches_fixtures;
|
||||
mod navigation;
|
||||
mod page_fixtures;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
use gpui_kit::{KeyDownEvent, KeyUpEvent, Keystroke, VisualTestContext};
|
||||
|
||||
/// Presses and releases `key` on the element focused, as a button reads it (a keystroke alone
|
||||
/// does not activate it).
|
||||
pub(super) fn press_key(cx: &mut VisualTestContext, key: &str) {
|
||||
let keystroke =
|
||||
cx.update(|_, cx| Keystroke::parse_with_os(key, cx.platform_info().os).unwrap());
|
||||
cx.simulate_event(KeyDownEvent {
|
||||
keystroke: keystroke.clone(),
|
||||
is_held: false,
|
||||
prefer_character_input: false,
|
||||
});
|
||||
cx.simulate_event(KeyUpEvent { keystroke });
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
//! The details a click or a key unfolds under a player of the recap.
|
||||
|
||||
use super::key_fixtures::press_key;
|
||||
use super::matches_fixtures::{ALICE, chosen, open_matches, recap_ready};
|
||||
use super::page_fixtures::{center, draw, switch_tab};
|
||||
use crate::page::matches::{Recap, ShownPlayer, UNAVAILABLE};
|
||||
use crate::page::{Page, Tab};
|
||||
use gpui_kit::{Entity, Modifiers, TestAppContext, VisualTestContext};
|
||||
|
||||
fn click(cx: &mut VisualTestContext, id: &'static str) {
|
||||
let at = center(cx, id);
|
||||
cx.simulate_click(at, Modifiers::none());
|
||||
draw(cx);
|
||||
}
|
||||
|
||||
/// The lines of the six players of the fixture.
|
||||
const LINES: [&str; 6] = [
|
||||
"recap-player-0",
|
||||
"recap-player-1",
|
||||
"recap-player-2",
|
||||
"recap-player-3",
|
||||
"recap-player-4",
|
||||
"recap-player-5",
|
||||
];
|
||||
|
||||
/// The player of the recap shown whose Riot ID starts with `name`, and their index.
|
||||
fn player(page: &Entity<Page>, cx: &mut VisualTestContext, name: &str) -> (usize, ShownPlayer) {
|
||||
page.read_with(cx, |p, _| {
|
||||
let shown = p.matches.shown().unwrap();
|
||||
(shown.teams.iter().flat_map(|t| t.players.iter()))
|
||||
.enumerate()
|
||||
.find(|(_, player)| player.riot_id.text.starts_with(name))
|
||||
.map(|(ix, player)| (ix, player.clone()))
|
||||
.unwrap()
|
||||
})
|
||||
}
|
||||
|
||||
/// The player unfolded.
|
||||
fn unfolded(page: &Entity<Page>, cx: &mut VisualTestContext) -> Option<usize> {
|
||||
page.read_with(cx, |p, _| match &p.matches.recap {
|
||||
Recap::Ready { open, .. } => *open,
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// The details of `player` as « title / caption » → text, the missing ones flagged.
|
||||
fn measure(player: &ShownPlayer, title: &str, caption: &str) -> (String, bool) {
|
||||
let value = player.details.get(title, caption).unwrap();
|
||||
(value.text.to_string(), value.missing)
|
||||
}
|
||||
|
||||
/// Opens the Match with the full recap (the oldest, third in the list).
|
||||
async fn open_full_recap(
|
||||
page: &Entity<Page>,
|
||||
cx: &mut TestAppContext,
|
||||
window: &mut VisualTestContext,
|
||||
) {
|
||||
click(window, "match-row-2");
|
||||
recap_ready(page, cx).await;
|
||||
draw(window);
|
||||
assert_eq!(chosen(page, window).as_deref(), Some(ALICE[2]));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_details_come_from_a_full_recap_as_published(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open_matches(cx).await;
|
||||
open_full_recap(&page, cx, &mut window).await;
|
||||
let (_, me) = player(&page, &mut window, "Joueur");
|
||||
let at = |title, caption| measure(&me, title, caption);
|
||||
// Thousands are grouped with a narrow no-break space; a unit follows after a plain one.
|
||||
let n = |text: &str| (text.replacen(' ', "\u{202f}", 1), false);
|
||||
let gold = |text: &str| (format!("{} or", text.replacen(' ', "\u{202f}", 1)), false);
|
||||
let dealt = "Dégâts aux champions";
|
||||
assert_eq!(at(dealt, "Total"), n("30 000"));
|
||||
assert_eq!(at(dealt, "Physiques"), n("12 000"));
|
||||
assert_eq!(at(dealt, "Magiques"), n("17 000"));
|
||||
assert_eq!(at(dealt, "Bruts"), n("1 000"));
|
||||
let taken = "Dégâts reçus";
|
||||
assert_eq!(at(taken, "Total"), n("20 000"));
|
||||
assert_eq!(at(taken, "Physiques"), n("9 000"));
|
||||
assert_eq!(at(taken, "Magiques"), n("10 000"));
|
||||
assert_eq!(at(taken, "Bruts"), n("1 000"));
|
||||
assert_eq!(at("Protection", "Dégâts atténués"), n("8 000"));
|
||||
assert_eq!(at("Protection", "Soins aux alliés"), n("500"));
|
||||
assert_eq!(at("Protection", "Boucliers sur les alliés"), n("250"));
|
||||
assert_eq!(at("Or", "Or gagné"), gold("15 000"));
|
||||
assert_eq!(at("Or", "Or dépensé"), gold("14 000"));
|
||||
assert_eq!(at("Contrôle", "Contrôle infligé"), ("45 s".into(), false));
|
||||
assert_eq!(at("Contrôle", "Score de contrôle"), n("20"));
|
||||
// A published total stays as given, though the types do not add up to it.
|
||||
let (_, other) = player(&page, &mut window, "Autre04");
|
||||
assert_eq!(measure(&other, dealt, "Total"), n("31 000"));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn a_missing_field_is_unavailable_and_a_given_zero_is_zero(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open_matches(cx).await;
|
||||
open_full_recap(&page, cx, &mut window).await;
|
||||
let missing = (UNAVAILABLE.to_string(), true);
|
||||
let zero = ("0".to_string(), false);
|
||||
|
||||
// No physical damage taken, the rest given.
|
||||
let (_, one) = player(&page, &mut window, "Autre01");
|
||||
assert_eq!(measure(&one, "Dégâts reçus", "Physiques"), missing);
|
||||
assert!(!measure(&one, "Dégâts reçus", "Total").1);
|
||||
// Zero true damage and no shield: the source says 0.
|
||||
let (_, three) = player(&page, &mut window, "Autre03");
|
||||
assert_eq!(measure(&three, "Dégâts aux champions", "Bruts"), zero);
|
||||
assert_eq!(
|
||||
measure(&three, "Protection", "Boucliers sur les alliés"),
|
||||
zero
|
||||
);
|
||||
// No gold spent, no crowd control time.
|
||||
let (_, six) = player(&page, &mut window, "Autre06");
|
||||
assert_eq!(measure(&six, "Or", "Or dépensé"), missing);
|
||||
assert_eq!(measure(&six, "Contrôle", "Contrôle infligé"), missing);
|
||||
assert!(!measure(&six, "Or", "Or gagné").1);
|
||||
|
||||
// A Match whose payload has no statistics: nothing is 0.
|
||||
click(&mut window, "match-row-0");
|
||||
recap_ready(&page, cx).await;
|
||||
let (_, me) = player(&page, &mut window, "Joueur");
|
||||
assert!(
|
||||
me.details
|
||||
.0
|
||||
.iter()
|
||||
.flat_map(|g| &g.measures)
|
||||
.all(|m| m.value.missing)
|
||||
);
|
||||
assert_eq!(measure(&me, "Or", "Or gagné"), missing);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn a_click_unfolds_a_player_and_another_click_folds_them(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open_matches(cx).await;
|
||||
open_full_recap(&page, cx, &mut window).await;
|
||||
let cx = &mut window;
|
||||
// Folded: nothing of the details is built.
|
||||
assert_eq!(unfolded(&page, cx), None);
|
||||
assert!(cx.debug_bounds("recap-details").is_none());
|
||||
|
||||
let (first, _) = player(&page, cx, "Autre03");
|
||||
let (second, _) = player(&page, cx, "Joueur");
|
||||
assert_ne!(first, second);
|
||||
click(cx, "recap-player-0");
|
||||
assert_eq!(unfolded(&page, cx), Some(0));
|
||||
assert!(cx.debug_bounds("recap-details").is_some());
|
||||
// The line stays above its details.
|
||||
let line = cx.debug_bounds("recap-player-0").unwrap();
|
||||
assert!(cx.debug_bounds("recap-details").unwrap().top() >= line.bottom());
|
||||
|
||||
// Another player: one at a time.
|
||||
let other = LINES[second];
|
||||
click(cx, other);
|
||||
assert_eq!(unfolded(&page, cx), Some(second));
|
||||
assert!(cx.debug_bounds("recap-details").is_some());
|
||||
click(cx, other);
|
||||
assert_eq!(unfolded(&page, cx), None);
|
||||
assert!(cx.debug_bounds("recap-details").is_none());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_keyboard_unfolds_and_folds_without_the_mouse(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open_matches(cx).await;
|
||||
open_full_recap(&page, cx, &mut window).await;
|
||||
let cx = &mut window;
|
||||
// The click gives the line the focus; from there, the keys do the rest.
|
||||
click(cx, "recap-player-1");
|
||||
assert_eq!(unfolded(&page, cx), Some(1));
|
||||
press_key(cx, "enter");
|
||||
assert_eq!(unfolded(&page, cx), None);
|
||||
assert!(cx.debug_bounds("recap-details").is_none());
|
||||
press_key(cx, "space");
|
||||
assert_eq!(unfolded(&page, cx), Some(1));
|
||||
// Tab reaches the next line, Enter unfolds it in place of the first.
|
||||
press_key(cx, "tab");
|
||||
press_key(cx, "enter");
|
||||
assert_eq!(unfolded(&page, cx), Some(2));
|
||||
press_key(cx, "enter");
|
||||
assert_eq!(unfolded(&page, cx), None);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_details_are_not_kept_from_one_match_to_another(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open_matches(cx).await;
|
||||
open_full_recap(&page, cx, &mut window).await;
|
||||
click(&mut window, "recap-player-2");
|
||||
assert_eq!(unfolded(&page, &mut window), Some(2));
|
||||
click(&mut window, "match-row-1");
|
||||
recap_ready(&page, cx).await;
|
||||
draw(&mut window);
|
||||
assert_eq!(unfolded(&page, &mut window), None);
|
||||
assert!(window.debug_bounds("recap-details").is_none());
|
||||
|
||||
// Nor from one opening of the screen to the next.
|
||||
click(&mut window, "recap-player-0");
|
||||
assert_eq!(unfolded(&page, &mut window), Some(0));
|
||||
switch_tab(&page, &mut window, Tab::Challenge);
|
||||
switch_tab(&page, &mut window, Tab::Matches);
|
||||
recap_ready(&page, cx).await;
|
||||
assert_eq!(unfolded(&page, &mut window), None);
|
||||
}
|
||||
@@ -1,24 +1,10 @@
|
||||
use super::key_fixtures::press_key;
|
||||
use super::page_fixtures::{
|
||||
animations, assert_at_rest, center, champions, draw, frame_after, open_page,
|
||||
open_page_in_season, show, shown_tab, start_switch, statistics, switch_tab, veil,
|
||||
};
|
||||
use crate::page::Tab;
|
||||
use gpui_kit::{
|
||||
KeyDownEvent, KeyUpEvent, Keystroke, Modifiers, TestAppContext, VisualTestContext,
|
||||
WindowVisibility,
|
||||
};
|
||||
|
||||
/// Presses Enter on the element focused, as the keyboard does.
|
||||
fn press_enter(cx: &mut VisualTestContext) {
|
||||
let enter =
|
||||
cx.update(|_, cx| Keystroke::parse_with_os("enter", cx.platform_info().os).unwrap());
|
||||
cx.simulate_event(KeyDownEvent {
|
||||
keystroke: enter.clone(),
|
||||
is_held: false,
|
||||
prefer_character_input: false,
|
||||
});
|
||||
cx.simulate_event(KeyUpEvent { keystroke: enter });
|
||||
}
|
||||
use gpui_kit::{Modifiers, TestAppContext, VisualTestContext, WindowVisibility};
|
||||
|
||||
/// Tab moves the focus `count` elements on, then Enter activates the one reached.
|
||||
fn tab_then_enter(cx: &mut VisualTestContext, count: usize) {
|
||||
@@ -28,7 +14,7 @@ fn tab_then_enter(cx: &mut VisualTestContext, count: usize) {
|
||||
}
|
||||
});
|
||||
draw(cx);
|
||||
press_enter(cx);
|
||||
press_key(cx, "enter");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
||||
@@ -77,6 +77,14 @@ pub fn duration(seconds: u32) -> String {
|
||||
format!("{} min {:02} s", seconds / 60, seconds % 60)
|
||||
}
|
||||
|
||||
/// A span of seconds, as the details write it: « 45 s », « 1 min 23 s ».
|
||||
pub fn seconds(seconds: u64) -> String {
|
||||
match seconds {
|
||||
0..60 => format!("{seconds} s"),
|
||||
_ => format!("{} min {:02} s", seconds / 60, seconds % 60),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn state_label(state: Option<ChampionState>) -> &'static str {
|
||||
match state {
|
||||
Some(ChampionState::Completed) => "Validé",
|
||||
@@ -177,6 +185,14 @@ mod tests {
|
||||
assert_eq!(duration(60), "1 min 00 s");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_span_of_seconds_drops_the_minutes_under_one() {
|
||||
assert_eq!(seconds(0), "0 s");
|
||||
assert_eq!(seconds(45), "45 s");
|
||||
assert_eq!(seconds(60), "1 min 00 s");
|
||||
assert_eq!(seconds(83), "1 min 23 s");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stored_matches_are_pluralised() {
|
||||
assert_eq!(stored(0), "Aucune Partie enregistrée");
|
||||
|
||||
Reference in new issue
Block a user