From 4aede64667142d5c50c8afb705770f66b193eba8 Mon Sep 17 00:00:00 2001 From: uo288543 Date: Sun, 28 Apr 2024 21:50:16 +0200 Subject: [PATCH 1/2] fix wise men stack --- webapp/src/pages/games/WiseMenStackGame.js | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/webapp/src/pages/games/WiseMenStackGame.js b/webapp/src/pages/games/WiseMenStackGame.js index f056c51..0100f08 100644 --- a/webapp/src/pages/games/WiseMenStackGame.js +++ b/webapp/src/pages/games/WiseMenStackGame.js @@ -39,6 +39,7 @@ const WiseMenStackGame = () => { const [timerRunning, setTimerRunning] = React.useState(true); // indicate if the timer is working const [showConfetti, setShowConfetti] = React.useState(false); //indicates if the confetti must appear const [questionCountdownKey, ] = React.useState(60); //key to update question timer + const [targetTime, ] = React.useState(60); const [questionCountdownRunning, setQuestionCountdownRunning] = React.useState(false); //property to start and stop question timer const [userResponses, setUserResponses] = React.useState([]); const [language, setCurrentLanguage] = React.useState(i18n.language); @@ -64,19 +65,22 @@ const WiseMenStackGame = () => { // hook to initiating new rounds if the current number of rounds is less than or equal to 3 React.useEffect(() => { - if (totalTimePlayed <= questionCountdownKey) { + if (totalTimePlayed <= targetTime) { startNewRound(); - setQuestionCountdownRunning(true); - } else { - setTimerRunning(false); - setShouldRedirect(true); - setQuestionCountdownRunning(false); - updateStatistics(); - updateQuestionsRecord(); + setQuestionCountdownRunning(true) } // eslint-disable-next-line }, [round]); + const endGame = () => { + setTimerRunning(false); + setShouldRedirect(true); + setQuestionCountdownRunning(false); + updateStatistics(); + updateQuestionsRecord(); + // eslint-disable-next-line + } + // stablish if the confetti must show or not React.useEffect(() => { if (correctlyAnsweredQuestions > incorrectlyAnsweredQuestions) { @@ -108,7 +112,7 @@ const WiseMenStackGame = () => { setQuestionData(quest.data[0]); setButtonStates(new Array(2).fill(null)); getPossibleOptions(quest.data[0]); - + }).catch(error => { console.error("Could not get questions", error); }); @@ -163,6 +167,7 @@ const WiseMenStackGame = () => { // this function is called when a user selects a response. const selectResponse = async (index, response) => { + setQuestionCountdownRunning(false); setAnswered(true); const newButtonStates = [...buttonStates]; @@ -308,7 +313,7 @@ const WiseMenStackGame = () => { - { answered ? + { false ? // Pausa togglePause()} sx={{ height: 100, width: 100, border: `2px solid ${theme.palette.primary.main}` }} @@ -317,8 +322,8 @@ const WiseMenStackGame = () => { : // Cronómetro - selectResponse(-1, "FAILED")}> + endGame()}> {({ remainingTime }) => { return ( From 434c0d5b8a5a3f9d166c99d34c96422740ce2b57 Mon Sep 17 00:00:00 2001 From: uo288543 Date: Sun, 28 Apr 2024 22:01:26 +0200 Subject: [PATCH 2/2] delete test --- .../pages/games/WiseMenStackGame.test.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/webapp/src/__tests__/pages/games/WiseMenStackGame.test.js b/webapp/src/__tests__/pages/games/WiseMenStackGame.test.js index 55588ac..dd75f8c 100644 --- a/webapp/src/__tests__/pages/games/WiseMenStackGame.test.js +++ b/webapp/src/__tests__/pages/games/WiseMenStackGame.test.js @@ -116,21 +116,6 @@ describe('Wise Men Stack Game component', () => { }, 4500); - it('should render pause & play buttons when answered', async () => { - await waitFor(() => screen.getByText('GAME CONFIGURATION')); - const button = screen.getByTestId('start-button'); - fireEvent.click(button); - - await waitFor(() => screen.getByText('Which is the capital of Spain?'.toUpperCase())); - const correctAnswer = screen.getByRole('button', { name: 'Madrid' }); - fireEvent.click(correctAnswer); - - const pauseButton = screen.getByTestId("pause"); - expect(pauseButton); - fireEvent.click(pauseButton); - expect(screen.getByTestId("play")); - }) - it('should render progress bar', async () => { await waitFor(() => screen.getByText('GAME CONFIGURATION')); const button = screen.getByTestId('start-button');