Refactored all forms to follow new pattern.

This commit is contained in:
mikestefanello 2021-12-24 08:42:42 -05:00
parent d5adf010db
commit 6f50552a15
11 changed files with 133 additions and 195 deletions

View file

@ -10,7 +10,6 @@ import (
"goweb/config"
"goweb/middleware"
"goweb/msg"
"goweb/services"
"goweb/tests"
@ -18,8 +17,6 @@ import (
"github.com/eko/gocache/v2/marshaler"
"github.com/go-playground/validator/v10"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -56,25 +53,6 @@ func TestController_Redirect(t *testing.T) {
assert.Equal(t, http.StatusFound, ctx.Response().Status)
}
func TestController_SetValidationErrorMessages(t *testing.T) {
type example struct {
Name string `validate:"required" label:"Label test"`
}
e := example{}
v := validator.New()
err := v.Struct(e)
require.Error(t, err)
ctx, _ := tests.NewContext(c.Web, "/")
tests.InitSession(ctx)
ctr := NewController(c)
ctr.SetValidationErrorMessages(ctx, err, e)
msgs := msg.Get(ctx, msg.TypeDanger)
require.Len(t, msgs, 1)
assert.Equal(t, "<strong>Label test</strong> is required.", msgs[0])
}
func TestController_RenderPage(t *testing.T) {
setup := func() (echo.Context, *httptest.ResponseRecorder, Controller, Page) {
ctx, rec := tests.NewContext(c.Web, "/test/TestController_RenderPage")