From c7e267e314e7ee9d1736d7c48087ad06439f2dc8 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 13 Nov 2020 09:36:17 -0800 Subject: [PATCH] ;web: begin work on a forecasting test (#1390) --- hledger-web/hledger-web.cabal | 4 +++- hledger-web/package.yaml | 2 ++ hledger-web/test/test.hs | 43 +++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/hledger-web/hledger-web.cabal b/hledger-web/hledger-web.cabal index 6a8562638..16c474767 100644 --- a/hledger-web/hledger-web.cabal +++ b/hledger-web/hledger-web.cabal @@ -4,7 +4,7 @@ cabal-version: 1.12 -- -- see: https://github.com/sol/hpack -- --- hash: 929ce1d9b5d6a14f13fa77dd3a21d8772a58c1e13310e4940510878718fa4d96 +-- hash: 80d248f9e183a9f4f099aab192fd5041fe081ed554baa8ba48b8a3fc4ed777c3 name: hledger-web version: 1.19.99 @@ -232,6 +232,8 @@ test-suite test cpp-options: -DVERSION="1.19.99" build-depends: base + , hledger + , hledger-lib , hledger-web , hspec , yesod diff --git a/hledger-web/package.yaml b/hledger-web/package.yaml index d79bc28e9..abe8fa518 100644 --- a/hledger-web/package.yaml +++ b/hledger-web/package.yaml @@ -166,6 +166,8 @@ tests: cpp-options: -DVERSION="1.19.99" dependencies: - base + - hledger-lib + - hledger - hledger-web - hspec - yesod diff --git a/hledger-web/test/test.hs b/hledger-web/test/test.hs index 982910488..aecce8243 100644 --- a/hledger-web/test/test.hs +++ b/hledger-web/test/test.hs @@ -10,18 +10,34 @@ module Main where import Test.Hspec (hspec) import Yesod.Default.Config import Yesod.Test + import Hledger.Web.Application (makeFoundation) import Hledger.Web.Foundation import Hledger.Web.Settings (parseExtra) -import Hledger.Web.WebOptions (defwebopts) +import Hledger.Web.WebOptions -- (defwebopts, cliopts_) +-- import Hledger.Cli.CliOptions -- (defcliopts, reportspec_) +-- import Hledger -- .Reports.ReportOptions (defreportopts, forecast_) main :: IO () main = do conf <- Yesod.Default.Config.loadConfig $ (configSettings Testing){ csParseExtra = parseExtra } + foundation <- makeFoundation conf defwebopts hspec $ yesodSpec foundation specs + -- run hledger-web with some forecasted transactions + -- XXX problem: these tests use makeFoundation, bypassing the journal setup in Hledger.Web.Main + -- d <- getCurrentDay + -- let + -- ropts = defreportopts{forecast_=Just nulldatespan} + -- rspec = case reportOptsToSpec d ropts of + -- Left e -> error $ "failed to set up report options for tests, shouldn't happen: " ++ show e + -- Right rs -> rs + -- foundationForecast <- makeFoundation conf + -- defwebopts{cliopts_=defcliopts{file_=["hledger-web/tests/forecast.j"], reportspec_=rspec}} + -- hspec $ yesodSpec foundationForecast specsForecast + -- https://hackage.haskell.org/package/yesod-test/docs/Yesod-Test.html specs :: YesodSpec App @@ -38,13 +54,22 @@ specs = do statusIs 200 bodyContains "accounts" - -- post "/" $ do - -- addNonce - -- fileByLabel "Choose a file" "tests/main.hs" "text/plain" -- talk about self-reference - -- byLabel "What's on the file?" "Some Content" +-- specsForecast :: YesodSpec App +-- specsForecast = do +-- ydescribe "hledger-web --forecast" $ do +-- yit "serves a reasonable-looking journal page" $ do +-- get JournalR +-- statusIs 200 +-- bodyContains "Add a transaction" - -- statusIs 200 - -- htmlCount ".message" 1 - -- htmlAllContain ".message" "Some Content" - -- htmlAllContain ".message" "text/plain" + + +-- post "/" $ do +-- addNonce +-- fileByLabel "Choose a file" "tests/main.hs" "text/plain" -- talk about self-reference +-- byLabel "What's on the file?" "Some Content" +-- statusIs 200 +-- htmlCount ".message" 1 +-- htmlAllContain ".message" "Some Content" +-- htmlAllContain ".message" "text/plain"