-
Notifications
You must be signed in to change notification settings - Fork 27
/
elem_test.go
40 lines (32 loc) · 1.23 KB
/
elem_test.go
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 elem
import (
"github.com/stretchr/testify/assert"
"testing"
)
// MockStyleManager simulates the StyleManager for testing purposes.
type MockStyleManager struct{}
// GenerateCSS returns a fixed CSS string for testing.
func (m *MockStyleManager) GenerateCSS() string {
return "body { background-color: #fff; }"
}
func TestRenderWithOptionsInjectsCSSIntoHead(t *testing.T) {
// Setup a simple element that represents an HTML document structure
e := &Element{
Tag: "html",
Children: []Node{
&Element{Tag: "head"},
&Element{Tag: "body"},
},
}
// Use the MockStyleManager
mockStyleManager := &MockStyleManager{}
// Assuming RenderOptions expects a StyleManager interface, pass the mock
opts := RenderOptions{
StyleManager: mockStyleManager, // This should be adjusted to how your options are structured
}
htmlOutput := e.RenderWithOptions(opts)
// Construct the expected HTML string with the CSS injected
expectedHTML := "<!DOCTYPE html><html><head><style>body { background-color: #fff; }</style></head><body></body></html>"
// Use testify's assert.Equal to check if the HTML output matches the expected HTML
assert.Equal(t, expectedHTML, htmlOutput, "The generated HTML should include the CSS in the <head> section")
}