Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/PlayerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { memo, type CSSProperties } from "react";
import type { Card, StatKey } from "@/lib/scoring/types";
import { countryName } from "@/lib/countries";
import { languageLogoUrl } from "@/lib/github/languages";
import { cardDisplayName } from "@/lib/text";
import { resolveCardTheme } from "./finishTheme";
Expand Down Expand Up @@ -227,7 +228,7 @@ function PlayerCard({ card }: { card: Card }) {
<img
src={`/badges/flags/${card.country}.png`}
onError={hideOnError}
alt={card.country}
alt={countryName(card.country) ?? card.country}
style={{
...at(17.59, 33.17),
width: "14.81%",
Expand Down
20 changes: 20 additions & 0 deletions tests/playerCardAccessibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import PlayerCard from "@/components/PlayerCard";
import { SAMPLE_CARDS } from "@/lib/github/samples";

describe("PlayerCard accessibility", () => {
it.each([
["us", "United States"],
["sct", "Scotland"],
])("labels the %s flag with its country name", (country, expectedName) => {
const html = renderToStaticMarkup(
createElement(PlayerCard, {
card: { ...SAMPLE_CARDS[0], country },
}),
);

expect(html).toContain(`alt="${expectedName}"`);
});
});