don't mark goalies recorded unless at least one has been entered

This commit is contained in:
Jonathan Lamothe
2019-11-04 01:24:33 -05:00
parent b0cf9a83a1
commit 3f38160abd
3 changed files with 25 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ module Mtlstats.Actions
, addGoalie , addGoalie
, resetCreatePlayerState , resetCreatePlayerState
, resetCreateGoalieState , resetCreateGoalieState
, finishGameGoalieEntry
, recordGoalAssists , recordGoalAssists
, awardGoal , awardGoal
, awardAssist , awardAssist
@@ -200,6 +201,11 @@ resetCreateGoalieState = progMode.createGoalieStateL
%~ (cgsNumber .~ Nothing) %~ (cgsNumber .~ Nothing)
. (cgsName .~ "") . (cgsName .~ "")
-- | Attempts to finish game goalie entry
finishGameGoalieEntry :: ProgState -> ProgState
finishGameGoalieEntry s = s & progMode.gameStateL.goaliesRecorded
.~ not (null $ s^.progMode.gameStateL.gameGoalieStats)
-- | Awards the goal and assists to the players -- | Awards the goal and assists to the players
recordGoalAssists :: ProgState -> ProgState recordGoalAssists :: ProgState -> ProgState
recordGoalAssists ps = fromMaybe ps $ do recordGoalAssists ps = fromMaybe ps $ do

View File

@@ -338,7 +338,7 @@ goalieNamePrompt = strPrompt "Goalie name: " $
selectGameGoaliePrompt :: Prompt selectGameGoaliePrompt :: Prompt
selectGameGoaliePrompt = selectGoaliePrompt "Which goalie played this game: " $ selectGameGoaliePrompt = selectGoaliePrompt "Which goalie played this game: " $
\case \case
Nothing -> modify $ progMode.gameStateL.goaliesRecorded .~ True Nothing -> modify finishGameGoalieEntry
Just n -> modify $ progMode.gameStateL.gameSelectedGoalie ?~ n Just n -> modify $ progMode.gameStateL.gameSelectedGoalie ?~ n
-- | Prompts for the number of minutes the goalie has played -- | Prompts for the number of minutes the goalie has played

View File

@@ -62,6 +62,7 @@ spec = describe "Mtlstats.Actions" $ do
addGoalieSpec addGoalieSpec
resetCreatePlayerStateSpec resetCreatePlayerStateSpec
resetCreateGoalieStateSpec resetCreateGoalieStateSpec
finishGameGoalieEntrySpec
recordGoalAssistsSpec recordGoalAssistsSpec
awardGoalSpec awardGoalSpec
awardAssistSpec awardAssistSpec
@@ -439,6 +440,23 @@ resetCreateGoalieStateSpec = describe "resetCreateGoalieState" $ let
newProgState & progMode.createGoalieStateL .~ cgs newProgState & progMode.createGoalieStateL .~ cgs
in TS.compareTest (ps^.progMode.createGoalieStateL) newCreateGoalieState in TS.compareTest (ps^.progMode.createGoalieStateL) newCreateGoalieState
finishGameGoalieEntrySpec :: Spec
finishGameGoalieEntrySpec = describe "finishGameGoalieEntry" $ do
let
progState stats = newProgState
& progMode.gameStateL.gameGoalieStats .~ stats
& finishGameGoalieEntry
context "no goalie data" $
it "should not set goaliesRecorded" $ let
s = progState M.empty
in s^.progMode.gameStateL.goaliesRecorded `shouldBe` False
context "goalie data" $
it "should set goaliesRecorded" $ let
s = progState $ M.fromList [(1, newGoalieStats)]
in s^.progMode.gameStateL.goaliesRecorded `shouldBe` True
recordGoalAssistsSpec :: Spec recordGoalAssistsSpec :: Spec
recordGoalAssistsSpec = describe "recordGoalAssists" $ do recordGoalAssistsSpec = describe "recordGoalAssists" $ do
let let