Skip to content

Commit

Permalink
fix: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
clara-ribeiro committed Dec 17, 2024
1 parent 720b12a commit 2c8130a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/Components/Checkfield/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ describe("CheckField Component", () => {
});

it("should update the state when 'checked' prop changes", () => {
const { rerender } = render(<CheckField label="Test Label" checked={false} />);
const { rerender } = render(
<CheckField label="Test Label" checked={false} />
);

const checkbox = screen.getByRole("checkbox");
expect(checkbox).not.toBeChecked();
Expand Down
34 changes: 24 additions & 10 deletions src/Components/Checklist/index.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import "@testing-library/jest-dom";
import { render, screen, fireEvent, waitFor, within } from "@testing-library/react";
import {
render,
screen,
fireEvent,
waitFor,
within,
} from "@testing-library/react";
import { describe, it, expect, vi, beforeEach } from "vitest";
import CheckList from "./index";

Expand Down Expand Up @@ -65,7 +71,9 @@ describe("CheckList Component", () => {
});

it("should render the list of items correctly", () => {
render(<CheckList items={items} value={selectedValues} onChange={mockOnChange} />);
render(
<CheckList items={items} value={selectedValues} onChange={mockOnChange} />
);

expect(screen.getByText("John Doe")).toBeInTheDocument();
expect(screen.getByText("Jane Doe")).toBeInTheDocument();
Expand All @@ -77,7 +85,9 @@ describe("CheckList Component", () => {
});

it("should call onChange with updated values when a checkbox is clicked", () => {
render(<CheckList items={items} value={selectedValues} onChange={mockOnChange} />);
render(
<CheckList items={items} value={selectedValues} onChange={mockOnChange} />
);

const secondCheckbox = screen.getAllByRole("checkbox")[1];
fireEvent.click(secondCheckbox);
Expand All @@ -86,15 +96,17 @@ describe("CheckList Component", () => {
});

it("should open the modal and display user details when an item is clicked", async () => {
render(<CheckList items={items} value={selectedValues} onChange={mockOnChange} />);

render(
<CheckList items={items} value={selectedValues} onChange={mockOnChange} />
);

fireEvent.click(screen.getByText("John Doe"));

const modal = screen.getByTestId("big-modal");
expect(modal).toBeVisible();

const modalContent = within(modal);

expect(modalContent.getByText("Nome:")).toBeInTheDocument();
expect(modalContent.getByText("John Doe")).toBeInTheDocument();
expect(modalContent.getByText("Email:")).toBeInTheDocument();
Expand All @@ -103,10 +115,12 @@ describe("CheckList Component", () => {
expect(modalContent.getByText("Christian")).toBeInTheDocument();
expect(modalContent.getByText("Dependentes:")).toBeInTheDocument();
expect(modalContent.getByText("2")).toBeInTheDocument();
});
});

it("should close the modal when the close button is clicked", async () => {
render(<CheckList items={items} value={selectedValues} onChange={mockOnChange} />);
render(
<CheckList items={items} value={selectedValues} onChange={mockOnChange} />
);

fireEvent.click(screen.getByText("John Doe"));
const modal = screen.getByTestId("big-modal");
Expand Down
12 changes: 9 additions & 3 deletions src/Components/Footer/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ describe("Footer Component", () => {
render(<Footer />);

expect(
screen.getByText("Copyright © 2024 • Sindpol-DF • CNPJ 11.236.674/0001-06")
screen.getByText(
"Copyright © 2024 • Sindpol-DF • CNPJ 11.236.674/0001-06"
)
).toBeInTheDocument();

expect(
screen.getByText("Setor de Diversões Sul (SDS), Conjunto Baracat Bloco F 27, Salas 313/315 • Asa Sul")
screen.getByText(
"Setor de Diversões Sul (SDS), Conjunto Baracat Bloco F 27, Salas 313/315 • Asa Sul"
)
).toBeInTheDocument();

expect(screen.getByText("Brasília/DF • CEP 70392-900")).toBeInTheDocument();
Expand All @@ -40,7 +44,9 @@ describe("Footer Component", () => {
const links = screen.getAllByRole("link");

expectedLinks.forEach((expectedHref) => {
const link = links.find((link) => link.getAttribute("href") === expectedHref);
const link = links.find(
(link) => link.getAttribute("href") === expectedHref
);
expect(link).toBeInTheDocument();
});

Expand Down
14 changes: 8 additions & 6 deletions src/Components/SideBar/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ describe("SideBar Component", () => {
const mockUser = { name: "John Doe", role: "admin" };
renderSideBar(mockUser);

expect(screen.getByText("Você está logado como John Doe")).toBeInTheDocument();
expect(
screen.getByText("Você está logado como John Doe")
).toBeInTheDocument();
});

it("should call Logout and navigate to '/' on logout", () => {
Expand Down Expand Up @@ -98,16 +100,16 @@ describe("SideBar Component", () => {

it("should hide restricted buttons if user has no permissions", () => {
usePermissions.mockReturnValue([]);

renderSideBar();

const menuIcon = screen.getAllByRole("button")[0];
fireEvent.click(menuIcon);

const cadastrosButton = screen.getByText("CADASTROS");
expect(cadastrosButton).toBeInTheDocument();

const beneficiosButton = screen.getByText("BENEFÍCIOS");
expect(beneficiosButton).toBeInTheDocument();
});
});
});
8 changes: 6 additions & 2 deletions src/Components/SideButton/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ describe("SideButton Component", () => {
});

it("should hide the button when 'hidden' prop is set to 'none'", () => {
render(<SideButton text="Hidden Button" hidden="none" onClick={() => {}} />);
render(
<SideButton text="Hidden Button" hidden="none" onClick={() => {}} />
);

const button = screen.queryByRole("button", { name: "Hidden Button" });
expect(button).not.toBeInTheDocument();
});

it("should show the button when 'hidden' prop is set to 'flex'", () => {
render(<SideButton text="Visible Button" hidden="flex" onClick={() => {}} />);
render(
<SideButton text="Visible Button" hidden="flex" onClick={() => {}} />
);

const button = screen.getByRole("button", { name: "Visible Button" });
expect(button).toBeInTheDocument();
Expand Down
5 changes: 2 additions & 3 deletions src/Pages/Protected/Carteirinha/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Carteirinha from "./index";
import html2canvas from "html2canvas";
import { jsPDF } from "jspdf";


vi.mock("html2canvas", () => ({
default: vi.fn().mockResolvedValue({
toDataURL: () => "data:image/png;base64,mockImage",
Expand Down Expand Up @@ -53,15 +52,15 @@ describe("Carteirinha Component", () => {

it("should render membership data correctly", async () => {
render(<Carteirinha />);

await waitFor(() => {

Check failure on line 56 in src/Pages/Protected/Carteirinha/index.test.jsx

View workflow job for this annotation

GitHub Actions / test

src/Pages/Protected/Carteirinha/index.test.jsx > Carteirinha Component > should render membership data correctly

TestingLibraryElementError: Unable to find an element with the text: 12/31/1989. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible. Ignored nodes: comments, script, style <body> <div> <div class="carteirinha-container" > <div class="carteirinha" > <header class="carteirinha-header" > <h1> SINDPOL-DF </h1> <p> SINDICATO DOS POLICIAIS PENAIS DO DISTRITO FEDERAL </p> </header> <div class="info-and-badge" > <div class="carteirinha-info" > <div class="info-line" > <div class="info-block" > <strong> TITULAR: </strong> <br /> <p class="info-color-titular" /> <p class="info-color-titular" > <span> John Doe </span> </p> </div> </div> <div class="info-line" > <div class="info-block" > <strong> DATA DE NASCIMENTO: </strong> <br /> <p class="info-color" /> <p class="info-color" > <span> 1/1/1990 </span> </p> </div> <div class="info-block" > <strong> DATA DE EXPEDIÇÃO: </strong> <br /> <p class="info-color" /> <p class="info-color" > <span> 8/1/2023 </span> </p> </div> </div> <div class="info-line" > <div class="info-block" > <strong> CPF: </strong> <br /> <p class="info-color" /> <p class="info-color" > <span> 123.456.789-00 </span> </p> </div> <div class="info-block" > <strong> CONTRATAÇÃO: </strong> <br /> <p class="info-color" /> <p class="info-color" > <span> 6/15/2022 </span> </p> </div> </div> </div> <div class="badge-section" > <img alt="Sindicalizado Badge" class="badge-logo" src="/src/assets/sindpol-logo.png" /> <p class="Sind" > SINDICALIZADO </p> </div> </div> </div> <div class="carteirinha" > <footer class="carteirinha-footer" > <p> Setor de Diversões Sul (SDS), Conjunto Baracat, Bloco F, 27, Salas 313/315, Asa Sul, Brasília/DF, CEP 70392-900 </p> </footer> <div class="qr-section" > <div class="qr-code" > <svg height="170" viewBox="0 0 29 29"
expect(screen.getByText("John Doe")).toBeInTheDocument();
expect(screen.getByText("12/31/1989")).toBeInTheDocument(); // Data de nascimento
expect(screen.getByText("7/31/2023")).toBeInTheDocument(); // Data de expedição
expect(screen.getByText("6/14/2022")).toBeInTheDocument(); // Data de contratação
expect(screen.getByText("123.456.789-00")).toBeInTheDocument(); // CPF
});
});
});

it("should call downloadPDF when clicking on 'BAIXAR CARTEIRINHA' button", async () => {
const mockSave = vi.fn();
Expand Down

0 comments on commit 2c8130a

Please sign in to comment.