feat(cases): mídia no topo, títulos de busca curtos e CreativeWork

Case com mídia ao lado do título e play acessível; problema de cada cliente reescrito com base nos dados; serviços relacionados em 2 cards; FAQ antes do próximo passo e bloco 'Onde já apliquei isso'; Apolo citada em IoT e arquitetura. metaTitle até 43 caracteres e descrições até 155 com teste; JSON-LD CreativeWork; imagens de compartilhamento abaixo de 100 KB; 404 e robots corrigidos; server-only nos módulos com node:.
This commit is contained in:
Evandro Fonseca Junior committed 2026-10-14 14:15:25 -03:00
1 parent c9a0b80656
commit e80f73d075
52 files changed
+2593 -439

No files matched your search

@@ -0,0 +1,67 @@
import { render, screen } from "@testing-library/react";
import { getRelatedServices } from "@/lib/site-content";
import { CaseContactSection } from "./CaseContactSection";
/**
* Testes de caminhos-base de CaseContactSection: o convite de um case de cliente ("projeto parecido") e o de
* um projeto de laboratório ("problema parecido"), o link para a lista de cases e os serviços ligados.
*/
const sev = { id: "sev-modaintima", title: "SEV Moda Íntima" };
const nutri = { id: "nutriscan", title: "NutriScan" };
function messageOf(link: HTMLElement) {
return new URL(link.getAttribute("href") ?? "").searchParams.get("text");
}
describe("CaseContactSection", () => {
it("path: client case -> 'projeto parecido' invitation, WhatsApp with the case title, services listed", () => {
render(<CaseContactSection caseStudy={sev} isClient />);
expect(
screen.getByRole("heading", {
level: 2,
name: "Quer um projeto parecido com este?",
}),
).toBeVisible();
const cta = screen.getByRole("link", {
name: "Conversar sobre um projeto parecido",
});
expect(cta).toHaveAttribute("target", "_blank");
expect(messageOf(cta)).toContain(
`Quero conversar sobre um projeto parecido com o da ${sev.title}.`,
);
expect(getRelatedServices(sev.id).length).toBeGreaterThan(0);
expect(
screen.getAllByRole("link", { name: /^Ver o serviço:/ }).length,
).toBeGreaterThan(0);
expect(
screen.getByRole("link", { name: "Ver outros cases" }),
).toHaveAttribute("href", "/cases");
});
it("path: laboratory case -> 'problema parecido' invitation and no mention of a similar project", () => {
render(<CaseContactSection caseStudy={nutri} isClient={false} />);
expect(
screen.getByRole("heading", { level: 2, name: "Fale sobre o seu caso" }),
).toBeVisible();
const cta = screen.getByRole("link", {
name: "Tem um problema parecido? Vamos conversar.",
});
expect(messageOf(cta)).toContain(
`Quero conversar sobre um problema parecido com o do projeto ${nutri.title}.`,
);
expect(
screen.queryByRole("link", {
name: "Conversar sobre um projeto parecido",
}),
).toBeNull();
// o NutriScan não é citado por nenhum serviço: sem cartões, o convite continua
expect(getRelatedServices(nutri.id)).toHaveLength(0);
expect(screen.queryByRole("link", { name: /^Ver o serviço:/ })).toBeNull();
expect(
screen.getByRole("link", { name: "Ver outros cases" }),
).toBeVisible();
});
});
@@ -0,0 +1,64 @@
import Link from "next/link";
import {
primaryButton,
secondaryButtonDark,
} from "@/app/components/button-styles";
import WhatsAppLink from "@/app/components/WhatsAppLink";
import type { CaseStudyContent } from "@/lib/site-content";
import { CaseRelatedServices } from "./CaseRelatedServices";
/** Textos do convite ao contato: o case de cliente fala de um projeto parecido; o de laboratório, de um problema parecido. */
const contactCopy = {
client: {
title: "Quer um projeto parecido com este?",
action: "Conversar sobre um projeto parecido",
subject: (title: string) => `um projeto parecido com o da ${title}`,
},
lab: {
title: "Fale sobre o seu caso",
action: "Tem um problema parecido? Vamos conversar.",
subject: (title: string) =>
`um problema parecido com o do projeto ${title}`,
},
} as const;
/** Fecho do case: convite ao WhatsApp, volta para a lista de cases e os serviços ligados ao projeto. */
export function CaseContactSection({
caseStudy,
isClient,
}: {
caseStudy: Pick<CaseStudyContent, "id" | "title">;
isClient: boolean;
}) {
const copy = contactCopy[isClient ? "client" : "lab"];
return (
<section
className="ds-section ds-section-dark"
aria-labelledby="case-contact"
>
<div className="ds-section-shell">
<h2 id="case-contact" className="ds-card-title !mt-0 text-white">
{copy.title}
</h2>
<p className="ds-copy max-w-[60ch]">
Conte o que você precisa. A conversa começa direto no WhatsApp, sem
formulário.
</p>
<div className="mt-sp-6 flex flex-wrap items-center gap-sp-3">
<WhatsAppLink
service={copy.subject(caseStudy.title)}
placement="case_detail"
className={primaryButton}
>
{copy.action}
</WhatsAppLink>
<Link href="/cases" className={secondaryButtonDark}>
Ver outros cases
</Link>
</div>
<CaseRelatedServices caseId={caseStudy.id} />
</div>
</section>
);
}
-1
View File
@@ -4,7 +4,6 @@ import {
displayUrl,
} from "@/app/components/showcase/BrowserFrame";
import { getCaseMedia } from "./case-media";
import "../../components/showcase/showcase.css";
/** Capa do case: o pôster do site dentro de uma moldura de navegador. Sem captura gravada, não mostra nada. */
export function CaseCover({
@@ -0,0 +1,102 @@
import { render, screen } from "@testing-library/react";
import { getShowcaseAssets } from "@/lib/project-showcase";
import { CaseCoverLink } from "./CaseCoverLink";
import { getCaseMedia } from "./case-media";
/**
* Testes de caminhos-base de CaseCoverLink: sem captura (nada), com captura (link fora da leitura e do teclado,
* com a capa dentro), os valores padrão de `sizes`, `priority` e `prefetch`, e os valores dados.
*/
jest.mock("./case-media", () => ({ getCaseMedia: jest.fn() }));
jest.mock("next/link", () => ({
__esModule: true,
default: ({
children,
prefetch,
...props
}: { children?: React.ReactNode; prefetch?: boolean | null } & Record<
string,
unknown
>) => (
<a data-prefetch={String(prefetch)} {...props}>
{children}
</a>
),
}));
const mockedGetCaseMedia = jest.mocked(getCaseMedia);
const props = {
id: "sev-modaintima",
title: "SEV Moda Íntima",
demoUrl: "https://sevmodaintima.com.br",
};
afterEach(() => {
mockedGetCaseMedia.mockReset();
});
describe("CaseCoverLink", () => {
it("path: no desktop capture -> renders nothing, not even the link", () => {
mockedGetCaseMedia.mockReturnValue(undefined);
const { container } = render(<CaseCoverLink {...props} />);
expect(container).toBeEmptyDOMElement();
expect(mockedGetCaseMedia).toHaveBeenCalledWith(props.id, "desktop");
});
it("path: capture found -> a link to the case, out of reading order and tab order, around the cover", () => {
mockedGetCaseMedia.mockImplementation(getShowcaseAssets);
const { container } = render(<CaseCoverLink {...props} />);
const link = container.querySelector("a");
expect(link).toHaveAttribute("href", `/cases/${props.id}`);
expect(link).toHaveAttribute("aria-hidden", "true");
expect(link).toHaveAttribute("tabindex", "-1");
expect(link?.querySelector(".ds-bframe-url")).toHaveTextContent(
"sevmodaintima.com.br",
);
expect(
screen.getByAltText(`Captura de tela do site ${props.title}`),
).toBeInTheDocument();
});
it("path: sizes, priority and prefetch omitted -> default sizes, lazy image and the link's own prefetch", () => {
mockedGetCaseMedia.mockImplementation(getShowcaseAssets);
const { container } = render(<CaseCoverLink {...props} />);
const image = screen.getByAltText(`Captura de tela do site ${props.title}`);
expect(image).toHaveAttribute("sizes", "(min-width: 1024px) 560px, 100vw");
expect(image).toHaveAttribute("loading", "lazy");
expect(container.querySelector("a")).toHaveAttribute(
"data-prefetch",
"undefined",
);
});
it("path: sizes, priority and prefetch given -> all of them are used", () => {
mockedGetCaseMedia.mockImplementation(getShowcaseAssets);
const { container } = render(
<CaseCoverLink {...props} sizes="320px" priority prefetch={false} />,
);
const image = screen.getByAltText(`Captura de tela do site ${props.title}`);
expect(image).toHaveAttribute("sizes", "320px");
expect(image).not.toHaveAttribute("loading", "lazy");
expect(container.querySelector("a")).toHaveAttribute(
"data-prefetch",
"false",
);
});
it("path: no demo address -> the browser bar falls back to the project title", () => {
mockedGetCaseMedia.mockImplementation(getShowcaseAssets);
const { container } = render(
<CaseCoverLink id={props.id} title={props.title} demoUrl={null} />,
);
expect(container.querySelector(".ds-bframe-url")).toHaveTextContent(
props.title,
);
});
});
+43
View File
@@ -0,0 +1,43 @@
import Link from "next/link";
import { CaseCover } from "./CaseCover";
import { getCaseMedia } from "./case-media";
/**
* Capa do case dentro de um cartão: a imagem leva ao case, mas fica fora da leitura e da ordem de tabulação,
* porque o link de texto do mesmo cartão já leva ao mesmo lugar. Sem captura gravada, não mostra nada.
*/
export function CaseCoverLink({
id,
title,
demoUrl,
sizes = "(min-width: 1024px) 560px, 100vw",
priority = false,
prefetch,
}: {
id: string;
title: string;
demoUrl?: string | null;
sizes?: string;
priority?: boolean;
prefetch?: boolean;
}) {
if (!getCaseMedia(id, "desktop")) return null;
return (
<Link
href={`/cases/${id}`}
aria-hidden="true"
tabIndex={-1}
prefetch={prefetch}
className="mb-sp-5 block"
>
<CaseCover
id={id}
title={title}
demoUrl={demoUrl}
sizes={sizes}
priority={priority}
/>
</Link>
);
}
@@ -0,0 +1,130 @@
import { render, screen } from "@testing-library/react";
import { getShowcaseAssets } from "@/lib/project-showcase";
import { caseStudies } from "@/lib/site-content";
import { CaseHero } from "./CaseHero";
import { getCaseMedia } from "./case-media";
/**
* Testes de caminhos-base de CaseHero e dos fatos do projeto: com e sem captura gravada, case de cliente e de
* laboratório, e a lista de fatos ausente, vazia ou preenchida. A existência da captura é simulada em getCaseMedia.
*/
jest.mock("./case-media", () => ({ getCaseMedia: jest.fn() }));
const mockedGetCaseMedia = jest.mocked(getCaseMedia);
function getCase(id: string) {
const caseStudy = caseStudies.find((item) => item.id === id);
if (!caseStudy) throw new Error(`Missing case ${id}`);
return caseStudy;
}
const client = getCase("sev-modaintima");
const lab = getCase("twins-lab");
function withCapture(has: boolean) {
mockedGetCaseMedia.mockImplementation((id, device) =>
has ? getShowcaseAssets(id, device) : undefined,
);
}
afterEach(() => {
mockedGetCaseMedia.mockReset();
});
describe("CaseHero: captura gravada e tipo de case", () => {
it("path: client case with a capture -> two columns, the cover on the right, the client eyebrow", () => {
withCapture(true);
const { container } = render(<CaseHero caseStudy={client} isClient />);
expect(container.querySelector(".ds-section-shell")).toHaveClass("grid");
expect(container.querySelector(".ds-bframe")).toBeInTheDocument();
expect(screen.getByText(/Case de cliente/)).toBeVisible();
expect(
screen.getByRole("heading", { level: 1, name: client.headline }),
).toBeVisible();
});
it("path: client case without a capture -> one column and no cover", () => {
withCapture(false);
const { container } = render(<CaseHero caseStudy={client} isClient />);
expect(container.querySelector(".ds-section-shell")).not.toHaveClass(
"grid",
);
expect(container.querySelector(".ds-bframe")).toBeNull();
expect(screen.getByText(client.summary)).toBeVisible();
});
it("path: laboratory case with a capture -> the cover shows, with the laboratory eyebrow", () => {
withCapture(true);
const { container } = render(<CaseHero caseStudy={lab} isClient={false} />);
expect(container.querySelector(".ds-bframe")).toBeInTheDocument();
expect(screen.getByText(/Projeto de laboratório/)).toBeVisible();
expect(screen.queryByText(/Case de cliente/)).toBeNull();
});
it("path: laboratory case without a capture -> one column, laboratory eyebrow, title and summary", () => {
withCapture(false);
const { container } = render(<CaseHero caseStudy={lab} isClient={false} />);
expect(container.querySelector(".ds-section-shell")).not.toHaveClass(
"grid",
);
expect(container.querySelector(".ds-bframe")).toBeNull();
expect(screen.getByText(/Projeto de laboratório/)).toBeVisible();
expect(screen.getByText(lab.summary)).toBeVisible();
});
it("path: breadcrumb -> Início, Cases and the case itself as the current page", () => {
withCapture(false);
render(<CaseHero caseStudy={client} isClient />);
const links = screen.getAllByRole("link");
expect(links.map((link) => link.getAttribute("href"))).toEqual([
"/",
"/cases",
`/cases/${client.id}`,
]);
expect(links[2]).toHaveAttribute("aria-current", "page");
});
});
describe("CaseHero: fatos do projeto", () => {
const withFacts = (facts: string[] | undefined) => ({
...client,
facts,
});
it("path: no facts field -> no list", () => {
withCapture(false);
render(<CaseHero caseStudy={withFacts(undefined)} isClient />);
expect(screen.queryByRole("list", { name: "Fatos do projeto" })).toBeNull();
});
it("path: empty facts list -> no list", () => {
withCapture(false);
render(<CaseHero caseStudy={withFacts([])} isClient />);
expect(screen.queryByRole("list", { name: "Fatos do projeto" })).toBeNull();
});
it("path: filled facts -> one item each, after the summary", () => {
withCapture(false);
render(
<CaseHero
caseStudy={withFacts(["No ar desde 2025", "Dois painéis"])}
isClient
/>,
);
const list = screen.getByRole("list", { name: "Fatos do projeto" });
expect(list.querySelectorAll("li")).toHaveLength(2);
expect(
screen.getByText(client.summary).compareDocumentPosition(list) &
Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
});
});
+86
View File
@@ -0,0 +1,86 @@
import { Breadcrumb } from "@/app/components/Breadcrumb";
import { pageTop } from "@/app/components/button-styles";
import type { CaseStudyContent } from "@/lib/site-content";
import { CaseCover } from "./CaseCover";
import { getCaseMedia } from "./case-media";
/** Fatos verificáveis do projeto. Sem nenhum, a lista não aparece. */
function CaseFacts({ facts }: { facts?: string[] }) {
if (!facts?.length) return null;
return (
<ul
className="mt-sp-5 flex flex-wrap gap-x-sp-6 gap-y-sp-2 text-[15px] leading-6 text-white/80"
aria-label="Fatos do projeto"
>
{facts.map((fact) => (
<li key={fact}>{fact}</li>
))}
</ul>
);
}
/** Pôster do site na coluna da direita (no celular, logo abaixo do título). */
function CaseHeroCover({ caseStudy }: { caseStudy: CaseStudyContent }) {
return (
<div className="min-w-0 lg:col-start-2 lg:row-span-2 lg:row-start-1">
<CaseCover
id={caseStudy.id}
title={caseStudy.title}
demoUrl={caseStudy.demoUrl}
sizes="(min-width: 1024px) 560px, 100vw"
priority
/>
</div>
);
}
/**
* Topo do case: trilha, título, resumo e fatos. Com captura gravada, o texto fica à esquerda e o pôster à direita;
* no celular a mídia vem logo abaixo do título.
*/
export function CaseHero({
caseStudy,
isClient,
}: {
caseStudy: CaseStudyContent;
isClient: boolean;
}) {
const hasMedia = Boolean(getCaseMedia(caseStudy.id, "desktop"));
return (
<section className={`ds-section ds-section-dark ${pageTop}`}>
<div
className={`ds-section-shell ${
hasMedia
? "grid items-center gap-y-sp-6 lg:grid-cols-[minmax(0,1.1fr)_minmax(0,1fr)] lg:gap-x-sp-16 lg:gap-y-0"
: ""
}`}
>
<div className="max-w-[860px] lg:col-start-1 lg:row-start-1 lg:self-end">
<Breadcrumb
items={[
{ label: "Início", href: "/" },
{ label: "Cases", href: "/cases" },
{ label: caseStudy.title, href: `/cases/${caseStudy.id}` },
]}
/>
<p className="ds-eyebrow">
{isClient ? "Case de cliente" : "Projeto de laboratório"} ·{" "}
{caseStudy.title}
</p>
<h1 className="ds-section-title text-balance text-white">
{caseStudy.headline}
</h1>
</div>
{hasMedia ? <CaseHeroCover caseStudy={caseStudy} /> : null}
<div className="max-w-[68ch] lg:col-start-1 lg:row-start-2 lg:self-start">
<p className="ds-copy !text-[rgba(255,255,255,.78)]">
{caseStudy.summary}
</p>
<CaseFacts facts={caseStudy.facts} />
</div>
</div>
</section>
);
}
+48 -9
View File
@@ -1,10 +1,11 @@
import { render, screen } from "@testing-library/react";
import { fireEvent, render, screen } from "@testing-library/react";
import { getShowcaseAssets } from "@/lib/project-showcase";
import { CaseMedia } from "./CaseMedia";
import { getCaseMedia } from "./case-media";
/**
* Testes de caminhos-base de CaseMedia: com computador e celular, só um dos dois, ou nenhum.
* Cada quadro mostra o pôster com um botão de play; o vídeo só aparece depois do clique.
* A existência dos arquivos em disco é simulada em getCaseMedia, para o teste não depender de public/.
*/
@@ -23,8 +24,10 @@ const props = {
title: "SEV Moda Íntima",
demoUrl: "https://sevmodaintima.com.br",
};
const desktopLabel = `Vídeo do site ${props.title} no computador`;
const mobileLabel = `Vídeo do site ${props.title} no celular`;
const desktopPlay = `Reproduzir o vídeo do site ${props.title} no computador`;
const mobilePlay = `Reproduzir o vídeo do site ${props.title} no celular`;
const desktopVideo = `Vídeo do site ${props.title} no computador`;
const mobileVideo = `Vídeo do site ${props.title} no celular`;
afterEach(() => {
mockedGetCaseMedia.mockReset();
@@ -36,10 +39,10 @@ describe("CaseMedia", () => {
const { container } = render(<CaseMedia {...props} />);
expect(container.querySelector(".ds-bframe")).toContainElement(
screen.getByLabelText(desktopLabel),
screen.getByRole("button", { name: desktopPlay }),
);
expect(container.querySelector(".ds-phone")).toContainElement(
screen.getByLabelText(mobileLabel),
screen.getByRole("button", { name: mobilePlay }),
);
expect(container.querySelector(".ds-bframe-url")).toHaveTextContent(
"sevmodaintima.com.br",
@@ -63,8 +66,10 @@ describe("CaseMedia", () => {
withCaptures(["mobile"]);
const { container } = render(<CaseMedia {...props} />);
expect(screen.getByLabelText(mobileLabel)).toBeInTheDocument();
expect(screen.queryByLabelText(desktopLabel)).toBeNull();
expect(
screen.getByRole("button", { name: mobilePlay }),
).toBeInTheDocument();
expect(screen.queryByRole("button", { name: desktopPlay })).toBeNull();
expect(container.querySelector(".ds-bframe")).toBeNull();
expect(container.querySelector(".ds-phone")).not.toBeNull();
expect(screen.queryByText(/no computador\./)).toBeNull();
@@ -74,13 +79,47 @@ describe("CaseMedia", () => {
withCaptures(["desktop"]);
const { container } = render(<CaseMedia {...props} />);
expect(screen.getByLabelText(desktopLabel)).toBeInTheDocument();
expect(screen.queryByLabelText(mobileLabel)).toBeNull();
expect(
screen.getByRole("button", { name: desktopPlay }),
).toBeInTheDocument();
expect(screen.queryByRole("button", { name: mobilePlay })).toBeNull();
expect(container.querySelector(".ds-phone")).toBeNull();
expect(container.querySelector(".ds-bframe")).not.toBeNull();
expect(screen.queryByText("No celular.")).toBeNull();
});
it("path: both captures -> no video until play, then only the pressed frame plays", () => {
withCaptures(["desktop", "mobile"]);
const { container } = render(<CaseMedia {...props} />);
expect(container.querySelector("video")).toBeNull();
// o pôster do computador vem com texto alternativo vazio: o botão já descreve o quadro
expect(container.querySelector(".ds-bframe img")).toHaveAttribute(
"alt",
"",
);
fireEvent.click(screen.getByRole("button", { name: mobilePlay }));
const phone = screen.getByLabelText(mobileVideo);
expect(container.querySelector(".ds-phone")).toContainElement(phone);
expect(phone).toHaveAttribute("poster", `/videos/${props.id}/mobile.webp`);
expect(phone.querySelectorAll("source")).toHaveLength(2);
expect(screen.queryByLabelText(desktopVideo)).toBeNull();
expect(
screen.getByRole("button", { name: desktopPlay }),
).toBeInTheDocument();
expect(container.querySelectorAll("video")).toHaveLength(1);
fireEvent.click(screen.getByRole("button", { name: desktopPlay }));
expect(screen.getByLabelText(desktopVideo)).toHaveAttribute(
"poster",
`/videos/${props.id}/desktop.webp`,
);
expect(container.querySelectorAll("video")).toHaveLength(2);
expect(screen.queryByRole("button")).toBeNull();
});
it("path: no demo address -> the browser bar falls back to the project title", () => {
withCaptures(["desktop"]);
const { container } = render(
+6 -44
View File
@@ -3,43 +3,13 @@ import {
displayUrl,
} from "@/app/components/showcase/BrowserFrame";
import { PhoneFrame } from "@/app/components/showcase/PhoneFrame";
import type { ShowcaseAssets } from "@/lib/project-showcase";
import { CasePlayer } from "./CasePlayer";
import { getCaseMedia } from "./case-media";
import "../../components/showcase/showcase.css";
function CaseVideo({
assets,
label,
className,
}: {
assets: ShowcaseAssets;
label: string;
className: string;
}) {
return (
<video
className={className}
controls
muted
loop
playsInline
preload="none"
poster={assets.poster}
width={assets.width}
height={assets.height}
aria-label={label}
disablePictureInPicture
>
{assets.sources.map((source) => (
<source key={source.src} src={source.src} type={source.type} />
))}
</video>
);
}
/**
* Pôster e vídeo do projeto: o site no computador (moldura de navegador) e no celular (moldura de celular).
* O vídeo só baixa quando a pessoa aperta o play. Sem captura gravada, não mostra nada.
* Cada quadro mostra o pôster com um botão de play; o vídeo só baixa quando a pessoa aperta o botão.
* Sem captura gravada, não mostra nada.
*/
export function CaseMedia({
id,
@@ -55,16 +25,12 @@ export function CaseMedia({
if (!desktop && !mobile) return null;
return (
<div className="mt-sp-8 grid items-end gap-sp-8 md:grid-cols-[minmax(0,1fr)_auto]">
<div className="mt-sp-8 grid max-w-[1040px] items-end gap-sp-8 md:grid-cols-[minmax(0,1fr)_auto]">
{desktop ? (
<figure className="min-w-0">
<BrowserFrame url={displayUrl({ demoUrl, title })}>
<div className="relative aspect-[16/10] bg-[#0a0a0a]">
<CaseVideo
assets={desktop}
label={`Vídeo do site ${title} no computador`}
className="absolute inset-0 h-full w-full object-cover object-top"
/>
<CasePlayer assets={desktop} title={title} device="desktop" />
</div>
</BrowserFrame>
<figcaption className="mt-sp-3 font-[family-name:var(--font-body)] text-[15px] text-white/70">
@@ -75,11 +41,7 @@ export function CaseMedia({
{mobile ? (
<figure className="mx-auto w-[min(62vw,220px)] md:mx-0">
<PhoneFrame poster={mobile.poster}>
<CaseVideo
assets={mobile}
label={`Vídeo do site ${title} no celular`}
className="absolute inset-0 h-full w-full object-cover object-top"
/>
<CasePlayer assets={mobile} title={title} device="mobile" />
</PhoneFrame>
<figcaption className="mt-sp-3 text-center font-[family-name:var(--font-body)] text-[15px] text-white/70">
No celular.
+1 -1
View File
@@ -28,7 +28,7 @@ export function CaseMediaSection({
className="ds-section ds-section-dark"
aria-labelledby="case-media"
>
<div className="ds-section-shell max-w-[960px]">
<div className="ds-section-shell">
<h2 id="case-media" className="ds-card-title !mt-0 text-white">
Como ficou
</h2>
+85
View File
@@ -0,0 +1,85 @@
import { fireEvent, render, screen } from "@testing-library/react";
import { getShowcaseAssets } from "@/lib/project-showcase";
import { CasePlayer } from "./CasePlayer";
const title = "SEV Moda Íntima";
describe("CasePlayer", () => {
it("shows the poster and an accessible play button instead of a paused video", () => {
const { container } = render(
<div className="relative">
<CasePlayer
assets={getShowcaseAssets("sev-modaintima", "desktop")}
title={title}
device="desktop"
/>
</div>,
);
expect(container.querySelector("video")).toBeNull();
// a imagem é decorativa: o botão já diz o que o quadro mostra
const poster = container.querySelector("img");
expect(poster).toHaveAttribute("alt", "");
expect(poster?.getAttribute("src")).toContain(
encodeURIComponent("/videos/sev-modaintima/desktop.webp"),
);
const button = screen.getByRole("button", {
name: `Reproduzir o vídeo do site ${title} no computador`,
});
expect(button).toHaveAttribute("type", "button");
// só botão de contato é limão: o de play é escuro, com contorno branco
expect(button.innerHTML).not.toContain("--slash");
expect(button.querySelector("[aria-hidden='true']")).not.toBeNull();
});
it("mounts the video with its sources only after the click, muted and looping, with focus on it", () => {
const assets = getShowcaseAssets("lavacao-047", "desktop");
render(
<div className="relative">
<CasePlayer assets={assets} title="Lavação 047" device="desktop" />
</div>,
);
fireEvent.click(screen.getByRole("button"));
const video = screen.getByLabelText(
"Vídeo do site Lavação 047 no computador",
);
expect(video).toHaveFocus();
expect(video).toHaveAttribute("controls");
expect(video).toHaveAttribute("poster", assets.poster);
expect(video).toHaveAttribute("width", String(assets.width));
expect(video).toHaveAttribute("height", String(assets.height));
expect((video as HTMLVideoElement).muted).toBe(true);
expect((video as HTMLVideoElement).loop).toBe(true);
expect(
[...video.querySelectorAll("source")].map((source) => [
source.getAttribute("src"),
source.getAttribute("type"),
]),
).toEqual(assets.sources.map(({ src, type }) => [src, type]));
expect(screen.queryByRole("button")).toBeNull();
});
it("leaves the poster to the phone frame on mobile and names the device in the labels", () => {
const { container } = render(
<div className="relative">
<CasePlayer
assets={getShowcaseAssets("sc-plus", "mobile")}
title="SC Plus Aquicultura"
device="mobile"
/>
</div>,
);
expect(container.querySelector("img")).toBeNull();
fireEvent.click(
screen.getByRole("button", {
name: "Reproduzir o vídeo do site SC Plus Aquicultura no celular",
}),
);
expect(
screen.getByLabelText("Vídeo do site SC Plus Aquicultura no celular"),
).toHaveAttribute("poster", "/videos/sc-plus/mobile.webp");
});
});
+88
View File
@@ -0,0 +1,88 @@
"use client";
import { Play } from "lucide-react";
import Image from "next/image";
import { useEffect, useRef, useState } from "react";
import type { Device, ShowcaseAssets } from "@/lib/project-showcase";
const deviceLabel: Record<Device, string> = {
desktop: "no computador",
mobile: "no celular",
};
/**
* Pôster com um botão de play. O vídeo só é montado, e só baixa, quando a pessoa aperta o botão:
* antes disso a página mostra a imagem do site, não um vídeo parado em 0:00 com controles do navegador.
* Vai dentro de um quadro com `position: relative` (moldura de navegador ou de celular) que dá o tamanho.
*/
export function CasePlayer({
assets,
title,
device,
sizes = "(min-width: 1280px) 900px, 100vw",
}: {
assets: ShowcaseAssets;
title: string;
device: Device;
sizes?: string;
}) {
const [playing, setPlaying] = useState(false);
const videoRef = useRef<HTMLVideoElement>(null);
// o botão sai de cena ao tocar: o foco vai para o vídeo, para quem usa o teclado não o perder
useEffect(() => {
if (playing) videoRef.current?.focus();
}, [playing]);
if (playing) {
return (
<video
ref={videoRef}
className="absolute inset-0 h-full w-full object-cover object-top"
autoPlay
controls
muted
loop
playsInline
poster={assets.poster}
width={assets.width}
height={assets.height}
tabIndex={0}
aria-label={`Vídeo do site ${title} ${deviceLabel[device]}`}
disablePictureInPicture
>
{assets.sources.map((source) => (
<source key={source.src} src={source.src} type={source.type} />
))}
</video>
);
}
return (
<>
{/* o quadro do celular já mostra o pôster como fundo; no computador a imagem entra aqui */}
{device === "desktop" ? (
<Image
src={assets.poster}
alt=""
fill
sizes={sizes}
className="object-cover object-top"
/>
) : null}
<button
type="button"
onClick={() => setPlaying(true)}
aria-label={`Reproduzir o vídeo do site ${title} ${deviceLabel[device]}`}
className="group absolute inset-0 grid place-items-center focus-visible:outline-2 focus-visible:-outline-offset-4 focus-visible:outline-white"
>
<span
aria-hidden="true"
className="grid size-14 place-items-center rounded-full border border-white/70 bg-black/65 text-white transition-colors group-hover:bg-black/85 motion-reduce:transition-none sm:size-16"
>
<Play className="ml-1 size-6" fill="currentColor" />
</span>
</button>
</>
);
}
+24 -13
View File
@@ -1,23 +1,34 @@
import Link from "next/link";
import { textLink } from "@/app/components/button-styles";
import { textLinkDark } from "@/app/components/button-styles";
import { getRelatedServices } from "@/lib/site-content";
/** Links para os serviços que citam este case. Sem serviço relacionado, não mostra nada. */
/** Quantos serviços aparecem no fim do case: dois cards bastam para levar a pessoa ao serviço certo sem virar um menu. */
export const MAX_RELATED_SERVICES = 2;
/** Cards dos serviços que citam este case (no máximo dois), sobre fundo escuro. Sem serviço relacionado, não mostra nada. */
export function CaseRelatedServices({ caseId }: { caseId: string }) {
const services = getRelatedServices(caseId);
const services = getRelatedServices(caseId).slice(0, MAX_RELATED_SERVICES);
if (services.length === 0) return null;
return (
<div className="mt-sp-6 flex flex-wrap gap-x-sp-6">
{services.map((service) => (
<Link
key={service.slug}
className={textLink}
href={`/servicos/${service.slug}`}
>
Ver serviço relacionado: {service.navLabel}
</Link>
))}
<div className="mt-sp-10">
<p className="ds-kicker">Serviços ligados a este projeto</p>
<ul className="mt-sp-4 grid gap-sp-4 md:grid-cols-2">
{services.map((service) => (
<li key={service.slug} className="flex">
<article className="ds-card w-full">
<h3 className="ds-card-title !mt-0">{service.navLabel}</h3>
<p className="ds-copy">{service.intro}</p>
<Link
className={`${textLinkDark} mt-sp-4 self-start`}
href={`/servicos/${service.slug}`}
>
Ver o serviço: {service.navLabel}
</Link>
</article>
</li>
))}
</ul>
</div>
);
}
+2 -2
View File
@@ -4,11 +4,11 @@ export function CaseResultSection({ result }: { result?: string[] }) {
return (
<section className="ds-section" aria-labelledby="case-result">
<div className="ds-section-shell max-w-[960px]">
<div className="ds-section-shell">
<h2 id="case-result" className="ds-card-title !mt-0">
Resultado
</h2>
<ul className="ds-list space-y-sp-3 pl-[1.15rem]">
<ul className="ds-list max-w-[78ch] space-y-sp-3 pl-[1.15rem]">
{result.map((item) => (
<li key={item}>{item}</li>
))}
+1
View File
@@ -1,3 +1,4 @@
import "server-only";
import { existsSync } from "node:fs";
import { join } from "node:path";
import {