From f8b9678e89b23a956b1248a03860a0d87cd43ef1 Mon Sep 17 00:00:00 2001 From: Kureszn Date: Thu, 30 Jul 2026 13:59:20 +0100 Subject: [PATCH] test(useQuiz): assert second answer to same question is a no-op --- src/hooks/__tests__/useQuiz.test.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/hooks/__tests__/useQuiz.test.tsx b/src/hooks/__tests__/useQuiz.test.tsx index d42bcce9..5ea706e6 100644 --- a/src/hooks/__tests__/useQuiz.test.tsx +++ b/src/hooks/__tests__/useQuiz.test.tsx @@ -71,6 +71,23 @@ describe('quiz grading helpers', () => { }); describe('useQuiz', () => { + it('ignores a second answer to an already-answered question', () => { + const { result } = renderHook(() => useQuiz({ quiz: quizFixture, autoStart: false })); + + act(() => { + result.current.actions.answerQuestion('mc-1', 'b'); // correct + }); + + const firstAnswer = result.current.answers['mc-1']; + + act(() => { + result.current.actions.answerQuestion('mc-1', 'a'); // attempt to change to wrong + }); + + expect(result.current.answers['mc-1']).toBe(firstAnswer); + expect(result.current.score).toBe(2); + }); + it('tracks partial code-credit and regular grading without regressing score updates', () => { const { result } = renderHook(() => useQuiz({ quiz: quizFixture, autoStart: false }));