160 lines
4.4 KiB
TypeScript
160 lines
4.4 KiB
TypeScript
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import type { ReactNode } from "react";
|
|
|
|
import Hero from "./Hero";
|
|
|
|
jest.mock("next/dynamic", () => () => {
|
|
const DynamicComponent = () => <div data-testid="hero-scene" />;
|
|
DynamicComponent.displayName = "MockHeroScene";
|
|
return DynamicComponent;
|
|
});
|
|
|
|
jest.mock("motion/react", () => {
|
|
const React = require("react");
|
|
|
|
const motion = new Proxy(
|
|
{},
|
|
{
|
|
get: (_, tag: string) => {
|
|
const Component = ({
|
|
children,
|
|
initial: _initial,
|
|
animate: _animate,
|
|
whileHover: _whileHover,
|
|
whileTap: _whileTap,
|
|
variants: _variants,
|
|
transition: _transition,
|
|
...props
|
|
}: { children?: ReactNode } & Record<string, unknown>) =>
|
|
React.createElement(tag, props, children);
|
|
Component.displayName = `motion.${tag}`;
|
|
return Component;
|
|
},
|
|
},
|
|
);
|
|
|
|
return {
|
|
AnimatePresence: ({ children }: { children: React.ReactNode }) => children,
|
|
motion,
|
|
useInView: () => true,
|
|
useReducedMotion: () => false,
|
|
useMotionValue: (initial: number) => ({
|
|
get: () => initial,
|
|
set: jest.fn(),
|
|
}),
|
|
useSpring: (
|
|
value: { get: () => number; set: (v: number) => void },
|
|
_config: unknown,
|
|
) => value,
|
|
useTransform: (
|
|
value: { get: () => number; set: (v: number) => void },
|
|
_input: number[],
|
|
_output: number[],
|
|
) => value,
|
|
};
|
|
});
|
|
|
|
jest.mock("cobe", () => ({
|
|
__esModule: true,
|
|
default: jest.fn(() => ({
|
|
destroy: jest.fn(),
|
|
})),
|
|
}));
|
|
|
|
function mockMatchMedia(matches = false) {
|
|
Object.defineProperty(window, "matchMedia", {
|
|
writable: true,
|
|
value: jest.fn().mockImplementation((query) => ({
|
|
matches,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
addEventListener: jest.fn(),
|
|
removeEventListener: jest.fn(),
|
|
dispatchEvent: jest.fn(),
|
|
})),
|
|
});
|
|
}
|
|
|
|
describe("Hero", () => {
|
|
beforeEach(() => {
|
|
mockMatchMedia(false);
|
|
jest.spyOn(window, "open").mockImplementation(() => null);
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
it("renders the published command-center content and primary actions", () => {
|
|
render(<Hero />);
|
|
|
|
expect(
|
|
screen.getByText("Disponível para novas oportunidades"),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.getByRole("heading", {
|
|
level: 1,
|
|
name: "Engenharia de software para sistemas que precisam operar de verdade.",
|
|
}),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.getByRole("button", {
|
|
name: "Conversar sobre uma oportunidade",
|
|
}),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.getByRole("button", { name: "Agendar no WhatsApp" }),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.getByRole("link", { name: "Ver casos selecionados" }),
|
|
).toHaveAttribute("href", "/cases");
|
|
expect(screen.getByRole("link", { name: "Download CV" })).toHaveAttribute(
|
|
"href",
|
|
"/Profile.pdf",
|
|
);
|
|
expect(screen.queryByTestId("hero-scene")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("keeps social destinations, operational proof and WhatsApp action", () => {
|
|
render(<Hero />);
|
|
|
|
expect(screen.getByRole("link", { name: "GitHub" })).toHaveAttribute(
|
|
"href",
|
|
"https://github.com/evandrodevbr",
|
|
);
|
|
expect(screen.getByRole("link", { name: "LinkedIn" })).toHaveAttribute(
|
|
"href",
|
|
"https://www.linkedin.com/in/evandro-fonseca-junior-0969aa1b0/",
|
|
);
|
|
expect(screen.getByRole("link", { name: "Email" })).toHaveAttribute(
|
|
"href",
|
|
"mailto:[email protected]",
|
|
);
|
|
expect(screen.getByText("Garuva, SC / Brasil")).toBeInTheDocument();
|
|
expect(screen.getByText("Operação")).toBeInTheDocument();
|
|
expect(screen.getByText("Clareza")).toBeInTheDocument();
|
|
expect(screen.getByText("Resultado")).toBeInTheDocument();
|
|
expect(
|
|
screen.getByRole("region", {
|
|
name: "Telemetria operacional em tempo real",
|
|
}),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.getByText(/Globo interativo centrado em Joinville/i),
|
|
).toBeInTheDocument();
|
|
|
|
fireEvent.click(
|
|
screen.getByRole("button", {
|
|
name: "Conversar sobre uma oportunidade",
|
|
}),
|
|
);
|
|
expect(window.open).toHaveBeenCalledWith(
|
|
expect.stringContaining("https://wa.me/"),
|
|
"_blank",
|
|
"noopener,noreferrer",
|
|
);
|
|
});
|
|
});
|