Skip to content

Commit

Permalink
game test terminado
Browse files Browse the repository at this point in the history
  • Loading branch information
UO290054 committed Apr 29, 2024
1 parent 5b6a3e3 commit 0b6d3d5
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion webapp/src/components/Game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
});

});
});

0 comments on commit 0b6d3d5

Please sign in to comment.