v4, alpha 6 (#17)
Reviewed-on: #17
This commit was merged in pull request #17.
This commit is contained in:
@@ -6,7 +6,7 @@ open Giraffe.Htmx
|
||||
/// Test to ensure the version was updated
|
||||
let version =
|
||||
test "HtmxVersion is correct" {
|
||||
Expect.equal HtmxVersion "2.0.8" "htmx version incorrect"
|
||||
Expect.equal HtmxVersion "4.0.0-alpha6" "htmx version incorrect"
|
||||
}
|
||||
|
||||
/// Tests for the HxSwap module
|
||||
@@ -18,21 +18,48 @@ let swap =
|
||||
test "OuterHtml is correct" {
|
||||
Expect.equal HxSwap.OuterHtml "outerHTML" "Outer HTML swap value incorrect"
|
||||
}
|
||||
test "BeforeBegin is correct" {
|
||||
Expect.equal HxSwap.BeforeBegin "beforebegin" "Before Begin swap value incorrect"
|
||||
test "InnerMorph is correct" {
|
||||
Expect.equal HxSwap.InnerMorph "innerMorph" "Inner Morph swap value incorrect"
|
||||
}
|
||||
test "BeforeEnd is correct" {
|
||||
Expect.equal HxSwap.BeforeEnd "beforeend" "Before End swap value incorrect"
|
||||
test "OuterMorph is correct" {
|
||||
Expect.equal HxSwap.OuterMorph "innerMorph" "Outer Morph swap value incorrect"
|
||||
}
|
||||
test "TextContent is correct" {
|
||||
Expect.equal HxSwap.TextContent "textContent" "Text Content swap value incorrect"
|
||||
}
|
||||
test "Before is correct" {
|
||||
Expect.equal HxSwap.Before "before" "Before swap value incorrect"
|
||||
}
|
||||
test "BeforeBegin is correct" {
|
||||
Expect.equal HxSwap.BeforeBegin HxSwap.Before "Before Begin swap value incorrect"
|
||||
}
|
||||
test "Prepend is correct" {
|
||||
Expect.equal HxSwap.Prepend "prepend" "Prepend swap value incorrect"
|
||||
}
|
||||
test "AfterBegin is correct" {
|
||||
Expect.equal HxSwap.AfterBegin "afterbegin" "After Begin swap value incorrect"
|
||||
Expect.equal HxSwap.AfterBegin HxSwap.Prepend "Prepend swap value incorrect"
|
||||
}
|
||||
test "Append is correct" {
|
||||
Expect.equal HxSwap.Append "append" "Append swap value incorrect"
|
||||
}
|
||||
test "BeforeEnd is correct" {
|
||||
Expect.equal HxSwap.BeforeEnd HxSwap.Append "Before End swap value incorrect"
|
||||
}
|
||||
test "After is correct" {
|
||||
Expect.equal HxSwap.After "after" "After swap value incorrect"
|
||||
}
|
||||
test "AfterEnd is correct" {
|
||||
Expect.equal HxSwap.AfterEnd "afterend" "After End swap value incorrect"
|
||||
Expect.equal HxSwap.AfterEnd HxSwap.After "After End swap value incorrect"
|
||||
}
|
||||
test "Delete is correct" {
|
||||
Expect.equal HxSwap.Delete "delete" "Delete swap value incorrect"
|
||||
}
|
||||
test "None is correct" {
|
||||
Expect.equal HxSwap.None "none" "None swap value incorrect"
|
||||
}
|
||||
test "Upsert is correct" {
|
||||
Expect.equal HxSwap.Upsert "upsert" "Upsert swap value incorrect"
|
||||
}
|
||||
]
|
||||
|
||||
/// All tests for this module
|
||||
|
||||
@@ -3,7 +3,6 @@ module Htmx
|
||||
open System
|
||||
open Expecto
|
||||
open Giraffe.Htmx
|
||||
open Microsoft.AspNetCore.Html
|
||||
open Microsoft.AspNetCore.Http
|
||||
open NSubstitute
|
||||
|
||||
@@ -74,21 +73,6 @@ let dictExtensions =
|
||||
ctx.Request.Headers.HxHistoryRestoreRequest.Value "The header should have been false"
|
||||
}
|
||||
]
|
||||
testList "HxPrompt" [
|
||||
test "succeeds when the header is not present" {
|
||||
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")
|
||||
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"
|
||||
}
|
||||
]
|
||||
testList "HxRequest" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
@@ -112,6 +96,44 @@ let dictExtensions =
|
||||
Expect.isFalse ctx.Request.Headers.HxRequest.Value "The header should have been false"
|
||||
}
|
||||
]
|
||||
testList "HxSource" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxSource "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present and both parts exist" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Source", "button#theId")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let hdr = ctx.Request.Headers.HxSource
|
||||
Expect.isSome hdr "There should be a header present"
|
||||
Expect.equal (fst hdr.Value) "button" "The source tag was incorrect"
|
||||
Expect.isSome (snd hdr.Value) "There should be a source ID present"
|
||||
Expect.equal (snd hdr.Value).Value "theId" "The source ID was incorrect"
|
||||
}
|
||||
test "succeeds when the header is present and ID is blank" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Source", "a#")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let hdr = ctx.Request.Headers.HxSource
|
||||
Expect.isSome hdr "There should be a header present"
|
||||
Expect.equal (fst hdr.Value) "a" "The source tag was incorrect"
|
||||
Expect.isNone (snd hdr.Value) "There should not be a source ID present"
|
||||
}
|
||||
test "succeeds when the header is present and ID is missing" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Source", "form")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let hdr = ctx.Request.Headers.HxSource
|
||||
Expect.isSome hdr "There should be a header present"
|
||||
Expect.equal (fst hdr.Value) "form" "The source tag was incorrect"
|
||||
Expect.isNone (snd hdr.Value) "There should not be a source ID present"
|
||||
}
|
||||
]
|
||||
testList "HxTarget" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
@@ -127,36 +149,6 @@ let dictExtensions =
|
||||
Expect.equal ctx.Request.Headers.HxTarget.Value "#leItem" "The header value was incorrect"
|
||||
}
|
||||
]
|
||||
testList "HxTrigger" [
|
||||
test "succeeds when the header is not present" {
|
||||
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")
|
||||
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"
|
||||
}
|
||||
]
|
||||
testList "HxTriggerName" [
|
||||
test "succeeds when the header is not present" {
|
||||
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")
|
||||
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"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
/// Tests for the HttpRequest extension properties
|
||||
@@ -366,5 +358,55 @@ let script =
|
||||
}
|
||||
]
|
||||
|
||||
#nowarn 44 // Obsolete items still have tests
|
||||
let dictExtensionsObs =
|
||||
testList "IHeaderDictionaryExtensions (Obsolete)" [
|
||||
testList "HxPrompt" [
|
||||
test "succeeds when the header is not present" {
|
||||
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")
|
||||
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"
|
||||
}
|
||||
]
|
||||
testList "HxTrigger" [
|
||||
test "succeeds when the header is not present" {
|
||||
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")
|
||||
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"
|
||||
}
|
||||
]
|
||||
testList "HxTriggerName" [
|
||||
test "succeeds when the header is not present" {
|
||||
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")
|
||||
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"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
/// All tests for this module
|
||||
let allTests = testList "Htmx" [ dictExtensions; reqExtensions; handlers; script ]
|
||||
let allTests = testList "Htmx" [ dictExtensions; reqExtensions; handlers; script; dictExtensionsObs ]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user