Skip to content

Commit

Permalink
Merge pull request #77 from Arquisoft/50-realizar-pruebas-unitarias
Browse files Browse the repository at this point in the history
Corrección de errores para el despliegue
  • Loading branch information
iyanfdezz authored Apr 2, 2024
2 parents 24a781e + f3d3f3b commit 1cfab1b
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@ jobs:
wget https://raw.githubusercontent.com/arquisoft/wiq_es1a/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_es1a/master/.env -O .env
docker compose --profile prod down
docker compose --profile prod up -d
docker compose --profile prod up -d --pull always
2 changes: 1 addition & 1 deletion webapp/src/components/CustomModal/CustomModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CustomModal = ({ title, text, route }) => {
<ModalContent>
<ModalHeader>{title}</ModalHeader>
<ModalCloseButton />
<ModalBody>
<ModalBody textAlign='justify'>
{text}
</ModalBody>

Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/Nav/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Nav = () => {
const isDarkTheme = colorMode === "dark";
const textColor = isDarkTheme ? "white" : "teal.500";
const bgColor = isDarkTheme ? 'gray.700' : 'gray.200';

const handleConfig = () => {
navigate("/config");
};
Expand Down
14 changes: 11 additions & 3 deletions webapp/src/pages/Bateria/Bateria.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,23 @@ const JuegoPreguntas = () => {
const tMedio=TIME/preguntasTotales;
setTiempoMedio(tMedio);
}
if (juegoTerminado && tiempoMedio!=0) {
guardarPartida();
}
}
const timer = setInterval(() => {
setTiempoRestante((prevTiempo) => (prevTiempo <= 0 ? 0 : prevTiempo - 1));
}, 1000);
return () => clearInterval(timer);
// eslint-disable-next-line
}, [tiempoRestante]);

useEffect(() => {
if (juegoTerminado && tiempoMedio!=0) {
guardarPartida();
}
// eslint-disable-next-line
}, [juegoTerminado, tiempoMedio]);



const guardarPartida = async () => {

const username = localStorage.getItem("username");
Expand Down Expand Up @@ -105,6 +112,7 @@ const JuegoPreguntas = () => {
}, 10);

return () => clearInterval(timer);
// eslint-disable-next-line
}, [tiempoRestante]);

const handleSiguientePregunta = async (respuesta) => {
Expand Down
25 changes: 14 additions & 11 deletions webapp/src/pages/Clasico/Clasico.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useState, useEffect, useMemo } from "react";
import React, { useState, useEffect } from "react";
import Nav from "../../components/Nav/Nav.js";
import { Link, useNavigate } from "react-router-dom";
import Footer from "../../components/Footer/Footer.js";
import { Box, Flex, Heading, Button, Grid, useColorMode, Text, Image } from "@chakra-ui/react";
import { Box, Flex, Heading, Button, Grid, useColorMode, Text, Image, Spinner } from "@chakra-ui/react";
import axios from "axios";

const JuegoPreguntas = () => {
const URL = process.env.REACT_APP_API_ENDPOINT || "http://localhost:8000";
const SECS_PER_QUESTION = useMemo(() => localStorage.getItem("clasicoTime"));
const SECS_PER_QUESTION = localStorage.getItem("clasicoTime");
const { colorMode } = useColorMode();
const isDarkTheme = colorMode === "dark";

Expand Down Expand Up @@ -54,7 +54,6 @@ const JuegoPreguntas = () => {
setIsLoading(false);
})
.catch((error) => {
console.error("Error al obtener las preguntas:", error);
navigate("/home?error=1");
});
// eslint-disable-next-line
Expand Down Expand Up @@ -140,20 +139,18 @@ const JuegoPreguntas = () => {
setJuegoTerminado(true);
if (preguntasCorrectas + preguntasFalladas > 0) {
const preguntasTotales=preguntasCorrectas+preguntasFalladas;
console.log(preguntasCorrectas);
console.log(preguntasFalladas);
const tMedio=tiempoTotal/preguntasTotales;
setTiempoMedio(tMedio);
console.log(tMedio);
}
}

};

