/** * Testes de caminhos-base da ordem de `clientCasesForListing` (lib/site-content.ts), com a lista de projetos de * cliente trocada por um dublê de `isClientProject`. * * listingRank (CC 2): o id está em `clientListingOrder` (a posição dele) | não está (o fim, depois de todos). O * `sort` é estável: os que não estão na lista ficam na ordem em que `caseStudies` os traz. * Os dados reais só têm os quatro clientes da lista; o caminho do cliente fora da lista só existe aqui. */ const LISTED = ["sev-modaintima", "lavacao-047", "sc-plus", "as-servicos"]; function loadWithClients(clientIds: readonly string[] | "all") { let loaded: typeof import("./site-content") | undefined; jest.isolateModules(() => { jest.doMock("./proof", () => ({ ...jest.requireActual("./proof"), isClientProject: ({ id }: { id: string }) => clientIds === "all" || clientIds.includes(id), })); loaded = require("./site-content"); }); jest.dontMock("./proof"); if (!loaded) throw new Error("site-content não carregou"); return loaded; } describe("clientCasesForListing: ordem", () => { it("path: only listed clients -> the fixed order, the SEV first, whatever order the cases come in", () => { const { clientCasesForListing, clientCases } = loadWithClients(LISTED); expect(clientCasesForListing.map(({ id }) => id)).toEqual(LISTED); expect(clientCasesForListing).toHaveLength(clientCases.length); }); it("path: a client that is not in the order list -> goes after all the listed ones", () => { const { clientCasesForListing, caseStudies } = loadWithClients([ ...LISTED, "gcc-installer", ]); if (!caseStudies.some(({ id }) => id === "gcc-installer")) throw new Error("Missing gcc-installer case"); expect(clientCasesForListing.map(({ id }) => id)).toEqual([ ...LISTED, "gcc-installer", ]); }); it("path: several clients outside the list -> they keep the order of caseStudies among themselves (stable sort)", () => { const { clientCasesForListing, caseStudies } = loadWithClients("all"); const unlisted = clientCasesForListing .map(({ id }) => id) .filter((id) => !LISTED.includes(id)); expect(unlisted.length).toBeGreaterThan(1); expect(unlisted).toEqual( caseStudies.map(({ id }) => id).filter((id) => !LISTED.includes(id)), ); expect( clientCasesForListing.slice(0, LISTED.length).map(({ id }) => id), ).toEqual(LISTED); }); it("path: no client at all -> an empty list, no crash", () => { const { clientCasesForListing } = loadWithClients([]); expect(clientCasesForListing).toEqual([]); }); it("path: the real data -> the SEV is the first client, as in the home showcase", () => { jest.resetModules(); const { clientCasesForListing } = jest.requireActual("./site-content"); expect(clientCasesForListing[0]?.id).toBe("sev-modaintima"); }); });