2019-11-13 01:07:23 -05:00
|
|
|
{-
|
|
|
|
|
|
|
|
mtlstats
|
|
|
|
Copyright (C) 2019 Rhéal Lamothe
|
|
|
|
<rheal.lamothe@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or (at
|
|
|
|
your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Actions.EditGoalieSpec (spec) where
|
|
|
|
|
|
|
|
import Data.Maybe (fromJust)
|
|
|
|
import Lens.Micro ((^.), (&), (.~))
|
|
|
|
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
|
|
|
|
|
|
|
import Mtlstats.Actions.EditGoalie
|
|
|
|
import Mtlstats.Types
|
|
|
|
import Mtlstats.Util
|
|
|
|
|
|
|
|
spec :: Spec
|
2019-11-13 23:50:02 -05:00
|
|
|
spec = describe "EditGoalie" $ do
|
2019-11-13 11:06:12 -05:00
|
|
|
editGoalieNumberSpec
|
2019-11-13 23:50:02 -05:00
|
|
|
editGoalieNameSpec
|
2019-11-14 00:59:00 -05:00
|
|
|
editGoalieYtdGamesSpec
|
2019-11-14 01:11:50 -05:00
|
|
|
editGoalieYtdMinsSpec
|
2019-11-13 01:07:23 -05:00
|
|
|
|
2019-11-13 11:06:12 -05:00
|
|
|
editGoalieNumberSpec :: Spec
|
2019-11-13 23:50:02 -05:00
|
|
|
editGoalieNumberSpec = describe "editGoalieNumber" $ editTest
|
|
|
|
(editGoalieNumber 5)
|
|
|
|
EGNumber
|
|
|
|
(uncurry newGoalie)
|
|
|
|
[ ( "set Joe"
|
|
|
|
, Just 0
|
|
|
|
, (5, "Joe")
|
|
|
|
, (3, "Bob")
|
|
|
|
, EGMenu
|
|
|
|
)
|
|
|
|
, ( "set Bob"
|
|
|
|
, Just 1
|
|
|
|
, (2, "Joe")
|
|
|
|
, (5, "Bob")
|
|
|
|
, EGMenu
|
|
|
|
)
|
|
|
|
, ( "out of bounds"
|
|
|
|
, Just 2
|
|
|
|
, (2, "Joe")
|
|
|
|
, (3, "Bob")
|
|
|
|
, EGNumber
|
|
|
|
)
|
|
|
|
, ( "no goalie selected"
|
|
|
|
, Nothing
|
|
|
|
, (2, "Joe")
|
|
|
|
, (3, "Bob")
|
|
|
|
, EGNumber
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
editGoalieNameSpec :: Spec
|
|
|
|
editGoalieNameSpec = describe "editGoalieName" $ editTest
|
|
|
|
(editGoalieName "foo")
|
|
|
|
EGName
|
|
|
|
(uncurry newGoalie)
|
|
|
|
[ ( "set Joe"
|
|
|
|
, Just 0
|
|
|
|
, ( 2, "foo" )
|
|
|
|
, ( 3, "Bob" )
|
|
|
|
, EGMenu
|
|
|
|
)
|
|
|
|
, ( "set Bob"
|
|
|
|
, Just 1
|
|
|
|
, ( 2, "Joe" )
|
|
|
|
, ( 3, "foo" )
|
|
|
|
, EGMenu
|
|
|
|
)
|
|
|
|
, ( "out of bounds"
|
|
|
|
, Just 2
|
|
|
|
, ( 2, "Joe" )
|
|
|
|
, ( 3, "Bob" )
|
|
|
|
, EGName
|
|
|
|
)
|
|
|
|
, ( "no goalie selected"
|
|
|
|
, Nothing
|
|
|
|
, ( 2, "Joe" )
|
|
|
|
, ( 3, "Bob" )
|
|
|
|
, EGName
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
2019-11-14 00:59:00 -05:00
|
|
|
editGoalieYtdGamesSpec :: Spec
|
|
|
|
editGoalieYtdGamesSpec = describe "editGoalieYtdGames" $ editTest
|
|
|
|
(editGoalieYtdGames 1)
|
|
|
|
EGYtdGames
|
|
|
|
(\(num, name, games) -> newGoalie num name & gYtd.gsGames .~ games)
|
|
|
|
[ ( "set Joe"
|
|
|
|
, Just 0
|
|
|
|
, ( 2, "Joe", 1 )
|
|
|
|
, ( 3, "Bob", 0 )
|
|
|
|
, EGYtd
|
|
|
|
)
|
|
|
|
, ( "set Bob"
|
|
|
|
, Just 1
|
|
|
|
, ( 2, "Joe", 0 )
|
|
|
|
, ( 3, "Bob", 1 )
|
|
|
|
, EGYtd
|
|
|
|
)
|
|
|
|
, ( "out of bounds"
|
|
|
|
, Just 2
|
|
|
|
, ( 2, "Joe", 0 )
|
|
|
|
, ( 3, "Bob", 0 )
|
|
|
|
, EGYtdGames
|
|
|
|
)
|
|
|
|
, ( "no goalie selected"
|
|
|
|
, Nothing
|
|
|
|
, ( 2, "Joe", 0 )
|
|
|
|
, ( 3, "Bob", 0 )
|
|
|
|
, EGYtdGames
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
2019-11-14 01:11:50 -05:00
|
|
|
editGoalieYtdMinsSpec :: Spec
|
|
|
|
editGoalieYtdMinsSpec = describe "editGoalieYtdMins" $ editTest
|
|
|
|
(editGoalieYtdMins 1)
|
|
|
|
EGYtdMins
|
|
|
|
(\(num, name, mins) -> newGoalie num name & gYtd.gsMinsPlayed .~ mins)
|
|
|
|
[ ( "set Joe"
|
|
|
|
, Just 0
|
|
|
|
, ( 2, "Joe", 1 )
|
|
|
|
, ( 3, "Bob", 0 )
|
|
|
|
, EGYtd
|
|
|
|
)
|
|
|
|
, ( "set Bob"
|
|
|
|
, Just 1
|
|
|
|
, (2, "Joe", 0 )
|
|
|
|
, (3, "Bob", 1 )
|
|
|
|
, EGYtd
|
|
|
|
)
|
|
|
|
, ( "out of bounds"
|
|
|
|
, Just 2
|
|
|
|
, ( 2, "Joe", 0 )
|
|
|
|
, ( 3, "Bob", 0 )
|
|
|
|
, EGYtdMins
|
|
|
|
)
|
|
|
|
, ( "no goalie selected"
|
|
|
|
, Nothing
|
|
|
|
, ( 2, "Joe", 0 )
|
|
|
|
, ( 3, "Bob", 0 )
|
|
|
|
, EGYtdMins
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
2019-11-13 23:50:02 -05:00
|
|
|
editTest
|
|
|
|
:: (ProgState -> ProgState)
|
|
|
|
-> EditGoalieMode
|
|
|
|
-> (a -> Goalie)
|
|
|
|
-> [(String, Maybe Int, a, a, EditGoalieMode)]
|
|
|
|
-> Spec
|
|
|
|
editTest func setMode mkGoalie params = do
|
2019-11-13 01:07:23 -05:00
|
|
|
mapM_
|
2019-11-13 23:50:02 -05:00
|
|
|
(\(setLabel, setGid, joeData, bobData, expectMode) -> context setLabel $ do
|
2019-11-13 01:07:23 -05:00
|
|
|
let
|
|
|
|
egs = newEditGoalieState
|
|
|
|
& egsSelectedGoalie .~ setGid
|
2019-11-13 23:50:02 -05:00
|
|
|
& egsMode .~ setMode
|
2019-11-13 01:07:23 -05:00
|
|
|
|
2019-11-13 23:50:02 -05:00
|
|
|
ps = func $ progState $ EditGoalie egs
|
2019-11-13 01:07:23 -05:00
|
|
|
|
|
|
|
mapM_
|
2019-11-13 23:50:02 -05:00
|
|
|
(\(chkLabel, chkGid, goalieData) -> context chkLabel $ let
|
|
|
|
actual = fromJust $ nth chkGid $ ps^.database.dbGoalies
|
|
|
|
expected = mkGoalie goalieData
|
|
|
|
in it ("should be " ++ show expected) $
|
|
|
|
actual `shouldBe` expected)
|
|
|
|
-- label, goalie ID, goalie data
|
|
|
|
[ ( "check Joe", 0, joeData )
|
|
|
|
, ( "check Bob", 1, bobData )
|
2019-11-13 01:07:23 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
context "check mode" $
|
2019-11-13 23:50:02 -05:00
|
|
|
it ("should be " ++ show expectMode) $
|
|
|
|
ps^.progMode.editGoalieStateL.egsMode `shouldBe` expectMode)
|
|
|
|
|
|
|
|
params
|
2019-11-13 01:07:23 -05:00
|
|
|
|
|
|
|
context "wrong progMode" $ do
|
2019-11-13 23:50:02 -05:00
|
|
|
let ps = func $ progState MainMenu
|
2019-11-13 01:07:23 -05:00
|
|
|
|
|
|
|
it "should not change the database" $
|
|
|
|
ps^.database `shouldBe` db
|
|
|
|
|
|
|
|
it "should not change the progMode" $
|
|
|
|
show (ps^.progMode) `shouldBe` "MainMenu"
|
2019-11-13 23:50:02 -05:00
|
|
|
|
|
|
|
joe :: Goalie
|
|
|
|
joe = newGoalie 2 "Joe"
|
|
|
|
|
|
|
|
bob :: Goalie
|
|
|
|
bob = newGoalie 3 "Bob"
|
|
|
|
|
|
|
|
db :: Database
|
|
|
|
db = newDatabase & dbGoalies .~ [joe, bob]
|
|
|
|
|
|
|
|
progState :: ProgMode -> ProgState
|
|
|
|
progState mode = newProgState
|
|
|
|
& progMode .~ mode
|
|
|
|
& database .~ db
|