Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentacion pruebas de carga #195

Merged
merged 9 commits into from
Apr 29, 2024
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();
}
});
});

});
});