Implement htmax as auto-htmx selection (#59)
- Move program support items to MyWebLog namespace - Fix parameter ordering in some tests
This commit is contained in:
@@ -6,6 +6,20 @@ open MyWebLog
|
||||
open MyWebLog.Converters.Json
|
||||
open Newtonsoft.Json
|
||||
|
||||
/// Unit tests for the AutoHtmxTypeConverter type
|
||||
let autoHtmxTypeConverterTests = testList "AutoHtmxTypeConverter" [
|
||||
let opts = JsonSerializerSettings()
|
||||
opts.Converters.Add(AutoHtmxTypeConverter())
|
||||
test "succeeds when serializing" {
|
||||
let after = JsonConvert.SerializeObject(AutoHtmax, opts)
|
||||
Expect.equal after "\"Max\"" "Auto htmx type serialized incorrectly"
|
||||
}
|
||||
test "succeeds when deserializing" {
|
||||
let after = JsonConvert.DeserializeObject<AutoHtmxType>("\"Yes\"", opts)
|
||||
Expect.equal after AutoHtmx "Auto htmx type not serialized incorrectly"
|
||||
}
|
||||
]
|
||||
|
||||
/// Unit tests for the CategoryIdConverter type
|
||||
let categoryIdConverterTests = testList "CategoryIdConverter" [
|
||||
let opts = JsonSerializerSettings()
|
||||
@@ -264,6 +278,7 @@ open NodaTime.Serialization.JsonNet
|
||||
let configureTests = test "Json.configure succeeds" {
|
||||
let has typ (converter: JsonConverter) = converter.GetType() = typ
|
||||
let ser = configure (JsonSerializer.Create())
|
||||
Expect.hasCountOf ser.Converters 1u (has typeof<AutoHtmxTypeConverter>) "Auto htmx type converter not found"
|
||||
Expect.hasCountOf ser.Converters 1u (has typeof<CategoryIdConverter>) "Category ID converter not found"
|
||||
Expect.hasCountOf ser.Converters 1u (has typeof<CommentIdConverter>) "Comment ID converter not found"
|
||||
Expect.hasCountOf ser.Converters 1u (has typeof<CommentStatusConverter>) "Comment status converter not found"
|
||||
@@ -290,6 +305,7 @@ let configureTests = test "Json.configure succeeds" {
|
||||
|
||||
/// All tests for the Data.Converters file
|
||||
let all = testList "Converters" [
|
||||
autoHtmxTypeConverterTests
|
||||
categoryIdConverterTests
|
||||
commentIdConverterTests
|
||||
commentStatusConverterTests
|
||||
|
||||
@@ -30,7 +30,7 @@ let ``Add succeeds`` (data: IData) = task {
|
||||
IsTagEnabled = false
|
||||
Copyright = Some "go for it"
|
||||
CustomFeeds = [] }
|
||||
AutoHtmx = true
|
||||
AutoHtmx = AutoHtmax
|
||||
Uploads = Disk
|
||||
RedirectRules = [ { From = "/here"; To = "/there"; IsRegex = false } ]
|
||||
AutoOpenGraph = false }
|
||||
@@ -46,7 +46,7 @@ let ``Add succeeds`` (data: IData) = task {
|
||||
Expect.equal it.ThemeId (ThemeId "default") "Theme ID is incorrect"
|
||||
Expect.equal it.UrlBase "https://example.com/new" "URL base is incorrect"
|
||||
Expect.equal it.TimeZone "America/Los_Angeles" "Time zone is incorrect"
|
||||
Expect.isTrue it.AutoHtmx "Auto htmx flag is incorrect"
|
||||
Expect.equal it.AutoHtmx AutoHtmax "Auto htmx type is incorrect"
|
||||
Expect.equal it.Uploads Disk "Upload destination is incorrect"
|
||||
Expect.equal it.RedirectRules [ { From = "/here"; To = "/there"; IsRegex = false } ] "Redirect rules are incorrect"
|
||||
Expect.isFalse it.AutoOpenGraph "Auto OpenGraph flag is incorrect"
|
||||
@@ -91,7 +91,7 @@ let ``FindById succeeds when a web log is found`` (data: IData) = task {
|
||||
Expect.equal it.ThemeId (ThemeId "default") "Theme ID is incorrect"
|
||||
Expect.equal it.UrlBase "http://localhost:8081" "URL base is incorrect"
|
||||
Expect.equal it.TimeZone "America/Denver" "Time zone is incorrect"
|
||||
Expect.isTrue it.AutoHtmx "Auto htmx flag is incorrect"
|
||||
Expect.equal it.AutoHtmx AutoHtmx "Auto htmx type is incorrect"
|
||||
Expect.equal it.Uploads Database "Upload destination is incorrect"
|
||||
Expect.isEmpty it.RedirectRules "Redirect rules are incorrect"
|
||||
let rss = it.Rss
|
||||
@@ -165,10 +165,10 @@ let ``UpdateRssOptions succeeds when the web log does not exist`` (data: IData)
|
||||
let ``UpdateSettings succeeds when the web log exists`` (data: IData) = task {
|
||||
let! webLog = data.WebLog.FindById rootId
|
||||
Expect.isSome webLog "The root web log should have been returned"
|
||||
do! data.WebLog.UpdateSettings { webLog.Value with AutoHtmx = false; Subtitle = None }
|
||||
do! data.WebLog.UpdateSettings { webLog.Value with AutoHtmx = NoAutoHtmx; Subtitle = None }
|
||||
let! updated = data.WebLog.FindById rootId
|
||||
Expect.isSome updated "The updated web log should have been returned"
|
||||
Expect.isFalse updated.Value.AutoHtmx "Auto htmx flag not updated correctly"
|
||||
Expect.equal updated.Value.AutoHtmx NoAutoHtmx "Auto htmx type not updated correctly"
|
||||
Expect.isNone updated.Value.Subtitle "Subtitle not updated correctly"
|
||||
}
|
||||
|
||||
|
||||
@@ -31,16 +31,16 @@ let nodaTests = testList "Noda" [
|
||||
let accessLevelTests = testList "AccessLevel" [
|
||||
testList "Parse" [
|
||||
test "succeeds for \"Author\"" {
|
||||
Expect.equal Author (AccessLevel.Parse "Author") "Author not parsed correctly"
|
||||
Expect.equal (AccessLevel.Parse "Author") Author "Author not parsed correctly"
|
||||
}
|
||||
test "succeeds for \"Editor\"" {
|
||||
Expect.equal Editor (AccessLevel.Parse "Editor") "Editor not parsed correctly"
|
||||
Expect.equal (AccessLevel.Parse "Editor") Editor "Editor not parsed correctly"
|
||||
}
|
||||
test "succeeds for \"WebLogAdmin\"" {
|
||||
Expect.equal WebLogAdmin (AccessLevel.Parse "WebLogAdmin") "WebLogAdmin not parsed correctly"
|
||||
Expect.equal (AccessLevel.Parse "WebLogAdmin") WebLogAdmin "WebLogAdmin not parsed correctly"
|
||||
}
|
||||
test "succeeds for \"Administrator\"" {
|
||||
Expect.equal Administrator (AccessLevel.Parse "Administrator") "Administrator not parsed correctly"
|
||||
Expect.equal (AccessLevel.Parse "Administrator") Administrator "Administrator not parsed correctly"
|
||||
}
|
||||
test "fails when given an unrecognized value" {
|
||||
Expect.throwsT<ArgumentException>
|
||||
@@ -113,17 +113,47 @@ let accessLevelTests = testList "AccessLevel" [
|
||||
]
|
||||
]
|
||||
|
||||
/// Tests for the AutoHtmxType type
|
||||
let autoHtmxTypeTests = testList "AutoHtmxType" [
|
||||
testList "Parse" [
|
||||
test "succeeds for \"NoAutoHtmx\"" {
|
||||
Expect.equal (AutoHtmxType.Parse "No") NoAutoHtmx "No not parsed correctly"
|
||||
}
|
||||
test "succeeds for \"AutoHtmx\"" {
|
||||
Expect.equal (AutoHtmxType.Parse "Yes") AutoHtmx "Yes not parsed correctly"
|
||||
}
|
||||
test "succeeds for \"AutoHtmax\"" {
|
||||
Expect.equal (AutoHtmxType.Parse "Max") AutoHtmax "Max not parsed correctly"
|
||||
}
|
||||
test "fails for unrecognized value" {
|
||||
Expect.throwsT<ArgumentException>
|
||||
(fun () -> ignore (AutoHtmxType.Parse "Sure")) "Invalid value should have raised an exception"
|
||||
}
|
||||
]
|
||||
testList "ToString" [
|
||||
test "NoAutoHtmx succeeds" {
|
||||
Expect.equal (string NoAutoHtmx) "No" "NoAutoHtmx string incorrect"
|
||||
}
|
||||
test "AutoHtmx succeeds" {
|
||||
Expect.equal (string AutoHtmx) "Yes" "AutoHtmx string incorrect"
|
||||
}
|
||||
test "AutoHtmax succeeds" {
|
||||
Expect.equal (string AutoHtmax) "Max" "AutoHtmax string incorrect"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
/// Tests for the CommentStatus type
|
||||
let commentStatusTests = testList "CommentStatus" [
|
||||
testList "Parse" [
|
||||
test "succeeds for \"Approved\"" {
|
||||
Expect.equal Approved (CommentStatus.Parse "Approved") "Approved not parsed correctly"
|
||||
Expect.equal (CommentStatus.Parse "Approved") Approved "Approved not parsed correctly"
|
||||
}
|
||||
test "succeeds for \"Pending\"" {
|
||||
Expect.equal Pending (CommentStatus.Parse "Pending") "Pending not parsed correctly"
|
||||
Expect.equal (CommentStatus.Parse "Pending") Pending "Pending not parsed correctly"
|
||||
}
|
||||
test "succeeds for \"Spam\"" {
|
||||
Expect.equal Spam (CommentStatus.Parse "Spam") "Spam not parsed correctly"
|
||||
Expect.equal (CommentStatus.Parse "Spam") Spam "Spam not parsed correctly"
|
||||
}
|
||||
test "fails for unrecognized value" {
|
||||
Expect.throwsT<ArgumentException>
|
||||
@@ -147,13 +177,13 @@ let commentStatusTests = testList "CommentStatus" [
|
||||
let explicitRatingTests = testList "ExplicitRating" [
|
||||
testList "Parse" [
|
||||
test "succeeds for \"yes\"" {
|
||||
Expect.equal Yes (ExplicitRating.Parse "yes") "\"yes\" not parsed correctly"
|
||||
Expect.equal (ExplicitRating.Parse "yes") Yes "\"yes\" not parsed correctly"
|
||||
}
|
||||
test "succeeds for \"no\"" {
|
||||
Expect.equal No (ExplicitRating.Parse "no") "\"no\" not parsed correctly"
|
||||
Expect.equal (ExplicitRating.Parse "no") No "\"no\" not parsed correctly"
|
||||
}
|
||||
test "succeeds for \"clean\"" {
|
||||
Expect.equal Clean (ExplicitRating.Parse "clean") "\"clean\" not parsed correctly"
|
||||
Expect.equal (ExplicitRating.Parse "clean") Clean "\"clean\" not parsed correctly"
|
||||
}
|
||||
test "fails for unrecognized value" {
|
||||
Expect.throwsT<ArgumentException>
|
||||
@@ -780,6 +810,7 @@ let uploadDestinationTests = testList "UploadDestination" [
|
||||
let all = testList "SupportTypes" [
|
||||
nodaTests
|
||||
accessLevelTests
|
||||
autoHtmxTypeTests
|
||||
commentStatusTests
|
||||
explicitRatingTests
|
||||
episodeTests
|
||||
|
||||
@@ -1363,7 +1363,7 @@ let settingsModelTests = testList "SettingsModel" [
|
||||
PostsPerPage = 18
|
||||
TimeZone = "America/Denver"
|
||||
ThemeId = ThemeId "my-theme"
|
||||
AutoHtmx = true
|
||||
AutoHtmx = AutoHtmx
|
||||
AutoOpenGraph = false }
|
||||
Expect.equal model.Name "The Web Log" "Name not filled properly"
|
||||
Expect.equal model.Slug "the-web-log" "Slug not filled properly"
|
||||
@@ -1372,7 +1372,7 @@ let settingsModelTests = testList "SettingsModel" [
|
||||
Expect.equal model.PostsPerPage 18 "PostsPerPage not filled properly"
|
||||
Expect.equal model.TimeZone "America/Denver" "TimeZone not filled properly"
|
||||
Expect.equal model.ThemeId "my-theme" "ThemeId not filled properly"
|
||||
Expect.isTrue model.AutoHtmx "AutoHtmx should have been set"
|
||||
Expect.equal model.AutoHtmx (string AutoHtmx) "AutoHtmx should have been set"
|
||||
Expect.equal model.Uploads "Database" "Uploads not filled properly"
|
||||
Expect.isFalse model.AutoOpenGraph "AutoOpenGraph should have been unset"
|
||||
}
|
||||
@@ -1391,7 +1391,7 @@ let settingsModelTests = testList "SettingsModel" [
|
||||
PostsPerPage = 8
|
||||
TimeZone = "America/Chicago"
|
||||
ThemeId = "test-theme"
|
||||
AutoHtmx = true
|
||||
AutoHtmx = (string AutoHtmax)
|
||||
Uploads = "Disk"
|
||||
AutoOpenGraph = false }.Update WebLog.Empty
|
||||
Expect.equal webLog.Name "Interesting" "Name not filled properly"
|
||||
@@ -1401,7 +1401,7 @@ let settingsModelTests = testList "SettingsModel" [
|
||||
Expect.equal webLog.PostsPerPage 8 "PostsPerPage not filled properly"
|
||||
Expect.equal webLog.TimeZone "America/Chicago" "TimeZone not filled properly"
|
||||
Expect.equal webLog.ThemeId (ThemeId "test-theme") "ThemeId not filled properly"
|
||||
Expect.isTrue webLog.AutoHtmx "AutoHtmx should have been set"
|
||||
Expect.equal webLog.AutoHtmx AutoHtmax "AutoHtmx should have been set"
|
||||
Expect.equal webLog.Uploads Disk "Uploads not filled properly"
|
||||
Expect.isFalse webLog.AutoOpenGraph "AutoOpenGraph should have been unset"
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"AutoHtmx": true,
|
||||
"AutoHtmx": "Yes",
|
||||
"Uploads": "Database",
|
||||
"RedirectRules": []
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user