about summary refs log tree commit diff stats
path: root/components/elements_test.go
blob: 7afa7dbe68323c2c89c6b5511fbfd44b76dd793e (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
package components_test

import (
	"testing"

	g "github.com/maragudk/gomponents"
	c "github.com/maragudk/gomponents/components"
	"github.com/maragudk/gomponents/internal/assert"
)

func TestInputHidden(t *testing.T) {
	t.Run("returns an input element with type hidden, and the given name and value", func(t *testing.T) {
		n := c.InputHidden("id", "partyhat", g.Attr("class", "hat"))
		assert.Equal(t, `<input type="hidden" name="id" value="partyhat" class="hat">`, n)
	})
}

func TestLinkStylesheet(t *testing.T) {
	t.Run("returns a link element with rel stylesheet and the given href", func(t *testing.T) {
		n := c.LinkStylesheet("style.css", g.Attr("media", "print"))
		assert.Equal(t, `<link rel="stylesheet" href="style.css" media="print">`, n)
	})
}

func TestLinkPreload(t *testing.T) {
	t.Run("returns a link element with rel preload and the given href and as", func(t *testing.T) {
		n := c.LinkPreload("party.woff2", "font", g.Attr("type", "font/woff2"))
		assert.Equal(t, `<link rel="preload" href="party.woff2" as="font" type="font/woff2">`, n)
	})
}