diff --git a/webapp/src/components/Game.test.js b/webapp/src/components/Game.test.js index 6b4f6a3e..536032c7 100644 --- a/webapp/src/components/Game.test.js +++ b/webapp/src/components/Game.test.js @@ -84,6 +84,64 @@ describe('Game component', () => { }); + + it('should close confirmation dialog on cancel', async () => { + renderGameComponent(); + + // Open the confirmation dialog + fireEvent.click(screen.getByText('Volver al menú principal')); + + // Simulate clicking the cancel button + fireEvent.click(screen.getByText('Cancelar')); + + // Verify that the dialog is closed + await waitFor(() => { + expect(screen.queryByText('Confirmación')).not.toBeInTheDocument(); + }); + }); + + it('should redirect to main page after confirmation', async () => { + renderGameComponent(); + + // Open the confirmation dialog + fireEvent.click(screen.getByText('Volver al menú principal')); + + // Simulate clicking the confirm button + fireEvent.click(screen.getByText('Confirmar')); + // Wait for the component to unmount (indicating the redirection) + await waitFor(() => { + expect(screen.queryByText('Game')).not.toBeInTheDocument(); + }); + + }); + + it('should display end game message and enable "Back to Main Menu" button when game is finished', async () => { + renderGameComponent(); + + + for (let i = 1; i <= 5; i++) { + mockAxios.onGet('http://localhost:8000/createquestion').reply(200, { data: mockQuestionData }); + + await waitFor(() => { + if (screen.queryByText(`Pregunta ${i}:`)) { + fireEvent.click(screen.getByText('4')); + expect(screen.getByText(`Correctas: ${i}`)).toBeInTheDocument(); + expect(screen.getByText(`Preguntas restantes: ${5 - i}`)).toBeInTheDocument(); + expect(screen.getByText('Incorrectas: 0')).toBeInTheDocument(); + } + }); + } + + // Verificar que la partida haya finalizado correctamente + await waitFor(() => { + if (screen.queryByText(/Partida finalizada/i)) { + expect(screen.getByText(/Partida finalizada/i)).toBeInTheDocument(); + expect(screen.getByText(/Gracias por jugar/i)).toBeInTheDocument(); + expect(screen.getByText(/Puntuación/i)).toBeInTheDocument(); + expect(screen.getByText(/Volver al menú principal/i)).toBeInTheDocument(); + } + }); + }); -}); +});