summaryrefslogtreecommitdiff
path: root/internal/handlers/template_test.go
blob: b0b23786f6f962599ee80dd2866e7ffab3cea7d9 (plain)
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
package handlers_test

import (
	"html/template"
	"io"
	"testing"
	"task-dashboard/internal/models"
)

func TestNotesTemplateRendering(t *testing.T) {
	// Parse templates (adjust paths relative to where test runs, usually package root)
	// Since we run 'go test ./...', paths might need to be absolute or relative to project root if we use a helper.
	// But standard 'go test' in a subdir uses that subdir as CWD.
	// We will assume the test runs from 'internal/handlers'.
	// So paths are "../../web/templates/..."

	tmpl, err := template.ParseGlob("../../web/templates/*.html")
	if err != nil {
		t.Fatalf("Failed to parse templates: %v", err)
	}
	tmpl, err = tmpl.ParseGlob("../../web/templates/partials/*.html")
	if err != nil {
		t.Fatalf("Failed to parse partials: %v", err)
	}

	// Define the data structure we EXPECT to use (with Errors)
	data := struct {
		Notes  []models.Note
		Errors []string
	}{
		Notes:  []models.Note{},
		Errors: []string{"Test Error"},
	}

	// Execute
	err = tmpl.ExecuteTemplate(io.Discard, "notes-tab", data)
	if err != nil {
		t.Errorf("Failed to render notes-tab with corrected data: %v", err)
	}
}