-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_test.go
More file actions
105 lines (99 loc) · 4.17 KB
/
Copy pathhtml_test.go
File metadata and controls
105 lines (99 loc) · 4.17 KB
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
package test
import (
"bytes"
"testing"
d "github.com/ramonpetgrave64/go-html-compose/pkg/doc"
a "github.com/ramonpetgrave64/go-html-compose/pkg/html/attrs"
e "github.com/ramonpetgrave64/go-html-compose/pkg/html/elems"
"github.com/ramonpetgrave64/go-html-compose/pkg/internal/test"
)
func Test_Example(tt *testing.T) {
tt.Parallel()
tests := []struct {
name string
want string
content d.IContent
}{
{
name: "example HTML page",
want: `<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="color-scheme" content="light dark"><title>Example HTML Page</title><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"></head><body><header class="container"><h1>Welcome to My Website</h1><nav><ul><li><a href="#home">Home</a></li><li><a href="#about">About</a></li><li><a href="#contact">Contact</a></li></ul></nav></header><main class="container"><section id="home"><h2>Home</h2><p>This is the home section.</p></section><section id="about"><h2>About</h2><p>This is the about section.</p></section><section id="contact"><h2>Contact</h2><p>Please subscribe!🥺</p><form><div class="grid"><input type="text" name="firstname" placeholder="First name" aria-label="First name" required="required"><input type="email" name="email" placeholder="Email address" aria-label="Email address" autocomplete="email" required="required"><button type="submit">Subscribe</button></div><fieldset><label for="terms"><input type="checkbox" role="switch" id="terms" name="terms">I agree to the <a href="#" onclick="alert('Hello, World!')">Privacy Policy</a></label></fieldset></form></section></main><footer class="container"><p>© 2025 My Website</p></footer></body></html>`,
content: e.Html(a.Lang("en"))(
e.Head()(
e.Meta(a.Charset("UTF-8")),
e.Meta(a.Name("viewport"), a.Content("width=device-width, initial-scale=1.0")),
e.Meta(a.Name("color-scheme"), a.Content("light dark")),
e.Title()(d.TextS("Example HTML Page")),
e.Link(a.Rel("stylesheet"), a.Href("https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css")),
),
e.Body()(
e.Header(a.Class("container"))(
e.H1()(d.TextS("Welcome to My Website")),
e.Nav()(
e.Ul()(
e.Li()(e.A(a.Href("#home"))(d.TextS("Home"))),
e.Li()(e.A(a.Href("#about"))(d.TextS("About"))),
e.Li()(e.A(a.Href("#contact"))(d.TextS("Contact"))),
),
),
),
e.Main(a.Class("container"))(
e.Section(a.Id("home"))(
e.H2()(d.TextS("Home")),
e.P()(d.TextS("This is the home section.")),
),
e.Section(a.Id("about"))(
e.H2()(d.TextS("About")),
e.P()(d.TextS("This is the about section.")),
),
e.Section(a.Id("contact"))(
e.H2()(d.TextS("Contact")),
e.P()(d.TextS("Please subscribe!🥺")),
e.Form()(
e.Div(a.Class("grid"))(
e.Input(
a.Type("text"),
a.Name("firstname"),
a.Placeholder("First name"),
a.AriaProp("label", "First name"),
a.Required(true),
),
e.Input(
a.Type("email"),
a.Name("email"),
a.Placeholder("Email address"),
a.AriaProp("label", "Email address"),
a.Autocomplete("email"),
a.Required(true),
),
e.Button(a.Type("submit"))(d.TextS("Subscribe")),
),
e.Fieldset()(
e.Label(a.For("terms"))(
e.Input(a.Type("checkbox"), a.Role("switch"), a.Id("terms"), a.Name("terms")),
d.TextS("I agree to the "),
e.A(a.Href("#"), a.Onclick("alert('Hello, World!')"))(d.TextS("Privacy Policy")),
),
),
),
),
),
e.Footer(a.Class("container"))(
e.P()(d.TextS("© 2025 My Website")),
),
),
),
},
}
for _, tc := range tests {
tc := tc // create a new variable to hold the value of tc
tt.Run(tc.name, func(tt *testing.T) {
tt.Parallel()
var buffer bytes.Buffer
if err := tc.content.RenderConent(&buffer); err != nil {
tt.Errorf("unexpected error: %s", err.Error())
}
got := buffer.String()
test.TestDiffError(tt, tc.want, got)
})
}
}