v4, beta4 (#19)
- Update with header/attribute changes between alpha8 and beta4 - Add support for htmax script, attributes, headers, and extension config Reviewed-on: #19
This commit was merged in pull request #19.
This commit is contained in:
1 parent
d4a7e0c9ce
commit
5c12ad7cef
22 files changed
+1066
-214
No files matched your search
+120
-67
@@ -1,6 +1,7 @@
|
||||
module ViewEngine
|
||||
|
||||
open Expecto
|
||||
open Giraffe.Htmx
|
||||
open Giraffe.ViewEngine
|
||||
open Giraffe.ViewEngine.Htmx
|
||||
|
||||
@@ -129,22 +130,12 @@ let hxEvent =
|
||||
Expect.equal (AfterRequest.ToHxOnString()) "after:request" "AfterRequest hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "AfterSseMessage" [
|
||||
testList "AfterSettle" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string AfterSseMessage) "afterSseMessage" "AfterSseMessage event name not correct"
|
||||
Expect.equal (string AfterSettle) "afterSettle" "AfterSettle event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(AfterSseMessage.ToHxOnString()) "after:sse:message" "AfterSseMessage hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "AfterSseStream" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string AfterSseStream) "afterSseStream" "AfterSseStream event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(AfterSseStream.ToHxOnString()) "after:sse:stream" "AfterSseStream hx-on event name not correct"
|
||||
Expect.equal (AfterSettle.ToHxOnString()) "after:settle" "AfterSettle hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "AfterSwap" [
|
||||
@@ -184,6 +175,15 @@ let hxEvent =
|
||||
Expect.equal (BeforeInit.ToHxOnString()) "before:init" "BeforeInit hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeProcess" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeProcess) "beforeProcess" "BeforeProcess event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeProcess.ToHxOnString()) "before:process" "BeforeProcess hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeRestoreHistory" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal
|
||||
@@ -205,36 +205,13 @@ let hxEvent =
|
||||
(BeforeRequest.ToHxOnString()) "before:request" "BeforeRequest hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSseMessage" [
|
||||
testList "BeforeResponse" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeSseMessage) "beforeSseMessage" "BeforeSseMessage event name not correct"
|
||||
Expect.equal (string BeforeResponse) "beforeResponse" "BeforeResponse event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeSseMessage.ToHxOnString())
|
||||
"before:sse:message"
|
||||
"BeforeSseMessage hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSseReconnect" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal
|
||||
(string BeforeSseReconnect) "beforeSseReconnect" "BeforeSseReconnect event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeSseReconnect.ToHxOnString())
|
||||
"before:sse:reconnect"
|
||||
"BeforeSseReconnect hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSseStream" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeSseStream) "beforeSseStream" "BeforeSseStream event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeSseStream.ToHxOnString()) "before:sse:stream" "BeforeSseStream hx-on event name not correct"
|
||||
(BeforeResponse.ToHxOnString()) "before:response" "BeforeResponse hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSwap" [
|
||||
@@ -279,6 +256,15 @@ let hxEvent =
|
||||
(FinallyRequest.ToHxOnString()) "finally:request" "FinallyRequest hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "ResponseError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string ResponseError) "responseError" "ResponseError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(ResponseError.ToHxOnString()) "response:error" "ResponseError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
/// Tests for the HxHeaders module
|
||||
@@ -572,7 +558,7 @@ let attributes =
|
||||
}
|
||||
test "_hxOnHxEvent succeeds" {
|
||||
strong [ _hxOnHxEvent BeforeSwap "changeStuff()" ] []
|
||||
|> shouldRender """<strong hx-on::before:swap="changeStuff()"></strong>"""
|
||||
|> shouldRender """<strong hx-on:htmx:before:swap="changeStuff()"></strong>"""
|
||||
}
|
||||
test "_hxPatch succeeds" {
|
||||
div [ _hxPatch "/arrrgh" ] [] |> shouldRender """<div hx-patch="/arrrgh"></div>"""
|
||||
@@ -598,6 +584,18 @@ let attributes =
|
||||
test "_hxSelectOob succeeds" {
|
||||
section [ _hxSelectOob "#oob" ] [] |> shouldRender """<section hx-select-oob="#oob"></section>"""
|
||||
}
|
||||
testList "_hxStatus" [
|
||||
test "succeeds for a full code with no action" {
|
||||
div [ _hxStatus "403" HxSwap.After "" ] [] |> shouldRender """<div hx-status:403="swap:after"></div>"""
|
||||
}
|
||||
test "succeeds for a two-digit range with action" {
|
||||
span [ _hxStatus "41" HxSwap.Before "target:main" ] []
|
||||
|> shouldRender """<span hx-status:41x="swap:before target:main"></span>"""
|
||||
}
|
||||
test "succeeds for a one-digit range with no action" {
|
||||
p [ _hxStatus "5" HxSwap.None "" ] [] |> shouldRender """<p hx-status:5xx="swap:none"></p>"""
|
||||
}
|
||||
]
|
||||
test "_hxSwap succeeds" {
|
||||
del [ _hxSwap "innerHTML" ] [] |> shouldRender """<del hx-swap="innerHTML"></del>"""
|
||||
}
|
||||
@@ -625,12 +623,6 @@ let attributes =
|
||||
dt [ _hxVals """{ "extra": "values" }""" ] []
|
||||
|> shouldRender """<dt hx-vals="{ "extra": "values" }"></dt>"""
|
||||
}
|
||||
test "_sseConnect succeeds" {
|
||||
div [ _sseConnect "/gps/sse" ] [] |> shouldRender """<div sse-connect="/gps/sse"></div>"""
|
||||
}
|
||||
test "_sseSwap succeeds" {
|
||||
ul [ _sseSwap "sseMessageName" ] [] |> shouldRender """<ul sse-swap="sseMessageName"></ul>"""
|
||||
}
|
||||
]
|
||||
|
||||
/// Tests for the HxModifiers module
|
||||
@@ -671,8 +663,6 @@ let hxTags =
|
||||
}
|
||||
]
|
||||
|
||||
open Giraffe.Htmx.Common
|
||||
|
||||
/// Tests for the Script module
|
||||
let script =
|
||||
testList "Script" [
|
||||
@@ -687,16 +677,39 @@ let script =
|
||||
let html = RenderView.AsString.htmlNode Script.cdnMinified
|
||||
Expect.equal
|
||||
html
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.min.js" integrity="sha384-hUj4cz/Dd2p+Dq0r8A6TAMS1u7gu2bTyisk8xCQX3nodazPP+fRmcAWJrTh4Ycwb" crossorigin="anonymous"></script>"""
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.min.js" integrity="sha384-aWZK1NtOs/aWb/+YZdTM8q2JkWEshlMc9mgZ189numT9bwFhyAyYEoO4nO/2dTXt" crossorigin="anonymous"></script>"""
|
||||
"CDN minified script tag is incorrect"
|
||||
}
|
||||
test "cdnUnminified succeeds" {
|
||||
let html = RenderView.AsString.htmlNode Script.cdnUnminified
|
||||
Expect.equal
|
||||
html
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.js" integrity="sha384-CHKZYHwIgmpkwoWtoPaiFIiMxP1Up7yHcsZ2NeECzLxRTXCO0mqXlujZwdJgFsFC" crossorigin="anonymous"></script>"""
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.js" integrity="sha384-OFLRIZpuqI2wwFozxvDGcuF3TQ36ySMgp44WEthOiR4wFzRkhZbK72HFaBo2C3cx" crossorigin="anonymous"></script>"""
|
||||
"CDN unminified script tag is incorrect"
|
||||
}
|
||||
testList "Max" [
|
||||
test "localMax succeeds" {
|
||||
let html = RenderView.AsString.htmlNode Script.Max.local
|
||||
Expect.equal
|
||||
html
|
||||
$"""<script src="/_content/Giraffe.Htmx.Common/htmax.min.js?ver={HtmxVersion}"></script>"""
|
||||
"Local script tag is incorrect"
|
||||
}
|
||||
test "cdnMaxMinified succeeds" {
|
||||
let html = RenderView.AsString.htmlNode Script.Max.cdnMinified
|
||||
Expect.equal
|
||||
html
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.min.js" integrity="sha384-Qoqie5IRtOE79SDFFRSb/yKi+pkzpSnfjgwr1KksyP14OaHkLHar0KrLVxUwlsJF" crossorigin="anonymous"></script>"""
|
||||
"CDN minified script tag is incorrect"
|
||||
}
|
||||
test "cdnMaxUnminified succeeds" {
|
||||
let html = RenderView.AsString.htmlNode Script.Max.cdnUnminified
|
||||
Expect.equal
|
||||
html
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.js" integrity="sha384-gGi3Urue6ZkE4NrJCmXWIZkfNkrt1IrdP3fr0kb/v06GWg3V1RnD9Pg/Ul3qhtAK" crossorigin="anonymous"></script>"""
|
||||
"CDN unminified script tag is incorrect"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
open System.Text
|
||||
@@ -864,15 +877,25 @@ let hxEventObs =
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(AfterProcessNode.ToHxOnString()) "after:init" "AfterProcessNode hx-on event name not correct"
|
||||
(AfterProcessNode.ToHxOnString()) "after:process" "AfterProcessNode hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "AfterSettle" [
|
||||
testList "AfterSseMessage" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string AfterSettle) "afterSettle" "AfterSettle event name not correct"
|
||||
Expect.equal (string AfterSseMessage) "afterSseMessage" "AfterSseMessage event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (AfterSettle.ToHxOnString()) "after:swap" "AfterSettle hx-on event name not correct"
|
||||
Expect.equal
|
||||
(AfterSseMessage.ToHxOnString()) "after:sse:message" "AfterSseMessage hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "AfterSseStream" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string AfterSseStream) "afterSseStream" "AfterSseStream event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(AfterSseStream.ToHxOnString()) "after:sse:stream" "AfterSseStream hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeCleanupElement" [
|
||||
@@ -912,7 +935,7 @@ let hxEventObs =
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeProcessNode.ToHxOnString()) "before:init" "BeforeProcessNode hx-on event name not correct"
|
||||
(BeforeProcessNode.ToHxOnString()) "before:process" "BeforeProcessNode hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSend" [
|
||||
@@ -923,6 +946,38 @@ let hxEventObs =
|
||||
Expect.equal (BeforeSend.ToHxOnString()) "before:request" "BeforeSend hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSseMessage" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeSseMessage) "beforeSseMessage" "BeforeSseMessage event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeSseMessage.ToHxOnString())
|
||||
"before:sse:message"
|
||||
"BeforeSseMessage hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSseReconnect" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal
|
||||
(string BeforeSseReconnect) "beforeSseReconnect" "BeforeSseReconnect event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeSseReconnect.ToHxOnString())
|
||||
"before:sse:reconnect"
|
||||
"BeforeSseReconnect hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSseStream" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeSseStream) "beforeSseStream" "BeforeSseStream event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeSseStream.ToHxOnString()) "before:sse:stream" "BeforeSseStream hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "HistoryCacheError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string HistoryCacheError) "historyCacheError" "HistoryCacheError event name not correct"
|
||||
@@ -1049,14 +1104,6 @@ let hxEventObs =
|
||||
"PushedIntoHistory hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "ResponseError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string ResponseError) "responseError" "ResponseError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (ResponseError.ToHxOnString()) "error" "ResponseError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "SendError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string SendError) "sendError" "SendError event name not correct"
|
||||
@@ -1070,7 +1117,7 @@ let hxEventObs =
|
||||
Expect.equal (string SseError) "sseError" "SseError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (SseError.ToHxOnString()) "error" "SseError hx-on event name not correct"
|
||||
Expect.equal (SseError.ToHxOnString()) "sse:error" "SseError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "SseOpen" [
|
||||
@@ -1078,7 +1125,7 @@ let hxEventObs =
|
||||
Expect.equal (string SseOpen) "sseOpen" "SseOpen event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (SseOpen.ToHxOnString()) "sse-open" "SseOpen hx-on event name not correct"
|
||||
Expect.equal (SseOpen.ToHxOnString()) "after:sse:connection" "SseOpen hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "SwapError" [
|
||||
@@ -1144,7 +1191,7 @@ let hxEventObs =
|
||||
Expect.equal (string XhrAbort) "xhr:abort" "XhrAbort event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (XhrAbort.ToHxOnString()) "xhr:abort" "XhrAbort hx-on event name not correct"
|
||||
Expect.equal (XhrAbort.ToHxOnString()) "error" "XhrAbort hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "XhrLoadEnd" [
|
||||
@@ -1152,7 +1199,7 @@ let hxEventObs =
|
||||
Expect.equal (string XhrLoadEnd) "xhr:loadend" "XhrLoadEnd event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (XhrLoadEnd.ToHxOnString()) "xhr:loadend" "XhrLoadEnd hx-on event name not correct"
|
||||
Expect.equal (XhrLoadEnd.ToHxOnString()) "finally:request" "XhrLoadEnd hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "XhrLoadStart" [
|
||||
@@ -1274,6 +1321,12 @@ let attributesObs =
|
||||
test "_hxRequest succeeds" {
|
||||
u [ _hxRequest "noHeaders" ] [] |> shouldRender """<u hx-request="noHeaders"></u>"""
|
||||
}
|
||||
test "_sseConnect succeeds" {
|
||||
div [ _sseConnect "/gps/sse" ] [] |> shouldRender """<div sse-connect="/gps/sse"></div>"""
|
||||
}
|
||||
test "_sseSwap succeeds" {
|
||||
ul [ _sseSwap "sseMessageName" ] [] |> shouldRender """<ul sse-swap="sseMessageName"></ul>"""
|
||||
}
|
||||
]
|
||||
|
||||
let obsolete = testList "Obsolete" [ hxEventObs; hxParamsObs; hxRequestObs; attributesObs ]
|
||||
|
||||
Reference in new issue
Block a user