diff --git a/packages/scout-for-lol/packages/app/src/components/matchup/matchup-hero.tsx b/packages/scout-for-lol/packages/app/src/components/matchup/matchup-hero.tsx new file mode 100644 index 0000000000..3d3487331f --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/components/matchup/matchup-hero.tsx @@ -0,0 +1,70 @@ +import type { Lane } from "@scout-for-lol/data"; +import { Chip } from "@scout-for-lol/design-system/components/surfaces/chip"; +import { ChampionFace } from "@scout-for-lol/design-system/domain/profile/champion-face"; +import { DuelHero } from "@scout-for-lol/design-system/domain/profile/duel-hero"; +import { Search } from "lucide-react"; +import { useSpaLink } from "#src/hooks/use-spa-link.ts"; +import { laneLine } from "#src/lib/matchup/matchup-page.ts"; +import { matchupPath } from "#src/lib/matchup/matchup-path.ts"; + +export type MatchupSide = { championId: number; name: string }; + +function OtherSide(props: { side: MatchupSide; to: string }) { + const link = useSpaLink(props.to); + return ( + + + I'm playing {props.side.name} + + ); +} + +function ChangeMatchup(props: { to: string }) { + const link = useSpaLink(props.to); + return ( + + + ); +} + +/** + * The lead panel: the two champions facing each other, which side the viewer + * plays (the other side is a link to the same matchup from there) and the lane. + */ +export function MatchupHero(props: { + champion: MatchupSide; + opponent: MatchupSide; + lane: Lane; +}) { + const { champion, opponent, lane } = props; + return ( + +

+ {champion.name}{" "} + against{" "} + {opponent.name} +

+
+ + + I'm playing {champion.name} + + + +
+

{laneLine(lane)}

+
+ ); +} diff --git a/packages/scout-for-lol/packages/app/src/components/matchup/matchup-records.tsx b/packages/scout-for-lol/packages/app/src/components/matchup/matchup-records.tsx new file mode 100644 index 0000000000..84d796708c --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/components/matchup/matchup-records.tsx @@ -0,0 +1,70 @@ +import type { ReactNode } from "react"; +import { Panel } from "@scout-for-lol/design-system/components/surfaces/panel"; +import { GameSentenceRow } from "@scout-for-lol/design-system/domain/rows/game-sentence-row"; +import { + aheadLine, + recentRow, + recordLead, + type MatchupData, + type MatchupTally, +} from "#src/lib/matchup/matchup-page.ts"; + +const HEADING = "m-0 font-display text-2xl leading-tight font-bold"; +const LEAD = "mt-3 mb-0 font-display text-3xl leading-tight text-balance"; +const SUB = "mt-2 mb-0 text-scout-subtle"; + +function Record(props: { + heading: string; + id: string; + tally: MatchupTally; + who: "you" | "friends"; + children?: ReactNode; +}) { + const ahead = aheadLine(props.tally); + return ( + +
+

+ {props.heading} +

+

{recordLead(props.tally, props.who)}

+ {ahead === undefined ? null :

{ahead}

} + {props.children} +
+
+ ); +} + +/** The viewer's record in the matchup and their newest games in it. */ +export function YourGames(props: { + matchup: MatchupData; + championId: number; + nowMs: number; +}) { + const { matchup } = props; + return ( + +
    + {matchup.recent.map((game) => ( +
  1. + +
  2. + ))} +
+
+ ); +} + +/** The record of everyone else in scope, one game per person and match. */ +export function FriendsRecord(props: { matchup: MatchupData }) { + return ( + + ); +} diff --git a/packages/scout-for-lol/packages/app/src/components/matchup/matchup-shell.tsx b/packages/scout-for-lol/packages/app/src/components/matchup/matchup-shell.tsx new file mode 100644 index 0000000000..d3973929e6 --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/components/matchup/matchup-shell.tsx @@ -0,0 +1,52 @@ +import { chipVariants } from "@scout-for-lol/design-system/components/surfaces/chip"; +import { EmptyState } from "@scout-for-lol/design-system/layout"; +import type { ReactNode } from "react"; +import { Link } from "react-router"; +import { DelayedLoadingState } from "#src/components/chrome/section-skeleton.tsx"; + +/** The column the Matchup page sits in. */ +export function MatchupShell(props: { children: ReactNode }) { + return ( +
+ {props.children} +
+ ); +} + +export function MatchupLoading() { + return ; +} + +/** The matchup could not be read: say so, and offer the retry. */ +export function MatchupUnavailable(props: { onRetry: () => void }) { + return ( + +

+ This matchup could not be loaded +

+ +
+ ); +} + +/** A champion the game does not have. */ +export function MatchupGone() { + return ( + + +

+ This matchup is not available +

+ + Players + +
+
+ ); +} diff --git a/packages/scout-for-lol/packages/app/src/components/matchup/matchup-tips-panel.tsx b/packages/scout-for-lol/packages/app/src/components/matchup/matchup-tips-panel.tsx new file mode 100644 index 0000000000..cf5577da3f --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/components/matchup/matchup-tips-panel.tsx @@ -0,0 +1,73 @@ +import { Panel } from "@scout-for-lol/design-system/components/surfaces/panel"; +import { GeneratedTipList } from "@scout-for-lol/design-system/domain/tips/generated-tip-list"; +import { GameFactProvider } from "@scout-for-lol/design-system/domain/tooltips/game-fact"; +import { loadGameFact } from "@scout-for-lol/data/game-facts/client.ts"; +import { useQuery } from "@tanstack/react-query"; +import { ZodError } from "zod"; +import { + loadChampionTips, + matchupTips, + type MatchupTips, +} from "#src/lib/matchup/matchup-tips.ts"; +import type { Lane } from "@scout-for-lol/data"; + +/** The generated tips, led by the abilities they name; the other side is closed. */ +export function MatchupTipsPanel(props: { tips: MatchupTips }) { + return ( + +
+

+ Scout's tips +

+ + + +
+
+ ); +} + +type Side = { key: string; name: string }; + +/** + * Reads both champions' tips files and shows the matchup's tips, or nothing + * while they load or when the generated matrix has none for this pair. A + * download that fails leaves the page without tips; a file that does not match + * its schema is a broken contract and fails loudly. + */ +export function MatchupTipsSection(props: { + champion: Side; + opponent: Side; + lane: Lane; +}) { + const { champion, opponent, lane } = props; + const tips = useQuery({ + queryKey: ["matchup-tips", champion.key, opponent.key, lane], + staleTime: Infinity, + retry: (count, error) => !(error instanceof ZodError) && count < 2, + queryFn: async () => { + const [championFile, opponentFile] = await Promise.all([ + loadChampionTips(champion.key), + loadChampionTips(opponent.key), + ]); + return ( + matchupTips({ + champion: { ...champion, file: championFile }, + opponent: { ...opponent, file: opponentFile }, + lane, + }) ?? null + ); + }, + }); + if (tips.error instanceof ZodError) throw tips.error; + return tips.data === undefined || tips.data === null ? null : ( + + ); +} diff --git a/packages/scout-for-lol/packages/app/src/components/matchup/matchup-view.test.tsx b/packages/scout-for-lol/packages/app/src/components/matchup/matchup-view.test.tsx new file mode 100644 index 0000000000..112a8d9728 --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/components/matchup/matchup-view.test.tsx @@ -0,0 +1,168 @@ +import type { ReactElement, ReactNode } from "react"; +import { renderToStaticMarkup } from "react-dom/server"; +import { MemoryRouter } from "react-router"; +import { describe, expect, test, vi } from "vitest"; +import { MatchupTipsPanel } from "#src/components/matchup/matchup-tips-panel.tsx"; +import { + MatchupGone, + MatchupUnavailable, +} from "#src/components/matchup/matchup-shell.tsx"; +import { + MatchupRecords, + MatchupView, +} from "#src/components/matchup/matchup-view.tsx"; +import { matchupFixture, NOW_MS } from "#src/lib/matchup/matchup-fixtures.ts"; +import type { MatchupOutput } from "#src/lib/matchup/matchup-page.ts"; +import { + loadChampionTips, + matchupTips, +} from "#src/lib/matchup/matchup-tips.ts"; + +const retry = vi.fn(); + +function render(element: ReactElement): string { + return renderToStaticMarkup({element}); +} + +/** What a reader sees: the markup with its tags gone and spaces collapsed. */ +function text(html: string): string { + const withoutTags = html.replaceAll(/<[^>]+>/g, " "); + return withoutTags.replaceAll("'", "'").replaceAll(/\s{2,}/g, " "); +} + +function records(matchup: MatchupOutput): string { + return render( + , + ); +} + +function view(options?: { records?: ReactNode }): string { + return render( + , + ); +} + +describe("MatchupView", () => { + test("opens on the two champions, the side you play and the lane", () => { + const words = text(view()); + expect(words).toContain("Ahri against Syndra"); + expect(words).toContain("I'm playing Ahri"); + expect(words).toContain("I'm playing Syndra"); + expect(words).toContain("Change matchup"); + expect(words).toContain("Mid lane"); + }); + + test("the pressed side is the viewer's, the other is the same matchup from there", () => { + const html = view(); + expect(html).toContain('aria-pressed="true"'); + expect(html).toContain('href="/champions/134/middle/vs/103"'); + expect(html).toContain('href="/champions/103"'); + }); + + test("names no Scout statistic the endpoint does not give it", () => { + const words = text(view()); + expect(words).not.toContain("wins"); + expect(words).not.toContain("patch"); + }); +}); + +describe("MatchupRecords", () => { + test("shows the viewer's record, their newest games and the friends' record", () => { + const words = text(records(matchupFixture())); + expect(words).toContain("Your games"); + expect(words).toContain("You've won 1 of 5"); + expect(words).toContain("Ahead at 15 minutes in 1 of 5."); + expect(words).toContain("Lost as Ahri, 4/5/5, −19 LP"); + expect(words).toContain("2 days ago, behind at 15 minutes"); + expect(words).toContain("Won as Ahri, 8/3/7, +20 LP"); + expect(words).toContain("Friends"); + expect(words).toContain("Friends have won 3 of 8"); + expect(words).toContain("Ahead at 15 minutes in 5 of 7."); + }); + + test("a game with no 15:00 frame has no standing and no LP change", () => { + const words = text(records(matchupFixture())); + expect(words).toContain("Lost as Ahri, 8/3/7 2 weeks ago"); + }); + + test("while the lake has no lane data there is nothing to show, and no error", () => { + const html = records({ status: "unavailable", reason: "lane-data" }); + expect(html).toBe(""); + }); + + test("a matchup nobody has played shows no panels", () => { + const empty = { games: 0, wins: 0, ahead15: { games: 0, ahead: 0 } }; + expect( + records(matchupFixture({ you: empty, friends: empty, recent: [] })), + ).toBe(""); + }); + + test("friends who played it without the viewer keep their panel alone", () => { + const words = text( + records( + matchupFixture({ + you: { games: 0, wins: 0, ahead15: { games: 0, ahead: 0 } }, + recent: [], + }), + ), + ); + expect(words).not.toContain("Your games"); + expect(words).toContain("Friends have won 3 of 8"); + }); + + test("leaves out the ahead line for a tally with no 15:00 frames", () => { + const words = text( + records( + matchupFixture({ + friends: { games: 4, wins: 2, ahead15: { games: 0, ahead: 0 } }, + }), + ), + ); + expect(words).toContain("Friends have won 2 of 4"); + expect(words).not.toContain("in 5 of 7"); + }); +}); + +describe("states", () => { + test("a failed read offers the retry", () => { + const words = text(render()); + expect(words).toContain("This matchup could not be loaded"); + expect(words).toContain("Retry"); + }); + + test("a champion that does not exist is not available", () => { + expect(text(render())).toContain( + "This matchup is not available", + ); + }); +}); + +describe("MatchupTipsPanel", () => { + test("lists the tips and closes the other side's under them", async () => { + const tips = matchupTips({ + champion: { + key: "Ahri", + name: "Ahri", + file: await loadChampionTips("Ahri"), + }, + opponent: { + key: "Zed", + name: "Zed", + file: await loadChampionTips("Zed"), + }, + lane: "middle", + }); + if (tips === undefined) throw new Error("Ahri into Zed has tips"); + const html = render(); + expect(text(html)).toContain("Scout's tips"); + expect(text(html)).toContain("Playing Zed into Ahri"); + expect(html).toContain(" 0; + const hasFriends = matchup.friends.games > 0; + if (!hasYou && !hasFriends) return null; + return ( +
+ {hasYou ? ( + + ) : null} + {hasFriends ? : null} +
+ ); +} + +/** One champion against another in a lane: the hero, the records and the tips. */ +export function MatchupView(props: { + champion: MatchupSide; + opponent: MatchupSide; + lane: Lane; + /** The records, or the state that stands in for them while they load. */ + records: ReactNode; + tips: ReactNode; +}) { + return ( + + + {props.records} + {props.tips} + + ); +} diff --git a/packages/scout-for-lol/packages/app/src/lib/analytics-events.ts b/packages/scout-for-lol/packages/app/src/lib/analytics-events.ts index b3322564e2..20d08e0f3a 100644 --- a/packages/scout-for-lol/packages/app/src/lib/analytics-events.ts +++ b/packages/scout-for-lol/packages/app/src/lib/analytics-events.ts @@ -51,6 +51,7 @@ const SCOUT_ANALYTICS_EVENTS = [ "live_games_opened", "live_game_opened", "server_page_opened", + "matchup_page_opened", "match_detail_opened", "match_timeline_viewed", // Competitions diff --git a/packages/scout-for-lol/packages/app/src/lib/analytics-path.ts b/packages/scout-for-lol/packages/app/src/lib/analytics-path.ts new file mode 100644 index 0000000000..24cea5eb4d --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/lib/analytics-path.ts @@ -0,0 +1,58 @@ +/** + * Collapse dynamic route segments to templates so pageviews group by shape + * instead of exposing guild/report/player identifiers. + */ +export function normalizePath(pathname: string): string { + const normalized = pathname + .replace(/^\/players\/[^/]+/, "/players/:playerId") + .replace( + /^\/players\/:playerId\/matches\/[^/]+/, + "/players/:playerId/matches/:matchId", + ) + .replace( + /^\/champions\/[^/]+\/[^/]+\/vs\/[^/]+/, + "/champions/:championId/:lane/vs/:opponentChampionId", + ) + .replace(/^\/champions\/[^/]+/, "/champions/:championId") + .replace(/^\/compare\/[^/]+\/[^/]+/, "/compare/:left/:right") + .replace(/^\/live\/[^/]+/, "/live/:riotMatchId") + .replace(/^\/(halls|servers)\/[^/]+/, "/$1/:guildId") + .replace(/^\/challenge-runs\/[^/]+/, "/challenge-runs/:runId") + .replace(/^\/challenges\/drafts\/[^/]+/, "/challenges/drafts/:draftId") + .replace( + /^\/challenges\/(?!drafts(?:\/|$))[^/]+/, + "/challenges/:templateId", + ) + .replace(/^\/duels\/[^/]+/, "/duels/:guildId") + .replace( + /^\/duels\/:guildId\/events\/[^/]+/, + "/duels/:guildId/events/:eventId", + ) + .replace( + /^\/duels\/:guildId\/series\/[^/]+/, + "/duels/:guildId/series/:seriesId", + ) + .replace(/^\/g\/[^/]+/, "/g/:guildId") + .replace(/^\/g\/:guildId\/players\/[^/]+/, "/g/:guildId/players/:alias") + .replace( + /\/competitions\/(?!new(?:\/|$))[^/]+/, + "/competitions/:competitionId", + ) + .replace( + /\/reports\/(?!new(?:\/|$)|help(?:\/|$))[^/]+/, + "/reports/:reportId", + ) + .replace(/^\/dares\/(?!settings$)[^/]+/, "/dares/:dareId") + // Share token first, so the conversation rule's lookahead then sees the + // already-templated `s` segment. The token is the share credential — it + // is templated away before anything reaches PostHog. + .replace(/^\/explore\/s\/[^/]+/, "/explore/s/:shareToken") + .replace(/^\/explore\/matches\/[^/]+/, "/explore/matches/:matchId") + .replace( + /^\/explore\/(?!s(?:\/|$)|matches(?:\/|$))[^/]+/, + "/explore/:conversationId", + ); + const knownRoute = + /^(?:\/|\/(?:login|welcome|installed|manage)|\/explore(?:\/(?::conversationId|s\/:shareToken|matches\/:matchId))?|\/players(?:\/:playerId(?:\/matches\/:matchId)?)?|\/champions\/:championId(?:\/:lane\/vs\/:opponentChampionId)?|\/compare\/:left\/:right|\/live(?:\/:riotMatchId)?|\/servers\/:guildId|\/halls\/:guildId|\/challenges(?:\/(?:drafts\/:draftId|:templateId))?|\/clash|\/challenge-runs\/:runId|\/duels\/:guildId(?:\/(?:events\/:eventId(?:\/standings)?|series\/:seriesId|head-to-head))?|\/dares(?:\/(?:settings|:dareId))?|\/g\/:guildId(?:\/(?:access|audit|subscriptions|players(?:\/:alias(?:\/manage)?)?|competitions(?:\/(?:new|:competitionId(?:\/edit)?))?|reports(?:\/(?:new|help|:reportId(?:\/edit)?))?|hall-of-fame)?)?)$/; + return knownRoute.test(normalized) ? normalized : "/not-found"; +} diff --git a/packages/scout-for-lol/packages/app/src/lib/analytics.test.ts b/packages/scout-for-lol/packages/app/src/lib/analytics.test.ts index 9a000c45e9..cfc8e6058d 100644 --- a/packages/scout-for-lol/packages/app/src/lib/analytics.test.ts +++ b/packages/scout-for-lol/packages/app/src/lib/analytics.test.ts @@ -5,7 +5,6 @@ import { analyticsMeta, analyticsPrivacySettings, identifyUser, - normalizePath, resetIdentity, setAnalyticsForTesting, analyticsContextRoute, @@ -22,6 +21,7 @@ import { trackPageview, type AnalyticsConfig, } from "#src/lib/analytics.ts"; +import { normalizePath } from "#src/lib/analytics-path.ts"; type CapturedEvent = { event: string; @@ -177,6 +177,9 @@ describe("normalizePath", () => { ); expect(normalizePath("/champions/22")).toBe("/champions/:championId"); expect(normalizePath("/compare/3/7")).toBe("/compare/:left/:right"); + expect(normalizePath("/champions/103/middle/vs/134")).toBe( + "/champions/:championId/:lane/vs/:opponentChampionId", + ); expect(normalizePath("/live")).toBe("/live"); expect(normalizePath("/live/NA1_5500000777")).toBe("/live/:riotMatchId"); expect(normalizePath("/servers/123")).toBe("/servers/:guildId"); diff --git a/packages/scout-for-lol/packages/app/src/lib/analytics.ts b/packages/scout-for-lol/packages/app/src/lib/analytics.ts index ee282b4d5b..4d62b44616 100644 --- a/packages/scout-for-lol/packages/app/src/lib/analytics.ts +++ b/packages/scout-for-lol/packages/app/src/lib/analytics.ts @@ -5,6 +5,7 @@ import { type AnalyticsProps, type ScoutAnalyticsEvent, } from "#src/lib/analytics-events.ts"; +import { normalizePath } from "#src/lib/analytics-path.ts"; /** * Product analytics for the Scout SPA, backed by PostHog Cloud. @@ -437,61 +438,6 @@ export function stopAnalyticsCapture(): void { client.optOutCapturing(); } -/** - * Collapse dynamic route segments to templates so pageviews group by shape - * instead of exposing guild/report/player identifiers. - */ -export function normalizePath(pathname: string): string { - const normalized = pathname - .replace(/^\/players\/[^/]+/, "/players/:playerId") - .replace( - /^\/players\/:playerId\/matches\/[^/]+/, - "/players/:playerId/matches/:matchId", - ) - .replace(/^\/champions\/[^/]+/, "/champions/:championId") - .replace(/^\/compare\/[^/]+\/[^/]+/, "/compare/:left/:right") - .replace(/^\/live\/[^/]+/, "/live/:riotMatchId") - .replace(/^\/(halls|servers)\/[^/]+/, "/$1/:guildId") - .replace(/^\/challenge-runs\/[^/]+/, "/challenge-runs/:runId") - .replace(/^\/challenges\/drafts\/[^/]+/, "/challenges/drafts/:draftId") - .replace( - /^\/challenges\/(?!drafts(?:\/|$))[^/]+/, - "/challenges/:templateId", - ) - .replace(/^\/duels\/[^/]+/, "/duels/:guildId") - .replace( - /^\/duels\/:guildId\/events\/[^/]+/, - "/duels/:guildId/events/:eventId", - ) - .replace( - /^\/duels\/:guildId\/series\/[^/]+/, - "/duels/:guildId/series/:seriesId", - ) - .replace(/^\/g\/[^/]+/, "/g/:guildId") - .replace(/^\/g\/:guildId\/players\/[^/]+/, "/g/:guildId/players/:alias") - .replace( - /\/competitions\/(?!new(?:\/|$))[^/]+/, - "/competitions/:competitionId", - ) - .replace( - /\/reports\/(?!new(?:\/|$)|help(?:\/|$))[^/]+/, - "/reports/:reportId", - ) - .replace(/^\/dares\/(?!settings$)[^/]+/, "/dares/:dareId") - // Share token first, so the conversation rule's lookahead then sees the - // already-templated `s` segment. The token is the share credential — it - // is templated away before anything reaches PostHog. - .replace(/^\/explore\/s\/[^/]+/, "/explore/s/:shareToken") - .replace(/^\/explore\/matches\/[^/]+/, "/explore/matches/:matchId") - .replace( - /^\/explore\/(?!s(?:\/|$)|matches(?:\/|$))[^/]+/, - "/explore/:conversationId", - ); - const knownRoute = - /^(?:\/|\/(?:login|welcome|installed|manage)|\/explore(?:\/(?::conversationId|s\/:shareToken|matches\/:matchId))?|\/players(?:\/:playerId(?:\/matches\/:matchId)?)?|\/champions\/:championId|\/compare\/:left\/:right|\/live(?:\/:riotMatchId)?|\/servers\/:guildId|\/halls\/:guildId|\/challenges(?:\/(?:drafts\/:draftId|:templateId))?|\/clash|\/challenge-runs\/:runId|\/duels\/:guildId(?:\/(?:events\/:eventId(?:\/standings)?|series\/:seriesId|head-to-head))?|\/dares(?:\/(?:settings|:dareId))?|\/g\/:guildId(?:\/(?:access|audit|subscriptions|players(?:\/:alias(?:\/manage)?)?|competitions(?:\/(?:new|:competitionId(?:\/edit)?))?|reports(?:\/(?:new|help|:reportId(?:\/edit)?))?|hall-of-fame)?)?)$/; - return knownRoute.test(normalized) ? normalized : "/not-found"; -} - function pageUrl(siteDomain: string, normalizedPath: string): string { return `https://${siteDomain}${BASENAME}${normalizedPath}`; } diff --git a/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-fixtures.ts b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-fixtures.ts new file mode 100644 index 0000000000..510fcfbaa9 --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-fixtures.ts @@ -0,0 +1,57 @@ +import { RiotMatchIdSchema } from "@scout-for-lol/data"; +import type { + MatchupData, + MatchupRecentGame, +} from "#src/lib/matchup/matchup-page.ts"; + +export const NOW_MS = Date.UTC(2026, 11, 3, 12); +const DAY_MS = 86_400_000; + +function game( + index: number, + overrides: Partial, +): MatchupRecentGame { + return { + matchId: RiotMatchIdSchema.parse( + `NA1_${(5_500_000_100 + index).toString()}`, + ), + win: true, + playedAtMs: NOW_MS - 2 * DAY_MS, + kills: 8, + deaths: 3, + assists: 7, + at15: "ahead", + lpDelta: 20, + ...overrides, + }; +} + +/** Ahri against Syndra in mid: the viewer won 1 of 5, friends 3 of 8. */ +export function matchupFixture(overrides?: Partial): MatchupData { + return { + status: "available", + champion: { championId: 103, name: "Ahri" }, + opponent: { championId: 134, name: "Syndra" }, + lane: "middle", + you: { games: 5, wins: 1, ahead15: { games: 5, ahead: 1 } }, + friends: { games: 8, wins: 3, ahead15: { games: 7, ahead: 5 } }, + recent: [ + game(1, { + win: false, + kills: 4, + deaths: 5, + assists: 5, + at15: "behind", + lpDelta: -19, + }), + game(2, { playedAtMs: NOW_MS - 9 * DAY_MS }), + game(3, { + win: false, + at15: null, + lpDelta: null, + playedAtMs: NOW_MS - 20 * DAY_MS, + }), + ], + ...overrides, + }; +} diff --git a/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-page.test.ts b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-page.test.ts new file mode 100644 index 0000000000..2aa279e436 --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-page.test.ts @@ -0,0 +1,105 @@ +import { describe, expect, test } from "vitest"; +import { matchupFixture, NOW_MS } from "#src/lib/matchup/matchup-fixtures.ts"; +import { + agoText, + aheadLine, + laneLine, + recentDetail, + recentRow, + recordLead, +} from "#src/lib/matchup/matchup-page.ts"; +import { matchupPath } from "#src/lib/matchup/matchup-path.ts"; + +const DAY_MS = 86_400_000; + +describe("matchupPath", () => { + test("names the champion, the lane and the opponent", () => { + expect(matchupPath(103, 134, "middle")).toBe( + "/champions/103/middle/vs/134", + ); + expect(matchupPath(134, 103, "adc")).toBe("/champions/134/adc/vs/103"); + }); +}); + +describe("laneLine", () => { + test("names the lane the way the rest of Scout does", () => { + expect(laneLine("middle")).toBe("Mid lane"); + expect(laneLine("jungle")).toBe("Jungle lane"); + expect(laneLine("adc")).toBe("ADC lane"); + }); +}); + +describe("agoText", () => { + test.each([ + [0, "today"], + [1, "yesterday"], + [2, "2 days ago"], + [13, "13 days ago"], + [14, "2 weeks ago"], + [59, "8 weeks ago"], + ])("%d days is %s", (days, text) => { + expect(agoText(NOW_MS - days * DAY_MS, NOW_MS)).toBe(text); + }); + + test("a game older than that is dated, so the line stays put", () => { + const played = Date.UTC(2026, 0, 1, 11); + expect(agoText(played, played + 90 * DAY_MS)).toBe("Jan 1, 2026"); + expect(agoText(played, played + 400 * DAY_MS)).toBe("Jan 1, 2026"); + }); + + test("a game from the future reads as today", () => { + expect(agoText(NOW_MS + DAY_MS, NOW_MS)).toBe("today"); + }); +}); + +describe("records", () => { + const matchup = matchupFixture(); + + test("leads with the record and its game count", () => { + expect(recordLead(matchup.you, "you")).toBe("You've won 1 of 5"); + expect(recordLead(matchup.friends, "friends")).toBe( + "Friends have won 3 of 8", + ); + }); + + test("ahead at 15 minutes counts only the games with a 15:00 frame", () => { + expect(aheadLine(matchup.you)).toBe("Ahead at 15 minutes in 1 of 5."); + expect(aheadLine(matchup.friends)).toBe("Ahead at 15 minutes in 5 of 7."); + }); + + test("has no ahead line when no game has a 15:00 frame", () => { + expect( + aheadLine({ games: 3, wins: 2, ahead15: { games: 0, ahead: 0 } }), + ).toBeUndefined(); + }); +}); + +describe("recent games", () => { + const [lost, won, unknown] = matchupFixture().recent; + if (lost === undefined || won === undefined || unknown === undefined) { + throw new Error("The fixture has three recent games"); + } + + test("say when and where the game stood at 15 minutes", () => { + expect(recentDetail(lost, NOW_MS)).toBe("2 days ago, behind at 15 minutes"); + expect(recentDetail(won, NOW_MS)).toBe("9 days ago, ahead at 15 minutes"); + }); + + test("leave out the standing a game has no 15:00 frame for", () => { + expect(recentDetail(unknown, NOW_MS)).toBe("2 weeks ago"); + }); + + test("become a sentence row with the scoreline and LP change", () => { + expect(recentRow(lost, 103, NOW_MS)).toEqual({ + result: "loss", + champion: 103, + kda: { kills: 4, deaths: 5, assists: 5 }, + lpChange: -19, + detail: "2 days ago, behind at 15 minutes", + }); + }); + + test("have no LP change where none is recorded", () => { + expect(recentRow(unknown, 103, NOW_MS)).not.toHaveProperty("lpChange"); + }); +}); diff --git a/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-page.ts b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-page.ts new file mode 100644 index 0000000000..3926dc1ddb --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-page.ts @@ -0,0 +1,74 @@ +import { laneToString, type Lane } from "@scout-for-lol/data"; +import type { GameSentenceRowProps } from "@scout-for-lol/design-system/domain/rows/game-sentence-row"; +import type { RouterOutputs } from "#src/lib/query/trpc.ts"; + +export type MatchupOutput = RouterOutputs["consumerChampion"]["matchup"]; +/** The matchup the lake could answer: its absence is the `unavailable` case. */ +export type MatchupData = Extract; +export type MatchupTally = MatchupData["you"]; +export type MatchupRecentGame = MatchupData["recent"][number]; + +const DAY_MS = 86_400_000; + +/** "Mid lane", "Jungle lane": the one line of context the hero keeps. */ +export function laneLine(lane: Lane): string { + return `${laneToString(lane)} lane`; +} + +/** + * "2 days ago", "3 weeks ago", or the date for a game older than that, so an + * old game's line does not change as the weeks pass. + */ +export function agoText(playedAtMs: number, nowMs: number): string { + const days = Math.max(0, Math.floor((nowMs - playedAtMs) / DAY_MS)); + if (days === 0) return "today"; + if (days === 1) return "yesterday"; + if (days < 14) return `${days.toString()} days ago`; + if (days < 60) return `${Math.floor(days / 7).toString()} weeks ago`; + return new Date(playedAtMs).toLocaleDateString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + }); +} + +/** "Ahead at 15 minutes in 1 of 5": only the games that have a 15:00 frame count. */ +export function aheadLine(tally: MatchupTally): string | undefined { + const { games, ahead } = tally.ahead15; + return games === 0 + ? undefined + : `Ahead at 15 minutes in ${ahead.toString()} of ${games.toString()}.`; +} + +/** "You've won 1 of 5", or "Friends have won 3 of 8". */ +export function recordLead(tally: MatchupTally, who: "you" | "friends") { + const record = `won ${tally.wins.toString()} of ${tally.games.toString()}`; + return who === "you" ? `You've ${record}` : `Friends have ${record}`; +} + +const STANDING_TEXT: Record, string> = { + ahead: "ahead at 15 minutes", + even: "even at 15 minutes", + behind: "behind at 15 minutes", +}; + +/** "2 days ago, behind at 15 minutes"; just the time when there is no 15:00 frame. */ +export function recentDetail(game: MatchupRecentGame, nowMs: number): string { + const ago = agoText(game.playedAtMs, nowMs); + return game.at15 === null ? ago : `${ago}, ${STANDING_TEXT[game.at15]}`; +} + +/** What a game sentence row needs for one of the viewer's games in the matchup. */ +export function recentRow( + game: MatchupRecentGame, + championId: number, + nowMs: number, +): GameSentenceRowProps { + return { + result: game.win ? "win" : "loss", + champion: championId, + kda: { kills: game.kills, deaths: game.deaths, assists: game.assists }, + ...(game.lpDelta === null ? {} : { lpChange: game.lpDelta }), + detail: recentDetail(game, nowMs), + }; +} diff --git a/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-path.ts b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-path.ts new file mode 100644 index 0000000000..65b1e762c3 --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-path.ts @@ -0,0 +1,15 @@ +import type { Lane } from "@scout-for-lol/data"; + +/** + * Where the in-app Matchup page lives: one champion against another in a lane, + * read from the first champion's side. Pages that list a matchup (the Champion + * page's matchup rows, the Live lobby) link here. It mirrors the public site's + * `/champions///vs/`. + */ +export function matchupPath( + championId: number, + opponentChampionId: number, + lane: Lane, +): string { + return `/champions/${championId.toString()}/${lane}/vs/${opponentChampionId.toString()}`; +} diff --git a/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-tips.test.ts b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-tips.test.ts new file mode 100644 index 0000000000..579c610b65 --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-tips.test.ts @@ -0,0 +1,84 @@ +import { describe, expect, test } from "vitest"; +import { + loadChampionTips, + matchupTips, +} from "#src/lib/matchup/matchup-tips.ts"; + +async function sides() { + return { + champion: { + key: "Ahri", + name: "Ahri", + file: await loadChampionTips("Ahri"), + }, + opponent: { key: "Zed", name: "Zed", file: await loadChampionTips("Zed") }, + }; +} + +describe("loadChampionTips", () => { + test("reads a champion's generated file", async () => { + const file = await loadChampionTips("Ahri"); + expect(file?.champion).toBe("Ahri"); + }); + + test("a champion with no file has no tips", async () => { + expect(await loadChampionTips("Syndra")).toBeUndefined(); + }); +}); + +describe("matchupTips", () => { + test("gives the viewer's side and the other side closed", async () => { + const tips = matchupTips({ ...(await sides()), lane: "middle" }); + expect(tips?.tips.length).toBeGreaterThan(0); + expect(tips?.reverse?.label).toBe("Playing Zed into Ahri"); + expect(tips?.reverse?.champion).toBe("Zed"); + expect(tips?.reverse?.tips.length).toBeGreaterThan(0); + }); + + test("reading from the other side swaps them", async () => { + const { champion, opponent } = await sides(); + const tips = matchupTips({ + champion: opponent, + opponent: champion, + lane: "middle", + }); + expect(tips?.reverse?.label).toBe("Playing Ahri into Zed"); + }); + + test("a lane the pair has no set in has no tips", async () => { + expect(matchupTips({ ...(await sides()), lane: "top" })).toBeUndefined(); + }); + + test("a pair with no files has no tips", () => { + expect( + matchupTips({ + champion: { key: "Ahri", name: "Ahri", file: undefined }, + opponent: { key: "Syndra", name: "Syndra", file: undefined }, + lane: "middle", + }), + ).toBeUndefined(); + }); + + test("tips judged wrong and hidden stay off the page", async () => { + const { champion, opponent } = await sides(); + const hidden = champion.file?.matchups + .flatMap((set) => set.tips) + .filter((tip) => tip.hidden === true); + const tips = matchupTips({ champion, opponent, lane: "middle" }); + const shown = [...(tips?.tips ?? []), ...(tips?.reverse?.tips ?? [])]; + for (const tip of hidden ?? []) { + expect(shown.map((candidate) => candidate.id)).not.toContain(tip.id); + } + }); + + test("only the other side having tips still shows the closed row", async () => { + const { champion, opponent } = await sides(); + const only = matchupTips({ + champion: { ...champion, file: undefined }, + opponent, + lane: "middle", + }); + expect(only?.tips).toEqual([]); + expect(only?.reverse?.label).toBe("Playing Zed into Ahri"); + }); +}); diff --git a/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-tips.ts b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-tips.ts new file mode 100644 index 0000000000..1e400c3bf1 --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/lib/matchup/matchup-tips.ts @@ -0,0 +1,83 @@ +import type { Lane } from "@scout-for-lol/data"; +import type { GeneratedTipReverse } from "@scout-for-lol/design-system/domain/tips/generated-tip-list"; +import { + ChampionTipsFileSchema, + type ChampionTipsFile, + type OutputTip, +} from "@scout-for-lol/data/tips/output/champion-tips.ts"; + +/** The tips a matchup shows: the viewer's side, and the other side closed. */ +export type MatchupTips = { + tips: readonly OutputTip[]; + reverse?: GeneratedTipReverse; +}; + +type Side = { + /** Data Dragon key, which names the file and the opponent in the other's. */ + key: string; + name: string; + file: ChampionTipsFile | undefined; +}; + +const files = import.meta.glob<{ default: unknown }>( + "../../../../data/src/tips/generated/champions/*.json", +); +const FILES_PREFIX = "../../../../data/src/tips/generated/champions"; + +/** + * One champion's generated tips file. The matrix is pruned to the champions + * played in a lane, so a champion with no file has no tips: `undefined`, not an + * error. A file that does not match its schema is a broken contract and throws. + */ +export async function loadChampionTips( + key: string, +): Promise { + const load = files[`${FILES_PREFIX}/${key}.json`]; + if (load === undefined) return undefined; + const module = await load(); + const file = ChampionTipsFileSchema.parse(module.default); + if (file.champion !== key) { + throw new Error(`Tips file ${key}.json holds ${file.champion}`); + } + return file; +} + +function sideTips( + side: Side, + opponent: Side, + lane: Lane, +): readonly OutputTip[] { + const set = side.file?.matchups.find( + (candidate) => + candidate.lane === lane && candidate.opponent === opponent.key, + ); + return set === undefined ? [] : set.tips.filter((tip) => tip.hidden !== true); +} + +/** + * The tips for playing `champion` into `opponent` in a lane, with the other + * side's tips beside them. Tips judged wrong and hidden stay out of both. + * Undefined when neither side has a tip to show. + */ +export function matchupTips(options: { + champion: Side; + opponent: Side; + lane: Lane; +}): MatchupTips | undefined { + const { champion, opponent, lane } = options; + const tips = sideTips(champion, opponent, lane); + const reverseTips = sideTips(opponent, champion, lane); + if (tips.length === 0 && reverseTips.length === 0) return undefined; + return { + tips, + ...(reverseTips.length === 0 + ? {} + : { + reverse: { + label: `Playing ${opponent.name} into ${champion.name}`, + champion: opponent.key, + tips: reverseTips, + }, + }), + }; +} diff --git a/packages/scout-for-lol/packages/app/src/lib/routes/matchup-loaders.test.ts b/packages/scout-for-lol/packages/app/src/lib/routes/matchup-loaders.test.ts new file mode 100644 index 0000000000..8c4f89f8a2 --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/lib/routes/matchup-loaders.test.ts @@ -0,0 +1,72 @@ +import { + matchRoutes, + RouterContextProvider, + type LoaderFunctionArgs, +} from "react-router"; +import { afterEach, describe, expect, test, vi } from "vitest"; +import { queryClient } from "#src/lib/query/query-client.ts"; +import { consumerMatchupLoader } from "#src/lib/routes/route-loaders.ts"; +import { routes } from "#src/router.tsx"; + +function loaderArgs(params: Record): LoaderFunctionArgs { + const url = "http://localhost/app/champions/103/middle/vs/134"; + return { + request: new Request(url), + url: new URL(url), + pattern: "/champions/:championId/:lane/vs/:opponentChampionId", + params, + context: new RouterContextProvider(), + }; +} + +afterEach(() => { + vi.restoreAllMocks(); +}); + +describe("matchup loader", () => { + test("warms the one matchup the URL names, and never blocks", () => { + const query = vi.spyOn(queryClient, "query").mockResolvedValue(undefined); + const result = consumerMatchupLoader( + loaderArgs({ + championId: "103", + lane: "middle", + opponentChampionId: "134", + }), + ); + expect(result).toBeNull(); + const keys = query.mock.calls.map((call) => JSON.stringify(call[0])); + expect(keys).toHaveLength(1); + expect(keys[0]).toContain("consumerChampion"); + expect(keys[0]).toContain("matchup"); + expect(keys[0]).toContain('"championId":103'); + expect(keys[0]).toContain('"opponentChampionId":134'); + expect(keys[0]).toContain('"lane":"middle"'); + }); + + test.each([ + { championId: "x", lane: "middle", opponentChampionId: "134" }, + { championId: "103", lane: "mid", opponentChampionId: "134" }, + { championId: "103", lane: "middle", opponentChampionId: "-1" }, + ])("a URL that is not a matchup warms nothing", (params) => { + const query = vi.spyOn(queryClient, "query").mockResolvedValue(undefined); + expect(consumerMatchupLoader(loaderArgs(params))).toBeNull(); + expect(query).not.toHaveBeenCalled(); + }); +}); + +describe("matchup route", () => { + test("is registered under the champion with its loader", () => { + const route = matchRoutes(routes, "/champions/103/middle/vs/134")?.at( + -1, + )?.route; + expect(route?.path).toBe( + "champions/:championId/:lane/vs/:opponentChampionId", + ); + expect(route?.loader).toBe(consumerMatchupLoader); + }); + + test("the champion page keeps its own route", () => { + const route = matchRoutes(routes, "/champions/103")?.at(-1)?.route; + expect(route?.path).toBe("champions/:championId"); + }); +}); diff --git a/packages/scout-for-lol/packages/app/src/lib/routes/route-loaders.ts b/packages/scout-for-lol/packages/app/src/lib/routes/route-loaders.ts index b78ee710b5..61e38fb694 100644 --- a/packages/scout-for-lol/packages/app/src/lib/routes/route-loaders.ts +++ b/packages/scout-for-lol/packages/app/src/lib/routes/route-loaders.ts @@ -7,6 +7,7 @@ import { ReportIdSchema, RiotMatchIdSchema, } from "@scout-for-lol/data"; +import { ConsumerMatchupParamsSchema } from "#src/lib/routes/route-params.ts"; import { queryClient } from "#src/lib/query/query-client.ts"; import { trpcOptions } from "#src/lib/query/trpc-options.ts"; import { STALE_TIME_SLOW_LIST } from "#src/lib/query/stale-times.ts"; @@ -152,6 +153,17 @@ export function consumerLiveGameLoader({ params }: LoaderFunctionArgs): null { return null; } +export function consumerMatchupLoader({ params }: LoaderFunctionArgs): null { + const parsed = ConsumerMatchupParamsSchema.safeParse(params); + if (!parsed.success) return null; + void preloadQuery( + queryClient.query( + trpcOptions.consumerChampion.matchup.queryOptions(parsed.data), + ), + ); + return null; +} + export function consumerServerLoader({ params }: LoaderFunctionArgs): null { const parsed = DiscordGuildIdSchema.safeParse(params["guildId"]); if (!parsed.success) return null; diff --git a/packages/scout-for-lol/packages/app/src/lib/routes/route-params.ts b/packages/scout-for-lol/packages/app/src/lib/routes/route-params.ts index 49318c8f42..b0549d7076 100644 --- a/packages/scout-for-lol/packages/app/src/lib/routes/route-params.ts +++ b/packages/scout-for-lol/packages/app/src/lib/routes/route-params.ts @@ -4,6 +4,7 @@ import { CompetitionIdSchema, ChampionIdSchema, ExploreConversationIdSchema, + LaneSchema, RiotMatchIdSchema, PlayerIdSchema, ReportIdSchema, @@ -39,6 +40,12 @@ export const ConsumerChampionParamsSchema = z.object({ championId: z.coerce.number().pipe(ChampionIdSchema), }); +export const ConsumerMatchupParamsSchema = z.object({ + championId: z.coerce.number().pipe(ChampionIdSchema), + lane: LaneSchema, + opponentChampionId: z.coerce.number().pipe(ChampionIdSchema), +}); + export const ConsumerLiveGameParamsSchema = z.object({ riotMatchId: RiotMatchIdSchema, }); @@ -134,6 +141,12 @@ export function useConsumerChampionParams(): z.infer< return parseRouteParams(ConsumerChampionParamsSchema, useParams()); } +export function useConsumerMatchupParams(): z.infer< + typeof ConsumerMatchupParamsSchema +> { + return parseRouteParams(ConsumerMatchupParamsSchema, useParams()); +} + export function useConsumerLiveGameParams(): z.infer< typeof ConsumerLiveGameParamsSchema > { diff --git a/packages/scout-for-lol/packages/app/src/router.test.ts b/packages/scout-for-lol/packages/app/src/router.test.ts index 66cbd74ea4..96f1e5e5f6 100644 --- a/packages/scout-for-lol/packages/app/src/router.test.ts +++ b/packages/scout-for-lol/packages/app/src/router.test.ts @@ -25,6 +25,7 @@ const KNOWN_URLS = [ "/live", "/live/NA1_5500000777", "/servers/1", + "/champions/103/middle/vs/134", "/halls", "/halls/1", "/challenges", diff --git a/packages/scout-for-lol/packages/app/src/router.tsx b/packages/scout-for-lol/packages/app/src/router.tsx index 507587a811..552962f19b 100644 --- a/packages/scout-for-lol/packages/app/src/router.tsx +++ b/packages/scout-for-lol/packages/app/src/router.tsx @@ -33,6 +33,7 @@ import { ConsumerPlayerSearch } from "#src/routes/consumer/consumer-player-searc import { ConsumerPlayerProfile } from "#src/routes/consumer/consumer-player-profile.tsx"; import { ConsumerChampion } from "#src/routes/consumer/consumer-champion.tsx"; import { ConsumerCompare } from "#src/routes/consumer/consumer-compare.tsx"; +import { ConsumerMatchup } from "#src/routes/consumer/consumer-matchup.tsx"; import { ConsumerLive } from "#src/routes/consumer/consumer-live.tsx"; import { ConsumerLiveGame } from "#src/routes/consumer/consumer-live-game.tsx"; import { ConsumerServer } from "#src/routes/consumer/consumer-server.tsx"; @@ -78,6 +79,7 @@ import { consumerCompareLoader, consumerLiveGameLoader, consumerLiveLoader, + consumerMatchupLoader, consumerPlayerLoader, consumerServerLoader, consumerPlayersLoader, @@ -300,6 +302,12 @@ export const routes: RouteObject[] = [ loader: consumerServerLoader, errorElement: , }, + { + path: "champions/:championId/:lane/vs/:opponentChampionId", + element: , + loader: consumerMatchupLoader, + errorElement: , + }, { path: "champions/:championId", element: , diff --git a/packages/scout-for-lol/packages/app/src/routes/consumer/consumer-matchup.tsx b/packages/scout-for-lol/packages/app/src/routes/consumer/consumer-matchup.tsx new file mode 100644 index 0000000000..1a072bfe58 --- /dev/null +++ b/packages/scout-for-lol/packages/app/src/routes/consumer/consumer-matchup.tsx @@ -0,0 +1,72 @@ +import { getChampionById } from "@scout-for-lol/data"; +import { Loaded } from "@shepherdjerred/loaded"; +import { useQuery } from "@tanstack/react-query"; +import { useEffect, useRef, useState } from "react"; +import { MatchupTipsSection } from "#src/components/matchup/matchup-tips-panel.tsx"; +import { + MatchupGone, + MatchupLoading, + MatchupUnavailable, +} from "#src/components/matchup/matchup-shell.tsx"; +import { + MatchupRecords, + MatchupView, +} from "#src/components/matchup/matchup-view.tsx"; +import { track } from "#src/lib/analytics.ts"; +import { useTRPC } from "#src/lib/query/trpc.ts"; +import { useConsumerMatchupParams } from "#src/lib/routes/route-params.ts"; + +/** One champion against another in a lane: how you and your friends have done. */ +export function ConsumerMatchup() { + const { championId, opponentChampionId, lane } = useConsumerMatchupParams(); + const champion = getChampionById(championId); + const opponent = getChampionById(opponentChampionId); + const trpc = useTRPC(); + const matchup = useQuery( + trpc.consumerChampion.matchup.queryOptions( + { championId, opponentChampionId, lane }, + { enabled: champion !== undefined && opponent !== undefined }, + ), + ); + const [nowMs] = useState(() => Date.now()); + const opened = useRef(false); + useEffect(() => { + if (opened.current || (!matchup.isSuccess && !matchup.isError)) return; + opened.current = true; + track("matchup_page_opened", { + outcome: matchup.isSuccess ? "succeeded" : "failed", + }); + }, [matchup.isError, matchup.isSuccess]); + + // Scope is re-resolved on every read: `strict` drops the retained records + // when a refresh fails, so they never outlive the access behind them. + const loaded = Loaded.strict(Loaded.fromQuery(matchup, ["matchup"])); + if (champion === undefined || opponent === undefined) return ; + const records = + loaded.status === "loading" ? ( + + ) : loaded.status === "error" ? ( + void matchup.refetch()} /> + ) : ( + + ); + return ( + + } + /> + ); +} diff --git a/packages/scout-for-lol/packages/app/src/routes/root-layout.tsx b/packages/scout-for-lol/packages/app/src/routes/root-layout.tsx index 0ad6c2fd53..55e59c3e2b 100644 --- a/packages/scout-for-lol/packages/app/src/routes/root-layout.tsx +++ b/packages/scout-for-lol/packages/app/src/routes/root-layout.tsx @@ -11,13 +11,13 @@ import { } from "#src/components/chrome/version-info.tsx"; import { analyticsContextRoute, - normalizePath, resolvedAnalyticsContextRoute, startAnalyticsCapture, stopAnalyticsCapture, subscribeAnalyticsContext, trackPageview, } from "#src/lib/analytics.ts"; +import { normalizePath } from "#src/lib/analytics-path.ts"; import { useAnalyticsIdentity } from "#src/hooks/use-analytics-identity.ts"; import { FeedbackPrompt } from "#src/components/dialogs/feedback-prompt.tsx"; import { UserMenu } from "#src/components/chrome/user-menu.tsx"; diff --git a/packages/scout-for-lol/packages/design-audit/README.md b/packages/scout-for-lol/packages/design-audit/README.md index d47de2dfc2..0c6ac4d9c7 100644 --- a/packages/scout-for-lol/packages/design-audit/README.md +++ b/packages/scout-for-lol/packages/design-audit/README.md @@ -1,16 +1,16 @@ # Scout design audit -The design audit exercises all 68 shipped Scout public, documentation, and app -routes through a deliberate 774-case matrix. Every route gets all four themes +The design audit exercises all 70 shipped Scout public, documentation, and app +routes through a deliberate 800-case matrix. Every route gets all four themes on Chromium desktop, classic-light responsive coverage on Chromium tablet and -mobile, and modern-light coverage on WebKit desktop and mobile. The 23 visual +mobile, and modern-light coverage on WebKit desktop and mobile. The 24 visual golden routes retain the complete four-theme, four-viewport Chromium matrix. It is read-only: app forms are rendered and keyboard-tested, but no mutation is submitted. -The deduplicated total is 272 all-route Chromium desktop cases, 136 all-route -classic-light Chromium tablet/mobile cases, 230 additional golden-route -Chromium theme/viewport cases, and 136 all-route modern-light WebKit +The deduplicated total is 280 all-route Chromium desktop cases, 140 all-route +classic-light Chromium tablet/mobile cases, 240 additional golden-route +Chromium theme/viewport cases, and 140 all-route modern-light WebKit desktop/mobile cases. Run the deterministic checks locally with: @@ -50,7 +50,7 @@ Chromium and WebKit are the supported browser engines; Firefox is deliberately omitted. `SCOUT_DESIGN_AUDIT_MODE=nightly` selects the scheduled validation boundary but does not expand the browser matrix. When local servers are enabled, as they are -in CI, nightly runs the 774 cases exactly once across 16 sequential shards so +in CI, nightly runs the 800 cases exactly once across 16 sequential shards so each Playwright process stays inside the 16 GiB pod limit and the complete run fits the cluster's 30-minute pod-readiness budget. It uses the same deterministic fixture and needs no external origins or Discord credentials. An explicitly diff --git a/packages/scout-for-lol/packages/design-audit/src/app-routes.ts b/packages/scout-for-lol/packages/design-audit/src/app-routes.ts index 4484984b0e..0aa43ad9eb 100644 --- a/packages/scout-for-lol/packages/design-audit/src/app-routes.ts +++ b/packages/scout-for-lol/packages/design-audit/src/app-routes.ts @@ -257,5 +257,24 @@ export function appRoutes(): AuditRoute[] { authenticated: true, golden: true, }, + // The seeded Ahri against Syndra in mid (backend design-audit champion + // fixture): the viewer's five games and the friends' four, with Ahri's + // generated tips for the pair. + { + name: "matchup-app", + surface: "app", + path: "/app/champions/103/middle/vs/134", + authenticated: true, + golden: true, + }, + // Ahri against Zed: nobody played it, and both sides have generated tips, + // so the other side's closed row shows under them. + { + name: "matchup-app-tips", + surface: "app", + path: "/app/champions/103/middle/vs/238", + authenticated: true, + golden: false, + }, ]; } diff --git a/packages/scout-for-lol/packages/design-audit/src/routes.test.ts b/packages/scout-for-lol/packages/design-audit/src/routes.test.ts index 422597f51d..5cce03583a 100644 --- a/packages/scout-for-lol/packages/design-audit/src/routes.test.ts +++ b/packages/scout-for-lol/packages/design-audit/src/routes.test.ts @@ -34,17 +34,17 @@ describe("Scout design audit matrix", () => { 9, ); expect(routes.filter((route) => route.surface === "docs")).toHaveLength(29); - expect(routes.filter((route) => route.surface === "app")).toHaveLength(30); - expect(routes.filter((route) => route.golden)).toHaveLength(23); + expect(routes.filter((route) => route.surface === "app")).toHaveLength(32); + expect(routes.filter((route) => route.golden)).toHaveLength(24); }); - test("runs exactly the intentional 774 browser cases", () => { + test("runs exactly the intentional 800 browser cases", () => { const cases = auditCases(); const keys = cases.map( ({ project, route, theme }) => `${project.name}/${route.name}/${theme.name}`, ); - expect(cases).toHaveLength(774); + expect(cases).toHaveLength(800); expect(new Set(keys).size).toBe(cases.length); for (const project of auditProjects) { diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-desktop.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-desktop.png new file mode 100644 index 0000000000..c8178501f8 Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-desktop.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-laptop.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-laptop.png new file mode 100644 index 0000000000..2023b95c49 Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-laptop.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-mobile.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-mobile.png new file mode 100644 index 0000000000..2134b390b4 Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-mobile.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-tablet.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-tablet.png new file mode 100644 index 0000000000..4f207826c1 Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-dark-chromium-tablet.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-desktop.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-desktop.png new file mode 100644 index 0000000000..18e6740d3a Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-desktop.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-laptop.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-laptop.png new file mode 100644 index 0000000000..9485dbd3e3 Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-laptop.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-mobile.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-mobile.png new file mode 100644 index 0000000000..39cedef9b9 Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-mobile.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-tablet.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-tablet.png new file mode 100644 index 0000000000..ee374d50b1 Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-classic-light-chromium-tablet.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-desktop.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-desktop.png new file mode 100644 index 0000000000..d1327d6bea Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-desktop.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-laptop.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-laptop.png new file mode 100644 index 0000000000..492cd1485c Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-laptop.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-mobile.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-mobile.png new file mode 100644 index 0000000000..1b895ac89a Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-mobile.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-tablet.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-tablet.png new file mode 100644 index 0000000000..2ae2146455 Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-dark-chromium-tablet.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-desktop.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-desktop.png new file mode 100644 index 0000000000..3ce25bf36c Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-desktop.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-laptop.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-laptop.png new file mode 100644 index 0000000000..e0fd684d81 Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-laptop.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-mobile.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-mobile.png new file mode 100644 index 0000000000..491e4d964e Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-mobile.png differ diff --git a/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-tablet.png b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-tablet.png new file mode 100644 index 0000000000..74f5a7af0b Binary files /dev/null and b/packages/scout-for-lol/packages/design-audit/tests/__screenshots__/design-audit.spec.ts-snapshots/matchup-app-modern-light-chromium-tablet.png differ diff --git a/packages/scout-for-lol/packages/design-system/src/domain/tips/tip-text.tsx b/packages/scout-for-lol/packages/design-system/src/domain/tips/tip-text.tsx index 507648d22e..be9e46ab4e 100644 --- a/packages/scout-for-lol/packages/design-system/src/domain/tips/tip-text.tsx +++ b/packages/scout-for-lol/packages/design-system/src/domain/tips/tip-text.tsx @@ -38,7 +38,9 @@ export type TipTextProps = { /** * One generated sentence with each referenced entity's first mention as a * rich-tooltip trigger: "Charm" opens the ability, "stunned" opens the - * keyword. Later mentions of the same entity in the text are plain text. Must sit + * keyword. Later mentions of the same entity in the text are plain text. A + * reference sits inside a sentence, which WCAG 2.5.8 exempts from the 24px + * target size, so the design audit's small-target check skips it. Must sit * inside a `GameFactProvider`. A span that does not fit the text throws; see * `splitTipText`. */ @@ -57,7 +59,11 @@ export function TipText(props: TipTextProps) { label={segment.text} {...tooltipExtras?.(segment.ref.kind, segment.ref.key)} > -