From 9b8e335f49dc21e6f11b03b01f26fc24c5d6fe2c Mon Sep 17 00:00:00 2001 From: RodrigoAmaral Date: Sun, 15 Dec 2024 19:22:13 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Cria=C3=A7=C3=A3o=20de=20testes=20para=20a?= =?UTF-8?q?=20pagina=20benefitsValue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Protected/Benefit/BenefitsValue/index.jsx | 2 +- .../Benefit/BenefitsValue/index.test.jsx | 97 +++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/Pages/Protected/Benefit/BenefitsValue/index.test.jsx diff --git a/src/Pages/Protected/Benefit/BenefitsValue/index.jsx b/src/Pages/Protected/Benefit/BenefitsValue/index.jsx index ef9711b..6351cbe 100644 --- a/src/Pages/Protected/Benefit/BenefitsValue/index.jsx +++ b/src/Pages/Protected/Benefit/BenefitsValue/index.jsx @@ -31,7 +31,7 @@ export default function BenefitsValue() {
-

Valores dos benefícios

+

Valores dos benefícios

Benefícios disponíveis

diff --git a/src/Pages/Protected/Benefit/BenefitsValue/index.test.jsx b/src/Pages/Protected/Benefit/BenefitsValue/index.test.jsx new file mode 100644 index 0000000..77b9950 --- /dev/null +++ b/src/Pages/Protected/Benefit/BenefitsValue/index.test.jsx @@ -0,0 +1,97 @@ +import { describe, it, expect, beforeEach, vi, afterEach } from "vitest"; +import { render, screen, fireEvent, waitFor } from "@testing-library/react"; +import { BrowserRouter as Router } from "react-router-dom"; +import BenefitsValue from "./index"; +import { getBenefitsForm } from "../../../../Services/benefitsService"; + +import "@testing-library/jest-dom"; + +vi.mock("../../../../Services/benefitsService"); +vi.mock("../../../../Utils/permission", () => ({ + usePermissions: () => ({ + somePermission: true, + }), + checkAction: () => true, +})); + +describe("BenefitsValue", () => { + beforeEach(() => { + localStorage.setItem("@App:user", JSON.stringify({ token: "mock-token" })); + }); + + afterEach(() => { + vi.clearAllMocks(); + localStorage.clear(); + }); + + it("renders correctly", async () => { + getBenefitsForm.mockResolvedValue([]); + + render( + + + + ); + + expect(screen.getByText("Valores dos benefícios")).toBeInTheDocument(); + expect(screen.getByText("Benefícios disponíveis")).toBeInTheDocument(); + + await waitFor(() => expect(getBenefitsForm).toHaveBeenCalledTimes(1)); + }); + + it("fetches and displays benefits", async () => { + const benefits = [ + { _id: "1", nome: "Benefício 1", descricao: "descrição beneficio 1" }, + { _id: "2", nome: "Benefício 2", descricao: "descrição beneficio 2" }, + ]; + getBenefitsForm.mockResolvedValue(benefits); + + render( + + + + ); + + await waitFor(() => expect(getBenefitsForm).toHaveBeenCalledTimes(1)); + expect(screen.getByText("Benefício 1")).toBeInTheDocument(); + expect(screen.getByText("Benefício 2")).toBeInTheDocument(); + + const detailButtons = screen.getAllByText("Mais Detalhes"); + expect(detailButtons).toHaveLength(benefits.length); + + const valorText = screen.getAllByText("Valor"); + expect(valorText).toHaveLength(benefits.length); + + expect(screen.getByText("Incluso na filiação")).toBeInTheDocument(); + expect(screen.getByText("Disconto de 15%")).toBeInTheDocument(); + }); + + it("exibits benefit details on Mais detalhes click", async () => { + const benefits = [ + { _id: "1", nome: "Benefício 1", descricao: "descrição beneficio 1" }, + { _id: "2", nome: "Benefício 2", descricao: "descrição beneficio 2" }, + ]; + getBenefitsForm.mockResolvedValue(benefits); + + render( + + + + ); + + await waitFor(() => expect(getBenefitsForm).toHaveBeenCalledTimes(1)); + await waitFor(() => { + const detailButtons = screen.getAllByText("Mais Detalhes"); + fireEvent.click(detailButtons[0]); + }); + + expect(screen.getByText("descrição beneficio 1")).toBeInTheDocument(); + + await waitFor(() => { + const detailButtons = screen.getAllByText("Mais Detalhes"); + fireEvent.click(detailButtons[1]); + }); + + expect(screen.getByText("descrição beneficio 2")).toBeInTheDocument(); + }); +}); From fe55f086098115cb86e8319cd3266c93900a3227 Mon Sep 17 00:00:00 2001 From: RodrigoAmaral Date: Sun, 15 Dec 2024 20:14:11 -0300 Subject: [PATCH 2/2] =?UTF-8?q?atualiza=20teste=20da=20p=C3=A1gina=20login?= =?UTF-8?q?Novo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Components/AdvantagesModal/index.jsx | 2 +- src/Pages/Public/LoginNovo/index.test.jsx | 122 +++++++++++++++++++++- 2 files changed, 118 insertions(+), 6 deletions(-) diff --git a/src/Components/AdvantagesModal/index.jsx b/src/Components/AdvantagesModal/index.jsx index 7c0c6d6..8cfed32 100644 --- a/src/Components/AdvantagesModal/index.jsx +++ b/src/Components/AdvantagesModal/index.jsx @@ -7,7 +7,7 @@ export default function AdvantagesModal({ title, description, onClose }) {

{title}

diff --git a/src/Pages/Public/LoginNovo/index.test.jsx b/src/Pages/Public/LoginNovo/index.test.jsx index 29bf9e6..bc905c2 100644 --- a/src/Pages/Public/LoginNovo/index.test.jsx +++ b/src/Pages/Public/LoginNovo/index.test.jsx @@ -1,10 +1,49 @@ import "@testing-library/jest-dom"; -import { render, screen, fireEvent } from "@testing-library/react"; -import { describe, it, expect } from "vitest"; +import { render, screen, fireEvent, waitFor } from "@testing-library/react"; +import { describe, it, expect, vi, afterEach } from "vitest"; import LoginNovo from "./index"; // Substituído Login por LoginNovo import { BrowserRouter } from "react-router-dom"; +import { getBenefitsForm } from "../../../Services/benefitsService"; + +vi.mock("../../../Services/benefitsService"); describe("LoginNovo", () => { + afterEach(() => { + vi.clearAllMocks(); + }); + + it("should render header sentinela image", () => { + render( + + + + ); + + expect(screen.getByAltText("Logo Sentinela")).toBeInTheDocument(); + }); + + it("should render header vantagens and filiar buttons", () => { + render( + + + + ); + + expect(screen.getByText("Vantagens")).toBeInTheDocument(); + expect(screen.getByText("Filiar")).toBeInTheDocument(); + }); + + it("should render body vantagens and filiar buttons", () => { + render( + + + + ); + + expect(screen.getByText("Filiar-me ao sindicato")).toBeInTheDocument(); + expect(screen.getByText("Ver vantagens")).toBeInTheDocument(); + }); + it("should render email and password input fields", () => { render( @@ -39,15 +78,36 @@ describe("LoginNovo", () => { expect(forgotPasswordButton).toBeInTheDocument(); }); - it("should render secondary button with text 'Filiar-me ao sindicato'", () => { + it("should render quero filiar and voltar ao topo buttons", () => { + render( + + + + ); + + expect(screen.getByText("Quero filiar")).toBeInTheDocument(); + expect(screen.getByText("Voltar ao Topo")).toBeInTheDocument(); + }); + + it("fetches and displays benefits", async () => { + const benefits = [ + { _id: "1", nome: "Benefício 1", descricao: "descrição beneficio 1" }, + { _id: "2", nome: "Benefício 2", descricao: "descrição beneficio 2" }, + ]; + getBenefitsForm.mockResolvedValue(benefits); + render( ); - const secondaryButton = screen.getByText("Filiar-me ao sindicato"); - expect(secondaryButton).toBeInTheDocument(); + await waitFor(() => expect(getBenefitsForm).toHaveBeenCalledTimes(1)); + expect(screen.getByText("Benefício 1")).toBeInTheDocument(); + expect(screen.getByText("Benefício 2")).toBeInTheDocument(); + + const detailButtons = screen.getAllByText("Saber mais"); + expect(detailButtons).toHaveLength(benefits.length); }); it("should update email field", () => { @@ -63,6 +123,7 @@ describe("LoginNovo", () => { expect(emailField.value).toBe("test@example.com"); }); + it("should update password field", () => { render( @@ -76,4 +137,55 @@ describe("LoginNovo", () => { expect(passwordField.value).toBe("password123"); }); + + it("modal should be visible after clicking saber mais", async () => { + const benefits = [ + { _id: "1", nome: "Benefício 1", descricao: "descrição beneficio 1" }, + { _id: "2", nome: "Benefício 2", descricao: "descrição beneficio 2" }, + ]; + getBenefitsForm.mockResolvedValue(benefits); + + render( + + + + ); + + await waitFor(() => expect(getBenefitsForm).toHaveBeenCalledTimes(1)); + await waitFor(() => { + const detailButtons = screen.getAllByText("Saber mais"); + fireEvent.click(detailButtons[0]); + }); + + expect(screen.getByText("descrição beneficio 1")).toBeVisible(); + }); + + it("modal should not be visible after clicking on the x", async () => { + const benefits = [ + { _id: "1", nome: "Benefício 1", descricao: "descrição beneficio 1" }, + { _id: "2", nome: "Benefício 2", descricao: "descrição beneficio 2" }, + ]; + getBenefitsForm.mockResolvedValue(benefits); + + render( + + + + ); + + await waitFor(() => expect(getBenefitsForm).toHaveBeenCalledTimes(1)); + await waitFor(() => { + const detailButtons = screen.getAllByText("Saber mais"); + fireEvent.click(detailButtons[0]); + }); + + expect(screen.getByText("descrição beneficio 1")).toBeVisible(); + + await waitFor(() => { + const xButton = screen.getByText("x"); + fireEvent.click(xButton); + }); + + expect(screen.queryByText("descrição beneficio 1")).toBeNull(); + }); });