Skip to content

Commit

Permalink
refactor: update unit test to be more descriptive
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed Nov 3, 2023
1 parent 49f8001 commit a463e64
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 37 deletions.
9 changes: 7 additions & 2 deletions generator/test-call/expected.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<div><h1>Luiz Bonfa</h1><div style="font-family: &#39;sans-serif&#39;" id="test" data-contents="something with &#34;quotes&#34; and a &lt;tag&gt;"><div>email:<a href="mailto: [email protected]">[email protected]</a></div></div></div>

<div>A</div>
<div>B</div>
<div>C</div>
<div>Legacy call style</div>
<div id="wrapper">
<div>Child content</div>
</div>
5 changes: 1 addition & 4 deletions generator/test-call/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import (
var expected string

func Test(t *testing.T) {
component := personTemplate(person{
name: "Luiz Bonfa",
email: "[email protected]",
})
component := showAll()

diff, err := htmldiff.Diff(component, expected)
if err != nil {
Expand Down
37 changes: 28 additions & 9 deletions generator/test-call/template.templ
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
package testcall

templ personTemplate(p person) {
<div>
<h1>{ p.name }</h1>
<div style="font-family: &#39;sans-serif&#39;" id="test" data-contents={ `something with "quotes" and a <tag>` }>
{! email(p.email) }
</div>
</div>
templ showAll() {
@a()
@b(c("C"))
{! d() }
@wrapChildren() {
<div>Child content</div>
}
}

templ a() {
<div>A</div>
}

templ b(child templ.Component) {
<div>B</div>
@child
}

templ email(s string) {
<div>email:<a href={ templ.URL("mailto: " + s) }>{ s }</a></div>
templ c(text string) {
<div>{ text }</div>
}

templ d() {
<div>Legacy call style</div>
}

templ wrapChildren() {
<div id="wrapper">
{ children... }
</div>
}
172 changes: 150 additions & 22 deletions generator/test-call/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a463e64

Please sign in to comment.