Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

melhorando a cobertura do sidebar #57

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Components/SideBar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}}
Expand All @@ -225,8 +228,4 @@ export default function SideBar() {
</>
);
}
/*
SideBar.propTypes = {
fullHeight: PropTypes.bool,
};
*/

27 changes: 26 additions & 1 deletion src/Components/SideBar/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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(<SideBar logout={mockLogout} />);
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(<SideBar />);

const userButton = getByText(/usuário teste/i);

fireEvent.click(userButton);
expect(window.location.href).not.toContain('/editar-usuario');
});


});
Empty file removed src/Pages/Public/About/index.js
Empty file.
Loading