Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { render, screen } from "@testing-library/react";
import { LangflowCounts } from "../langflow-counts";

jest.mock("@/stores/darkStore", () => ({
useDarkStore: (
selector: (s: { stars: number; discordCount: number }) => unknown,
) => selector({ stars: 1234, discordCount: 5678 }),
}));

jest.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string) => {
const map: Record<string, string> = {
"header.goToGithub": "Go to GitHub repo",
"header.goToDiscord": "Go to Discord server",
};
return map[key] ?? key;
},
}),
}));

jest.mock("@/components/common/shadTooltipComponent", () => ({
__esModule: true,
default: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));

jest.mock("@/utils/utils", () => ({
formatNumber: (n: number) => String(n),
cn: (...classes: (string | undefined | null | false)[]) =>
classes.filter(Boolean).join(" "),
}));

jest.mock("@/shared/components/caseComponent", () => ({
Case: ({
condition,
children,
}: {
condition: boolean;
children: React.ReactNode;
}) => (condition ? <>{children}</> : null),
}));

describe("LangflowCounts accessibility", () => {
beforeEach(() => {
render(<LangflowCounts />);
});

it("should_expose_github_button_with_accessible_name", () => {
expect(
screen.getByRole("button", { name: /go to github repo/i }),
).toBeInTheDocument();
});

it("should_expose_discord_button_with_accessible_name", () => {
expect(
screen.getByRole("button", { name: /go to discord server/i }),
).toBeInTheDocument();
});

it("should_hide_github_icon_from_assistive_technology", () => {
const githubButton = screen.getByRole("button", {
name: /go to github repo/i,
});
const svg = githubButton.querySelector("svg");
expect(svg).toHaveAttribute("aria-hidden", "true");
});

it("should_hide_discord_icon_from_assistive_technology", () => {
const discordButton = screen.getByRole("button", {
name: /go to discord server/i,
});
const svg = discordButton.querySelector("svg");
expect(svg).toHaveAttribute("aria-hidden", "true");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ export const LangflowCounts = () => {
onClick={() => window.open(GITHUB_URL, "_blank")}
className="hit-area-hover flex items-center gap-2 rounded-md p-1 text-muted-foreground"
>
<span className="sr-only">{t("header.goToGithub")}</span>
<div className="relative items-center rounded-md px-2 py-1 flex">
<FaGithub className="h-4 w-4" />
<FaGithub aria-hidden="true" className="h-4 w-4" />
<Case condition={Boolean(formattedStars) && formattedStars !== "0"}>
<span className="text-xs font-semibold pl-2">
<span className="text-xs font-semibold pl-2" aria-hidden="true">
{formattedStars}
</span>
</Case>
Expand All @@ -48,14 +49,15 @@ export const LangflowCounts = () => {
onClick={() => window.open(DISCORD_URL, "_blank")}
className="hit-area-hover flex items-center gap-2 rounded-md p-1 text-muted-foreground"
>
<span className="sr-only">{t("header.goToDiscord")}</span>
<div className="relative items-center rounded-md px-2 py-1 flex">
<FaDiscord className="h-4 w-4" />
<FaDiscord aria-hidden="true" className="h-4 w-4" />
<Case
condition={
Boolean(formattedDiscordCount) && formattedDiscordCount !== "0"
}
>
<span className="text-xs font-semibold pl-2">
<span className="text-xs font-semibold pl-2" aria-hidden="true">
{formattedDiscordCount}
</span>
</Case>
Expand Down
Loading