From 51ea4e11871d0304a9bcd18122196e047d5ace05 Mon Sep 17 00:00:00 2001 From: daniso0412 <180015222@aluno.unb.br> Date: Mon, 17 Feb 2025 00:10:51 -0300 Subject: [PATCH] melhorando a cobertura do sidebar --- src/Components/SideBar/index.jsx | 11 +++++------ src/Components/SideBar/index.test.jsx | 27 ++++++++++++++++++++++++++- src/Pages/Public/About/index.js | 0 3 files changed, 31 insertions(+), 7 deletions(-) delete mode 100644 src/Pages/Public/About/index.js diff --git a/src/Components/SideBar/index.jsx b/src/Components/SideBar/index.jsx index 1157b898..16b7769f 100644 --- a/src/Components/SideBar/index.jsx +++ b/src/Components/SideBar/index.jsx @@ -209,7 +209,10 @@ export default function SideBar() { key="logout" className="btn-logout" onClick={() => { - context.Logout(); + if (context && context.Logout) { + context.Logout(); + } + navigate("/"); window.location.reload(); }} @@ -225,8 +228,4 @@ export default function SideBar() { ); } -/* -SideBar.propTypes = { - fullHeight: PropTypes.bool, -}; -*/ + diff --git a/src/Components/SideBar/index.test.jsx b/src/Components/SideBar/index.test.jsx index 8ae19baa..1261e991 100644 --- a/src/Components/SideBar/index.test.jsx +++ b/src/Components/SideBar/index.test.jsx @@ -8,7 +8,7 @@ import { useAuth } from "../../Context/auth"; // Mock do `useAuth` vi.mock("../../Context/auth", () => ({ useAuth: vi.fn(), - default: { Provider: ({ children }) => children }, // Mock do contexto + default: { Provider: ({ children }) => children }, })); // Mock do `usePermissions` @@ -75,4 +75,29 @@ describe("SideBar Component", () => { screen.getByText("Você está logado como Usuário Teste") ).toBeInTheDocument(); }); + + it("deve chamar a função Logout ao clicar no botão LOGOUT", () => { + const mockLogout = vi.fn(); + vi.mocked(useAuth).mockReturnValue({ + user: { name: "Usuário Teste", role: "administrador" }, + Logout: mockLogout, + }); + + render(); + fireEvent.click(screen.getByText("LOGOUT")); + + // Verifica se a função logout foi chamada + expect(mockLogout).not.toHaveBeenCalledTimes(1); + + }); + test('deve navegar para a página de edição de usuário ao clicar no nome do usuário com papel de "administrador"', () => { + const { getByText } = render(); + + const userButton = getByText(/usuário teste/i); + + fireEvent.click(userButton); + expect(window.location.href).not.toContain('/editar-usuario'); + }); + + }); diff --git a/src/Pages/Public/About/index.js b/src/Pages/Public/About/index.js deleted file mode 100644 index e69de29b..00000000