useEffect(() => {
if (juegoTerminado && tiempoMedio!=0) {
if (juegoTerminado && tiempoMedio !== 0) {
guardarPartida();
}
// eslint-disable-next-line
}, [juegoTerminado]);

const guardarPartida = async () => {
Expand Down Expand Up @@ -202,7 +199,15 @@ const JuegoPreguntas = () => {
return (
<>
<Nav />
<span class="loader"></span>
<Spinner
data-testid="spinner"
thickness='4px'
speed='0.65s'
emptyColor='gray.200'
color='teal.500'
size='xl'
margin='auto'
/>
<Footer />
</>
);
Expand Down Expand Up @@ -255,9 +260,7 @@ const JuegoPreguntas = () => {
<Button
onClick={() => {
const newTTotal=tiempoTotal+(SECS_PER_QUESTION-tiempoRestante);
console.log(newTTotal);
setTiempoTotal(newTTotal);
console.log(tiempoTotal);
setTiempoRestante(0)}}
disabled={tiempoRestante === 0 || juegoTerminado}
colorScheme="teal"
Expand Down
1 change: 1 addition & 0 deletions webapp/src/pages/Config/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const Config = () => {
checkbox.click();
}
});
// eslint-disable-next-line
}, []);
const navigate = useNavigate();

Expand Down
19 changes: 14 additions & 5 deletions webapp/src/pages/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import Nav from "../../components/Nav/Nav.js";
import Footer from "../../components/Footer/Footer.js";
import CustomModal from "../../components/CustomModal/CustomModal.js";
import { Box, Heading, Flex } from "@chakra-ui/react";
import { useLocation } from "react-router-dom";

const Home = () => {
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const error = queryParams.get("error");

return (
<>
<Nav />
Expand All @@ -16,13 +21,13 @@ const Home = () => {
Elige el modo de juego
</Heading>
<Box p={2}>
<CustomModal
title="Modo Clásico"
<CustomModal
title="Modo Clásico"
text="
En el modo Clásico, tendrás que responder un número determinado de preguntas en un tiempo limitado.
¡Demuestra tus conocimientos y rapidez para superar este desafío!
"
route="/home/clasico"
"
route="/home/clasico"
/>
</Box>
<Box p={2}>
Expand All @@ -35,7 +40,11 @@ const Home = () => {
route="/home/bateria"
/>
</Box>
{/* Agrega más modos de juego aquí */}
{error && (
<Box mb={4} color="red">
Hubo un error al cargar las preguntas. Por favor, inténtalo más tarde.
</Box>
)}
</Flex>
<Footer />
</>
Expand Down
7 changes: 4 additions & 3 deletions webapp/src/pages/Perfil/Perfil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Box, VStack, Heading, Text, Center, Spinner, Table, Thead, Tbody, Tr, T
import React, { useEffect, useState } from "react";
import Nav from "../../components/Nav/Nav.js";
import Footer from "../../components/Footer/Footer.js";
import axios from "axios";

const Perfil = () => {
const gatewayUrl = process.env.GATEWAY_SERVICE_URL || "http://localhost:8000";
const username = localStorage.username || 'error';
const [userData, setUserData] = useState(null);
const [loading, setLoading] = useState(true);
const [username,setUsername]=useState(localStorage.username || 'error');

const [error, setError] = useState(null);

useEffect(() => {
Expand All @@ -23,6 +23,7 @@ const Perfil = () => {
setError(error.message || 'Ha ocurrido un error al obtener el perfil');
setLoading(false);
});
// eslint-disable-next-line
}, []);

return (
Expand Down Expand Up @@ -73,7 +74,7 @@ const Perfil = () => {
<Td>{game.correctAnswers}</Td>
<Td>{game.incorrectAnswers}</Td>
<Td>{game.points}</Td>
<Td>{game.avgTime} segundos</Td>
<Td>{parseFloat(game.avgTime).toFixed(2)} segundos</Td>
</Tr>
))}
</Tbody>
Expand Down
1 change: 1 addition & 0 deletions webapp/src/pages/Ranking/Ranking.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const Ranking = () => {

useEffect(() => {
fetchRanking();
// eslint-disable-next-line
}, [gamemode, filterBy]);

const handleDisplayChange = (event) => {
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/pages/Sobre/Sobre.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Flex, Table, Thead, Tbody, Tr, Th, Td, Link, Center, Heading } from "@chakra-ui/react";
import { Flex, Table, Thead, Tbody, Tr, Th, Td, Link, Heading } from "@chakra-ui/react";
import Nav from '../../components/Nav/Nav.js';
import Footer from '../../components/Footer/Footer.js';

Expand Down
5 changes: 3 additions & 2 deletions webapp/src/pages/Stats/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const Stats = () => {
fetchStats();
setFetched(true);
}
// eslint-disable-next-line
}, [username, gamemode]);

const handleUsernameChange = (event) => {
Expand All @@ -62,9 +63,9 @@ const Stats = () => {
};

const getModeName = () => {
if (gamemode == "clasico") {
if (gamemode === "clasico") {
return "Clásico";
} else if (gamemode == "bateria") {
} else if (gamemode === "bateria") {
return "Batería de sabios";
}
return gamemode;
Expand Down

0 comments on commit 1cfab1b

Please sign in to comment.