From 667cf344756a9db34a0b52cf71a694b3ff81fc17 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 25 Oct 2019 01:44:56 -0400 Subject: [PATCH] implemented resetCreatePlayerState and resetCreateGoalieState --- src/Mtlstats/Actions.hs | 15 +++++++++++++++ test/ActionsSpec.hs | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index acd03d1..4de1cd6 100644 --- a/src/Mtlstats/Actions.hs +++ b/src/Mtlstats/Actions.hs @@ -34,6 +34,8 @@ module Mtlstats.Actions , createGoalie , addPlayer , addGoalie + , resetCreatePlayerState + , resetCreateGoalieState , recordGoalAssists , awardGoal , awardAssist @@ -172,6 +174,19 @@ addPlayer s = fromMaybe s $ do addGoalie :: ProgState -> ProgState addGoalie = undefined +-- | Resets the 'CreatePlayerState' value +resetCreatePlayerState :: ProgState -> ProgState +resetCreatePlayerState = progMode.createPlayerStateL + %~ (cpsNumber .~ Nothing) + . (cpsName .~ "") + . (cpsPosition .~ "") + +-- | Resets the 'CreateGoalieState' value +resetCreateGoalieState :: ProgState -> ProgState +resetCreateGoalieState = progMode.createGoalieStateL + %~ (cgsNumber .~ Nothing) + . (cgsName .~ "") + -- | Awards the goal and assists to the players recordGoalAssists :: ProgState -> ProgState recordGoalAssists ps = fromMaybe ps $ do diff --git a/test/ActionsSpec.hs b/test/ActionsSpec.hs index 343e442..4b38d79 100644 --- a/test/ActionsSpec.hs +++ b/test/ActionsSpec.hs @@ -43,6 +43,8 @@ import Mtlstats.Actions import Mtlstats.Types import Mtlstats.Util +import qualified TypesSpec as TS + spec :: Spec spec = describe "Mtlstats.Actions" $ do startNewSeasonSpec @@ -56,6 +58,8 @@ spec = describe "Mtlstats.Actions" $ do createPlayerSpec createGoalieSpec addPlayerSpec + resetCreatePlayerStateSpec + resetCreateGoalieStateSpec recordGoalAssistsSpec awardGoalSpec awardAssistSpec @@ -384,6 +388,25 @@ addPlayerSpec = describe "addPlayer" $ do s' = addPlayer $ s MainMenu in s'^.database.dbPlayers `shouldBe` [p1] +resetCreatePlayerStateSpec :: Spec +resetCreatePlayerStateSpec = describe "resetCreatePlayerState" $ let + cps = newCreatePlayerState + & cpsNumber ?~ 1 + & cpsName .~ "Joe" + & cpsPosition .~ "centre" + ps = resetCreatePlayerState $ + newProgState & progMode.createPlayerStateL .~ cps + in TS.compareTest (ps^.progMode.createPlayerStateL) newCreatePlayerState + +resetCreateGoalieStateSpec :: Spec +resetCreateGoalieStateSpec = describe "resetCreateGoalieState" $ let + cgs = newCreateGoalieState + & cgsNumber ?~ 1 + & cgsName .~ "Joe" + ps = resetCreateGoalieState $ + newProgState & progMode.createGoalieStateL .~ cgs + in TS.compareTest (ps^.progMode.createGoalieStateL) newCreateGoalieState + recordGoalAssistsSpec :: Spec recordGoalAssistsSpec = describe "recordGoalAssists" $ do let