- Embed htmx library to `Giraffe.Htmx.Common`, add links to load package-provided script
- Update CDN links for v2.0.8
- Add .NET 10 support

Reviewed-on: #16
This commit was merged in pull request #16.
This commit is contained in:
2025-12-28 16:53:44 +00:00
parent 6b7458070b
commit 121eb95d87
13 changed files with 103 additions and 34 deletions

View File

@@ -3,6 +3,12 @@ module Common
open Expecto
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"
}
/// Tests for the HxSwap module
let swap =
testList "HxSwap" [
@@ -30,4 +36,4 @@ let swap =
]
/// All tests for this module
let allTests = testList "Htmx.Common" [ swap ]
let allTests = testList "Htmx.Common" [ version; swap ]

View File

@@ -3,6 +3,7 @@ module Htmx
open System
open Expecto
open Giraffe.Htmx
open Microsoft.AspNetCore.Html
open Microsoft.AspNetCore.Http
open NSubstitute
@@ -354,5 +355,16 @@ let handlers =
}
]
/// Tests for the HtmxScript module
let script =
testList "HtmxScript" [
test "local generates correct link" {
Expect.equal
(string HtmxScript.local)
$"""<script src="/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"></script>"""
"htmx script link is incorrect"
}
]
/// All tests for this module
let allTests = testList "Htmx" [ dictExtensions; reqExtensions; handlers ]
let allTests = testList "Htmx" [ dictExtensions; reqExtensions; handlers; script ]

View File

@@ -842,22 +842,31 @@ let attributes =
}
]
open Giraffe.Htmx.Common
/// Tests for the Script module
let script =
testList "Script" [
test "minified succeeds" {
let html = RenderView.AsString.htmlNode Script.minified
test "local succeeds" {
let html = RenderView.AsString.htmlNode Script.local
Expect.equal
html
"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.6/dist/htmx.min.js" integrity="sha384-Akqfrbj/HpNVo8k11SXBb6TlBWmXXlYQrCSqEWmyKJe+hDm3Z/B2WVG4smwBkRVm" crossorigin="anonymous"></script>"""
"Minified script tag is incorrect"
$"""<script src="/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"></script>"""
"Local script tag is incorrect"
}
test "unminified succeeds" {
let html = RenderView.AsString.htmlNode Script.unminified
test "cdnMinified succeeds" {
let html = RenderView.AsString.htmlNode Script.cdnMinified
Expect.equal
html
"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.6/dist/htmx.js" integrity="sha384-ksKjJrwjL5VxqAkAZAVOPXvMkwAykMaNYegdixAESVr+KqLkKE8XBDoZuwyWVUDv" crossorigin="anonymous"></script>"""
"Unminified script tag is incorrect"
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.min.js" integrity="sha256-Iig+9oy3VFkU8KiKG97cclanA9HVgMHSVSF9ClDTExM=" 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="sha256-upUwYnay6R+DA68rROTAP+EdfO3NvOqtE513PgDyAYM=" crossorigin="anonymous"></script>"""
"CDN unminified script tag is incorrect"
}
]