From 168ee9a180fd717b039dd770ab2a95d9a5d84140 Mon Sep 17 00:00:00 2001 From: Evandro Fonseca Junior Date: Thu, 8 Oct 2026 10:28:00 -0300 Subject: [PATCH] fix(home): arredondar para baixo o 'Mais de N' dos projetos do GitHub Co-Authored-By: Claude Sonnet 5.5 --- app/components/Hero.test.tsx | 20 ++++++++++++++++++-- app/components/Hero.tsx | 10 ++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/components/Hero.test.tsx b/app/components/Hero.test.tsx index fb6e099..e4c7539 100644 --- a/app/components/Hero.test.tsx +++ b/app/components/Hero.test.tsx @@ -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(); + + expect( + screen.queryByText(/projetos desenvolvidos/i), + ).not.toBeInTheDocument(); + }); + it("omits the repo count when the GitHub lookup is unavailable", () => { render(); diff --git a/app/components/Hero.tsx b/app/components/Hero.tsx index 36b9f6d..0d577e4 100644 --- a/app/components/Hero.tsx +++ b/app/components/Hero.tsx @@ -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 = [ 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`, }