2021-12-24 06:03:10 -08:00
|
|
|
package htmx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2024-07-09 17:57:05 -07:00
|
|
|
"github.com/labstack/echo/v4"
|
2021-12-24 06:03:10 -08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2024-07-09 17:57:05 -07:00
|
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/tests"
|
2021-12-24 06:03:10 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetRequest(t *testing.T) {
|
|
|
|
ctx, _ := tests.NewContext(echo.New(), "/")
|
|
|
|
ctx.Request().Header.Set(HeaderRequest, "true")
|
|
|
|
ctx.Request().Header.Set(HeaderBoosted, "true")
|
|
|
|
ctx.Request().Header.Set(HeaderTrigger, "a")
|
|
|
|
ctx.Request().Header.Set(HeaderTriggerName, "b")
|
|
|
|
ctx.Request().Header.Set(HeaderTarget, "c")
|
|
|
|
ctx.Request().Header.Set(HeaderPrompt, "d")
|
2024-06-22 08:07:43 -07:00
|
|
|
ctx.Request().Header.Set(HeaderHistoryRestoreRequest, "true")
|
2021-12-24 06:03:10 -08:00
|
|
|
|
|
|
|
r := GetRequest(ctx)
|
|
|
|
assert.Equal(t, true, r.Enabled)
|
|
|
|
assert.Equal(t, true, r.Boosted)
|
2024-06-22 08:07:43 -07:00
|
|
|
assert.Equal(t, true, r.HistoryRestore)
|
2021-12-24 06:03:10 -08:00
|
|
|
assert.Equal(t, "a", r.Trigger)
|
|
|
|
assert.Equal(t, "b", r.TriggerName)
|
|
|
|
assert.Equal(t, "c", r.Target)
|
|
|
|
assert.Equal(t, "d", r.Prompt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestResponse_Apply(t *testing.T) {
|
|
|
|
ctx, _ := tests.NewContext(echo.New(), "/")
|
|
|
|
r := Response{
|
2024-06-22 08:07:43 -07:00
|
|
|
PushURL: "a",
|
2021-12-24 06:03:10 -08:00
|
|
|
Redirect: "b",
|
2024-06-22 08:07:43 -07:00
|
|
|
ReplaceURL: "f",
|
2021-12-24 06:03:10 -08:00
|
|
|
Refresh: true,
|
|
|
|
Trigger: "c",
|
|
|
|
TriggerAfterSwap: "d",
|
|
|
|
TriggerAfterSettle: "e",
|
|
|
|
NoContent: true,
|
|
|
|
}
|
|
|
|
r.Apply(ctx)
|
|
|
|
|
2024-06-22 08:07:43 -07:00
|
|
|
assert.Equal(t, "a", ctx.Response().Header().Get(HeaderPushURL))
|
2021-12-24 06:03:10 -08:00
|
|
|
assert.Equal(t, "b", ctx.Response().Header().Get(HeaderRedirect))
|
|
|
|
assert.Equal(t, "true", ctx.Response().Header().Get(HeaderRefresh))
|
|
|
|
assert.Equal(t, "c", ctx.Response().Header().Get(HeaderTrigger))
|
|
|
|
assert.Equal(t, "d", ctx.Response().Header().Get(HeaderTriggerAfterSwap))
|
|
|
|
assert.Equal(t, "e", ctx.Response().Header().Get(HeaderTriggerAfterSettle))
|
2024-06-22 08:07:43 -07:00
|
|
|
assert.Equal(t, "f", ctx.Response().Header().Get(HeaderReplaceURL))
|
2021-12-24 06:03:10 -08:00
|
|
|
assert.Equal(t, http.StatusNoContent, ctx.Response().Status)
|
|
|
|
}
|