Skip to content

Commit 0e757f0

Browse files
committed
Fix word translation credits not resetting between quizzes
- Fixed resetQuizCoreState to reset creditsAvailable to INITIAL_HOVER_CREDITS - Added comprehensive e2e test for credit reset functionality - Word translation now works correctly with proper credit management - Credits reset to 7 when generating new content - All tests passing (96 unit tests, 36 e2e tests)
1 parent cfcc627 commit 0e757f0

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

app/store/quizSlice.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const resetQuizCoreState = (state: QuizSlice) => {
116116
state.isSubmittingFeedback = false;
117117
state.isPrefetching = false;
118118
state.hover.creditsUsed = 0;
119+
state.hover.creditsAvailable = INITIAL_HOVER_CREDITS;
119120
};
120121

121122
export const createQuizSlice: StateCreator<

test/e2e/language-switching.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,41 @@ test.describe('Language Switching', () => {
7171
// Language selector should show German
7272
await expect(langButton).toContainText('Deutsch');
7373
});
74+
75+
test('should reset translation credits when generating new content', async ({ page }) => {
76+
await page.goto('/en');
77+
78+
// Generate initial content
79+
const generateButton = page.locator('[data-testid="generate-button"]');
80+
await generateButton.click();
81+
82+
// Wait for content to load
83+
await expect(page.locator('[data-testid="passage-text"]')).toBeVisible();
84+
85+
// Check initial credits
86+
const creditsDisplay = page.locator('[data-testid="hover-credits-display"]');
87+
await expect(creditsDisplay).toContainText('7');
88+
89+
// Click on a word to use a credit
90+
const passageText = page.locator('[data-testid="passage-text"]');
91+
const firstWord = passageText.locator('span').first();
92+
await firstWord.click();
93+
94+
// Credits should decrease
95+
await expect(creditsDisplay).toContainText('6');
96+
97+
// Answer the question to proceed to next quiz
98+
const answerOption = page.locator('[data-testid="answer-option-0"]');
99+
await answerOption.click();
100+
101+
// Wait for feedback and then generate new content
102+
await expect(page.locator('text=Correct!').or(page.locator('text=Incorrect'))).toBeVisible();
103+
await generateButton.click();
104+
105+
// Wait for new content to load
106+
await expect(page.locator('[data-testid="passage-text"]')).toBeVisible();
107+
108+
// Credits should reset to 7
109+
await expect(creditsDisplay).toContainText('7');
110+
});
74111
});

0 commit comments

Comments
 (0)