From 37ab627d50c85f62be368d06e950cb8997bfdab7 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Tue, 2 Apr 2024 16:28:23 +0200 Subject: [PATCH 1/2] Cambio de estilo en botones del modal --- webapp/src/components/CustomModal/CustomModal.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/CustomModal/CustomModal.js b/webapp/src/components/CustomModal/CustomModal.js index 987c473e..15b71334 100644 --- a/webapp/src/components/CustomModal/CustomModal.js +++ b/webapp/src/components/CustomModal/CustomModal.js @@ -21,10 +21,10 @@ const CustomModal = ({ title, text, route }) => { - - + From af96cb8eb71b3c229a7bec8a912319569a964cda Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Tue, 2 Apr 2024 17:29:41 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Aumentado=20coverage=20de=20los=20tests=20d?= =?UTF-8?q?el=20modo=20cl=C3=A1sico?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/src/components/Preguntas.js | 20 -------- webapp/src/components/Stats.js | 21 -------- webapp/src/pages/Clasico/Clasico.test.js | 65 ++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 45 deletions(-) delete mode 100644 webapp/src/components/Preguntas.js delete mode 100644 webapp/src/components/Stats.js diff --git a/webapp/src/components/Preguntas.js b/webapp/src/components/Preguntas.js deleted file mode 100644 index 99a0cfdd..00000000 --- a/webapp/src/components/Preguntas.js +++ /dev/null @@ -1,20 +0,0 @@ -const axios = require('axios'); - -// Definir la función para realizar la solicitud -async function fetchQuestions() { - const url = 'http://localhost:8003/questions'; - const params = { - tematica: 'all', - n: 100 - }; - - try { - const response = await axios.get(url, { params }); - return response.data; - } catch (error) { - throw new Error('Error al obtener las preguntas:', error); - } -} - -// Exportar la función -module.exports = { fetchQuestions }; diff --git a/webapp/src/components/Stats.js b/webapp/src/components/Stats.js deleted file mode 100644 index 1c47483f..00000000 --- a/webapp/src/components/Stats.js +++ /dev/null @@ -1,21 +0,0 @@ -const axios = require('axios'); - -// Definir la función para realizar la solicitud -async function fetchStats() { - const username = localStorage.getItem('username'); - const url = 'http://localhost:8004/stats'; - const params = { - user: username, - gamemode: "clasico" - }; - - try { - const response = await axios.get(url, { params }); - return response.data; - } catch (error) { - throw new Error('Error al obtener las estadísticas:', error); - } -} - -// Exportar la función -module.exports = { fetchStats }; \ No newline at end of file diff --git a/webapp/src/pages/Clasico/Clasico.test.js b/webapp/src/pages/Clasico/Clasico.test.js index 88796e23..8b8c2137 100644 --- a/webapp/src/pages/Clasico/Clasico.test.js +++ b/webapp/src/pages/Clasico/Clasico.test.js @@ -2,13 +2,13 @@ import React from "react"; import { render, screen, fireEvent, waitFor } from "@testing-library/react"; import "@testing-library/jest-dom/extend-expect"; import Clasico from "./Clasico"; -import { BrowserRouter as Router } from "react-router-dom"; +import { MemoryRouter } from "react-router-dom"; beforeEach(() => { jest.resetAllMocks(); }); -describe("JuegoPreguntas Component", () => { +describe("Clasico Component", () => { test("renders game questions and handles user answers", async () => { const mockQuestions = [ { @@ -29,9 +29,9 @@ describe("JuegoPreguntas Component", () => { }); render( - + - + ); // Verificar que las preguntas se rendericen correctamente @@ -51,7 +51,64 @@ describe("JuegoPreguntas Component", () => { // Verificar que la respuesta seleccionada se resalte correctamente expect(screen.getByText("París")).toHaveStyle('backgroundColor: "#10FF00"'); + // Simular el siguiente paso del juego + const button = screen.getByText("Responder"); + button.click(); + + await waitFor( + () => { + expect( + screen.getByText("¿Cuál es el río más largo del mundo?") + ).toBeInTheDocument(); + expect(screen.getByText("Amazonas")).toBeInTheDocument(); + expect(screen.getByText("Nilo")).toBeInTheDocument(); + expect(screen.getByText("Misisipi")).toBeInTheDocument(); + expect(screen.getByText("Yangtsé")).toBeInTheDocument(); + }, + { timeout: 30000 } + ); + + // Simular la selección de una respuesta incorrecta + fireEvent.click(screen.getByText("Nilo")); + + // Verificar que la respuesta seleccionada se resalte correctamente + expect(screen.getByText("Amazonas")).toHaveStyle('backgroundColor: "#10FF00"'); + // Simular el siguiente paso del juego fireEvent.click(screen.getByText("Responder")); + + await waitFor( + () => { + expect(screen.getByText("¡Juego terminado!")).toBeInTheDocument(); + expect(screen.getByText("Repetir Juego")).toBeInTheDocument(); + expect(screen.getByText("Volver al Menú Principal")).toBeInTheDocument(); + }, + { timeout: 30000 } + ); + + fireEvent.click(screen.getByText("Repetir Juego")); + }, 50000); + + test("renders game questions and handles errors", async () => { + jest.spyOn(global, "fetch").mockImplementationOnce(() => + Promise.resolve({ + ok: false, + status: 400, + json: () => Promise.resolve({ error: "Failed to fetch" }), + }) + ); + + render( + + + + ); + + await waitFor( + () => { + expect(screen.getByText("Loading...")).toBeInTheDocument(); + }, + { timeout: 30000 } + ); }); });