summaryrefslogtreecommitdiff
path: root/internal/handlers/tab_state_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers/tab_state_test.go')
-rw-r--r--internal/handlers/tab_state_test.go50
1 files changed, 28 insertions, 22 deletions
diff --git a/internal/handlers/tab_state_test.go b/internal/handlers/tab_state_test.go
index b95843e..d066966 100644
--- a/internal/handlers/tab_state_test.go
+++ b/internal/handlers/tab_state_test.go
@@ -1,40 +1,46 @@
package handlers
import (
+ "io"
"net/http"
"net/http/httptest"
"strings"
"testing"
- "task-dashboard/internal/api"
"task-dashboard/internal/config"
- "task-dashboard/internal/store"
)
func TestHandleDashboard_TabState(t *testing.T) {
- // Create a temporary database for testing
- db, err := store.New(":memory:", "../../migrations")
- if err != nil {
- t.Fatalf("Failed to create test database: %v", err)
- }
- defer func() { _ = db.Close() }()
-
- // Create mock API clients
- todoistClient := api.NewTodoistClient("test-key")
- trelloClient := api.NewTrelloClient("test-key", "test-token")
+ db, cleanup := setupTestDB(t)
+ defer cleanup()
- // Create test config
- cfg := &config.Config{
- Port: "8080",
- CacheTTLMinutes: 5,
+ // Create a mock renderer that captures template name and writes real HTML
+ mock := &MockRenderer{
+ RenderFunc: func(w io.Writer, name string, data interface{}) error {
+ // Write minimal HTML to satisfy the test assertions
+ html := `<!DOCTYPE html>
+<html>
+<head></head>
+<body>
+<button class="tab-button tab-button-active" hx-get="/tabs/tasks">Tasks</button>
+<button class="tab-button tab-button-active" hx-get="/tabs/planning">Planning</button>
+<button class="tab-button tab-button-active" hx-get="/tabs/meals">Meals</button>
+</body>
+</html>`
+ _, err := w.Write([]byte(html))
+ return err
+ },
}
- // Create handler
- h := New(db, todoistClient, trelloClient, nil, nil, nil, cfg)
-
- // Skip if templates are not loaded (test environment issue)
- if h.templates == nil {
- t.Skip("Templates not available in test environment")
+ h := &Handler{
+ store: db,
+ renderer: mock,
+ todoistClient: &mockTodoistClient{},
+ trelloClient: &mockTrelloClient{},
+ config: &config.Config{
+ Port: "8080",
+ CacheTTLMinutes: 5,
+ },
}
tests := []struct {