about summary refs log tree commit diff stats
path: root/el/elements_test.go
blob: a24e963ea9a538c3e46eb2e599f01801ed30044b (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package el_test

import (
	"testing"

	g "github.com/maragudk/gomponents"
	"github.com/maragudk/gomponents/assert"
	"github.com/maragudk/gomponents/el"
)

func TestDocument(t *testing.T) {
	t.Run("returns doctype and children", func(t *testing.T) {
		assert.Equal(t, `<!doctype html><html/>`, el.Document(g.El("html")))
	})
}

func TestHTML(t *testing.T) {
	t.Run("returns an html element", func(t *testing.T) {
		assert.Equal(t, "<html><div/><span/></html>", el.HTML(g.El("div"), g.El("span")))
	})
}

func TestHead(t *testing.T) {
	t.Run("returns a head element", func(t *testing.T) {
		assert.Equal(t, "<head><title/><link/></head>", el.Head(g.El("title"), g.El("link")))
	})
}

func TestBody(t *testing.T) {
	t.Run("returns a body element", func(t *testing.T) {
		assert.Equal(t, "<body><div/><span/></body>", el.Body(g.El("div"), g.El("span")))
	})
}

func TestTitle(t *testing.T) {
	t.Run("returns a title element with text content", func(t *testing.T) {
		assert.Equal(t, "<title>hat</title>", el.Title("hat"))
	})
}

func TestMeta(t *testing.T) {
	t.Run("returns a meta element", func(t *testing.T) {
		assert.Equal(t, `<meta charset="utf-8"/>`, el.Meta(g.Attr("charset", "utf-8")))
	})
}

func TestLink(t *testing.T) {
	t.Run("returns a link element", func(t *testing.T) {
		assert.Equal(t, `<link rel="stylesheet"/>`, el.Link(g.Attr("rel", "stylesheet")))
	})
}

func TestStyle(t *testing.T) {
	t.Run("returns a style element", func(t *testing.T) {
		assert.Equal(t, `<style type="text/css"/>`, el.Style(g.Attr("type", "text/css")))
	})
}

func TestDiv(t *testing.T) {
	t.Run("returns a div element", func(t *testing.T) {
		assert.Equal(t, `<div><span/></div>`, el.Div(el.Span()))
	})
}

func TestSpan(t *testing.T) {
	t.Run("returns a span element", func(t *testing.T) {
		assert.Equal(t, `<span>hat</span>`, el.Span(g.Text("hat")))
	})
}

func TestA(t *testing.T) {
	t.Run("returns an a element with a href attribute", func(t *testing.T) {
		assert.Equal(t, `<a href="#">hat</a>`, el.A("#", g.Text("hat")))
	})
}

func TestP(t *testing.T) {
	t.Run("returns a p element", func(t *testing.T) {
		assert.Equal(t, `<p>hat</p>`, el.P(g.Text("hat")))
	})
}

func TestH1(t *testing.T) {
	t.Run("returns an h1 element", func(t *testing.T) {
		assert.Equal(t, `<h1 id="headline">hat</h1>`, el.H1("hat", g.Attr("id", "headline")))
	})
}

func TestH2(t *testing.T) {
	t.Run("returns an h2 element", func(t *testing.T) {
		assert.Equal(t, `<h2 id="headline">hat</h2>`, el.H2("hat", g.Attr("id", "headline")))
	})
}

func TestH3(t *testing.T) {
	t.Run("returns an h3 element", func(t *testing.T) {
		assert.Equal(t, `<h3 id="headline">hat</h3>`, el.H3("hat", g.Attr("id", "headline")))
	})
}

func TestH4(t *testing.T) {
	t.Run("returns an h4 element", func(t *testing.T) {
		assert.Equal(t, `<h4 id="headline">hat</h4>`, el.H4("hat", g.Attr("id", "headline")))
	})
}

func TestH5(t *testing.T) {
	t.Run("returns an h5 element", func(t *testing.T) {
		assert.Equal(t, `<h5 id="headline">hat</h5>`, el.H5("hat", g.Attr("id", "headline")))
	})
}

func TestH6(t *testing.T) {
	t.Run("returns an h6 element", func(t *testing.T) {
		assert.Equal(t, `<h6 id="headline">hat</h6>`, el.H6("hat", g.Attr("id", "headline")))
	})
}

func TestOl(t *testing.T) {
	t.Run("returns an ol element", func(t *testing.T) {
		assert.Equal(t, `<ol><li/></ol>`, el.Ol(el.Li()))
	})
}

func TestUl(t *testing.T) {
	t.Run("returns a ul element", func(t *testing.T) {
		assert.Equal(t, `<ul><li/></ul>`, el.Ul(el.Li()))
	})
}

func TestLi(t *testing.T) {
	t.Run("returns an li element", func(t *testing.T) {
		assert.Equal(t, `<li>hat</li>`, el.Li(g.Text("hat")))
	})
}

func TestB(t *testing.T) {
	t.Run("returns a b element", func(t *testing.T) {
		assert.Equal(t, `<b id="text">hat</b>`, el.B("hat", g.Attr("id", "text")))
	})
}

func TestStrong(t *testing.T) {
	t.Run("returns a strong element", func(t *testing.T) {
		assert.Equal(t, `<strong id="text">hat</strong>`, el.Strong("hat", g.Attr("id", "text")))
	})
}

func TestI(t *testing.T) {
	t.Run("returns an i element", func(t *testing.T) {
		assert.Equal(t, `<i id="text">hat</i>`, el.I("hat", g.Attr("id", "text")))
	})
}

func TestEm(t *testing.T) {
	t.Run("returns an em element", func(t *testing.T) {
		assert.Equal(t, `<em id="text">hat</em>`, el.Em("hat", g.Attr("id", "text")))
	})
}

func TestImg(t *testing.T) {
	t.Run("returns an img element with href and alt attributes", func(t *testing.T) {
		assert.Equal(t, `<img src="hat.png" alt="hat" id="image"/>`, el.Img("hat.png", "hat", g.Attr("id", "image")))
	})
}