Compare commits
No commits in common. "v2oh5prep" and "main" have entirely different histories.
@ -1,53 +1,28 @@
|
||||
/// <summary>Common definitions shared between attribute values and response headers</summary>
|
||||
/// Common definitions shared between attribute values and response headers
|
||||
[<AutoOpen>]
|
||||
module Giraffe.Htmx.Common
|
||||
|
||||
/// <summary>Serialize a list of key/value pairs to JSON (very rudimentary)</summary>
|
||||
/// <param name="pairs">The key/value pairs to be serialized to JSON</param>
|
||||
/// <returns>A string with the key/value pairs serialized to JSON</returns>
|
||||
let internal toJson (pairs: (string * string) list) =
|
||||
pairs
|
||||
|> List.map (fun pair -> sprintf "\"%s\": \"%s\"" (fst pair) ((snd pair).Replace ("\"", "\\\"")))
|
||||
|> String.concat ", "
|
||||
|> sprintf "{ %s }"
|
||||
|
||||
/// <summary>Convert a boolean to lowercase "true" or "false"</summary>
|
||||
/// <param name="boolValue">The boolean value to convert</param>
|
||||
/// <returns>"true" for <c>true</c>, "false" for <c>false</c></returns>
|
||||
let internal toLowerBool (boolValue: bool) =
|
||||
(string boolValue).ToLowerInvariant()
|
||||
|
||||
|
||||
/// <summary>Valid values for the <c>hx-swap</c> attribute / <c>HX-Reswap</c> header</summary>
|
||||
/// <remarks>May be combined with <c>swap</c> / <c>settle</c> / <c>scroll</c> / <c>show</c> config)</remarks>
|
||||
/// <seealso href="https://htmx.org/attributes/hx-swap/">Documentation</seealso>
|
||||
/// Valid values for the `hx-swap` attribute / `HX-Reswap` header (may be combined with swap/settle/scroll/show config)
|
||||
[<RequireQualifiedAccess>]
|
||||
module HxSwap =
|
||||
|
||||
/// <summary>The default, replace the inner HTML of the target element</summary>
|
||||
[<Literal>]
|
||||
/// The default, replace the inner html of the target element
|
||||
let InnerHtml = "innerHTML"
|
||||
|
||||
/// <summary>Replace the entire target element with the response</summary>
|
||||
[<Literal>]
|
||||
/// Replace the entire target element with the response
|
||||
let OuterHtml = "outerHTML"
|
||||
|
||||
/// <summary>Insert the response before the target element</summary>
|
||||
[<Literal>]
|
||||
/// Insert the response before the target element
|
||||
let BeforeBegin = "beforebegin"
|
||||
|
||||
/// <summary>Insert the response before the first child of the target element</summary>
|
||||
[<Literal>]
|
||||
/// Insert the response before the first child of the target element
|
||||
let AfterBegin = "afterbegin"
|
||||
|
||||
/// <summary>Insert the response after the last child of the target element</summary>
|
||||
[<Literal>]
|
||||
/// Insert the response after the last child of the target element
|
||||
let BeforeEnd = "beforeend"
|
||||
|
||||
/// <summary>Insert the response after the target element</summary>
|
||||
[<Literal>]
|
||||
/// Insert the response after the target element
|
||||
let AfterEnd = "afterend"
|
||||
|
||||
/// <summary>Does not append content from response (out of band items will still be processed).</summary>
|
||||
[<Literal>]
|
||||
/// Does not append content from response (out of band items will still be processed).
|
||||
let None = "none"
|
||||
|
@ -4,7 +4,6 @@
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<Description>Common definitions for Giraffe.Htmx</Description>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -17,8 +16,4 @@
|
||||
<PackageReference Update="FSharp.Core" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="Giraffe.Htmx" />
|
||||
<InternalsVisibleTo Include="Giraffe.ViewEngine.Htmx" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -1,10 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
<VersionPrefix>2.0.5</VersionPrefix>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageReleaseNotes>Add full packaged XML documentation; update script tags to pull htmx 2.0.5 (no header or attribute changes)</PackageReleaseNotes>
|
||||
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||
<VersionPrefix>2.0.4</VersionPrefix>
|
||||
<PackageReleaseNotes>Update script tags to pull htmx 2.0.4 (no header or attribute changes)</PackageReleaseNotes>
|
||||
<Authors>danieljsummers</Authors>
|
||||
<Company>Bit Badger Solutions</Company>
|
||||
<PackageProjectUrl>https://git.bitbadger.solutions/bit-badger/Giraffe.Htmx</PackageProjectUrl>
|
||||
|
@ -4,7 +4,6 @@
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<Description>htmx header extensions and helpers for Giraffe</Description>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
189
src/Htmx/Htmx.fs
189
src/Htmx/Htmx.fs
@ -11,162 +11,121 @@ let private hdr (headers : IHeaderDictionary) hdr =
|
||||
/// Extensions to the header dictionary
|
||||
type IHeaderDictionary with
|
||||
|
||||
/// <summary>Indicates that the request is via an element using <c>hx-boost</c></summary>
|
||||
member this.HxBoosted
|
||||
with get () = hdr this "HX-Boosted" |> Option.map bool.Parse
|
||||
/// Indicates that the request is via an element using `hx-boost`
|
||||
member this.HxBoosted with get () = hdr this "HX-Boosted" |> Option.map bool.Parse
|
||||
|
||||
/// <summary>The current URL of the browser <em>(note that this does not update until after settle)</em></summary>
|
||||
member this.HxCurrentUrl
|
||||
with get () = hdr this "HX-Current-URL" |> Option.map Uri
|
||||
/// The current URL of the browser _(note that this does not update until after settle)_
|
||||
member this.HxCurrentUrl with get () = hdr this "HX-Current-URL" |> Option.map Uri
|
||||
|
||||
/// <summary><c>true</c> if the request is for history restoration after a miss in the local history cache</summary>
|
||||
member this.HxHistoryRestoreRequest
|
||||
with get () = hdr this "HX-History-Restore-Request" |> Option.map bool.Parse
|
||||
/// `true` if the request is for history restoration after a miss in the local history cache
|
||||
member this.HxHistoryRestoreRequest with get () = hdr this "HX-History-Restore-Request" |> Option.map bool.Parse
|
||||
|
||||
/// <summary>The user response to an <c>hx-prompt</c></summary>
|
||||
member this.HxPrompt
|
||||
with get () = hdr this "HX-Prompt"
|
||||
/// The user response to an `hx-prompt`
|
||||
member this.HxPrompt with get () = hdr this "HX-Prompt"
|
||||
|
||||
/// <summary><c>true</c> if the request came from htmx</summary>
|
||||
member this.HxRequest
|
||||
with get () = hdr this "HX-Request" |> Option.map bool.Parse
|
||||
/// `true` if the request came from HTMX
|
||||
member this.HxRequest with get () = hdr this "HX-Request" |> Option.map bool.Parse
|
||||
|
||||
/// <summary>The <c>id</c> attribute of the target element if it exists</summary>
|
||||
member this.HxTarget
|
||||
with get () = hdr this "HX-Target"
|
||||
/// The `id` of the target element if it exists
|
||||
member this.HxTarget with get () = hdr this "HX-Target"
|
||||
|
||||
/// <summary>The <c>id</c> attribute of the triggered element if it exists</summary>
|
||||
member this.HxTrigger
|
||||
with get () = hdr this "HX-Trigger"
|
||||
/// The `id` of the triggered element if it exists
|
||||
member this.HxTrigger with get () = hdr this "HX-Trigger"
|
||||
|
||||
/// <summary>The <c>name</c> attribute of the triggered element if it exists</summary>
|
||||
member this.HxTriggerName
|
||||
with get () = hdr this "HX-Trigger-Name"
|
||||
/// The `name` of the triggered element if it exists
|
||||
member this.HxTriggerName with get () = hdr this "HX-Trigger-Name"
|
||||
|
||||
|
||||
/// Extensions for the request object
|
||||
type HttpRequest with
|
||||
|
||||
/// <summary>Whether this request was initiated from htmx</summary>
|
||||
member this.IsHtmx
|
||||
with get () = this.Headers.HxRequest |> Option.defaultValue false
|
||||
/// Whether this request was initiated from htmx
|
||||
member this.IsHtmx with get () = this.Headers.HxRequest |> Option.defaultValue false
|
||||
|
||||
/// <summary>Whether this request is an htmx history-miss refresh request</summary>
|
||||
member this.IsHtmxRefresh
|
||||
with get () = this.IsHtmx && (this.Headers.HxHistoryRestoreRequest |> Option.defaultValue false)
|
||||
/// Whether this request is an htmx history-miss refresh request
|
||||
member this.IsHtmxRefresh with get () =
|
||||
this.IsHtmx && (this.Headers.HxHistoryRestoreRequest |> Option.defaultValue false)
|
||||
|
||||
|
||||
/// <summary>HTTP handlers for setting output headers</summary>
|
||||
/// HTTP handlers for setting output headers
|
||||
[<AutoOpen>]
|
||||
module Handlers =
|
||||
|
||||
open Giraffe.Htmx.Common
|
||||
/// Convert a boolean to lowercase `true` or `false`
|
||||
let private toLowerBool (trueOrFalse : bool) =
|
||||
(string trueOrFalse).ToLowerInvariant ()
|
||||
|
||||
/// <summary>Instruct htmx to perform a client-side redirect for content</summary>
|
||||
/// <param name="path">The path where the content should be found</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Location</c> header set</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-location/">Documentation</seealso>
|
||||
let withHxLocation (path: string) : HttpHandler =
|
||||
setHttpHeader "HX-Location" path
|
||||
/// Serialize a list of key/value pairs to JSON (very rudimentary)
|
||||
let private toJson (evts : (string * string) list) =
|
||||
evts
|
||||
|> List.map (fun evt -> sprintf "\"%s\": \"%s\"" (fst evt) ((snd evt).Replace ("\"", "\\\"")))
|
||||
|> String.concat ", "
|
||||
|> sprintf "{ %s }"
|
||||
|
||||
/// <summary>Pushes a new url into the history stack</summary>
|
||||
/// <param name="url">The URL to be pushed</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Push-Url</c> header set</returns>
|
||||
/// <remarks>Use <see cref="withHxNoPushUrl" /> to explicitly not push a new URL</remarks>
|
||||
/// <seealso href="https://htmx.org/headers/hx-push-url/">Documentation</seealso>
|
||||
let withHxPushUrl (url: string) : HttpHandler =
|
||||
setHttpHeader "HX-Push-Url" url
|
||||
/// Pushes a new url into the history stack
|
||||
let withHxPushUrl : string -> HttpHandler =
|
||||
setHttpHeader "HX-Push-Url"
|
||||
|
||||
/// <summary>Explicitly do not push a new URL into the history stack</summary>
|
||||
/// <returns>An HTTP handler with the <c>HX-Push-Url</c> header set to <c>false</c></returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-push-url/">Documentation</seealso>
|
||||
/// Explicitly do not push a new URL into the history stack
|
||||
let withHxNoPushUrl : HttpHandler =
|
||||
toLowerBool false |> withHxPushUrl
|
||||
|
||||
/// <summary>Can be used to do a client-side redirect to a new location</summary>
|
||||
/// <param name="url">The URL to which the client should be redirected</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Redirect</c> header set</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-redirect/">Documentation</seealso>
|
||||
let withHxRedirect (url: string) : HttpHandler =
|
||||
setHttpHeader "HX-Redirect" url
|
||||
/// Pushes a new url into the history stack
|
||||
[<Obsolete "Use withHxPushUrl; HX-Push was replaced by HX-Push-Url in v1.8.0">]
|
||||
let withHxPush = withHxPushUrl
|
||||
|
||||
/// <summary>If set to <c>true</c> the client side will do a full refresh of the page</summary>
|
||||
/// <param name="shouldRefresh">Whether the client should refresh their page</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Refresh</c> header set</returns>
|
||||
let withHxRefresh shouldRefresh : HttpHandler =
|
||||
(toLowerBool >> setHttpHeader "HX-Refresh") shouldRefresh
|
||||
/// Explicitly do not push a new URL into the history stack
|
||||
[<Obsolete "Use withHxNoPushUrl; HX-Push was replaced by HX-Push-Url in v1.8.0">]
|
||||
let withHxNoPush = withHxNoPushUrl
|
||||
|
||||
/// <summary>Replaces the current URL in the history stack</summary>
|
||||
/// <param name="url">The URL to place in the history stack in place of the current one</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Replace-URL</c> header set</returns>
|
||||
/// <remarks>Use <see cref="withHxNoRelaceUrl" /> to explicitly not replace the current URL</remarks>
|
||||
/// <seealso href="https://htmx.org/headers/hx-replace-url/">Documentation</seealso>
|
||||
let withHxReplaceUrl url : HttpHandler =
|
||||
setHttpHeader "HX-Replace-Url" url
|
||||
/// Can be used to do a client-side redirect to a new location
|
||||
let withHxRedirect : string -> HttpHandler =
|
||||
setHttpHeader "HX-Redirect"
|
||||
|
||||
/// <summary>Explicitly do not replace the current URL in the history stack</summary>
|
||||
/// <returns>An HTTP handler with the <c>HX-Replace-URL</c> header set to <c>false</c></returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-replace-url/">Documentation</seealso>
|
||||
/// If set to `true` the client side will do a a full refresh of the page
|
||||
let withHxRefresh : bool -> HttpHandler =
|
||||
toLowerBool >> setHttpHeader "HX-Refresh"
|
||||
|
||||
/// Replaces the current URL in the history stack
|
||||
let withHxReplaceUrl : string -> HttpHandler =
|
||||
setHttpHeader "HX-Replace-Url"
|
||||
|
||||
/// Explicitly do not replace the current URL in the history stack
|
||||
let withHxNoReplaceUrl : HttpHandler =
|
||||
toLowerBool false |> withHxReplaceUrl
|
||||
|
||||
/// <summary>Override which portion of the response will be swapped into the target document</summary>
|
||||
/// <param name="target">The selector for the new response target</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Reselect</c> header set</returns>
|
||||
let withHxReselect (target: string) : HttpHandler =
|
||||
setHttpHeader "HX-Reselect" target
|
||||
/// Override which portion of the response will be swapped into the target document
|
||||
let withHxReselect : string -> HttpHandler =
|
||||
setHttpHeader "HX-Reselect"
|
||||
|
||||
/// <summary>Override the <c>hx-swap</c> attribute from the initiating element</summary>
|
||||
/// <param name="swap">The swap value to override</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Reswap</c> header set</returns>
|
||||
/// <remarks>Use <see cref="T:Giraffe.Htmx.Common.HxSwap">HxSwap</see> constants for best results</remarks>
|
||||
let withHxReswap (swap: string) : HttpHandler =
|
||||
setHttpHeader "HX-Reswap" swap
|
||||
/// Override the `hx-swap` attribute from the initiating element
|
||||
let withHxReswap : string -> HttpHandler =
|
||||
setHttpHeader "HX-Reswap"
|
||||
|
||||
/// <summary>Allows you to override the <c>hx-target</c> attribute</summary>
|
||||
/// <param name="target">The new target for the response</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Retarget</c> header set</returns>
|
||||
let withHxRetarget (target: string) : HttpHandler =
|
||||
setHttpHeader "HX-Retarget" target
|
||||
/// Allows you to override the `hx-target` attribute
|
||||
let withHxRetarget : string -> HttpHandler =
|
||||
setHttpHeader "HX-Retarget"
|
||||
|
||||
/// <summary>Allows you to trigger a single client side event</summary>
|
||||
/// <param name="evt">The call to the event that should be triggered</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Trigger</c> header set</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-trigger/">Documentation</seealso>
|
||||
let withHxTrigger (evt: string) : HttpHandler =
|
||||
setHttpHeader "HX-Trigger" evt
|
||||
/// Allows you to trigger a single client side event
|
||||
let withHxTrigger : string -> HttpHandler =
|
||||
setHttpHeader "HX-Trigger"
|
||||
|
||||
/// <summary>Allows you to trigger multiple client side events</summary>
|
||||
/// <param name="evts">The calls to events that should be triggered</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Trigger</c> header set for all given events</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-trigger/">Documentation</seealso>
|
||||
/// Allows you to trigger multiple client side events
|
||||
let withHxTriggerMany evts : HttpHandler =
|
||||
toJson evts |> setHttpHeader "HX-Trigger"
|
||||
|
||||
/// <summary>Allows you to trigger a single client side event after changes have settled</summary>
|
||||
/// <param name="evt">The call to the event that should be triggered</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Trigger-After-Settle</c> header set</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-trigger/">Documentation</seealso>
|
||||
let withHxTriggerAfterSettle (evt: string) : HttpHandler =
|
||||
setHttpHeader "HX-Trigger-After-Settle" evt
|
||||
/// Allows you to trigger a single client side event after changes have settled
|
||||
let withHxTriggerAfterSettle : string -> HttpHandler =
|
||||
setHttpHeader "HX-Trigger-After-Settle"
|
||||
|
||||
/// <summary>Allows you to trigger multiple client side events after changes have settled</summary>
|
||||
/// <param name="evts">The calls to events that should be triggered</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Trigger-After-Settle</c> header set for all given events</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-trigger/">Documentation</seealso>
|
||||
/// Allows you to trigger multiple client side events after changes have settled
|
||||
let withHxTriggerManyAfterSettle evts : HttpHandler =
|
||||
toJson evts |> setHttpHeader "HX-Trigger-After-Settle"
|
||||
|
||||
/// <summary>Allows you to trigger a single client side event after DOM swapping occurs</summary>
|
||||
/// <param name="evt">The call to the event that should be triggered</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Trigger-After-Swap</c> header set</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-trigger/">Documentation</seealso>
|
||||
let withHxTriggerAfterSwap (evt: string) : HttpHandler =
|
||||
setHttpHeader "HX-Trigger-After-Swap" evt
|
||||
/// Allows you to trigger a single client side event after DOM swapping occurs
|
||||
let withHxTriggerAfterSwap : string -> HttpHandler =
|
||||
setHttpHeader "HX-Trigger-After-Swap"
|
||||
|
||||
/// <summary>Allows you to trigger multiple client side events after DOM swapping occurs</summary>
|
||||
/// <param name="evts">The calls to events that should be triggered</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Trigger-After-Swap</c> header set for all given events</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-trigger/">Documentation</seealso>
|
||||
/// Allows you to trigger multiple client side events after DOM swapping occurs
|
||||
let withHxTriggerManyAfterSwap evts : HttpHandler =
|
||||
toJson evts |> setHttpHeader "HX-Trigger-After-Swap"
|
||||
|
@ -11,22 +11,22 @@ let dictExtensions =
|
||||
testList "IHeaderDictionaryExtensions" [
|
||||
testList "HxBoosted" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxBoosted "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present and true" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Boosted", "true")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Boosted", "true")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxBoosted "There should be a header present"
|
||||
Expect.isTrue ctx.Request.Headers.HxBoosted.Value "The header value should have been true"
|
||||
}
|
||||
test "succeeds when the header is present and false" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Boosted", "false")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Boosted", "false")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxBoosted "There should be a header present"
|
||||
Expect.isFalse ctx.Request.Headers.HxBoosted.Value "The header value should have been false"
|
||||
@ -34,14 +34,14 @@ let dictExtensions =
|
||||
]
|
||||
testList "HxCurrentUrl" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxCurrentUrl "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Current-URL", "http://localhost/test.htm")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Current-URL", "http://localhost/test.htm")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxCurrentUrl "There should be a header present"
|
||||
Expect.equal
|
||||
@ -51,22 +51,22 @@ let dictExtensions =
|
||||
]
|
||||
testList "HxHistoryRestoreRequest" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxHistoryRestoreRequest "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present and true" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-History-Restore-Request", "true")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-History-Restore-Request", "true")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxHistoryRestoreRequest "There should be a header present"
|
||||
Expect.isTrue ctx.Request.Headers.HxHistoryRestoreRequest.Value "The header value should have been true"
|
||||
}
|
||||
test "succeeds when the header is present and false" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-History-Restore-Request", "false")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-History-Restore-Request", "false")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxHistoryRestoreRequest "There should be a header present"
|
||||
Expect.isFalse
|
||||
@ -75,14 +75,14 @@ let dictExtensions =
|
||||
]
|
||||
testList "HxPrompt" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxPrompt "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Prompt", "of course")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Prompt", "of course")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxPrompt "There should be a header present"
|
||||
Expect.equal ctx.Request.Headers.HxPrompt.Value "of course" "The header value was incorrect"
|
||||
@ -90,22 +90,22 @@ let dictExtensions =
|
||||
]
|
||||
testList "HxRequest" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxRequest "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present and true" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Request", "true")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Request", "true")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxRequest "There should be a header present"
|
||||
Expect.isTrue ctx.Request.Headers.HxRequest.Value "The header should have been true"
|
||||
}
|
||||
test "succeeds when the header is present and false" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Request", "false")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Request", "false")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxRequest "There should be a header present"
|
||||
Expect.isFalse ctx.Request.Headers.HxRequest.Value "The header should have been false"
|
||||
@ -113,14 +113,14 @@ let dictExtensions =
|
||||
]
|
||||
testList "HxTarget" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxTarget "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Target", "#leItem")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Target", "#leItem")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxTarget "There should be a header present"
|
||||
Expect.equal ctx.Request.Headers.HxTarget.Value "#leItem" "The header value was incorrect"
|
||||
@ -128,14 +128,14 @@ let dictExtensions =
|
||||
]
|
||||
testList "HxTrigger" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxTrigger "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Trigger", "#trig")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Trigger", "#trig")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxTrigger "There should be a header present"
|
||||
Expect.equal ctx.Request.Headers.HxTrigger.Value "#trig" "The header value was incorrect"
|
||||
@ -143,14 +143,14 @@ let dictExtensions =
|
||||
]
|
||||
testList "HxTriggerName" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxTriggerName "There should not have been a header returned"
|
||||
}
|
||||
test "HxTriggerName succeeds when the header is present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Trigger-Name", "click")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Trigger-Name", "click")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxTriggerName "There should be a header present"
|
||||
Expect.equal ctx.Request.Headers.HxTriggerName.Value "click" "The header value was incorrect"
|
||||
@ -163,36 +163,36 @@ let reqExtensions =
|
||||
testList "HttpRequestExtensions" [
|
||||
testList "IsHtmx" [
|
||||
test "succeeds when request is not from htmx" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isFalse ctx.Request.IsHtmx "The request should not be an htmx request"
|
||||
}
|
||||
test "succeeds when request is from htmx" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Request", "true")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Request", "true")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isTrue ctx.Request.IsHtmx "The request should have been an htmx request"
|
||||
}
|
||||
]
|
||||
testList "IsHtmxRefresh" [
|
||||
test "succeeds when request is not from htmx" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isFalse ctx.Request.IsHtmxRefresh "The request should not have been an htmx refresh"
|
||||
}
|
||||
test "succeeds when request is from htmx, but not a refresh" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Request", "true")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Request", "true")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isFalse ctx.Request.IsHtmxRefresh "The request should not have been an htmx refresh"
|
||||
}
|
||||
test "IsHtmxRefresh succeeds when request is from htmx and is a refresh" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Request", "true")
|
||||
dic.Add("HX-History-Restore-Request", "true")
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
dic.Add ("HX-Request", "true")
|
||||
dic.Add ("HX-History-Restore-Request", "true")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isTrue ctx.Request.IsHtmxRefresh "The request should have been an htmx refresh"
|
||||
}
|
||||
@ -202,38 +202,30 @@ let reqExtensions =
|
||||
open System.Threading.Tasks
|
||||
|
||||
/// Dummy "next" parameter to get the pipeline to execute/terminate
|
||||
let next (ctx: HttpContext) = Task.FromResult(Some ctx)
|
||||
let next (ctx : HttpContext) = Task.FromResult (Some ctx)
|
||||
|
||||
/// Tests for the HttpHandler functions provided in the Handlers module
|
||||
let handlers =
|
||||
testList "HandlerTests" [
|
||||
testTask "withHxLocation succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxLocation "/pagina-otro.html" next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Location") "The HX-Location header should be present"
|
||||
Expect.equal dic["HX-Location"].[0] "/pagina-otro.html" "The HX-Location value was incorrect"
|
||||
}
|
||||
testTask "withHxPushUrl succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxPushUrl "/a-new-url" next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Push-Url") "The HX-Push-Url header should be present"
|
||||
Expect.equal dic["HX-Push-Url"].[0] "/a-new-url" "The HX-Push-Url value was incorrect"
|
||||
}
|
||||
testTask "withHxNoPushUrl succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxNoPushUrl next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Push-Url") "The HX-Push-Url header should be present"
|
||||
Expect.equal dic["HX-Push-Url"].[0] "false" "The HX-Push-Url value was incorrect"
|
||||
}
|
||||
testTask "withHxRedirect succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxRedirect "/somewhere-else" next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Redirect") "The HX-Redirect header should be present"
|
||||
@ -241,16 +233,16 @@ let handlers =
|
||||
}
|
||||
testList "withHxRefresh" [
|
||||
testTask "succeeds when set to true" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxRefresh true next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Refresh") "The HX-Refresh header should be present"
|
||||
Expect.equal dic["HX-Refresh"].[0] "true" "The HX-Refresh value was incorrect"
|
||||
}
|
||||
testTask "succeeds when set to false" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxRefresh false next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Refresh") "The HX-Refresh header should be present"
|
||||
@ -258,56 +250,56 @@ let handlers =
|
||||
}
|
||||
]
|
||||
testTask "withHxReplaceUrl succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxReplaceUrl "/a-substitute-url" next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Replace-Url") "The HX-Replace-Url header should be present"
|
||||
Expect.equal dic["HX-Replace-Url"].[0] "/a-substitute-url" "The HX-Replace-Url value was incorrect"
|
||||
}
|
||||
testTask "withHxNoReplaceUrl succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxNoReplaceUrl next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Replace-Url") "The HX-Replace-Url header should be present"
|
||||
Expect.equal dic["HX-Replace-Url"].[0] "false" "The HX-Replace-Url value was incorrect"
|
||||
}
|
||||
testTask "withHxReselect succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxReselect "#test" next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Reselect") "The HX-Reselect header should be present"
|
||||
Expect.equal dic["HX-Reselect"].[0] "#test" "The HX-Reselect value was incorrect"
|
||||
}
|
||||
testTask "withHxReswap succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxReswap HxSwap.BeforeEnd next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Reswap") "The HX-Reswap header should be present"
|
||||
Expect.equal dic["HX-Reswap"].[0] HxSwap.BeforeEnd "The HX-Reswap value was incorrect"
|
||||
}
|
||||
testTask "withHxRetarget succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxRetarget "#somewhereElse" next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Retarget") "The HX-Retarget header should be present"
|
||||
Expect.equal dic["HX-Retarget"].[0] "#somewhereElse" "The HX-Retarget value was incorrect"
|
||||
}
|
||||
testTask "withHxTrigger succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxTrigger "doSomething" next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Trigger") "The HX-Trigger header should be present"
|
||||
Expect.equal dic["HX-Trigger"].[0] "doSomething" "The HX-Trigger value was incorrect"
|
||||
}
|
||||
testTask "withHxTriggerMany succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxTriggerMany [ "blah", "foo"; "bleh", "bar" ] next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Trigger") "The HX-Trigger header should be present"
|
||||
@ -315,8 +307,8 @@ let handlers =
|
||||
dic["HX-Trigger"].[0] """{ "blah": "foo", "bleh": "bar" }""" "The HX-Trigger value was incorrect"
|
||||
}
|
||||
testTask "withHxTriggerAfterSettle succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxTriggerAfterSettle "byTheWay" next ctx
|
||||
Expect.isTrue
|
||||
@ -324,8 +316,8 @@ let handlers =
|
||||
Expect.equal dic["HX-Trigger-After-Settle"].[0] "byTheWay" "The HX-Trigger-After-Settle value was incorrect"
|
||||
}
|
||||
testTask "withHxTriggerManyAfterSettle succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxTriggerManyAfterSettle [ "oof", "ouch"; "hmm", "uh" ] next ctx
|
||||
Expect.isTrue
|
||||
@ -335,16 +327,16 @@ let handlers =
|
||||
"The HX-Trigger-After-Settle value was incorrect"
|
||||
}
|
||||
testTask "withHxTriggerAfterSwap succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxTriggerAfterSwap "justASec" next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Trigger-After-Swap") "The HX-Trigger-After-Swap header should be present"
|
||||
Expect.equal dic["HX-Trigger-After-Swap"].[0] "justASec" "The HX-Trigger-After-Swap value was incorrect"
|
||||
}
|
||||
testTask "withHxTriggerManyAfterSwap succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxTriggerManyAfterSwap [ "this", "1"; "that", "2" ] next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Trigger-After-Swap") "The HX-Trigger-After-Swap header should be present"
|
||||
|
@ -406,8 +406,8 @@ let hxEvent =
|
||||
Expect.equal (XhrProgress.ToHxOnString()) "xhr:progress" "XhrProgress hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
]
|
||||
/// Tests for the HxHeaders module
|
||||
let hxHeaders =
|
||||
testList "HxHeaders" [
|
||||
@ -497,32 +497,6 @@ let hxRequest =
|
||||
]
|
||||
]
|
||||
|
||||
/// Tests for the HxSync module
|
||||
let hxSync =
|
||||
testList "HxSync" [
|
||||
test "Drop is correct" {
|
||||
Expect.equal HxSync.Drop "drop" "Drop is incorrect"
|
||||
}
|
||||
test "Abort is correct" {
|
||||
Expect.equal HxSync.Abort "abort" "Abort is incorrect"
|
||||
}
|
||||
test "Replace is correct" {
|
||||
Expect.equal HxSync.Replace "replace" "Replace is incorrect"
|
||||
}
|
||||
test "Queue is correct" {
|
||||
Expect.equal HxSync.Queue "queue" "Queue is incorrect"
|
||||
}
|
||||
test "QueueFirst is correct" {
|
||||
Expect.equal HxSync.QueueFirst "queue first" "QueueFirst is incorrect"
|
||||
}
|
||||
test "QueueLast is correct" {
|
||||
Expect.equal HxSync.QueueLast "queue last" "QueueLast is incorrect"
|
||||
}
|
||||
test "QueueAll is correct" {
|
||||
Expect.equal HxSync.QueueAll "queue all" "QueueAll is incorrect"
|
||||
}
|
||||
]
|
||||
|
||||
/// Tests for the HxTrigger module
|
||||
let hxTrigger =
|
||||
testList "HxTrigger" [
|
||||
@ -662,9 +636,6 @@ let hxTrigger =
|
||||
test "succeeds when it is not the first modifier" {
|
||||
Expect.equal (HxTrigger.Queue "def" "click") "click queue:def" "Queue modifier incorrect"
|
||||
}
|
||||
test "succeeds when no type of queueing is given" {
|
||||
Expect.equal (HxTrigger.Queue "" "blur") "blur queue" "Queue modifier incorrect"
|
||||
}
|
||||
]
|
||||
testList "QueueFirst" [
|
||||
test "succeeds when it is the first modifier" {
|
||||
@ -755,7 +726,7 @@ let attributes =
|
||||
|> shouldRender """<figure hx-headers="{ "X-Special-Header": "some-header" }"></figure>"""
|
||||
}
|
||||
test "_hxHistory succeeds" {
|
||||
span [ _hxHistory false ] [] |> shouldRender """<span hx-history="false"></span>"""
|
||||
span [ _hxHistory "false" ] [] |> shouldRender """<span hx-history="false"></span>"""
|
||||
}
|
||||
test "_hxHistoryElt succeeds" {
|
||||
table [ _hxHistoryElt ] [] |> shouldRender """<table hx-history-elt></table>"""
|
||||
@ -786,7 +757,7 @@ let attributes =
|
||||
hr [ _hxPost "/hear-ye-hear-ye" ] |> shouldRender """<hr hx-post="/hear-ye-hear-ye">"""
|
||||
}
|
||||
test "_hxPreserve succeeds" {
|
||||
img [ _hxPreserve ] |> shouldRender """<img hx-preserve>"""
|
||||
img [ _hxPreserve ] |> shouldRender """<img hx-preserve="true">"""
|
||||
}
|
||||
test "_hxPrompt succeeds" {
|
||||
strong [ _hxPrompt "Who goes there?" ] []
|
||||
@ -821,8 +792,7 @@ let attributes =
|
||||
li [ _hxSwapOob "true" ] [] |> shouldRender """<li hx-swap-oob="true"></li>"""
|
||||
}
|
||||
test "_hxSync succeeds" {
|
||||
nav [ _hxSync "closest form" HxSync.Abort ] []
|
||||
|> shouldRender """<nav hx-sync="closest form:abort"></nav>"""
|
||||
nav [ _hxSync "closest form:abort" ] [] |> shouldRender """<nav hx-sync="closest form:abort"></nav>"""
|
||||
}
|
||||
test "_hxTarget succeeds" {
|
||||
header [ _hxTarget "#somewhereElse" ] [] |> shouldRender """<header hx-target="#somewhereElse"></header>"""
|
||||
@ -869,7 +839,7 @@ let renderFragment =
|
||||
|
||||
/// Validate that the two object references are the same object
|
||||
let isSame obj1 obj2 message =
|
||||
Expect.isTrue (obj.ReferenceEquals(obj1, obj2)) message
|
||||
Expect.isTrue (obj.ReferenceEquals (obj1, obj2)) message
|
||||
|
||||
testList "findIdNode" [
|
||||
test "fails with a Text node" {
|
||||
@ -951,7 +921,7 @@ let renderFragment =
|
||||
}
|
||||
test "fails when an ID is not matched" {
|
||||
Expect.equal
|
||||
(RenderFragment.AsBytes.htmlFromNodes "whiff" []) (utf8.GetBytes(nodeNotFound "whiff"))
|
||||
(RenderFragment.AsBytes.htmlFromNodes "whiff" []) (utf8.GetBytes (nodeNotFound "whiff"))
|
||||
"HTML bytes are incorrect"
|
||||
}
|
||||
]
|
||||
@ -968,7 +938,7 @@ let renderFragment =
|
||||
}
|
||||
test "fails when an ID is not matched" {
|
||||
Expect.equal
|
||||
(RenderFragment.AsBytes.htmlFromNode "foo" (hr [])) (utf8.GetBytes(nodeNotFound "foo"))
|
||||
(RenderFragment.AsBytes.htmlFromNode "foo" (hr [])) (utf8.GetBytes (nodeNotFound "foo"))
|
||||
"HTML bytes are incorrect"
|
||||
}
|
||||
]
|
||||
@ -976,31 +946,31 @@ let renderFragment =
|
||||
testList "IntoStringBuilder" [
|
||||
testList "htmlFromNodes" [
|
||||
test "succeeds when an ID is matched" {
|
||||
let sb = StringBuilder()
|
||||
let sb = StringBuilder ()
|
||||
RenderFragment.IntoStringBuilder.htmlFromNodes sb "find-me"
|
||||
[ p [] []; p [ _id "peekaboo" ] [ str "bzz"; str "nope"; span [ _id "find-me" ] [ str ";)" ] ]]
|
||||
Expect.equal (string sb) """<span id="find-me">;)</span>""" "HTML is incorrect"
|
||||
}
|
||||
test "fails when an ID is not matched" {
|
||||
let sb = StringBuilder()
|
||||
let sb = StringBuilder ()
|
||||
RenderFragment.IntoStringBuilder.htmlFromNodes sb "missing" []
|
||||
Expect.equal (string sb) (nodeNotFound "missing") "HTML is incorrect"
|
||||
}
|
||||
]
|
||||
testList "htmlFromNode" [
|
||||
test "succeeds when ID is matched at top level" {
|
||||
let sb = StringBuilder()
|
||||
let sb = StringBuilder ()
|
||||
RenderFragment.IntoStringBuilder.htmlFromNode sb "top" (p [ _id "top" ] [ str "pinnacle" ])
|
||||
Expect.equal (string sb) """<p id="top">pinnacle</p>""" "HTML is incorrect"
|
||||
}
|
||||
test "succeeds when ID is matched in child element" {
|
||||
let sb = StringBuilder()
|
||||
let sb = StringBuilder ()
|
||||
div [] [ p [] [ str "nada" ]; p [ _id "it" ] [ str "is here" ]]
|
||||
|> RenderFragment.IntoStringBuilder.htmlFromNode sb "it"
|
||||
Expect.equal (string sb) """<p id="it">is here</p>""" "HTML is incorrect"
|
||||
}
|
||||
test "fails when an ID is not matched" {
|
||||
let sb = StringBuilder()
|
||||
let sb = StringBuilder ()
|
||||
RenderFragment.IntoStringBuilder.htmlFromNode sb "bar" (hr [])
|
||||
Expect.equal (string sb) (nodeNotFound "bar") "HTML is incorrect"
|
||||
}
|
||||
@ -1016,7 +986,6 @@ let allTests =
|
||||
hxHeaders
|
||||
hxParams
|
||||
hxRequest
|
||||
hxSync
|
||||
hxTrigger
|
||||
hxVals
|
||||
attributes
|
||||
|
@ -4,7 +4,6 @@
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<Description>Extensions to Giraffe View Engine to support htmx attributes and their values</Description>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user