2025-01-10 00:37:43 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
2025-01-19 12:04:25 +00:00
|
|
|
"embed"
|
2025-01-10 00:37:43 +00:00
|
|
|
"fmt"
|
|
|
|
"github.com/1f349/lavender/utils"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"html/template"
|
|
|
|
"io/fs"
|
2025-01-19 12:04:25 +00:00
|
|
|
"path"
|
|
|
|
"slices"
|
|
|
|
"strings"
|
2025-01-10 00:37:43 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadPages_FindErrors(t *testing.T) {
|
2025-01-19 12:04:25 +00:00
|
|
|
glob, err := fs.Glob(webDist, "dist/*/index.html")
|
2025-01-10 00:37:43 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
fmt.Println(glob)
|
|
|
|
|
|
|
|
for _, fileName := range glob {
|
|
|
|
t.Run("Parsing "+fileName, func(t *testing.T) {
|
|
|
|
_, err := template.New("web").Delims("[[", "]]").Funcs(template.FuncMap{
|
|
|
|
"emailHide": utils.EmailHide,
|
|
|
|
"renderOptionTag": renderOptionTag,
|
|
|
|
"renderCheckboxTag": renderCheckboxTag,
|
2025-01-19 12:04:25 +00:00
|
|
|
}).ParseFS(webDist, fileName)
|
2025-01-10 00:37:43 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2025-01-19 12:04:25 +00:00
|
|
|
|
|
|
|
//go:embed src/pages
|
|
|
|
var webSrcPages embed.FS
|
|
|
|
|
|
|
|
func TestLoadPage_FindMissing(t *testing.T) {
|
|
|
|
paths := make([]string, 0)
|
|
|
|
err := fs.WalkDir(webSrcPages, "src/pages", func(p string, d fs.DirEntry, err error) error {
|
|
|
|
if d.IsDir() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if strings.HasSuffix(path.Base(p), ".astro") {
|
|
|
|
p = strings.TrimPrefix(p, "src/pages/")
|
|
|
|
p = strings.TrimSuffix(p, ".astro")
|
|
|
|
p += ".html"
|
|
|
|
paths = append(paths, p)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
slices.Sort(paths)
|
|
|
|
|
|
|
|
err = LoadPages("")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
tmpls := make([]string, 0)
|
|
|
|
|
|
|
|
for _, i := range pageTemplates.Templates() {
|
|
|
|
if i.Name() == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
tmpls = append(tmpls, i.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
slices.Sort(tmpls)
|
|
|
|
|
|
|
|
assert.ElementsMatch(t, paths, tmpls)
|
|
|
|
}
|