Skip to content

Commit

Permalink
🧪 Mejorando tests de Game
Browse files Browse the repository at this point in the history
  • Loading branch information
coral2742 committed May 7, 2024
1 parent 071797f commit 0f30343
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 91 deletions.
44 changes: 8 additions & 36 deletions webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,8 @@ const Game = () => {
button.onmouse = colorOnMousePreguntas;
});

incrementQuestion();



setQuestionCounter(qc => qc + 1);


}catch (error){
console.error('Error:', error);
Expand All @@ -227,7 +225,7 @@ const Game = () => {
const correctButton = document.getElementById(buttonId);
if (correctButton) {
correctButton.style.backgroundColor = "rgba(79, 141, 18, 0.726)";
incrementCorrect();
setCorrectCounter(correct => correct + 1);
}
}else{
const buttonId = `button_${index}`;
Expand All @@ -244,7 +242,7 @@ const Game = () => {
}
}

incrementIncorrect();
setIncorrectCounter(incorrect => incorrect + 1);
}

const buttons = document.querySelectorAll('button[title="btnsPreg"]');
Expand All @@ -253,7 +251,7 @@ const Game = () => {
button.onmouse = null;
});

decrementQuestionsToAnswer();
setQuestionsToAnswer(toAnswer => toAnswer - 1);

if (!isGameFinished()) {
setTimeout(() => {
Expand Down Expand Up @@ -314,14 +312,6 @@ const getQuestions = () => {
correctAnswers: correctCounter,
incorrectAnswers: numberOfQuestions-correctCounter
};
//console.log("Se va a guardar la siguiente partida:");
//console.log("Username:", newGame.username);
//console.log("Duración:", newGame.duration);
//console.log("Preguntas:", newGame.questions);
//console.log("Porcentaje de Aciertos:", newGame.percentage);
//console.log("Número Total de Preguntas:", newGame.totalQuestions);
//console.log("Número de Respuestas Correctas:", newGame.correctAnswers);
//console.log("Número de Respuestas Incorrectas:", newGame.incorrectAnswers);
setGameData(newGame);


Expand All @@ -334,24 +324,6 @@ const getQuestions = () => {
});
}

const incrementCorrect = () => {
setCorrectCounter(correct => correct + 1);
};

const incrementIncorrect = () => {
setIncorrectCounter(incorrect => incorrect + 1);
}

const decrementQuestionsToAnswer = () => {
setQuestionsToAnswer(toAnswer => toAnswer - 1);
}

const incrementQuestion = () => {
setQuestionCounter(qc => qc + 1);
}



useEffect(() => {
if (isTimedOut && !isFinished) {
// mostrar la respuesta correcta
Expand All @@ -364,8 +336,8 @@ const getQuestions = () => {
}
}

incrementIncorrect();
decrementQuestionsToAnswer();
setIncorrectCounter(incorrect => incorrect + 1);
setQuestionsToAnswer(toAnswer => toAnswer - 1);

setTimeout(() => {
if (!isGameFinished()) {
Expand Down Expand Up @@ -417,7 +389,7 @@ const getQuestions = () => {
</div>


<div className="Timer">
<div className="Timer" data-testid="Timer">
<div className="container">
<div className="text">{time}</div>

Expand Down
Loading

0 comments on commit 0f30343

Please sign in to comment.