Version 8 (#43)
* Use htmx for front end (#36) * Use short GUIDs in URLs and forms (#1) * Refresh theme (#38) * Use ASP.NET Core for log on/off (#39) * Fix date/time / time zone issues (#41) * Update help for v8 (#42) * Add FAKE build script (#37)
This commit was merged in pull request #43.
This commit is contained in:
@@ -1,208 +1,215 @@
|
||||
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
|
||||
open System.IO
|
||||
|
||||
|
||||
[<Tests>]
|
||||
let iconSizedTests =
|
||||
testList "iconSized" [
|
||||
test "succeeds" {
|
||||
let ico = iconSized 18 "tom-&-jerry" |> renderHtmlNode
|
||||
Expect.equal ico "<i class=\"material-icons md-18\">tom-&-jerry</i>" "icon HTML not correct"
|
||||
}
|
||||
testList "iconSized" [
|
||||
test "succeeds" {
|
||||
let ico = iconSized 18 "tom-&-jerry" |> renderHtmlNode
|
||||
Expect.equal ico """<i class="material-icons md-18">tom-&-jerry</i>""" "icon HTML not correct"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let iconTests =
|
||||
testList "icon" [
|
||||
test "succeeds" {
|
||||
let ico = icon "bob-&-tom" |> renderHtmlNode
|
||||
Expect.equal ico "<i class=\"material-icons\">bob-&-tom</i>" "icon HTML not correct"
|
||||
}
|
||||
testList "icon" [
|
||||
test "succeeds" {
|
||||
let ico = icon "bob-&-tom" |> renderHtmlNode
|
||||
Expect.equal ico """<i class="material-icons">bob-&-tom</i>""" "icon HTML not correct"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let locStrTests =
|
||||
testList "locStr" [
|
||||
test "succeeds" {
|
||||
let enc = locStr (LocalizedString ("test", "test&")) |> renderHtmlNode
|
||||
Expect.equal enc "test&" "string not encoded correctly"
|
||||
}
|
||||
testList "locStr" [
|
||||
test "succeeds" {
|
||||
let enc = locStr (LocalizedString ("test", "test&")) |> renderHtmlNode
|
||||
Expect.equal enc "test&" "string not encoded correctly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let namedColorListTests =
|
||||
testList "namedColorList" [
|
||||
test "succeeds with default values" {
|
||||
let expected =
|
||||
[ "<select name=\"the-name\">"
|
||||
"<option value=\"aqua\" style=\"background-color:aqua;color:black;\">aqua</option>"
|
||||
"<option value=\"black\" style=\"background-color:black;color:white;\">black</option>"
|
||||
"<option value=\"blue\" style=\"background-color:blue;color:white;\">blue</option>"
|
||||
"<option value=\"fuchsia\" style=\"background-color:fuchsia;color:black;\">fuchsia</option>"
|
||||
"<option value=\"gray\" style=\"background-color:gray;color:white;\">gray</option>"
|
||||
"<option value=\"green\" style=\"background-color:green;color:white;\">green</option>"
|
||||
"<option value=\"lime\" style=\"background-color:lime;color:black;\">lime</option>"
|
||||
"<option value=\"maroon\" style=\"background-color:maroon;color:white;\">maroon</option>"
|
||||
"<option value=\"navy\" style=\"background-color:navy;color:white;\">navy</option>"
|
||||
"<option value=\"olive\" style=\"background-color:olive;color:white;\">olive</option>"
|
||||
"<option value=\"purple\" style=\"background-color:purple;color:white;\">purple</option>"
|
||||
"<option value=\"red\" style=\"background-color:red;color:black;\">red</option>"
|
||||
"<option value=\"silver\" style=\"background-color:silver;color:black;\">silver</option>"
|
||||
"<option value=\"teal\" style=\"background-color:teal;color:white;\">teal</option>"
|
||||
"<option value=\"white\" style=\"background-color:white;color:black;\">white</option>"
|
||||
"<option value=\"yellow\" style=\"background-color:yellow;color:black;\">yellow</option>"
|
||||
"</select>"
|
||||
]
|
||||
|> 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</option>" "Selected option not generated correctly"
|
||||
}
|
||||
test "succeeds with extra attributes" {
|
||||
let selectList = namedColorList "the-name" "" [ _id "myId" ] _s |> renderHtmlNode
|
||||
Expect.stringStarts selectList "<select name=\"the-name\" id=\"myId\">" "Attributes not included correctly"
|
||||
}
|
||||
testList "namedColorList" [
|
||||
test "succeeds with default values" {
|
||||
let expected =
|
||||
[ """<select name="the-name">"""
|
||||
"""<option value="aqua" style="background-color:aqua;color:black;">aqua</option>"""
|
||||
"""<option value="black" style="background-color:black;color:white;">black</option>"""
|
||||
"""<option value="blue" style="background-color:blue;color:white;">blue</option>"""
|
||||
"""<option value="fuchsia" style="background-color:fuchsia;color:black;">fuchsia</option>"""
|
||||
"""<option value="gray" style="background-color:gray;color:white;">gray</option>"""
|
||||
"""<option value="green" style="background-color:green;color:white;">green</option>"""
|
||||
"""<option value="lime" style="background-color:lime;color:black;">lime</option>"""
|
||||
"""<option value="maroon" style="background-color:maroon;color:white;">maroon</option>"""
|
||||
"""<option value="navy" style="background-color:navy;color:white;">navy</option>"""
|
||||
"""<option value="olive" style="background-color:olive;color:white;">olive</option>"""
|
||||
"""<option value="purple" style="background-color:purple;color:white;">purple</option>"""
|
||||
"""<option value="red" style="background-color:red;color:black;">red</option>"""
|
||||
"""<option value="silver" style="background-color:silver;color:black;">silver</option>"""
|
||||
"""<option value="teal" style="background-color:teal;color:white;">teal</option>"""
|
||||
"""<option value="white" style="background-color:white;color:black;">white</option>"""
|
||||
"""<option value="yellow" style="background-color:yellow;color:black;">yellow</option>"""
|
||||
"</select>"
|
||||
]
|
||||
|> 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</option>" "Selected option not generated correctly"
|
||||
}
|
||||
test "succeeds with extra attributes" {
|
||||
let selectList = namedColorList "the-name" "" [ _id "myId" ] _s |> renderHtmlNode
|
||||
Expect.stringStarts selectList """<select name="the-name" id="myId">""" "Attributes not included correctly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let radioTests =
|
||||
testList "radio" [
|
||||
test "succeeds when not selected" {
|
||||
let rad = radio "a-name" "anId" "test" "unit" |> renderHtmlNode
|
||||
Expect.equal rad "<input type=\"radio\" name=\"a-name\" id=\"anId\" value=\"test\">"
|
||||
"Unselected radio button not generated correctly"
|
||||
}
|
||||
test "succeeds when selected" {
|
||||
let rad = radio "a-name" "anId" "unit" "unit" |> renderHtmlNode
|
||||
Expect.equal rad "<input type=\"radio\" name=\"a-name\" id=\"anId\" value=\"unit\" checked>"
|
||||
"Selected radio button not generated correctly"
|
||||
}
|
||||
testList "radio" [
|
||||
test "succeeds when not selected" {
|
||||
let rad = radio "a-name" "anId" "test" "unit" |> renderHtmlNode
|
||||
Expect.equal rad """<input type="radio" name="a-name" id="anId" value="test">"""
|
||||
"Unselected radio button not generated correctly"
|
||||
}
|
||||
test "succeeds when selected" {
|
||||
let rad = radio "a-name" "anId" "unit" "unit" |> renderHtmlNode
|
||||
Expect.equal rad """<input type="radio" name="a-name" id="anId" value="unit" checked>"""
|
||||
"Selected radio button not generated correctly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
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"
|
||||
}
|
||||
testList "rawLocText" [
|
||||
test "succeeds" {
|
||||
use sw = new StringWriter ()
|
||||
let raw = rawLocText sw (LocalizedHtmlString ("test", "test&")) |> renderHtmlNode
|
||||
Expect.equal raw "test&" "string not written correctly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let selectDefaultTests =
|
||||
testList "selectDefault" [
|
||||
test "succeeds" {
|
||||
Expect.equal (selectDefault "a&b") "— a&b —" "Default selection not generated correctly"
|
||||
}
|
||||
testList "selectDefault" [
|
||||
test "succeeds" {
|
||||
Expect.equal (selectDefault "a&b") "— a&b —" "Default selection not generated correctly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let selectListTests =
|
||||
testList "selectList" [
|
||||
test "succeeds with minimum options" {
|
||||
let theList = selectList "a-list" "" [] [] |> renderHtmlNode
|
||||
Expect.equal theList "<select name=\"a-list\" id=\"a-list\"></select>" "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 =
|
||||
[ "<select name=\"the-list\" id=\"the-list\" style=\"ugly\">"
|
||||
"<option value=\"tom\">Tom&</option>"
|
||||
"<option value=\"bob\" selected>Bob</option>"
|
||||
"<option value=\"jan\">Jan</option>"
|
||||
"</select>"
|
||||
]
|
||||
|> String.concat ""
|
||||
Expect.equal theList expected "Filled select list not generated correctly"
|
||||
}
|
||||
testList "selectList" [
|
||||
test "succeeds with minimum options" {
|
||||
let theList = selectList "a-list" "" [] [] |> renderHtmlNode
|
||||
Expect.equal theList """<select name="a-list" id="a-list"></select>"""
|
||||
"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 =
|
||||
[ """<select name="the-list" id="the-list" style="ugly">"""
|
||||
"""<option value="tom">Tom&</option>"""
|
||||
"""<option value="bob" selected>Bob</option>"""
|
||||
"""<option value="jan">Jan</option>"""
|
||||
"""</select>"""
|
||||
]
|
||||
|> String.concat ""
|
||||
Expect.equal theList expected "Filled select list not generated correctly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let spaceTests =
|
||||
testList "space" [
|
||||
test "succeeds" {
|
||||
Expect.equal (renderHtmlNode space) " " "space literal not correct"
|
||||
}
|
||||
testList "space" [
|
||||
test "succeeds" {
|
||||
Expect.equal (renderHtmlNode space) " " "space literal not correct"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
[<Tests>]
|
||||
let submitTests =
|
||||
testList "submit" [
|
||||
test "succeeds" {
|
||||
let btn = submit [ _class "slick" ] "file-ico" _s.["a&b"] |> renderHtmlNode
|
||||
Expect.equal
|
||||
btn
|
||||
"<button type=\"submit\" class=\"slick\"><i class=\"material-icons\">file-ico</i> a&b</button>"
|
||||
"Submit button not generated correctly"
|
||||
}
|
||||
testList "submit" [
|
||||
test "succeeds" {
|
||||
let btn = submit [ _class "slick" ] "file-ico" _s["a&b"] |> renderHtmlNode
|
||||
Expect.equal
|
||||
btn
|
||||
"""<button type="submit" class="slick"><i class="material-icons">file-ico</i> a&b</button>"""
|
||||
"Submit button not generated correctly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let tableSummaryTests =
|
||||
testList "tableSummary" [
|
||||
test "succeeds for no entries" {
|
||||
let sum = tableSummary 0 _s |> renderHtmlNode
|
||||
Expect.equal sum "<div class=\"pt-center-text\"><small>No Entries to Display</small></div>"
|
||||
"Summary for no items is incorrect"
|
||||
}
|
||||
test "succeeds for one entry" {
|
||||
let sum = tableSummary 1 _s |> renderHtmlNode
|
||||
Expect.equal sum "<div class=\"pt-center-text\"><small>Displaying 1 Entry</small></div>"
|
||||
"Summary for one item is incorrect"
|
||||
}
|
||||
test "succeeds for many entries" {
|
||||
let sum = tableSummary 5 _s |> renderHtmlNode
|
||||
Expect.equal sum "<div class=\"pt-center-text\"><small>Displaying 5 Entries</small></div>"
|
||||
"Summary for many items is incorrect"
|
||||
}
|
||||
testList "tableSummary" [
|
||||
test "succeeds for no entries" {
|
||||
let sum = tableSummary 0 _s |> renderHtmlNode
|
||||
Expect.equal sum """<div class="pt-center-text"><small>No Entries to Display</small></div>"""
|
||||
"Summary for no items is incorrect"
|
||||
}
|
||||
test "succeeds for one entry" {
|
||||
let sum = tableSummary 1 _s |> renderHtmlNode
|
||||
Expect.equal sum """<div class="pt-center-text"><small>Displaying 1 Entry</small></div>"""
|
||||
"Summary for one item is incorrect"
|
||||
}
|
||||
test "succeeds for many entries" {
|
||||
let sum = tableSummary 5 _s |> renderHtmlNode
|
||||
Expect.equal sum """<div class="pt-center-text"><small>Displaying 5 Entries</small></div>"""
|
||||
"Summary for many items is incorrect"
|
||||
}
|
||||
]
|
||||
|
||||
module TimeZones =
|
||||
|
||||
open PrayerTracker.Views.CommonFunctions.TimeZones
|
||||
open PrayerTracker.Entities
|
||||
open PrayerTracker.Views.CommonFunctions.TimeZones
|
||||
|
||||
[<Tests>]
|
||||
let nameTests =
|
||||
testList "TimeZones.name" [
|
||||
test "succeeds for US Eastern time" {
|
||||
Expect.equal (name "America/New_York" _s |> string) "Eastern" "US Eastern time zone not returned correctly"
|
||||
}
|
||||
test "succeeds for US Central time" {
|
||||
Expect.equal (name "America/Chicago" _s |> string) "Central" "US Central time zone not returned correctly"
|
||||
}
|
||||
test "succeeds for US Mountain time" {
|
||||
Expect.equal (name "America/Denver" _s |> string) "Mountain" "US Mountain time zone not returned correctly"
|
||||
}
|
||||
test "succeeds for US Mountain (AZ) time" {
|
||||
Expect.equal (name "America/Phoenix" _s |> string) "Mountain (Arizona)"
|
||||
"US Mountain (AZ) time zone not returned correctly"
|
||||
}
|
||||
test "succeeds for US Pacific time" {
|
||||
Expect.equal (name "America/Los_Angeles" _s |> string) "Pacific" "US Pacific time zone not returned correctly"
|
||||
}
|
||||
test "succeeds for Central European time" {
|
||||
Expect.equal (name "Europe/Berlin" _s |> string) "Central European"
|
||||
"Central European time zone not returned correctly"
|
||||
}
|
||||
test "fails for unexpected time zone" {
|
||||
Expect.equal (name "Wakanda" _s |> string) "Wakanda" "Unexpected time zone should have returned the original ID"
|
||||
}
|
||||
]
|
||||
[<Tests>]
|
||||
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"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -5,189 +5,192 @@ open PrayerTracker
|
||||
|
||||
[<Tests>]
|
||||
let ckEditorToTextTests =
|
||||
testList "ckEditorToText" [
|
||||
test "replaces newline/tab sequence with nothing" {
|
||||
Expect.equal (ckEditorToText "Here is some \n\ttext") "Here is some text"
|
||||
"Newline/tab sequence should have been removed"
|
||||
}
|
||||
test "replaces with a space" {
|
||||
Expect.equal (ckEditorToText "Test text") "Test text" " should have been replaced with a space"
|
||||
}
|
||||
test "replaces double space with one non-breaking space and one regular space" {
|
||||
Expect.equal (ckEditorToText "Test text") "Test  text"
|
||||
"double space should have been replaced with one non-breaking space and one regular space"
|
||||
}
|
||||
test "replaces paragraph break with two line breaks" {
|
||||
Expect.equal (ckEditorToText "some</p><p>text") "some<br><br>text"
|
||||
"paragraph break should have been replaced with two line breaks"
|
||||
}
|
||||
test "removes start and end paragraph tags" {
|
||||
Expect.equal (ckEditorToText "<p>something something</p>") "something something"
|
||||
"start/end paragraph tags should have been removed"
|
||||
}
|
||||
test "trims the result" {
|
||||
Expect.equal (ckEditorToText " abc ") "abc" "Should have trimmed the resulting text"
|
||||
}
|
||||
test "does all the replacements and removals at one time" {
|
||||
Expect.equal (ckEditorToText " <p>Paragraph 1\n\t line two</p><p>Paragraph 2 x</p>")
|
||||
"Paragraph 1 line two<br><br>Paragraph 2  x"
|
||||
"all replacements and removals were not made correctly"
|
||||
}
|
||||
testList "ckEditorToText" [
|
||||
test "replaces newline/tab sequence with nothing" {
|
||||
Expect.equal (ckEditorToText "Here is some \n\ttext") "Here is some text"
|
||||
"Newline/tab sequence should have been removed"
|
||||
}
|
||||
test "replaces with a space" {
|
||||
Expect.equal (ckEditorToText "Test text") "Test text" " should have been replaced with a space"
|
||||
}
|
||||
test "replaces double space with one non-breaking space and one regular space" {
|
||||
Expect.equal (ckEditorToText "Test text") "Test  text"
|
||||
"double space should have been replaced with one non-breaking space and one regular space"
|
||||
}
|
||||
test "replaces paragraph break with two line breaks" {
|
||||
Expect.equal (ckEditorToText "some</p><p>text") "some<br><br>text"
|
||||
"paragraph break should have been replaced with two line breaks"
|
||||
}
|
||||
test "removes start and end paragraph tags" {
|
||||
Expect.equal (ckEditorToText "<p>something something</p>") "something something"
|
||||
"start/end paragraph tags should have been removed"
|
||||
}
|
||||
test "trims the result" {
|
||||
Expect.equal (ckEditorToText " abc ") "abc" "Should have trimmed the resulting text"
|
||||
}
|
||||
test "does all the replacements and removals at one time" {
|
||||
Expect.equal (ckEditorToText " <p>Paragraph 1\n\t line two</p><p>Paragraph 2 x</p>")
|
||||
"Paragraph 1 line two<br><br>Paragraph 2  x"
|
||||
"all replacements and removals were not made correctly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let htmlToPlainTextTests =
|
||||
testList "htmlToPlainText" [
|
||||
test "decodes HTML-encoded entities" {
|
||||
Expect.equal (htmlToPlainText "1 > 0") "1 > 0" "HTML-encoded entities should have been decoded"
|
||||
}
|
||||
test "trims the input HTML" {
|
||||
Expect.equal (htmlToPlainText " howdy ") "howdy" "HTML input string should have been trimmed"
|
||||
}
|
||||
test "replaces line breaks with new lines" {
|
||||
Expect.equal (htmlToPlainText "Lots<br>of<br />new<br>lines") "Lots\nof\nnew\nlines"
|
||||
"Break tags should have been converted to newline characters"
|
||||
}
|
||||
test "replaces non-breaking spaces with spaces" {
|
||||
Expect.equal (htmlToPlainText "Here is some more text") "Here is some more text"
|
||||
"Non-breaking spaces should have been replaced with spaces"
|
||||
}
|
||||
test "does all replacements at one time" {
|
||||
Expect.equal (htmlToPlainText " < <<br>test") "< <\ntest" "All replacements were not made correctly"
|
||||
}
|
||||
test "does not fail when passed null" {
|
||||
Expect.equal (htmlToPlainText null) "" "Should return an empty string for null input"
|
||||
}
|
||||
test "does not fail when passed an empty string" {
|
||||
Expect.equal (htmlToPlainText "") "" "Should return an empty string when given an empty string"
|
||||
}
|
||||
test "preserves blank lines for two consecutive line breaks" {
|
||||
let expected = "Paragraph 1\n\nParagraph 2\n\n...and paragraph 3"
|
||||
Expect.equal (htmlToPlainText "Paragraph 1<br><br>Paragraph 2<br><br>...and <strong>paragraph</strong> <i>3</i>")
|
||||
expected "Blank lines not preserved for consecutive line breaks"
|
||||
}
|
||||
testList "htmlToPlainText" [
|
||||
test "decodes HTML-encoded entities" {
|
||||
Expect.equal (htmlToPlainText "1 > 0") "1 > 0" "HTML-encoded entities should have been decoded"
|
||||
}
|
||||
test "trims the input HTML" {
|
||||
Expect.equal (htmlToPlainText " howdy ") "howdy" "HTML input string should have been trimmed"
|
||||
}
|
||||
test "replaces line breaks with new lines" {
|
||||
Expect.equal (htmlToPlainText "Lots<br>of<br />new<br>lines") "Lots\nof\nnew\nlines"
|
||||
"Break tags should have been converted to newline characters"
|
||||
}
|
||||
test "replaces non-breaking spaces with spaces" {
|
||||
Expect.equal (htmlToPlainText "Here is some more text") "Here is some more text"
|
||||
"Non-breaking spaces should have been replaced with spaces"
|
||||
}
|
||||
test "does all replacements at one time" {
|
||||
Expect.equal (htmlToPlainText " < <<br>test") "< <\ntest"
|
||||
"All replacements were not made correctly"
|
||||
}
|
||||
test "does not fail when passed null" {
|
||||
Expect.equal (htmlToPlainText null) "" "Should return an empty string for null input"
|
||||
}
|
||||
test "does not fail when passed an empty string" {
|
||||
Expect.equal (htmlToPlainText "") "" "Should return an empty string when given an empty string"
|
||||
}
|
||||
test "preserves blank lines for two consecutive line breaks" {
|
||||
let expected = "Paragraph 1\n\nParagraph 2\n\n...and paragraph 3"
|
||||
Expect.equal
|
||||
(htmlToPlainText "Paragraph 1<br><br>Paragraph 2<br><br>...and <strong>paragraph</strong> <i>3</i>")
|
||||
expected "Blank lines not preserved for consecutive line breaks"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let makeUrlTests =
|
||||
testList "makeUrl" [
|
||||
test "returns the URL when there are no parameters" {
|
||||
Expect.equal (makeUrl "/test" []) "/test" "The URL should not have had any query string parameters added"
|
||||
}
|
||||
test "returns the URL with one query string parameter" {
|
||||
Expect.equal (makeUrl "/test" [ "unit", "true" ]) "/test?unit=true" "The URL was not constructed properly"
|
||||
}
|
||||
test "returns the URL with multiple encoded query string parameters" {
|
||||
let url = makeUrl "/test" [ "space", "a space"; "turkey", "=" ]
|
||||
Expect.equal url "/test?space=a+space&turkey=%3D" "The URL was not constructed properly"
|
||||
}
|
||||
testList "makeUrl" [
|
||||
test "returns the URL when there are no parameters" {
|
||||
Expect.equal (makeUrl "/test" []) "/test" "The URL should not have had any query string parameters added"
|
||||
}
|
||||
test "returns the URL with one query string parameter" {
|
||||
Expect.equal (makeUrl "/test" [ "unit", "true" ]) "/test?unit=true" "The URL was not constructed properly"
|
||||
}
|
||||
test "returns the URL with multiple encoded query string parameters" {
|
||||
let url = makeUrl "/test" [ "space", "a space"; "turkey", "=" ]
|
||||
Expect.equal url "/test?space=a+space&turkey=%3D" "The URL was not constructed properly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let sndAsStringTests =
|
||||
testList "sndAsString" [
|
||||
test "converts the second item to a string" {
|
||||
Expect.equal (sndAsString ("a", 5)) "5" "The second part of the tuple should have been converted to a string"
|
||||
}
|
||||
testList "sndAsString" [
|
||||
test "converts the second item to a string" {
|
||||
Expect.equal (sndAsString ("a", 5)) "5"
|
||||
"The second part of the tuple should have been converted to a string"
|
||||
}
|
||||
]
|
||||
|
||||
module StringTests =
|
||||
|
||||
open PrayerTracker.Utils.String
|
||||
open PrayerTracker.Utils.String
|
||||
|
||||
[<Tests>]
|
||||
let replaceFirstTests =
|
||||
testList "String.replaceFirst" [
|
||||
test "replaces the first occurrence when it is found at the beginning of the string" {
|
||||
let testString = "unit unit unit"
|
||||
Expect.equal (replaceFirst "unit" "test" testString) "test unit unit"
|
||||
"First occurrence of a substring was not replaced properly at the beginning of the string"
|
||||
}
|
||||
test "replaces the first occurrence when it is found in the center of the string" {
|
||||
let testString = "test unit test"
|
||||
Expect.equal (replaceFirst "unit" "test" testString) "test test test"
|
||||
"First occurrence of a substring was not replaced properly when it is in the center of the string"
|
||||
}
|
||||
test "returns the original string if the replacement isn't found" {
|
||||
let testString = "unit tests"
|
||||
Expect.equal (replaceFirst "tested" "testing" testString) "unit tests"
|
||||
"String which did not have the target substring was not returned properly"
|
||||
}
|
||||
]
|
||||
[<Tests>]
|
||||
let replaceFirstTests =
|
||||
testList "String.replaceFirst" [
|
||||
test "replaces the first occurrence when it is found at the beginning of the string" {
|
||||
let testString = "unit unit unit"
|
||||
Expect.equal (replaceFirst "unit" "test" testString) "test unit unit"
|
||||
"First occurrence of a substring was not replaced properly at the beginning of the string"
|
||||
}
|
||||
test "replaces the first occurrence when it is found in the center of the string" {
|
||||
let testString = "test unit test"
|
||||
Expect.equal (replaceFirst "unit" "test" testString) "test test test"
|
||||
"First occurrence of a substring was not replaced properly when it is in the center of the string"
|
||||
}
|
||||
test "returns the original string if the replacement isn't found" {
|
||||
let testString = "unit tests"
|
||||
Expect.equal (replaceFirst "tested" "testing" testString) "unit tests"
|
||||
"String which did not have the target substring was not returned properly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let replaceTests =
|
||||
testList "String.replace" [
|
||||
test "succeeds" {
|
||||
Expect.equal (replace "a" "b" "abacab") "bbbcbb" "String did not replace properly"
|
||||
}
|
||||
]
|
||||
[<Tests>]
|
||||
let replaceTests =
|
||||
testList "String.replace" [
|
||||
test "succeeds" {
|
||||
Expect.equal (replace "a" "b" "abacab") "bbbcbb" "String did not replace properly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let trimTests =
|
||||
testList "String.trim" [
|
||||
test "succeeds" {
|
||||
Expect.equal (trim " abc ") "abc" "Space not trimmed from string properly"
|
||||
}
|
||||
]
|
||||
[<Tests>]
|
||||
let trimTests =
|
||||
testList "String.trim" [
|
||||
test "succeeds" {
|
||||
Expect.equal (trim " abc ") "abc" "Space not trimmed from string properly"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let stripTagsTests =
|
||||
let testString = "<p class=\"testing\">Here is some text<br> <br />and some more</p>"
|
||||
testList "stripTags" [
|
||||
test "does nothing if all tags are allowed" {
|
||||
Expect.equal (stripTags [ "p"; "br" ] testString) testString
|
||||
"There should have been no replacements in the target string"
|
||||
}
|
||||
test "strips the start/end tag for non allowed tag" {
|
||||
Expect.equal (stripTags [ "br" ] testString) "Here is some text<br> <br />and some more"
|
||||
"There should have been no \"p\" tag, but all \"br\" tags, in the returned string"
|
||||
}
|
||||
test "strips void/self-closing tags" {
|
||||
Expect.equal (stripTags [] testString) "Here is some text and some more"
|
||||
"There should have been no tags; all void and self-closing tags should have been stripped"
|
||||
}
|
||||
let testString = """<p class="testing">Here is some text<br> <br />and some more</p>"""
|
||||
testList "stripTags" [
|
||||
test "does nothing if all tags are allowed" {
|
||||
Expect.equal (stripTags [ "p"; "br" ] testString) testString
|
||||
"There should have been no replacements in the target string"
|
||||
}
|
||||
test "strips the start/end tag for non allowed tag" {
|
||||
Expect.equal (stripTags [ "br" ] testString) "Here is some text<br> <br />and some more"
|
||||
"There should have been no \"p\" tag, but all \"br\" tags, in the returned string"
|
||||
}
|
||||
test "strips void/self-closing tags" {
|
||||
Expect.equal (stripTags [] testString) "Here is some text and some more"
|
||||
"There should have been no tags; all void and self-closing tags should have been stripped"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let wordWrapTests =
|
||||
testList "wordWrap" [
|
||||
test "breaks where it is supposed to" {
|
||||
let testString = "The quick brown fox jumps over the lazy dog\nIt does!"
|
||||
Expect.equal (wordWrap 20 testString) "The quick brown fox\njumps over the lazy\ndog\nIt does!\n"
|
||||
"Line not broken correctly"
|
||||
}
|
||||
test "wraps long line without a space" {
|
||||
let testString = "Asamatteroffact, the dog does too"
|
||||
Expect.equal (wordWrap 10 testString) "Asamattero\nffact, the\ndog does\ntoo\n"
|
||||
"Longer line not broken correctly"
|
||||
}
|
||||
test "preserves blank lines" {
|
||||
let testString = "Here is\n\na string with blank lines"
|
||||
Expect.equal (wordWrap 80 testString) testString "Blank lines were not preserved"
|
||||
}
|
||||
testList "wordWrap" [
|
||||
test "breaks where it is supposed to" {
|
||||
let testString = "The quick brown fox jumps over the lazy dog\nIt does!"
|
||||
Expect.equal (wordWrap 20 testString) "The quick brown fox\njumps over the lazy\ndog\nIt does!\n"
|
||||
"Line not broken correctly"
|
||||
}
|
||||
test "wraps long line without a space" {
|
||||
let testString = "Asamatteroffact, the dog does too"
|
||||
Expect.equal (wordWrap 10 testString) "Asamattero\nffact, the\ndog does\ntoo\n"
|
||||
"Longer line not broken correctly"
|
||||
}
|
||||
test "preserves blank lines" {
|
||||
let testString = "Here is\n\na string with blank lines"
|
||||
Expect.equal (wordWrap 80 testString) testString "Blank lines were not preserved"
|
||||
}
|
||||
]
|
||||
|
||||
[<Tests>]
|
||||
let wordWrapBTests =
|
||||
testList "wordWrapB" [
|
||||
test "breaks where it is supposed to" {
|
||||
let testString = "The quick brown fox jumps over the lazy dog\nIt does!"
|
||||
Expect.equal (wordWrap 20 testString) "The quick brown fox\njumps over the lazy\ndog\nIt does!\n"
|
||||
"Line not broken correctly"
|
||||
}
|
||||
test "wraps long line without a space and a line with exact length" {
|
||||
let testString = "Asamatteroffact, the dog does too"
|
||||
Expect.equal (wordWrap 10 testString) "Asamattero\nffact, the\ndog does\ntoo\n"
|
||||
"Longer line not broken correctly"
|
||||
}
|
||||
test "wraps long line without a space and a line with non-exact length" {
|
||||
let testString = "Asamatteroffact, that dog does too"
|
||||
Expect.equal (wordWrap 10 testString) "Asamattero\nffact,\nthat dog\ndoes too\n"
|
||||
"Longer line not broken correctly"
|
||||
}
|
||||
test "preserves blank lines" {
|
||||
let testString = "Here is\n\na string with blank lines"
|
||||
Expect.equal (wordWrap 80 testString) testString "Blank lines were not preserved"
|
||||
}
|
||||
testList "wordWrapB" [
|
||||
test "breaks where it is supposed to" {
|
||||
let testString = "The quick brown fox jumps over the lazy dog\nIt does!"
|
||||
Expect.equal (wordWrap 20 testString) "The quick brown fox\njumps over the lazy\ndog\nIt does!\n"
|
||||
"Line not broken correctly"
|
||||
}
|
||||
test "wraps long line without a space and a line with exact length" {
|
||||
let testString = "Asamatteroffact, the dog does too"
|
||||
Expect.equal (wordWrap 10 testString) "Asamattero\nffact, the\ndog does\ntoo\n"
|
||||
"Longer line not broken correctly"
|
||||
}
|
||||
test "wraps long line without a space and a line with non-exact length" {
|
||||
let testString = "Asamatteroffact, that dog does too"
|
||||
Expect.equal (wordWrap 10 testString) "Asamattero\nffact,\nthat dog\ndoes too\n"
|
||||
"Longer line not broken correctly"
|
||||
}
|
||||
test "preserves blank lines" {
|
||||
let testString = "Here is\n\na string with blank lines"
|
||||
Expect.equal (wordWrap 80 testString) testString "Blank lines were not preserved"
|
||||
}
|
||||
]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user