Skip to content

Commit

Permalink
test: call router.úsh with the right parameters
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Monteiro <[email protected]>
Co-authored-by: Jessica Luiza Silva de Oliveira <[email protected]>
Co-authored-by: Marcella Sanderle <[email protected]>
  • Loading branch information
4 people committed Sep 21, 2024
1 parent 9c07a4b commit bcd4fc0
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/app/__tests__/Publicacao.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import React from "react";
import { render, screen } from "@testing-library/react-native";
import { render, screen, fireEvent } from "@testing-library/react-native";
import Publicacao from "../components/Publicacao";
import { router } from "expo-router";

// Mock do router.push
jest.mock("expo-router", () => ({
router: {
push: jest.fn(),
},
}));

const mockItem = {
id: 1,
Expand All @@ -22,12 +30,28 @@ const mockItemComFoto = {
categoria: "Categoria da publicação",
descricao: "Descrição da publicação",
dataHora: "2023-11-04T12:00:00Z",
idUsuarioReporte: [],
usuario: {
id: 1,
nome: "Nome do Usuário",
foto: "data:image/png;base64,base64-encoded-image-data",
},
};

const mockItemSemFoto = {
id: 1,
titulo: "Título da publicação",
categoria: "Categoria da publicação",
descricao: "Descrição da publicação",
dataHora: "2023-11-04T12:00:00Z",
idUsuarioReporte: [],
usuario: {
id: 1,
nome: "Nome do Usuário",
foto: null, // Sem foto
},
};

const hasFoto = (foto: string | null | undefined) => {
if (!foto) return false;

Expand All @@ -44,4 +68,18 @@ describe("Publicacao", () => {
const usernameElement = screen.getByText("Nome do Usuário");
expect(usernameElement).toBeTruthy();
});

it("deve chamar o router.push com os parâmetros corretos ao clicar na publicação", () => {
render(<Publicacao item={mockItem} crop={true} />);

// Simula o clique na publicação
fireEvent.press(screen.getByText("Título da publicação"));

// Verifique se o router.push foi chamado com os parâmetros esperados
const expectedParams = { ...mockItem, ...mockItem.usuario, id: mockItem.id };
expect(router.push).toHaveBeenCalledWith({
pathname: "/private/pages/visualizarPublicacao",
params: expectedParams,
});
});
});

0 comments on commit bcd4fc0

Please sign in to comment.