Skip to content

Commit 6fae209

Browse files
olayinkaadelakunOlayinka Adelakunautofix-ci[bot]
authored
fix(a11y): add accessible names and hide decorative icons in LangflowCounts (#13731)
* fix(a11y): add accessible names and hide decorative icons in LangflowCounts * [autofix.ci] apply automated fixes --------- Co-authored-by: Olayinka Adelakun <olayinkaadelakun@mac.war.can.ibm.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent d36083e commit 6fae209

2 files changed

Lines changed: 81 additions & 4 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { render, screen } from "@testing-library/react";
2+
import { LangflowCounts } from "../langflow-counts";
3+
4+
jest.mock("@/stores/darkStore", () => ({
5+
useDarkStore: (
6+
selector: (s: { stars: number; discordCount: number }) => unknown,
7+
) => selector({ stars: 1234, discordCount: 5678 }),
8+
}));
9+
10+
jest.mock("react-i18next", () => ({
11+
useTranslation: () => ({
12+
t: (key: string) => {
13+
const map: Record<string, string> = {
14+
"header.goToGithub": "Go to GitHub repo",
15+
"header.goToDiscord": "Go to Discord server",
16+
};
17+
return map[key] ?? key;
18+
},
19+
}),
20+
}));
21+
22+
jest.mock("@/components/common/shadTooltipComponent", () => ({
23+
__esModule: true,
24+
default: ({ children }: { children: React.ReactNode }) => <>{children}</>,
25+
}));
26+
27+
jest.mock("@/utils/utils", () => ({
28+
formatNumber: (n: number) => String(n),
29+
cn: (...classes: (string | undefined | null | false)[]) =>
30+
classes.filter(Boolean).join(" "),
31+
}));
32+
33+
jest.mock("@/shared/components/caseComponent", () => ({
34+
Case: ({
35+
condition,
36+
children,
37+
}: {
38+
condition: boolean;
39+
children: React.ReactNode;
40+
}) => (condition ? <>{children}</> : null),
41+
}));
42+
43+
describe("LangflowCounts accessibility", () => {
44+
beforeEach(() => {
45+
render(<LangflowCounts />);
46+
});
47+
48+
it("should_expose_github_button_with_accessible_name", () => {
49+
expect(
50+
screen.getByRole("button", { name: /go to github repo/i }),
51+
).toBeInTheDocument();
52+
});
53+
54+
it("should_expose_discord_button_with_accessible_name", () => {
55+
expect(
56+
screen.getByRole("button", { name: /go to discord server/i }),
57+
).toBeInTheDocument();
58+
});
59+
60+
it("should_hide_github_icon_from_assistive_technology", () => {
61+
const githubButton = screen.getByRole("button", {
62+
name: /go to github repo/i,
63+
});
64+
const svg = githubButton.querySelector("svg");
65+
expect(svg).toHaveAttribute("aria-hidden", "true");
66+
});
67+
68+
it("should_hide_discord_icon_from_assistive_technology", () => {
69+
const discordButton = screen.getByRole("button", {
70+
name: /go to discord server/i,
71+
});
72+
const svg = discordButton.querySelector("svg");
73+
expect(svg).toHaveAttribute("aria-hidden", "true");
74+
});
75+
});

src/frontend/src/components/core/appHeaderComponent/components/langflow-counts.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ export const LangflowCounts = () => {
2727
onClick={() => window.open(GITHUB_URL, "_blank")}
2828
className="hit-area-hover flex items-center gap-2 rounded-md p-1 text-muted-foreground"
2929
>
30+
<span className="sr-only">{t("header.goToGithub")}</span>
3031
<div className="relative items-center rounded-md px-2 py-1 flex">
31-
<FaGithub className="h-4 w-4" />
32+
<FaGithub aria-hidden="true" className="h-4 w-4" />
3233
<Case condition={Boolean(formattedStars) && formattedStars !== "0"}>
33-
<span className="text-xs font-semibold pl-2">
34+
<span className="text-xs font-semibold pl-2" aria-hidden="true">
3435
{formattedStars}
3536
</span>
3637
</Case>
@@ -48,14 +49,15 @@ export const LangflowCounts = () => {
4849
onClick={() => window.open(DISCORD_URL, "_blank")}
4950
className="hit-area-hover flex items-center gap-2 rounded-md p-1 text-muted-foreground"
5051
>
52+
<span className="sr-only">{t("header.goToDiscord")}</span>
5153
<div className="relative items-center rounded-md px-2 py-1 flex">
52-
<FaDiscord className="h-4 w-4" />
54+
<FaDiscord aria-hidden="true" className="h-4 w-4" />
5355
<Case
5456
condition={
5557
Boolean(formattedDiscordCount) && formattedDiscordCount !== "0"
5658
}
5759
>
58-
<span className="text-xs font-semibold pl-2">
60+
<span className="text-xs font-semibold pl-2" aria-hidden="true">
5961
{formattedDiscordCount}
6062
</span>
6163
</Case>

0 commit comments

Comments
 (0)