package components_test
import (
"os"
"testing"
g "github.com/maragudk/gomponents"
. "github.com/maragudk/gomponents/components"
. "github.com/maragudk/gomponents/html"
"github.com/maragudk/gomponents/internal/assert"
)
func TestHTML5(t *testing.T) {
t.Run("returns an html5 document template", func(t *testing.T) {
e := HTML5(HTML5Props{
Title: "Hat",
Description: "Love hats.",
Language: "en",
Head: []g.Node{Link(Rel("stylesheet"), Href("/hat.css"))},
Body: []g.Node{Div()},
})
assert.Equal(t, `
Hat`, e)
})
t.Run("returns no language, description, and extra head/body elements if empty", func(t *testing.T) {
e := HTML5(HTML5Props{
Title: "Hat",
})
assert.Equal(t, `Hat`, e)
})
}
func TestClasses(t *testing.T) {
t.Run("given a map, returns sorted keys from the map with value true", func(t *testing.T) {
assert.Equal(t, ` class="boheme-hat hat partyhat"`, Classes{
"boheme-hat": true,
"hat": true,
"partyhat": true,
"turtlehat": false,
})
})
t.Run("renders as attribute in an element", func(t *testing.T) {
e := g.El("div", Classes{"hat": true})
assert.Equal(t, ``, e)
})
t.Run("also works with fmt", func(t *testing.T) {
a := Classes{"hat": true}
if a.String() != ` class="hat"` {
t.FailNow()
}
})
}
func ExampleClasses() {
e := g.El("div", Classes{"party-hat": true, "boring-hat": false})
_ = e.Render(os.Stdout)
// Output:
}