From 7e0de77ef598aab99c7fe75d6657e987a9a37346 Mon Sep 17 00:00:00 2001 From: Fernando Jose Gonzalez Sierra <90760906+UO277938@users.noreply.github.com> Date: Thu, 25 Apr 2024 13:08:07 +0200 Subject: [PATCH 1/3] Delete webapp/src/components/Temporizador.test.js --- webapp/src/components/Temporizador.test.js | 49 ---------------------- 1 file changed, 49 deletions(-) delete mode 100644 webapp/src/components/Temporizador.test.js diff --git a/webapp/src/components/Temporizador.test.js b/webapp/src/components/Temporizador.test.js deleted file mode 100644 index 1a22c36..0000000 --- a/webapp/src/components/Temporizador.test.js +++ /dev/null @@ -1,49 +0,0 @@ -import React from 'react'; -import { render, screen, fireEvent } from '@testing-library/react'; -import Temporizador from './Temporizador'; - -describe('Temporizador', () => { - it('renders the initial countdown time', () => { - const tiempoInicial = 60; - render(); - const countdownElement = screen.getByText(tiempoInicial); - expect(countdownElement).toBeInTheDocument(); - }); - - it('decreases countdown time when not paused', () => { - jest.useFakeTimers(); - const tiempoInicial = 60; - render(); - jest.advanceTimersByTime(1000); - const updatedCountdownElement = screen.getByText(tiempoInicial - 1); - expect(updatedCountdownElement).toBeInTheDocument(); - jest.useRealTimers(); - }); - - it('stops countdown time when paused', () => { - jest.useFakeTimers(); - const tiempoInicial = 60; - render(); - jest.advanceTimersByTime(1000); - const updatedCountdownElement = screen.getByText(tiempoInicial); - expect(updatedCountdownElement).toBeInTheDocument(); - jest.useRealTimers(); - }); - - it('restarts countdown time when restart prop changes', () => { - jest.useFakeTimers(); - const tiempoInicial = 60; - const { rerender } = render(); - jest.advanceTimersByTime(1000); - const updatedCountdownElement = screen.getByText(tiempoInicial - 1); - expect(updatedCountdownElement).toBeInTheDocument(); - - // Simulate restart by changing the restart prop - rerender(); - - // Countdown should restart - const restartedCountdownElement = screen.getByText(tiempoInicial); - expect(restartedCountdownElement).toBeInTheDocument(); - jest.useRealTimers(); - }); -}); \ No newline at end of file From 3eefebc4dcb7c3cfe3031bea77e91d2c639f369b Mon Sep 17 00:00:00 2001 From: Fernando Jose Gonzalez Sierra Date: Thu, 25 Apr 2024 13:15:59 +0200 Subject: [PATCH 2/3] Delete App.test.js --- webapp/src/App.test.js | 68 ------------------------------------------ 1 file changed, 68 deletions(-) delete mode 100644 webapp/src/App.test.js diff --git a/webapp/src/App.test.js b/webapp/src/App.test.js deleted file mode 100644 index 0c8f791..0000000 --- a/webapp/src/App.test.js +++ /dev/null @@ -1,68 +0,0 @@ -import { render, screen } from '@testing-library/react'; -import App from './App'; - -/*test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/Welcome to the 2024 edition of the Software Architecture course/i); - expect(linkElement).toBeInTheDocument(); -}); -*/ - -describe('App', () => { - - it('renders login page when not logged in', () => { - render( - - - - ); - - expect(screen.getByText(/Login/i)).toBeInTheDocument(); - }); - - it('renders home page when logged in', () => { - // Mock local storage to simulate being logged in - const mockLocalStorage = { - getItem: jest.fn(() => 'true'), - setItem: jest.fn(), - clear: jest.fn() - }; - global.localStorage = mockLocalStorage; - - render( - - - - ); - - expect(screen.getByText(/Home/i)).toBeInTheDocument(); - }); - - it('redirects to login when trying to access stats page without logging in', () => { - render( - - - - ); - - expect(screen.getByText(/Login/i)).toBeInTheDocument(); - }); - - it('renders stats page when logged in and trying to access stats page', () => { - // Mock local storage to simulate being logged in - const mockLocalStorage = { - getItem: jest.fn(() => 'true'), - setItem: jest.fn(), - clear: jest.fn() - }; - global.localStorage = mockLocalStorage; - - render( - - - - ); - - expect(screen.getByText(/Estadisticas/i)).toBeInTheDocument(); - }); -}); \ No newline at end of file From 1b8efb3e7cf6f8dd5235be7c6092c63050e49aab Mon Sep 17 00:00:00 2001 From: Fernando Jose Gonzalez Sierra Date: Thu, 25 Apr 2024 14:11:48 +0200 Subject: [PATCH 3/3] Arreglos test --- webapp/src/components/Estilos/juego.css | 2 +- webapp/src/components/Pages/Juego.js | 13 +++++++------ webapp/src/components/Pages/Layout.js | 11 +++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/webapp/src/components/Estilos/juego.css b/webapp/src/components/Estilos/juego.css index 60077d6..6642e46 100644 --- a/webapp/src/components/Estilos/juego.css +++ b/webapp/src/components/Estilos/juego.css @@ -1,4 +1,4 @@ -#botonSiguiente{ +#botonSiguiente, #botonFinal{ width: 6em; font-size: 2em; padding: 0.1em; diff --git a/webapp/src/components/Pages/Juego.js b/webapp/src/components/Pages/Juego.js index a7416f4..025cfaf 100644 --- a/webapp/src/components/Pages/Juego.js +++ b/webapp/src/components/Pages/Juego.js @@ -4,7 +4,6 @@ import '../Estilos/juego.css'; import { Container } from '@mui/material'; import Temporizador from '../Temporizador'; import PropTypes from 'prop-types' -import {useNavigate} from 'react-router-dom' const Juego = ({isLogged, username, numPreguntas}) => { //La pregunta (string) @@ -29,7 +28,7 @@ const Juego = ({isLogged, username, numPreguntas}) => { const [numRespuestasIncorrectas, setNumRespuestasIncorrectas] = useState(0) const [disableFinish, setDisableFinish] = useState(false) - const navigate= useNavigate() + //const navigate= useNavigate() //Variables para la obtencion y modificacion de estadisticas del usuario y de preguntas const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; @@ -201,7 +200,6 @@ const Juego = ({isLogged, username, numPreguntas}) => { const clickFinalizar = () => { updateStats(); setDisableFinish(true) - navigate('/') } const handleRestart = () => { @@ -225,9 +223,12 @@ const Juego = ({isLogged, username, numPreguntas}) => { :

CARGANDO...

} {finishGame ? <>

PARTIDA FINALIZADA

-

ACERTADAS: {numRespuestasCorrectas} FALLADAS: {numRespuestasIncorrectas}

- +

ACERTADAS: {numRespuestasCorrectas} FALLADAS: {numRespuestasIncorrectas}

+ : <>} + + { disableFinish ? (

Comience nueva partida o visite sus estadísticas!!

) + : <> } ); }; @@ -235,7 +236,7 @@ const Juego = ({isLogged, username, numPreguntas}) => { Juego.propTypes = { isLogged: PropTypes.bool, username: PropTypes.string, - numPreguntas: PropTypes.number + numPreguntas: PropTypes.number, } diff --git a/webapp/src/components/Pages/Layout.js b/webapp/src/components/Pages/Layout.js index 389cb5d..c15c4a9 100644 --- a/webapp/src/components/Pages/Layout.js +++ b/webapp/src/components/Pages/Layout.js @@ -19,17 +19,16 @@ const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000 WIQ 5A - + { isLogged ? () : + }