Skip to content

Commit

Permalink
Añadir prueba saveStatistics
Browse files Browse the repository at this point in the history
  • Loading branch information
uo287998 committed Apr 6, 2024
1 parent 89637c2 commit d9bea9c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions webapp/src/components/QuizGame.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,32 @@ test('Pregunta incorrecta', async () => {

// Wait for the state updates to propagate
await waitFor(() => expect(screen.queryByText(/Loading questions.../i)).not.toBeInTheDocument());
});

test('Final del juego y llamada a saveStatistics', async () => {
mockAxios.onGet('http://localhost:8000/generate-question').reply(200, {
question: "pregunta",
correctAnswer: "correcta",
allAnswers: ["correcta", "no1", "no2", "no3"]
});

// Intercepta la llamada a saveStatistics
mockAxios.onPost('http://localhost:8000/save-statistics').reply(config => {
// Verifica que saveStatistics se haya llamado con los datos correctos
const { username, rightAnswers, wrongAnswers, time } = JSON.parse(config.data);
expect(username).toBe('username');
expect(rightAnswers).toBeGreaterThanOrEqual(0);
expect(wrongAnswers).toBeGreaterThanOrEqual(0);
expect(time).toBeGreaterThanOrEqual(0);
return [200];
});

render(<AuthProvider><QuizGame /></AuthProvider>);
expect(screen.getByText(/Loading questions.../i)).toBeInTheDocument();

// Simula la respuesta a todas las preguntas
while (screen.queryByRole('button', { name: /correcta/i })) {
const answerButton = await screen.findByRole('button', { name: /correcta/i });
fireEvent.click(answerButton);
}
});

0 comments on commit d9bea9c

Please sign in to comment.