diff --git a/exam.html b/exam.html index 44794ae..10bcd8a 100644 --- a/exam.html +++ b/exam.html @@ -120,6 +120,7 @@

How to use

+ diff --git a/exam.js b/exam.js index 4aaa21b..97ee554 100644 --- a/exam.js +++ b/exam.js @@ -88,9 +88,11 @@ function onPick(value, btn) { locked = true; const ans = window.VerbUtils.correctAnswer(currentV, currentT); + const isCorrect = value === ans; choicesEl.querySelectorAll('button').forEach(b => b.disabled = true); + window.FlashcardProgress?.recordAnswer(currentV, isCorrect); - if (value === ans) { + if (isCorrect) { score++; btn.classList.add('correct'); feedbackEl.textContent = '✅ Correct!'; diff --git a/tests/smoke.spec.js b/tests/smoke.spec.js index cc39445..29e294a 100644 --- a/tests/smoke.spec.js +++ b/tests/smoke.spec.js @@ -93,7 +93,7 @@ test('Exercises can answer, save progress, and move to next question', async ({ expect(errors).toEqual([]); }); -test('Exam can complete 10 questions and show final result', async ({ page }) => { +test('Exam can complete 10 questions, save progress, and show final result', async ({ page }) => { const errors = trackPageErrors(page); await page.goto(pageUrl('exam.html')); @@ -103,6 +103,13 @@ test('Exam can complete 10 questions and show final result', async ({ page }) => await page.locator('#nextExamBtn').click(); } + const progressRaw = await page.evaluate(() => window.localStorage.casualEnglishFlashcardProgress || null); + expect(progressRaw).not.toBeNull(); + + const progress = JSON.parse(progressRaw); + const totalViews = Object.values(progress).reduce((sum, entry) => sum + entry.views, 0); + expect(totalViews).toBe(10); + await expect(page.locator('#result')).toBeVisible(); await expect(page.locator('#resultScore')).toContainText('/ 10'); await expect(page.locator('#restartBtn')).toBeVisible();