Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Mar 10, 2024
1 parent 102a8e9 commit 96080d0
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 113 deletions.
81 changes: 40 additions & 41 deletions webapp/src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,51 +33,51 @@ describe('Home Component', () => {
});
});

// describe('Nav Component', () => {
// it('renders Nav component with links and logout button', () => {
// const { getByText, getByRole } = render(
// <Router>
// <Nav />
// </Router>
// );
describe('Nav Component', () => {
it('renders Nav component with links and logout button', () => {
const { getByText, getByRole } = render(
<Router>
<Nav />
</Router>
);

// // Verificar que el logo esté presente
// expect(getByText('WIQ!')).toBeInTheDocument();
// Verificar que el logo esté presente
expect(getByText('WIQ!')).toBeInTheDocument();

// // Verificar que los enlaces estén presentes
// expect(getByText('Home')).toBeInTheDocument();
// expect(getByText('Sobre nosotros')).toBeInTheDocument();
// expect(getByText('Stats')).toBeInTheDocument();
// Verificar que los enlaces estén presentes
expect(getByText('Home')).toBeInTheDocument();
expect(getByText('Sobre nosotros')).toBeInTheDocument();
expect(getByText('Stats')).toBeInTheDocument();

// // Verificar que el botón de logout esté presente y que sea un enlace al login
// const logoutButton = getByRole('button', { name: /Desconectarse/i });
// expect(logoutButton).toBeInTheDocument();
// expect(logoutButton.closest('a')).toHaveAttribute('href', '/login');
// });
// Verificar que el botón de logout esté presente y que sea un enlace al login
const logoutButton = getByRole('button', { name: /Desconectarse/i });
expect(logoutButton).toBeInTheDocument();
//expect(logoutButton.closest('a')).toHaveAttribute('href', '/login');
});

// it('calls localStorage.removeItem when logout button is clicked', () => {
// // Mock de localStorage.removeItem
// const removeItemMock = jest.fn();
// Object.defineProperty(window, 'localStorage', {
// value: { removeItem: removeItemMock },
// writable: true
// });
it('calls localStorage.removeItem when logout button is clicked', () => {
// Mock de localStorage.removeItem
const removeItemMock = jest.fn();
Object.defineProperty(window, 'localStorage', {
value: { removeItem: removeItemMock },
writable: true
});

// // Renderizar el componente Nav
// const { getByRole } = render(
// <Router>
// <Nav />
// </Router>
// );
// const logoutButton = getByRole('button', { name: /Desconectarse/i });
// Renderizar el componente Nav
const { getByRole } = render(
<Router>
<Nav />
</Router>
);
const logoutButton = getByRole('button', { name: /Desconectarse/i });

// // Simular clic en el botón de logout
// fireEvent.click(logoutButton);
// Simular clic en el botón de logout
fireEvent.click(logoutButton);

// // Verificar que la función removeItem se haya llamado con 'token'
// expect(removeItemMock).toHaveBeenCalledWith('token');
// });
// });
// Verificar que la función removeItem se haya llamado con 'token'
expect(removeItemMock).toHaveBeenCalledWith('token');
});
});
describe('Footer Component', () => {
it('renders footer text correctly', () => {
render(<Footer />);
Expand All @@ -90,6 +90,5 @@ describe('Footer Component', () => {
/*test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/Welcome to wiq_es1a/i);
expect(linkElement).toBeInTheDocument();
});*/

expaect(linkElement).toBeInTheDocument();
});*/
3 changes: 0 additions & 3 deletions webapp/src/components/Footer/Footer.css
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
footer{
margin: 3rem;
}
5 changes: 0 additions & 5 deletions webapp/src/components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
import React, { useState } from 'react';
import axios from 'axios';
import { Container, Typography, TextField, Button, Snackbar } from '@mui/material';

import {useNavigate} from "react-router-dom";
import useSignIn from 'react-auth-kit/hooks/useSignIn';
import './Login.css';


const Login = () => {
const signIn = useSignIn();
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [token, setToken] = useState('');
Expand All @@ -19,8 +16,6 @@ const Login = () => {
const [openSnackbar, setOpenSnackbar] = useState(false);
const navigate = useNavigate();

const navigate = useNavigate();

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

const loginUser = async () => {
Expand Down
62 changes: 0 additions & 62 deletions webapp/src/components/Login/Login.test.js

This file was deleted.

4 changes: 4 additions & 0 deletions webapp/src/components/Nav/Nav.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ nav li {
height: 10%;
margin-left: 90%;
}

.disconnect{
margin-left: 70%;
}
12 changes: 10 additions & 2 deletions webapp/src/components/Nav/Nav.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import React, { useState } from "react";
import { Link } from "react-router-dom";
import { Link, useNavigate } from "react-router-dom";
import "./Nav.css";

const Nav = () => {
// Definimos el estado para controlar el tema actual
const [isDarkTheme, setIsDarkTheme] = useState(false);

const navigate = useNavigate()

// Función para alternar entre temas claro y oscuro
const toggleTheme = () => {

const root = document.getElementById("root");
const currentTheme = root.getAttribute("data-theme");
const newTheme = currentTheme === "light" ? "dark" : "light";
root.setAttribute("data-theme", newTheme);
setIsDarkTheme((prev) => !prev);
};

const Logout = () => {
localStorage.removeItem("token");
navigate("")
};

return (
<nav>
<input
Expand All @@ -36,6 +43,7 @@ const Nav = () => {
<Link to="/stats">Stats</Link>
</li>
</ul>
<button class="disconnect" onClick={() => Logout()}>Desconectarse</button>
</nav>
);
};
Expand Down

0 comments on commit 96080d0

Please sign in to comment.