"""
+ }
+ ]
+
+/// Tests for the Script module
+let script =
+ testList "Script" [
+ test "minified succeeds" {
+ let html = RenderView.AsString.htmlNode Script.minified
+ Expect.equal
+ html
+ """"""
+ "Minified script tag is incorrect"
+ }
+ test "unminified succeeds" {
+ let html = RenderView.AsString.htmlNode Script.unminified
+ Expect.equal
+ html
+ """"""
+ "Unminified script tag is incorrect"
+ }
+ ]
+
+open System.Text
+
+/// Tests for the RenderFragment module
+let renderFragment =
+ testList "RenderFragment" [
+
+ /// Validate that the two object references are the same object
+ let isSame obj1 obj2 message =
+ Expect.isTrue (obj.ReferenceEquals (obj1, obj2)) message
+
+ testList "findIdNode" [
+ test "fails with a Text node" {
+ Expect.isNone (RenderFragment.findIdNode "blue" (Text "")) "There should not have been a node found"
+ }
+ test "fails with a VoidElement without a matching ID" {
+ Expect.isNone
+ (RenderFragment.findIdNode "purple" (br [ _id "mauve" ])) "There should not have been a node found"
+ }
+ test "fails with a ParentNode with no children with a matching ID" {
+ Expect.isNone
+ (RenderFragment.findIdNode "green" (p [] [ str "howdy"; span [] [ str "huh" ] ]))
+ "There should not have been a node found"
+ }
+ test "succeeds with a VoidElement with a matching ID" {
+ let leNode = hr [ _id "groovy" ]
+ let foundNode = RenderFragment.findIdNode "groovy" leNode
+ Expect.isSome foundNode "There should have been a node found"
+ isSame leNode foundNode.Value "The node should have been the same object"
+ }
+ test "succeeds with a ParentNode with a child with a matching ID" {
+ let leNode = span [ _id "its-me" ] [ str "Mario" ]
+ let foundNode =
+ RenderFragment.findIdNode "its-me" (p [] [ str "test"; str "again"; leNode; str "un mas" ])
+ Expect.isSome foundNode "There should have been a node found"
+ isSame leNode foundNode.Value "The node should have been the same object"
+ }
+ ]
+
+ /// Generate a message if the requested ID node is not found
+ let nodeNotFound (nodeId : string) =
+ $"– ID {nodeId} not found –"
+
+ testList "AsString" [
+ testList "htmlFromNodes" [
+ test "succeeds when an ID is matched" {
+ let html =
+ RenderFragment.AsString.htmlFromNodes "needle"
+ [ p [] []
+ p [ _id "haystack" ] [ str "hay"; span [ _id "needle" ] [ str "ouch" ]; str "hay" ]
+ ]
+ Expect.equal html """ouch""" "HTML is incorrect"
+ }
+ test "fails when an ID is not matched" {
+ Expect.equal
+ (RenderFragment.AsString.htmlFromNodes "oops" []) (nodeNotFound "oops") "HTML is incorrect"
+ }
+ ]
+ testList "htmlFromNode" [
+ test "succeeds when ID is matched at top level" {
+ let html = RenderFragment.AsString.htmlFromNode "wow" (p [ _id "wow" ] [ str "found it" ])
+ Expect.equal html """
found it
""" "HTML is incorrect"
+ }
+ test "succeeds when ID is matched in child element" {
+ let html =
+ div [] [ p [] [ str "not it" ]; p [ _id "hey" ] [ str "ta-da" ]]
+ |> RenderFragment.AsString.htmlFromNode "hey"
+ Expect.equal html """
ta-da
""" "HTML is incorrect"
+ }
+ test "fails when an ID is not matched" {
+ Expect.equal
+ (RenderFragment.AsString.htmlFromNode "me" (hr [])) (nodeNotFound "me") "HTML is incorrect"
+ }
+ ]
+ ]
+ testList "AsBytes" [
+
+ /// Alias for UTF-8 encoding
+ let utf8 = Encoding.UTF8
+
+ testList "htmlFromNodes" [
+ test "succeeds when an ID is matched" {
+ let bytes =
+ RenderFragment.AsBytes.htmlFromNodes "found"
+ [ p [] []
+ p [ _id "not-it" ] [ str "nope"; span [ _id "found" ] [ str "boo" ]; str "nope" ]
+ ]
+ Expect.equal bytes (utf8.GetBytes """boo""") "HTML bytes are incorrect"
+ }
+ test "fails when an ID is not matched" {
+ Expect.equal
+ (RenderFragment.AsBytes.htmlFromNodes "whiff" []) (utf8.GetBytes (nodeNotFound "whiff"))
+ "HTML bytes are incorrect"
+ }
+ ]
+ testList "htmlFromNode" [
+ test "succeeds when ID is matched at top level" {
+ let bytes = RenderFragment.AsBytes.htmlFromNode "first" (p [ _id "first" ] [ str "!!!" ])
+ Expect.equal bytes (utf8.GetBytes """
!!!
""") "HTML bytes are incorrect"
+ }
+ test "succeeds when ID is matched in child element" {
+ let bytes =
+ div [] [ p [] [ str "not me" ]; p [ _id "child" ] [ str "node" ]]
+ |> RenderFragment.AsBytes.htmlFromNode "child"
+ Expect.equal bytes (utf8.GetBytes """
node
""") "HTML bytes are incorrect"
+ }
+ test "fails when an ID is not matched" {
+ Expect.equal
+ (RenderFragment.AsBytes.htmlFromNode "foo" (hr [])) (utf8.GetBytes (nodeNotFound "foo"))
+ "HTML bytes are incorrect"
+ }
+ ]
+ ]
+ testList "IntoStringBuilder" [
+ testList "htmlFromNodes" [
+ test "succeeds when an ID is matched" {
+ 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) """;)""" "HTML is incorrect"
+ }
+ test "fails when an ID is not matched" {
+ 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 ()
+ RenderFragment.IntoStringBuilder.htmlFromNode sb "top" (p [ _id "top" ] [ str "pinnacle" ])
+ Expect.equal (string sb) """
pinnacle
""" "HTML is incorrect"
+ }
+ test "succeeds when ID is matched in child element" {
+ let sb = StringBuilder ()
+ div [] [ p [] [ str "nada" ]; p [ _id "it" ] [ str "is here" ]]
+ |> RenderFragment.IntoStringBuilder.htmlFromNode sb "it"
+ Expect.equal (string sb) """
is here
""" "HTML is incorrect"
+ }
+ test "fails when an ID is not matched" {
+ let sb = StringBuilder ()
+ RenderFragment.IntoStringBuilder.htmlFromNode sb "bar" (hr [])
+ Expect.equal (string sb) (nodeNotFound "bar") "HTML is incorrect"
+ }
+ ]
+ ]
+ ]
+
+/// All tests in this module
+let allTests =
+ testList "ViewEngine.Htmx"
+ [ hxEncoding; hxHeaders; hxParams; hxRequest; hxTrigger; hxVals; attributes; script; renderFragment ]
diff --git a/src/ViewEngine.Htmx.Tests/Giraffe.ViewEngine.Htmx.Tests.fsproj b/src/ViewEngine.Htmx.Tests/Giraffe.ViewEngine.Htmx.Tests.fsproj
deleted file mode 100644
index 9d9d736..0000000
--- a/src/ViewEngine.Htmx.Tests/Giraffe.ViewEngine.Htmx.Tests.fsproj
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
- false
- false
-
-
-
-
-
-
-
-
-
-
-
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
-
-
-
-
-
-
-
diff --git a/src/ViewEngine.Htmx.Tests/Program.fs b/src/ViewEngine.Htmx.Tests/Program.fs
deleted file mode 100644
index fdc31cd..0000000
--- a/src/ViewEngine.Htmx.Tests/Program.fs
+++ /dev/null
@@ -1 +0,0 @@
-module Program = let [] main _ = 0
diff --git a/src/ViewEngine.Htmx.Tests/Tests.fs b/src/ViewEngine.Htmx.Tests/Tests.fs
deleted file mode 100644
index c48cbf2..0000000
--- a/src/ViewEngine.Htmx.Tests/Tests.fs
+++ /dev/null
@@ -1,583 +0,0 @@
-module Giraffe.ViewEngine.Htmx.Tests
-
-open Giraffe.ViewEngine
-open Xunit
-
-/// Tests for the HxEncoding module
-module Encoding =
-
- []
- let ``Form is correct`` () =
- Assert.Equal ("application/x-www-form-urlencoded", HxEncoding.Form)
-
- []
- let ``MultipartForm is correct`` () =
- Assert.Equal ("multipart/form-data", HxEncoding.MultipartForm)
-
-
-/// Tests for the HxHeaders module
-module Headers =
-
- []
- let ``From succeeds with an empty list`` () =
- Assert.Equal ("{ }", HxHeaders.From [])
-
- []
- let ``From succeeds and escapes quotes`` () =
- Assert.Equal ("{ \"test\": \"one two three\", \"again\": \"four \\\"five\\\" six\" }",
- HxHeaders.From [ "test", "one two three"; "again", "four \"five\" six" ])
-
-
-/// Tests for the HxParams module
-module Params =
-
- []
- let ``All is correct`` () =
- Assert.Equal ("*", HxParams.All)
-
- []
- let ``None is correct`` () =
- Assert.Equal ("none", HxParams.None)
-
- []
- let ``With succeeds with empty list`` () =
- Assert.Equal ("", HxParams.With [])
-
- []
- let ``With succeeds with one list item`` () =
- Assert.Equal ("boo", HxParams.With [ "boo" ])
-
- []
- let ``With succeeds with multiple list items`` () =
- Assert.Equal ("foo,bar,baz", HxParams.With [ "foo"; "bar"; "baz" ])
-
- []
- let ``Except succeeds with empty list`` () =
- Assert.Equal ("not ", HxParams.Except [])
-
- []
- let ``Except succeeds with one list item`` () =
- Assert.Equal ("not that", HxParams.Except [ "that" ])
-
- []
- let ``Except succeeds with multiple list items`` () =
- Assert.Equal ("not blue,green", HxParams.Except [ "blue"; "green" ])
-
-
-/// Tests for the HxRequest module
-module Request =
-
- []
- let ``Configure succeeds with an empty list`` () =
- Assert.Equal ("{ }", HxRequest.Configure [])
-
- []
- let ``Configure succeeds with a non-empty list`` () =
- Assert.Equal ("{ \"a\": \"b\", \"c\": \"d\" }", HxRequest.Configure [ "\"a\": \"b\""; "\"c\": \"d\"" ])
-
- []
- let ``Configure succeeds with all known params configured`` () =
- Assert.Equal ("{ \"timeout\": 1000, \"credentials\": false, \"noHeaders\": true }",
- HxRequest.Configure [ HxRequest.Timeout 1000; HxRequest.Credentials false; HxRequest.NoHeaders true ])
-
- []
- let ``Timeout succeeds`` () =
- Assert.Equal ("\"timeout\": 50", HxRequest.Timeout 50)
-
- []
- let ``Credentials succeeds when set to true`` () =
- Assert.Equal ("\"credentials\": true", HxRequest.Credentials true)
-
- []
- let ``Credentials succeeds when set to false`` () =
- Assert.Equal ("\"credentials\": false", HxRequest.Credentials false)
-
- []
- let ``NoHeaders succeeds when set to true`` () =
- Assert.Equal ("\"noHeaders\": true", HxRequest.NoHeaders true)
-
- []
- let ``NoHeaders succeeds when set to false`` () =
- Assert.Equal ("\"noHeaders\": false", HxRequest.NoHeaders false)
-
-
-/// Tests for the HxTrigger module
-module Trigger =
-
- []
- let ``Click is correct`` () =
- Assert.Equal ("click", HxTrigger.Click)
-
- []
- let ``Load is correct`` () =
- Assert.Equal ("load", HxTrigger.Load)
-
- []
- let ``Revealed is correct`` () =
- Assert.Equal ("revealed", HxTrigger.Revealed)
-
- []
- let ``Every succeeds`` () =
- Assert.Equal ("every 3s", HxTrigger.Every "3s")
-
- []
- let ``Filter.Alt succeeds`` () =
- Assert.Equal ("click[altKey]", HxTrigger.Filter.Alt HxTrigger.Click)
-
- []
- let ``Filter.Ctrl succeeds`` () =
- Assert.Equal ("click[ctrlKey]", HxTrigger.Filter.Ctrl HxTrigger.Click)
-
- []
- let ``Filter.Shift succeeds`` () =
- Assert.Equal ("click[shiftKey]", HxTrigger.Filter.Shift HxTrigger.Click)
-
- []
- let ``Filter.CtrlAlt succeeds`` () =
- Assert.Equal ("click[ctrlKey&&altKey]", HxTrigger.Filter.CtrlAlt HxTrigger.Click)
-
- []
- let ``Filter.CtrlShift succeeds`` () =
- Assert.Equal ("click[ctrlKey&&shiftKey]", HxTrigger.Filter.CtrlShift HxTrigger.Click)
-
- []
- let ``Filter.CtrlAltShift succeeds`` () =
- Assert.Equal ("click[ctrlKey&&altKey&&shiftKey]", HxTrigger.Filter.CtrlAltShift HxTrigger.Click)
-
- []
- let ``Filter.AltShift succeeds`` () =
- Assert.Equal ("click[altKey&&shiftKey]", HxTrigger.Filter.AltShift HxTrigger.Click)
-
- []
- let ``Once succeeds when it is the first modifier`` () =
- Assert.Equal ("once", HxTrigger.Once "")
-
- []
- let ``Once succeeds when it is not the first modifier`` () =
- Assert.Equal ("click once", HxTrigger.Once "click")
-
- []
- let ``Changed succeeds when it is the first modifier`` () =
- Assert.Equal ("changed", HxTrigger.Changed "")
-
- []
- let ``Changed succeeds when it is not the first modifier`` () =
- Assert.Equal ("click changed", HxTrigger.Changed "click")
-
- []
- let ``Delay succeeds when it is the first modifier`` () =
- Assert.Equal ("delay:1s", HxTrigger.Delay "1s" "")
-
- []
- let ``Delay succeeds when it is not the first modifier`` () =
- Assert.Equal ("click delay:2s", HxTrigger.Delay "2s" "click")
-
- []
- let ``Throttle succeeds when it is the first modifier`` () =
- Assert.Equal ("throttle:4s", HxTrigger.Throttle "4s" "")
-
- []
- let ``Throttle succeeds when it is not the first modifier`` () =
- Assert.Equal ("click throttle:7s", HxTrigger.Throttle "7s" "click")
-
- []
- let ``From succeeds when it is the first modifier`` () =
- Assert.Equal ("from:.nav", HxTrigger.From ".nav" "")
-
- []
- let ``From succeeds when it is not the first modifier`` () =
- Assert.Equal ("click from:#somewhere", HxTrigger.From "#somewhere" "click")
-
- []
- let ``FromDocument succeeds when it is the first modifier`` () =
- Assert.Equal ("from:document", HxTrigger.FromDocument "")
-
- []
- let ``FromDocument succeeds when it is not the first modifier`` () =
- Assert.Equal ("click from:document", HxTrigger.FromDocument "click")
-
- []
- let ``FromWindow succeeds when it is the first modifier`` () =
- Assert.Equal ("from:window", HxTrigger.FromWindow "")
-
- []
- let ``FromWindow succeeds when it is not the first modifier`` () =
- Assert.Equal ("click from:window", HxTrigger.FromWindow "click")
-
- []
- let ``FromClosest succeeds when it is the first modifier`` () =
- Assert.Equal ("from:closest div", HxTrigger.FromClosest "div" "")
-
- []
- let ``FromClosest succeeds when it is not the first modifier`` () =
- Assert.Equal ("click from:closest p", HxTrigger.FromClosest "p" "click")
-
- []
- let ``FromFind succeeds when it is the first modifier`` () =
- Assert.Equal ("from:find li", HxTrigger.FromFind "li" "")
-
- []
- let ``FromFind succeeds when it is not the first modifier`` () =
- Assert.Equal ("click from:find .spot", HxTrigger.FromFind ".spot" "click")
-
- []
- let ``Target succeeds when it is the first modifier`` () =
- Assert.Equal ("target:main", HxTrigger.Target "main" "")
-
- []
- let ``Target succeeds when it is not the first modifier`` () =
- Assert.Equal ("click target:footer", HxTrigger.Target "footer" "click")
-
- []
- let ``Consume succeeds when it is the first modifier`` () =
- Assert.Equal ("consume", HxTrigger.Consume "")
-
- []
- let ``Consume succeeds when it is not the first modifier`` () =
- Assert.Equal ("click consume", HxTrigger.Consume "click")
-
- []
- let ``Queue succeeds when it is the first modifier`` () =
- Assert.Equal ("queue:abc", HxTrigger.Queue "abc" "")
-
- []
- let ``Queue succeeds when it is not the first modifier`` () =
- Assert.Equal ("click queue:def", HxTrigger.Queue "def" "click")
-
- []
- let ``QueueFirst succeeds when it is the first modifier`` () =
- Assert.Equal ("queue:first", HxTrigger.QueueFirst "")
-
- []
- let ``QueueFirst succeeds when it is not the first modifier`` () =
- Assert.Equal ("click queue:first", HxTrigger.QueueFirst "click")
-
- []
- let ``QueueLast succeeds when it is the first modifier`` () =
- Assert.Equal ("queue:last", HxTrigger.QueueLast "")
-
- []
- let ``QueueLast succeeds when it is not the first modifier`` () =
- Assert.Equal ("click queue:last", HxTrigger.QueueLast "click")
-
- []
- let ``QueueAll succeeds when it is the first modifier`` () =
- Assert.Equal ("queue:all", HxTrigger.QueueAll "")
-
- []
- let ``QueueAll succeeds when it is not the first modifier`` () =
- Assert.Equal ("click queue:all", HxTrigger.QueueAll "click")
-
- []
- let ``QueueNone succeeds when it is the first modifier`` () =
- Assert.Equal ("queue:none", HxTrigger.QueueNone "")
-
- []
- let ``QueueNone succeeds when it is not the first modifier`` () =
- Assert.Equal ("click queue:none", HxTrigger.QueueNone "click")
-
-
-/// Tests for the HxVals module
-module Vals =
-
- []
- let ``From succeeds with an empty list`` () =
- Assert.Equal ("{ }", HxVals.From [])
-
- []
- let ``From succeeds and escapes quotes`` () =
- Assert.Equal ("{ \"test\": \"a \\\"b\\\" c\", \"2\": \"d e f\" }",
- HxVals.From [ "test", "a \"b\" c"; "2", "d e f" ])
-
-
-/// Tests for the HtmxAttrs module
-module Attributes =
-
- /// Pipe-able assertion for a rendered node
- let shouldRender expected node = Assert.Equal (expected, RenderView.AsString.htmlNode node)
-
- []
- let ``_hxBoost succeeds`` () =
- div [ _hxBoost ] [] |> shouldRender """"""
-
- []
- let ``_hxConfirm succeeds`` () =
- button [ _hxConfirm "REALLY?!?" ] [] |> shouldRender """"""
-
- []
- let ``_hxDelete succeeds`` () =
- span [ _hxDelete "/this-endpoint" ] [] |> shouldRender """"""
-
- []
- let ``_hxDisable succeeds`` () =
- p [ _hxDisable ] [] |> shouldRender """"""
-
- []
- let ``_hxDisinherit succeeds`` () =
- strong [ _hxDisinherit "*" ] [] |> shouldRender """"""
-
- []
- let ``_hxEncoding succeeds`` () =
- form [ _hxEncoding "utf-7" ] [] |> shouldRender """"""
-
- []
- let ``_hxExt succeeds`` () =
- section [ _hxExt "extendme" ] [] |> shouldRender """"""
-
- []
- let ``_hxGet succeeds`` () =
- article [ _hxGet "/the-text" ] [] |> shouldRender """"""
-
- []
- let ``_hxHeaders succeeds`` () =
- figure [ _hxHeaders """{ "X-Special-Header": "some-header" }""" ] []
- |> shouldRender """"""
-
- []
- let ``_hxHistory succeeds`` () =
- span [ _hxHistory "false" ] [] |> shouldRender """"""
-
- []
- let ``_hxHistoryElt succeeds`` () =
- table [ _hxHistoryElt ] [] |> shouldRender """
"""
-
-
-/// Tests for the Script module
-module Script =
-
- []
- let ``Script.minified succeeds`` () =
- let html = RenderView.AsString.htmlNode Script.minified
- Assert.Equal
- ("""""",
- html)
-
- []
- let ``Script.unminified succeeds`` () =
- let html = RenderView.AsString.htmlNode Script.unminified
- Assert.Equal
- ("""""",
- html)
-
-
-/// Tests for the RenderFragment module
-module RenderFragment =
-
- open System.Text
-
- []
- let ``RenderFragment.findIdNode fails with a Text node`` () =
- Assert.False (Option.isSome (RenderFragment.findIdNode "blue" (Text "")))
-
- []
- let ``RenderFragment.findIdNode fails with a VoidElement without a matching ID`` () =
- Assert.False (Option.isSome (RenderFragment.findIdNode "purple" (br [ _id "mauve" ])))
-
- []
- let ``RenderFragment.findIdNode fails with a ParentNode with no children with a matching ID`` () =
- Assert.False (Option.isSome (RenderFragment.findIdNode "green" (p [] [ str "howdy"; span [] [ str "huh" ] ])))
-
- []
- let ``RenderFragment.findIdNode succeeds with a VoidElement with a matching ID`` () =
- let leNode = hr [ _id "groovy" ]
- let foundNode = RenderFragment.findIdNode "groovy" leNode
- Assert.True (Option.isSome foundNode)
- Assert.Same (leNode, foundNode.Value)
-
- []
- let ``RenderFragment.findIdNode succeeds with a ParentNode with a child with a matching ID`` () =
- let leNode = span [ _id "its-me" ] [ str "Mario" ]
- let foundNode = RenderFragment.findIdNode "its-me" (p [] [ str "test"; str "again"; leNode; str "un mas" ])
- Assert.True (Option.isSome foundNode)
- Assert.Same (leNode, foundNode.Value)
-
- /// Generate a message if the requested ID node is not found
- let private nodeNotFound (nodeId : string) =
- $"– ID {nodeId} not found –"
-
- /// Tests for the AsString module
- module AsString =
-
- []
- let ``RenderFragment.AsString.htmlFromNodes succeeds when an ID is matched`` () =
- let html =
- RenderFragment.AsString.htmlFromNodes "needle"
- [ p [] []; p [ _id "haystack" ] [ span [ _id "needle" ] [ str "ouch" ]; str "hay"; str "hay" ]]
- Assert.Equal ("""ouch""", html)
-
- []
- let ``RenderFragment.AsString.htmlFromNodes fails when an ID is not matched`` () =
- Assert.Equal (nodeNotFound "oops", RenderFragment.AsString.htmlFromNodes "oops" [])
-
- []
- let ``RenderFragment.AsString.htmlFromNode succeeds when ID is matched at top level`` () =
- let html = RenderFragment.AsString.htmlFromNode "wow" (p [ _id "wow" ] [ str "found it" ])
- Assert.Equal ("""
found it
""", html)
-
- []
- let ``RenderFragment.AsString.htmlFromNode succeeds when ID is matched in child element`` () =
- let html =
- div [] [ p [] [ str "not it" ]; p [ _id "hey" ] [ str "ta-da" ]]
- |> RenderFragment.AsString.htmlFromNode "hey"
- Assert.Equal ("""
ta-da
""", html)
-
- []
- let ``RenderFragment.AsString.htmlFromNode fails when an ID is not matched`` () =
- Assert.Equal (nodeNotFound "me", RenderFragment.AsString.htmlFromNode "me" (hr []))
-
- /// Tests for the AsBytes module
- module AsBytes =
-
- /// Alias for UTF-8 encoding
- let private utf8 = Encoding.UTF8
-
- []
- let ``RenderFragment.AsBytes.htmlFromNodes succeeds when an ID is matched`` () =
- let bytes =
- RenderFragment.AsBytes.htmlFromNodes "found"
- [ p [] []; p [ _id "not-it" ] [ str "nope"; span [ _id "found" ] [ str "boo" ]; str "nope" ]]
- Assert.Equal (utf8.GetBytes """boo""", bytes)
-
- []
- let ``RenderFragment.AsBytes.htmlFromNodes fails when an ID is not matched`` () =
- Assert.Equal (utf8.GetBytes (nodeNotFound "whiff"), RenderFragment.AsBytes.htmlFromNodes "whiff" [])
-
- []
- let ``RenderFragment.AsBytes.htmlFromNode succeeds when ID is matched at top level`` () =
- let bytes = RenderFragment.AsBytes.htmlFromNode "first" (p [ _id "first" ] [ str "!!!" ])
- Assert.Equal (utf8.GetBytes """
!!!
""", bytes)
-
- []
- let ``RenderFragment.AsBytes.htmlFromNode succeeds when ID is matched in child element`` () =
- let bytes =
- div [] [ p [] [ str "not me" ]; p [ _id "child" ] [ str "node" ]]
- |> RenderFragment.AsBytes.htmlFromNode "child"
- Assert.Equal (utf8.GetBytes """
node
""", bytes)
-
- []
- let ``RenderFragment.AsBytes.htmlFromNode fails when an ID is not matched`` () =
- Assert.Equal (utf8.GetBytes (nodeNotFound "foo"), RenderFragment.AsBytes.htmlFromNode "foo" (hr []))
-
- /// Tests for the IntoStringBuilder module
- module IntoStringBuilder =
-
- []
- let ``RenderFragment.IntoStringBuilder.htmlFromNodes succeeds when an ID is matched`` () =
- let sb = StringBuilder ()
- RenderFragment.IntoStringBuilder.htmlFromNodes sb "find-me"
- [ p [] []; p [ _id "peekaboo" ] [ str "bzz"; str "nope"; span [ _id "find-me" ] [ str ";)" ] ]]
- Assert.Equal (""";)""", string sb)
-
- []
- let ``RenderFragment.IntoStringBuilder.htmlFromNodes fails when an ID is not matched`` () =
- let sb = StringBuilder ()
- RenderFragment.IntoStringBuilder.htmlFromNodes sb "missing" []
- Assert.Equal (nodeNotFound "missing", string sb)
-
- []
- let ``RenderFragment.IntoStringBuilder.htmlFromNode succeeds when ID is matched at top level`` () =
- let sb = StringBuilder ()
- RenderFragment.IntoStringBuilder.htmlFromNode sb "top" (p [ _id "top" ] [ str "pinnacle" ])
- Assert.Equal ("""
pinnacle
""", string sb)
-
- []
- let ``RenderFragment.IntoStringBuilder.htmlFromNode succeeds when ID is matched in child element`` () =
- let sb = StringBuilder ()
- div [] [ p [] [ str "nada" ]; p [ _id "it" ] [ str "is here" ]]
- |> RenderFragment.IntoStringBuilder.htmlFromNode sb "it"
- Assert.Equal ("""
is here
""", string sb)
-
- []
- let ``RenderFragment.IntoStringBuilder.htmlFromNode fails when an ID is not matched`` () =
- let sb = StringBuilder ()
- RenderFragment.IntoStringBuilder.htmlFromNode sb "bar" (hr [])
- Assert.Equal (nodeNotFound "bar", string sb)