fix(home): arredondar para baixo o 'Mais de N' dos projetos do GitHub

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
Evandro Fonseca JuniorandClaude Sonnet 5.5 committed 2026-10-08 10:28:00 -03:00
1 parent 0350e7e883
commit 168ee9a180
2 files changed
+26 -4

No files matched your search

+18 -2
View File
@@ -1,7 +1,7 @@
import { fireEvent, render, screen } from "@testing-library/react";
import type { ReactNode } from "react";
import Hero from "./Hero";
import Hero, { roundedRepoFloor } from "./Hero";
jest.mock("motion/react", () => {
const React = require("react");
@@ -87,11 +87,27 @@ describe("Hero", () => {
expect(screen.getByText("projetos desenvolvidos")).toBeInTheDocument();
expect(screen.getByText("Mais de")).toBeInTheDocument();
expect(screen.getByText("68")).toBeInTheDocument();
expect(screen.getByText("65")).toBeInTheDocument();
expect(screen.getByText("25 públicos · 43 privados")).toBeInTheDocument();
expect(screen.queryByText(/projetos publicados/i)).not.toBeInTheDocument();
});
it("rounds the repo count down so 'mais de' is always true", () => {
expect(roundedRepoFloor(68)).toBe(65);
expect(roundedRepoFloor(66)).toBe(65);
expect(roundedRepoFloor(65)).toBe(60);
expect(roundedRepoFloor(6)).toBe(5);
expect(roundedRepoFloor(5)).toBe(0);
});
it("hides the repo count while the total is too small to round", () => {
render(<Hero stats={{ repos: { total: 4, public: 2, private: 2 } }} />);
expect(
screen.queryByText(/projetos desenvolvidos/i),
).not.toBeInTheDocument();
});
it("omits the repo count when the GitHub lookup is unavailable", () => {
render(<Hero stats={{ years: 5 }} />);
+8 -2
View File
@@ -34,17 +34,23 @@ type StatItem = {
detail?: string;
};
/** "Mais de N" só é verdade se N for estritamente menor que o total: arredonda para baixo, em múltiplos de 5. */
export function roundedRepoFloor(total: number) {
return Math.floor((total - 1) / 5) * 5;
}
function statItems(stats?: HeroStats): StatItem[] {
if (!stats) return [];
const { repos } = stats;
const repoFloor = repos ? roundedRepoFloor(repos.total) : 0;
const items: Array<StatItem | null> = [
stats.years
? { value: String(stats.years), label: "anos de experiência" }
: null,
repos && repos.total > 0
repos && repoFloor > 0
? {
prefix: "Mais de",
value: String(repos.total),
value: String(repoFloor),
label: "projetos desenvolvidos",
detail: `${repos.public} públicos · ${repos.private} privados`,
}