From 0b6d3d510f01571c6606bdcdbe630d6349c7d23a Mon Sep 17 00:00:00 2001 From: Raymond Debasa Peralta Date: Mon, 29 Apr 2024 02:01:36 +0200 Subject: [PATCH] game test terminado --- webapp/src/components/Game.test.js | 60 +++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) 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(); + } + }); + }); -}); +});