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 HxSwap module module Swap = [] let ``InnerHtml is correct`` () = Assert.Equal ("innerHTML", HxSwap.InnerHtml) [] let ``OuterHtml is correct`` () = Assert.Equal ("outerHTML", HxSwap.OuterHtml) [] let ``BeforeBegin is correct`` () = Assert.Equal ("beforebegin", HxSwap.BeforeBegin) [] let ``BeforeEnd is correct`` () = Assert.Equal ("beforeend", HxSwap.BeforeEnd) [] let ``AfterBegin is correct`` () = Assert.Equal ("afterbegin", HxSwap.AfterBegin) [] let ``AfterEnd is correct`` () = Assert.Equal ("afterend", HxSwap.AfterEnd) [] let ``None is correct`` () = Assert.Equal ("none", HxSwap.None) /// 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 ``_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 ``_hxHistoryElt succeeds`` () = table [ _hxHistoryElt ] [] |> shouldRender """
""" [] let ``_hxInclude succeeds`` () = a [ _hxInclude ".extra-stuff" ] [] |> shouldRender """""" [] let ``_hxIndicator succeeds`` () = aside [ _hxIndicator "#spinner" ] [] |> shouldRender """""" [] let ``_hxNoBoost succeeds`` () = td [ _hxNoBoost ] [] |> shouldRender """""" [] let ``_hxParams succeeds`` () = br [ _hxParams "[p1,p2]" ] |> shouldRender """
""" [] let ``_hxPatch succeeds`` () = div [ _hxPatch "/arrrgh" ] [] |> shouldRender """
""" [] let ``_hxPost succeeds`` () = hr [ _hxPost "/hear-ye-hear-ye" ] |> shouldRender """
""" [] let ``_hxPreserve succeeds`` () = img [ _hxPreserve ] |> shouldRender """""" [] let ``_hxPrompt succeeds`` () = strong [ _hxPrompt "Who goes there?" ] [] |> shouldRender """""" [] let ``_hxPushUrl succeeds`` () = dl [ _hxPushUrl ] [] |> shouldRender """
""" [] let ``_hxPut succeeds`` () = s [ _hxPut "/take-this" ] [] |> shouldRender """""" [] let ``_hxRequest succeeds`` () = u [ _hxRequest "noHeaders" ] [] |> shouldRender """""" [] let ``_hxSelect succeeds`` () = nav [ _hxSelect "#navbar" ] [] |> shouldRender """""" [] let ``_hxSse succeeds`` () = footer [ _hxSse "connect:/my-events" ] [] |> shouldRender """
""" [] let ``_hxSwap succeeds`` () = del [ _hxSwap "innerHTML" ] [] |> shouldRender """""" [] let ``_hxSwapOob succeeds`` () = li [ _hxSwapOob "true" ] [] |> shouldRender """
  • """ [] let ``_hxTarget succeeds`` () = header [ _hxTarget "#somewhereElse" ] [] |> shouldRender """
    """ [] let ``_hxTrigger succeeds`` () = figcaption [ _hxTrigger "load" ] [] |> shouldRender """
    """ [] let ``_hxVals succeeds`` () = dt [ _hxVals """{ "extra": "values" }""" ] [] |> shouldRender """
    """ [] let ``_hxWs succeeds`` () = ul [ _hxWs "connect:/web-socket" ] [] |> shouldRender """
      """