module PrayerTracker.UI.CommonFunctionsTests open System.IO open Expecto open Giraffe.ViewEngine open Microsoft.AspNetCore.Mvc.Localization open Microsoft.Extensions.Localization open PrayerTracker.Tests.TestLocalization open PrayerTracker.Views [] let iconSizedTests = testList "iconSized" [ test "succeeds" { let ico = iconSized 18 "tom-&-jerry" |> renderHtmlNode Expect.equal ico """tom-&-jerry""" "icon HTML not correct" } ] [] let iconTests = testList "icon" [ test "succeeds" { let ico = icon "bob-&-tom" |> renderHtmlNode Expect.equal ico """bob-&-tom""" "icon HTML not correct" } ] [] let locStrTests = testList "locStr" [ test "succeeds" { let enc = locStr (LocalizedString ("test", "test&")) |> renderHtmlNode Expect.equal enc "test&" "string not encoded correctly" } ] [] let namedColorListTests = testList "namedColorList" [ test "succeeds with default values" { let expected = [ """" ] |> String.concat "" let selectList = namedColorList "the-name" "" [] _s |> renderHtmlNode Expect.equal expected selectList "The default select list was not generated correctly" } test "succeeds with a selected value" { let selectList = namedColorList "the-name" "white" [] _s |> renderHtmlNode Expect.stringContains selectList " selected>white" "Selected option not generated correctly" } test "succeeds with extra attributes" { let selectList = namedColorList "the-name" "" [ _id "myId" ] _s |> renderHtmlNode Expect.stringStarts selectList """""" "Unselected radio button not generated correctly" } test "succeeds when selected" { let rad = radio "a-name" "anId" "unit" "unit" |> renderHtmlNode Expect.equal rad """""" "Selected radio button not generated correctly" } ] [] let rawLocTextTests = testList "rawLocText" [ test "succeeds" { use sw = new StringWriter () let raw = rawLocText sw (LocalizedHtmlString ("test", "test&")) |> renderHtmlNode Expect.equal raw "test&" "string not written correctly" } ] [] let selectDefaultTests = testList "selectDefault" [ test "succeeds" { Expect.equal (selectDefault "a&b") "— a&b —" "Default selection not generated correctly" } ] [] let selectListTests = testList "selectList" [ test "succeeds with minimum options" { let theList = selectList "a-list" "" [] [] |> renderHtmlNode Expect.equal theList """""" "Empty select list not generated correctly" } test "succeeds with all options" { let theList = [ "tom", "Tom&" "bob", "Bob" "jan", "Jan" ] |> selectList "the-list" "bob" [ _style "ugly" ] |> renderHtmlNode let expected = [ """""" ] |> String.concat "" Expect.equal theList expected "Filled select list not generated correctly" } ] [] let spaceTests = testList "space" [ test "succeeds" { Expect.equal (renderHtmlNode space) " " "space literal not correct" } ] [] let submitTests = testList "submit" [ test "succeeds" { let btn = submit [ _class "slick" ] "file-ico" _s["a&b"] |> renderHtmlNode Expect.equal btn """""" "Submit button not generated correctly" } ] [] let tableSummaryTests = testList "tableSummary" [ test "succeeds for no entries" { let sum = tableSummary 0 _s |> renderHtmlNode Expect.equal sum """
No Entries to Display
""" "Summary for no items is incorrect" } test "succeeds for one entry" { let sum = tableSummary 1 _s |> renderHtmlNode Expect.equal sum """
Displaying 1 Entry
""" "Summary for one item is incorrect" } test "succeeds for many entries" { let sum = tableSummary 5 _s |> renderHtmlNode Expect.equal sum """
Displaying 5 Entries
""" "Summary for many items is incorrect" } ] module TimeZones = open PrayerTracker.Entities open PrayerTracker.Views.CommonFunctions.TimeZones [] let nameTests = testList "TimeZones.name" [ test "succeeds for US Eastern time" { Expect.equal (name (TimeZoneId "America/New_York") _s |> string) "Eastern" "US Eastern time zone not returned correctly" } test "succeeds for US Central time" { Expect.equal (name (TimeZoneId "America/Chicago") _s |> string) "Central" "US Central time zone not returned correctly" } test "succeeds for US Mountain time" { Expect.equal (name (TimeZoneId "America/Denver") _s |> string) "Mountain" "US Mountain time zone not returned correctly" } test "succeeds for US Mountain (AZ) time" { Expect.equal (name (TimeZoneId "America/Phoenix") _s |> string) "Mountain (Arizona)" "US Mountain (AZ) time zone not returned correctly" } test "succeeds for US Pacific time" { Expect.equal (name (TimeZoneId "America/Los_Angeles") _s |> string) "Pacific" "US Pacific time zone not returned correctly" } test "succeeds for Central European time" { Expect.equal (name (TimeZoneId "Europe/Berlin") _s |> string) "Central European" "Central European time zone not returned correctly" } test "fails for unexpected time zone" { Expect.equal (name (TimeZoneId "Wakanda") _s |> string) "Wakanda" "Unexpected time zone should have returned the original ID" } ]