;web: begin work on a forecasting test (#1390)

This commit is contained in:
Simon Michael 2020-11-13 09:36:17 -08:00
parent 290428f9d4
commit c7e267e314
3 changed files with 39 additions and 10 deletions

View File

@ -4,7 +4,7 @@ cabal-version: 1.12
-- --
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
-- --
-- hash: 929ce1d9b5d6a14f13fa77dd3a21d8772a58c1e13310e4940510878718fa4d96 -- hash: 80d248f9e183a9f4f099aab192fd5041fe081ed554baa8ba48b8a3fc4ed777c3
name: hledger-web name: hledger-web
version: 1.19.99 version: 1.19.99
@ -232,6 +232,8 @@ test-suite test
cpp-options: -DVERSION="1.19.99" cpp-options: -DVERSION="1.19.99"
build-depends: build-depends:
base base
, hledger
, hledger-lib
, hledger-web , hledger-web
, hspec , hspec
, yesod , yesod

View File

@ -166,6 +166,8 @@ tests:
cpp-options: -DVERSION="1.19.99" cpp-options: -DVERSION="1.19.99"
dependencies: dependencies:
- base - base
- hledger-lib
- hledger
- hledger-web - hledger-web
- hspec - hspec
- yesod - yesod

View File

@ -10,18 +10,34 @@ module Main where
import Test.Hspec (hspec) import Test.Hspec (hspec)
import Yesod.Default.Config import Yesod.Default.Config
import Yesod.Test import Yesod.Test
import Hledger.Web.Application (makeFoundation) import Hledger.Web.Application (makeFoundation)
import Hledger.Web.Foundation import Hledger.Web.Foundation
import Hledger.Web.Settings (parseExtra) 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 :: IO ()
main = do main = do
conf <- Yesod.Default.Config.loadConfig $ conf <- Yesod.Default.Config.loadConfig $
(configSettings Testing){ csParseExtra = parseExtra } (configSettings Testing){ csParseExtra = parseExtra }
foundation <- makeFoundation conf defwebopts foundation <- makeFoundation conf defwebopts
hspec $ yesodSpec foundation specs 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 -- https://hackage.haskell.org/package/yesod-test/docs/Yesod-Test.html
specs :: YesodSpec App specs :: YesodSpec App
@ -38,13 +54,22 @@ specs = do
statusIs 200 statusIs 200
bodyContains "accounts" bodyContains "accounts"
-- post "/" $ do -- specsForecast :: YesodSpec App
-- addNonce -- specsForecast = do
-- fileByLabel "Choose a file" "tests/main.hs" "text/plain" -- talk about self-reference -- ydescribe "hledger-web --forecast" $ do
-- byLabel "What's on the file?" "Some Content" -- 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"