-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: adiciona testes em componentes
- Loading branch information
1 parent
535dbe5
commit 8df43c5
Showing
6 changed files
with
158 additions
and
108 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import "@testing-library/jest-dom"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import { describe, it, expect, vi } from "vitest"; | ||
import AdvantagesCard from "./index"; | ||
|
||
describe("AdvantagesCard", () => { | ||
it("should render the title correctly", () => { | ||
const mockTitle = "Benefícios exclusivos"; | ||
|
||
render(<AdvantagesCard title={mockTitle} onClick={() => {}} />); | ||
|
||
const titleElement = screen.getByText(mockTitle); | ||
expect(titleElement).toBeInTheDocument(); | ||
}); | ||
|
||
it("should call onClick when 'Saber mais' is clicked", () => { | ||
const mockOnClick = vi.fn(); | ||
const mockTitle = "Benefícios exclusivos"; | ||
|
||
render(<AdvantagesCard title={mockTitle} onClick={mockOnClick} />); | ||
|
||
const linkElement = screen.getByText("Saber mais"); | ||
fireEvent.click(linkElement); | ||
|
||
expect(mockOnClick).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should render without crashing when no props are provided", () => { | ||
render(<AdvantagesCard />); | ||
const linkElement = screen.getByText("Saber mais"); | ||
|
||
expect(linkElement).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import "@testing-library/jest-dom"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import { describe, it, expect, vi } from "vitest"; | ||
import AdvantagesModal from "./index"; | ||
|
||
describe("AdvantagesModal", () => { | ||
const mockTitle = "Vantagens do Sindicato"; | ||
const mockDescription = "Este é o detalhamento das vantagens oferecidas."; | ||
const mockOnClose = vi.fn(); | ||
|
||
it("should render the title correctly", () => { | ||
render( | ||
<AdvantagesModal | ||
title={mockTitle} | ||
description={mockDescription} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
const titleElement = screen.getByText(mockTitle); | ||
expect(titleElement).toBeInTheDocument(); | ||
}); | ||
|
||
it("should render the description correctly", () => { | ||
render( | ||
<AdvantagesModal | ||
title={mockTitle} | ||
description={mockDescription} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
const descriptionElement = screen.getByText(mockDescription); | ||
expect(descriptionElement).toBeInTheDocument(); | ||
}); | ||
|
||
it("should call onClose when the close button is clicked", () => { | ||
render( | ||
<AdvantagesModal | ||
title={mockTitle} | ||
description={mockDescription} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
const closeButton = screen.getByText("x"); | ||
fireEvent.click(closeButton); | ||
|
||
expect(mockOnClose).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("should render the contact information", () => { | ||
render( | ||
<AdvantagesModal | ||
title={mockTitle} | ||
description={mockDescription} | ||
onClose={mockOnClose} | ||
/> | ||
); | ||
|
||
const contactInfo = screen.getByText((content) => | ||
content.includes("Para mais informações, entre em contato com o Sindicato pelo número") | ||
); | ||
|
||
const phoneNumber = screen.getByText("(61) 3321-1949"); | ||
|
||
expect(contactInfo).toBeInTheDocument(); | ||
expect(phoneNumber).toBeInTheDocument(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import "@testing-library/jest-dom"; | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; | ||
import ChangePasswordPage from "./index"; | ||
import { MemoryRouter, Route, Routes } from "react-router-dom"; | ||
import { verifyToken } from "../../../Services/userService"; | ||
|
||
// Mock das funções do userService | ||
vi.mock("../../../Services/userService", () => ({ | ||
verifyToken: vi.fn(), | ||
changePasswordById: vi.fn(), | ||
})); | ||
|
||
describe("ChangePasswordPage", () => { | ||
|
||
const renderComponent = (token) => { | ||
render( | ||
<MemoryRouter initialEntries={[`/change-password/${token}`]}> | ||
<Routes> | ||
<Route path="/change-password/:token" element={<ChangePasswordPage />} /> | ||
</Routes> | ||
</MemoryRouter> | ||
); | ||
}; | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
vi.spyOn(window, "alert").mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach(() => { | ||
window.alert.mockRestore(); | ||
}); | ||
|
||
it("should render the expired message when the token is invalid", async () => { | ||
verifyToken.mockRejectedValueOnce(new Error("Token inválido")); | ||
|
||
renderComponent("invalid-token"); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByText("Essa página expirou ou não existe...") | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
expect(verifyToken).toHaveBeenCalledWith("invalid-token"); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.