From 9c40af0765ece37d4b726aa4e4e5430624659a33 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Tue, 19 Mar 2019 23:53:05 -0500 Subject: [PATCH] Added tests for as-of date logic --- src/PrayerTracker.Tests/UI/ViewModelsTests.fs | 64 ++++++++++++++++++- src/PrayerTracker.UI/ViewModels.fs | 2 +- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/PrayerTracker.Tests/UI/ViewModelsTests.fs b/src/PrayerTracker.Tests/UI/ViewModelsTests.fs index ac4a513..64a783a 100644 --- a/src/PrayerTracker.Tests/UI/ViewModelsTests.fs +++ b/src/PrayerTracker.Tests/UI/ViewModelsTests.fs @@ -482,7 +482,7 @@ let requestListTests = } |> f yield! testFixture withRequestList [ - "asHtml succeeds without header", + "asHtml succeeds without header or as-of date", fun reqList -> let htmlList = { reqList with listGroup = { reqList.listGroup with name = "Test HTML Group" } } let html = htmlList.asHtml _s @@ -538,7 +538,37 @@ let requestListTests = Expect.stringContains html lstHeading "Expected HTML for the list heading not found" // spot check; without header test tests this exhaustively Expect.stringContains html "Zeb — zyx" "Expected requests not found" - "asText succeeds", + "asHtml succeeds with short as-of date", + fun reqList -> + let htmlList = + { reqList with + listGroup = + { reqList.listGroup with + preferences = { reqList.listGroup.preferences with asOfDateDisplay = ShortDate } + } + } + let html = htmlList.asHtml _s + let expected = + htmlList.requests.[0].updatedDate.ToShortDateString () + |> sprintf "Zeb — zyx  (as of %s)" + // spot check; if one request has it, they all should + Expect.stringContains html expected "Expected short as-of date not found" + "asHtml succeeds with long as-of date", + fun reqList -> + let htmlList = + { reqList with + listGroup = + { reqList.listGroup with + preferences = { reqList.listGroup.preferences with asOfDateDisplay = LongDate } + } + } + let html = htmlList.asHtml _s + let expected = + htmlList.requests.[0].updatedDate.ToLongDateString () + |> sprintf "Zeb — zyx  (as of %s)" + // spot check; if one request has it, they all should + Expect.stringContains html expected "Expected long as-of date not found" + "asText succeeds with no as-of date", fun reqList -> let textList = { reqList with listGroup = { reqList.listGroup with name = "Test Group" } } let text = textList.asText _s @@ -552,6 +582,36 @@ let requestListTests = Expect.stringContains text "------------------\n PRAISE REPORTS\n------------------\n" "Heading for category \"Praise Reports\" not found" Expect.stringContains text " + nmo\n \n" "Last request not found" + "asText succeeds with short as-of date", + fun reqList -> + let textList = + { reqList with + listGroup = + { reqList.listGroup with + preferences = { reqList.listGroup.preferences with asOfDateDisplay = ShortDate } + } + } + let text = textList.asText _s + let expected = + textList.requests.[0].updatedDate.ToShortDateString () + |> sprintf " + Zeb - zyx (as of %s)" + // spot check; if one request has it, they all should + Expect.stringContains text expected "Expected short as-of date not found" + "asText succeeds with long as-of date", + fun reqList -> + let textList = + { reqList with + listGroup = + { reqList.listGroup with + preferences = { reqList.listGroup.preferences with asOfDateDisplay = LongDate } + } + } + let text = textList.asText _s + let expected = + textList.requests.[0].updatedDate.ToLongDateString () + |> sprintf " + Zeb - zyx (as of %s)" + // spot check; if one request has it, they all should + Expect.stringContains text expected "Expected long as-of date not found" "isNew succeeds for both old and new requests", fun reqList -> let reqs = reqList.requestsInCategory CurrentRequest diff --git a/src/PrayerTracker.UI/ViewModels.fs b/src/PrayerTracker.UI/ViewModels.fs index c9f3b6e..85701ad 100644 --- a/src/PrayerTracker.UI/ViewModels.fs +++ b/src/PrayerTracker.UI/ViewModels.fs @@ -636,7 +636,7 @@ with | ShortDate -> req.updatedDate.ToShortDateString () | LongDate -> req.updatedDate.ToLongDateString () | _ -> "" - yield i [ _style (sprintf "font-size:%fpt" asOfSize) ] [ + yield i [ _style (sprintf "font-size:%.2fpt" asOfSize) ] [ rawText "  ("; str s.["as of"].Value; str " "; str dt; rawText ")" ] ])