Merge pull request #76 from mtlstats/single-goalie

don't ask which goalie to assign the game to when there's only one
This commit is contained in:
Jonathan Lamothe 2020-02-14 23:02:47 -05:00 committed by GitHub
commit 0676bf4067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 16 deletions

View File

@ -4,6 +4,7 @@
- Added autocomplete to player position prompt - Added autocomplete to player position prompt
- Don't prompt for lifetime stats on rookie player/goalie creation - Don't prompt for lifetime stats on rookie player/goalie creation
- Ask whether a player/goalie is active on creation - Ask whether a player/goalie is active on creation
- Don't ask which goalie to assign the game to when there's only one
## 0.12.0 ## 0.12.0
- Edit lifetime stats on new player/goalie creation - Edit lifetime stats on new player/goalie creation

View File

@ -36,8 +36,12 @@ import Mtlstats.Util
-- | Attempts to finish game goalie entry -- | Attempts to finish game goalie entry
finishGoalieEntry :: ProgState -> ProgState finishGoalieEntry :: ProgState -> ProgState
finishGoalieEntry s = s & progMode.gameStateL.gameGoaliesRecorded finishGoalieEntry s = case M.toList $ s^.progMode.gameStateL.gameGoalieStats of
.~ not (null $ s^.progMode.gameStateL.gameGoalieStats) [] -> s
[(gid, _)] -> setGameGoalie gid s'
_ -> s'
where
s' = s & progMode.gameStateL.gameGoaliesRecorded .~ True
-- | Records the goalie's game stats -- | Records the goalie's game stats
recordGoalieStats :: ProgState -> ProgState recordGoalieStats :: ProgState -> ProgState

View File

@ -23,7 +23,7 @@ module Actions.NewGame.GoalieInputSpec (spec) where
import qualified Data.Map as M import qualified Data.Map as M
import Data.Maybe (fromJust) import Data.Maybe (fromJust)
import Lens.Micro ((^.), (&), (.~), (?~)) import Lens.Micro ((^.), (&), (.~), (?~), (%~))
import Test.Hspec (Spec, context, describe, it, shouldBe) import Test.Hspec (Spec, context, describe, it, shouldBe)
import Mtlstats.Actions.NewGame.GoalieInput import Mtlstats.Actions.NewGame.GoalieInput
@ -39,21 +39,44 @@ spec = describe "Mtlstats.Actions.GoalieInput" $ do
setGameGoalieSpec setGameGoalieSpec
finishGoalieEntrySpec :: Spec finishGoalieEntrySpec :: Spec
finishGoalieEntrySpec = describe "finishGoalieEntry" $ do finishGoalieEntrySpec = describe "finishGoalieEntry" $ mapM_
(\(label, stats, grFlag, gaFlag) -> context label $ do
let let
progState stats = newProgState ps = newProgState
& progMode.gameStateL.gameGoalieStats .~ stats & progMode.gameStateL
& finishGoalieEntry %~ (gameGoalieStats .~ stats)
. (gameType ?~ HomeGame)
. (homeScore ?~ 1)
. (awayScore ?~ 0)
. (overtimeFlag ?~ False)
& database.dbGoalies .~ goalies
context "no goalie data" $ ps' = finishGoalieEntry ps
it "should not set goaliesRecorded" $ let gs = ps'^.progMode.gameStateL
s = progState M.empty
in s^.progMode.gameStateL.gameGoaliesRecorded `shouldBe` False
context "goalie data" $ describe "gameGoaliesRecorded" $
it "should set goaliesRecorded" $ let it ("should be " ++ show grFlag) $
s = progState $ M.fromList [(1, newGoalieStats)] gs^.gameGoaliesRecorded `shouldBe` grFlag
in s^.progMode.gameStateL.gameGoaliesRecorded `shouldBe` True
describe "gameGoalieAssigned" $
it ("should be " ++ show gaFlag) $
gs^.gameGoalieAssigned `shouldBe` gaFlag)
-- label, initial stats, goalies recorded, goalie assigned
[ ( "no goalies", noGoalies, False, False )
, ( "one goalie", oneGoalie, True, True )
, ( "two goalies", twoGoalies, True, False )
]
where
goalies = [joe, bob]
joe = newGoalie 2 "Joe"
bob = newGoalie 3 "Bob"
noGoalies = M.empty
oneGoalie = M.fromList [joeStats]
twoGoalies = M.fromList [joeStats, bobStats]
joeStats = (0, newGoalieStats)
bobStats = (1, newGoalieStats)
recordGoalieStatsSpec :: Spec recordGoalieStatsSpec :: Spec
recordGoalieStatsSpec = describe "recordGoalieStats" $ let recordGoalieStatsSpec = describe "recordGoalieStats" $ let