1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package handlers
import (
"context"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/playwright-community/playwright-go"
"github.com/stretchr/testify/assert"
)
func TestQuestionFlow(t *testing.T) {
assert := assert.New(t)
// Setup test server
h := NewHandlers(
config.Config{},
slog.New(slog.NewJSONHandler(os.Stdout, nil),
&MockRepo{},
)
ts := httptest.NewServer(http.HandlerFunc(h.MainPage))
defer ts.Close()
// Setup Playwright
pw, err := playwright.Run()
assert.NoError(err)
defer pw.Stop()
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(true), // Change to false for debugging
})
assert.NoError(err)
defer browser.Close()
page, err := browser.NewPage()
assert.NoError(err)
// Test 1: Load page and verify question
_, err = page.Goto(ts.URL)
assert.NoError(err)
questionText, err := page.Locator(".question-text").TextContent()
assert.NoError(err)
assert.Contains(questionText, "Zweifel")
// Verify all options are present
options := []string{"Haben", "Hast", "Hat", "Habt"}
for _, opt := range options {
_, err := page.Locator("button:has-text('" + opt + "')").TextContent()
assert.NoError(err)
}
// Test 2: Click correct answer
err = page.Locator("button:has-text('Hast')").Click()
assert.NoError(err)
feedback, err := page.Locator("#feedback").TextContent()
assert.NoError(err)
assert.Contains(feedback, "Correct")
// Test 3: Click wrong answer
err = page.Locator("button:has-text('Haben')").Click()
assert.NoError(err)
feedback, err = page.Locator("#feedback").TextContent()
assert.NoError(err)
assert.Contains(feedback, "Wrong")
}
type MockRepo struct{}
func (m *MockRepo) DBGetDefaultsMap() (map[string]string, error) {
return map[string]string{}, nil
}
|