saasitone/pkg/msg/msg_test.go

46 lines
814 B
Go
Raw Permalink Normal View History

2021-12-21 18:42:53 -08:00
package msg
import (
"testing"
2024-07-09 17:57:05 -07:00
"github.com/labstack/echo/v4"
2022-01-20 15:02:14 -08:00
"github.com/stretchr/testify/assert"
2021-12-21 18:42:53 -08:00
"github.com/stretchr/testify/require"
2024-07-09 17:57:05 -07:00
"git.grosinger.net/tgrosinger/saasitone/pkg/tests"
2021-12-21 18:42:53 -08:00
)
func TestMsg(t *testing.T) {
e := echo.New()
ctx, _ := tests.NewContext(e, "/")
tests.InitSession(ctx)
assertMsg := func(typ Type, message string) {
ret := Get(ctx, typ)
require.Len(t, ret, 1)
assert.Equal(t, message, ret[0])
ret = Get(ctx, typ)
require.Len(t, ret, 0)
}
2021-12-25 18:04:19 -08:00
text := "aaa"
2021-12-21 18:42:53 -08:00
Success(ctx, text)
assertMsg(TypeSuccess, text)
2021-12-25 18:04:19 -08:00
text = "bbb"
2021-12-21 18:42:53 -08:00
Info(ctx, text)
assertMsg(TypeInfo, text)
2021-12-25 18:04:19 -08:00
text = "ccc"
2021-12-21 18:42:53 -08:00
Danger(ctx, text)
assertMsg(TypeDanger, text)
2021-12-25 18:04:19 -08:00
text = "ddd"
2021-12-21 18:42:53 -08:00
Warning(ctx, text)
assertMsg(TypeWarning, text)
2021-12-25 18:04:19 -08:00
text = "eee"
2021-12-21 18:42:53 -08:00
Set(ctx, TypeSuccess, text)
assertMsg(TypeSuccess, text)
}