Skip to content

Commit

Permalink
Merge pull request #80 from Arquisoft/50-realizar-pruebas-unitarias
Browse files Browse the repository at this point in the history
50 realizar pruebas unitarias
  • Loading branch information
CANCI0 authored Apr 2, 2024
2 parents 7664713 + af96cb8 commit 20947ea
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 47 deletions.
4 changes: 2 additions & 2 deletions webapp/src/components/CustomModal/CustomModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const CustomModal = ({ title, text, route }) => {
</ModalBody>

<ModalFooter>
<Button colorScheme='blue' mr={3} onClick={onClose}>
<Button variant='ghost' mr={3} onClick={onClose}>
Cerrar
</Button>
<Button variant='ghost' onClick={() => navigate(route)}>Jugar</Button>
<Button colorScheme='blue' onClick={() => navigate(route)}>Jugar</Button>
</ModalFooter>
</ModalContent>
</Modal>
Expand Down
20 changes: 0 additions & 20 deletions webapp/src/components/Preguntas.js

This file was deleted.

21 changes: 0 additions & 21 deletions webapp/src/components/Stats.js

This file was deleted.

65 changes: 61 additions & 4 deletions webapp/src/pages/Clasico/Clasico.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -29,9 +29,9 @@ describe("JuegoPreguntas Component", () => {
});

render(
<Router>
<MemoryRouter>
<Clasico />
</Router>
</MemoryRouter>
);

// Verificar que las preguntas se rendericen correctamente
Expand All @@ -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(
<MemoryRouter>
<Clasico />
</MemoryRouter>
);

await waitFor(
() => {
expect(screen.getByText("Loading...")).toBeInTheDocument();
},
{ timeout: 30000 }
);
});
});

0 comments on commit 20947ea

Please sign in to comment.