web: re-enable the test suite; add a test for /journal (#1390)

This commit is contained in:
Simon Michael 2020-11-12 18:09:02 -08:00
parent b76a88aa81
commit 290428f9d4
6 changed files with 69 additions and 62 deletions

View File

@ -41,3 +41,5 @@ cradle:
component: "hledger-web:lib"
- path: "hledger-web/app/"
component: "hledger-web:exe:hledger-web"
- path: "hledger-web/test/"
component: "hledger-web:test:test"

View File

@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 1d9dc492e44eb37e5c5db8a8d8d21ca089c3035b4f4fa72d95696d51613400be
-- hash: 929ce1d9b5d6a14f13fa77dd3a21d8772a58c1e13310e4940510878718fa4d96
name: hledger-web
version: 1.19.99
@ -222,3 +222,22 @@ executable hledger-web
if flag(threaded)
ghc-options: -threaded
default-language: Haskell2010
test-suite test
type: exitcode-stdio-1.0
main-is: test.hs
hs-source-dirs:
test
ghc-options: -Wall -fwarn-tabs -Wcompat -Wincomplete-uni-patterns -Wincomplete-record-updates -Wredundant-constraints
cpp-options: -DVERSION="1.19.99"
build-depends:
base
, hledger-web
, hspec
, yesod
, yesod-test
if (flag(dev)) || (flag(library-only))
cpp-options: -DDEVELOPMENT
if flag(dev)
ghc-options: -O0
default-language: Haskell2010

View File

@ -158,15 +158,15 @@ executables:
- condition: flag(threaded)
ghc-options: -threaded
# 2018/06 not building and not testing anything useful, disabled for now
# tests:
# test:
# source-dirs: test
# main: test.hs
# other-modules: [] # prevent double compilation, https://github.com/sol/hpack/issues/188
# cpp-options: -DVERSION="1.19.99"
# dependencies:
# - base
# - hledger-web
# - hspec
# - yesod-test
tests:
test:
source-dirs: test
main: test.hs
other-modules: [] # prevent double compilation, https://github.com/sol/hpack/issues/188
cpp-options: -DVERSION="1.19.99"
dependencies:
- base
- hledger-web
- hspec
- yesod
- yesod-test

View File

@ -1,25 +0,0 @@
{-# LANGUAGE OverloadedStrings #-}
module HomeTest
( homeSpecs
) where
import TestImport
homeSpecs :: Specs
homeSpecs =
ydescribe "Some hledger-web tests" $
yit "serves a reasonable-looking register page" $ do
get RegisterR
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"
-- statusIs 200
-- htmlCount ".message" 1
-- htmlAllContain ".message" "Some Content"
-- htmlAllContain ".message" "text/plain"

View File

@ -1,12 +0,0 @@
{-# LANGUAGE OverloadedStrings #-}
module TestImport
( module Yesod.Test
, module Foundation
, Specs
) where
import Yesod.Test
import Foundation
type Specs = YesodSpec App

View File

@ -7,21 +7,44 @@ module Main where
-- cabal missing-home-modules workaround from hledger-lib needed here ?
-- {-# LANGUAGE PackageImports #-}
import Import
import Test.Hspec (hspec)
import Yesod.Default.Config
import Yesod.Test
import Test.Hspec (hspec)
import Application (makeFoundation)
import Hledger.Web.Application (makeFoundation)
import Hledger.Web.Foundation
import Hledger.Web.Settings (parseExtra)
import Hledger.Web.WebOptions (defwebopts)
import HomeTest
main :: IO ()
main = do
conf <- Yesod.Default.Config.loadConfig $ (configSettings Testing)
{ csParseExtra = parseExtra
}
foundation <- makeFoundation conf defwebopts
hspec $ do
yesodSpec foundation $ do
homeSpecs
conf <- Yesod.Default.Config.loadConfig $
(configSettings Testing){ csParseExtra = parseExtra }
foundation <- makeFoundation conf defwebopts
hspec $ yesodSpec foundation specs
-- https://hackage.haskell.org/package/yesod-test/docs/Yesod-Test.html
specs :: YesodSpec App
specs = do
ydescribe "hledger-web basic functionality" $ do
yit "serves a reasonable-looking journal page" $ do
get JournalR
statusIs 200
bodyContains "Add a transaction"
yit "serves a reasonable-looking register page" $ do
get RegisterR
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"
-- statusIs 200
-- htmlCount ".message" 1
-- htmlAllContain ".message" "Some Content"
-- htmlAllContain ".message" "text/plain"