diff options
author | Grail Finder (aider) <wohilas@gmail.com> | 2025-04-05 14:36:27 +0300 |
---|---|---|
committer | Grail Finder (aider) <wohilas@gmail.com> | 2025-04-05 14:36:27 +0300 |
commit | 5673577dd44026093aab623c3faf10adfca94879 (patch) | |
tree | 96fcc950b0fe4c28d58d74b31efad42fa2b1656d | |
parent | fe7c14d271669b8d10ca0dd717b8cbc056f3b40a (diff) |
test: update handlers test to use data-testid selectors
-rw-r--r-- | internal/handlers/handlers_test.go | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index f9364db..3258cd8 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -45,35 +45,33 @@ func TestQuestionFlow(t *testing.T) { assert.NoError(err, "Failed to get question text") assert.Contains(questionText, "Zweifel", "Question text mismatch") - // Verify all options are present and clickable - options := []string{"Haben", "Hast", "Hat", "Habt"} - for _, opt := range options { - locator := page.Locator("button:has-text('" + opt + "')") - err := locator.WaitFor(playwright.LocatorWaitForOptions{ - State: playwright.WaitForSelectorStateVisible, - Timeout: playwright.Float(1000), - }) - assert.NoError(err, "Option button '%s' not found", opt) + // Set longer timeout for CI environments + page.SetDefaultTimeout(10000) + + // Verify options using test IDs + for i := 1; i <= 4; i++ { + testID := fmt.Sprintf("option%d", i) + locator := page.Locator(fmt.Sprintf("[data-testid='%s']", testID)) visible, err := locator.IsVisible() - assert.NoError(err, "Failed to check visibility for '%s'", opt) - assert.True(visible, "Option button '%s' not visible", opt) + assert.NoError(err, "Failed to check visibility for option %d", i) + assert.True(visible, "Option %d not visible", i) } - // Test 2: Click correct answer - err = page.Locator("button:has-text('Hast')").Click() + // Test correct answer (option2 is correct per test data) + err = page.Locator("[data-testid='option2']").Click() assert.NoError(err) - feedback, err := page.Locator("#feedback").TextContent() + feedback := page.Locator("[data-testid='feedback']") + text, err := feedback.TextContent() assert.NoError(err) - assert.Contains(feedback, "Correct") + assert.Contains(text, "Correct") - // Test 3: Click wrong answer - err = page.Locator("button:has-text('Haben')").Click() + // Test wrong answer + err = page.Locator("[data-testid='option1']").Click() assert.NoError(err) - - feedback, err = page.Locator("#feedback").TextContent() + text, err = feedback.TextContent() assert.NoError(err) - assert.Contains(feedback, "Wrong") + assert.Contains(text, "Wrong") } type MockRepo struct{} |