Improve form and template usage (#66)
* Improve form and template usage.
This commit is contained in:
parent
5f66b0ee71
commit
97bef0257e
22 changed files with 341 additions and 274 deletions
|
|
@ -4,36 +4,60 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/mikestefanello/pagoda/config"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewFuncMap(t *testing.T) {
|
||||
f := NewFuncMap(echo.New())
|
||||
assert.NotNil(t, f["hasField"])
|
||||
assert.NotNil(t, f["link"])
|
||||
assert.NotNil(t, f["file"])
|
||||
assert.NotNil(t, f["url"])
|
||||
}
|
||||
|
||||
func TestHasField(t *testing.T) {
|
||||
type example struct {
|
||||
name string
|
||||
}
|
||||
var e example
|
||||
assert.True(t, HasField(e, "name"))
|
||||
assert.False(t, HasField(e, "abcd"))
|
||||
f := new(funcMap)
|
||||
assert.True(t, f.hasField(e, "name"))
|
||||
assert.False(t, f.hasField(e, "abcd"))
|
||||
}
|
||||
|
||||
func TestLink(t *testing.T) {
|
||||
link := string(Link("/abc", "Text", "/abc"))
|
||||
f := new(funcMap)
|
||||
|
||||
link := string(f.link("/abc", "Text", "/abc"))
|
||||
expected := `<a class="is-active" href="/abc">Text</a>`
|
||||
assert.Equal(t, expected, link)
|
||||
|
||||
link = string(Link("/abc", "Text", "/abc", "first", "second"))
|
||||
link = string(f.link("/abc", "Text", "/abc", "first", "second"))
|
||||
expected = `<a class="first second is-active" href="/abc">Text</a>`
|
||||
assert.Equal(t, expected, link)
|
||||
|
||||
link = string(Link("/abc", "Text", "/def"))
|
||||
link = string(f.link("/abc", "Text", "/def"))
|
||||
expected = `<a class="" href="/abc">Text</a>`
|
||||
assert.Equal(t, expected, link)
|
||||
}
|
||||
|
||||
func TestFile(t *testing.T) {
|
||||
file := File("test.png")
|
||||
f := new(funcMap)
|
||||
|
||||
file := f.file("test.png")
|
||||
expected := fmt.Sprintf("/%s/test.png?v=%s", config.StaticPrefix, CacheBuster)
|
||||
assert.Equal(t, expected, file)
|
||||
}
|
||||
|
||||
func TestUrl(t *testing.T) {
|
||||
f := new(funcMap)
|
||||
f.web = echo.New()
|
||||
f.web.GET("/mypath/:id", func(c echo.Context) error {
|
||||
return nil
|
||||
}).Name = "test"
|
||||
out := f.url("test", 5)
|
||||
assert.Equal(t, "/mypath/5", out)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue