From 119032ca80beaba38d5e3b57f1968870df7671fa Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 14 Feb 2020 22:56:35 -0500 Subject: [PATCH] don't ask which goalie to assign the game to when there's only one --- ChangeLog.md | 1 + src/Mtlstats/Actions/NewGame/GoalieInput.hs | 8 +++- test/Actions/NewGame/GoalieInputSpec.hs | 51 +++++++++++++++------ 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 51b727e..f1da21a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,6 +4,7 @@ - Added autocomplete to player position prompt - Don't prompt for lifetime stats on rookie player/goalie 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 - Edit lifetime stats on new player/goalie creation diff --git a/src/Mtlstats/Actions/NewGame/GoalieInput.hs b/src/Mtlstats/Actions/NewGame/GoalieInput.hs index 879eb34..d4fb34c 100644 --- a/src/Mtlstats/Actions/NewGame/GoalieInput.hs +++ b/src/Mtlstats/Actions/NewGame/GoalieInput.hs @@ -36,8 +36,12 @@ import Mtlstats.Util -- | Attempts to finish game goalie entry finishGoalieEntry :: ProgState -> ProgState -finishGoalieEntry s = s & progMode.gameStateL.gameGoaliesRecorded - .~ not (null $ s^.progMode.gameStateL.gameGoalieStats) +finishGoalieEntry s = case M.toList $ s^.progMode.gameStateL.gameGoalieStats of + [] -> s + [(gid, _)] -> setGameGoalie gid s' + _ -> s' + where + s' = s & progMode.gameStateL.gameGoaliesRecorded .~ True -- | Records the goalie's game stats recordGoalieStats :: ProgState -> ProgState diff --git a/test/Actions/NewGame/GoalieInputSpec.hs b/test/Actions/NewGame/GoalieInputSpec.hs index 873ab31..eb8d83d 100644 --- a/test/Actions/NewGame/GoalieInputSpec.hs +++ b/test/Actions/NewGame/GoalieInputSpec.hs @@ -23,7 +23,7 @@ module Actions.NewGame.GoalieInputSpec (spec) where import qualified Data.Map as M import Data.Maybe (fromJust) -import Lens.Micro ((^.), (&), (.~), (?~)) +import Lens.Micro ((^.), (&), (.~), (?~), (%~)) import Test.Hspec (Spec, context, describe, it, shouldBe) import Mtlstats.Actions.NewGame.GoalieInput @@ -39,21 +39,44 @@ spec = describe "Mtlstats.Actions.GoalieInput" $ do setGameGoalieSpec finishGoalieEntrySpec :: Spec -finishGoalieEntrySpec = describe "finishGoalieEntry" $ do - let - progState stats = newProgState - & progMode.gameStateL.gameGoalieStats .~ stats - & finishGoalieEntry +finishGoalieEntrySpec = describe "finishGoalieEntry" $ mapM_ + (\(label, stats, grFlag, gaFlag) -> context label $ do + let + ps = newProgState + & progMode.gameStateL + %~ (gameGoalieStats .~ stats) + . (gameType ?~ HomeGame) + . (homeScore ?~ 1) + . (awayScore ?~ 0) + . (overtimeFlag ?~ False) + & database.dbGoalies .~ goalies - context "no goalie data" $ - it "should not set goaliesRecorded" $ let - s = progState M.empty - in s^.progMode.gameStateL.gameGoaliesRecorded `shouldBe` False + ps' = finishGoalieEntry ps + gs = ps'^.progMode.gameStateL - context "goalie data" $ - it "should set goaliesRecorded" $ let - s = progState $ M.fromList [(1, newGoalieStats)] - in s^.progMode.gameStateL.gameGoaliesRecorded `shouldBe` True + describe "gameGoaliesRecorded" $ + it ("should be " ++ show grFlag) $ + gs^.gameGoaliesRecorded `shouldBe` grFlag + + 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 = describe "recordGoalieStats" $ let