added callbacks to CreatePlayerState
This commit is contained in:
parent
db0084f991
commit
6dd9350189
|
@ -59,6 +59,8 @@ module Mtlstats.Types (
|
||||||
cpsNumber,
|
cpsNumber,
|
||||||
cpsName,
|
cpsName,
|
||||||
cpsPosition,
|
cpsPosition,
|
||||||
|
cpsSuccessCallback,
|
||||||
|
cpsFailureCallback,
|
||||||
-- ** Database Lenses
|
-- ** Database Lenses
|
||||||
dbPlayers,
|
dbPlayers,
|
||||||
dbGoalies,
|
dbGoalies,
|
||||||
|
@ -157,7 +159,7 @@ data ProgState = ProgState
|
||||||
-- ^ The program's mode
|
-- ^ The program's mode
|
||||||
, _inputBuffer :: String
|
, _inputBuffer :: String
|
||||||
-- ^ Buffer for user input
|
-- ^ Buffer for user input
|
||||||
} deriving (Eq, Show)
|
}
|
||||||
|
|
||||||
-- | The program mode
|
-- | The program mode
|
||||||
data ProgMode
|
data ProgMode
|
||||||
|
@ -165,7 +167,12 @@ data ProgMode
|
||||||
| NewSeason
|
| NewSeason
|
||||||
| NewGame GameState
|
| NewGame GameState
|
||||||
| CreatePlayer CreatePlayerState
|
| CreatePlayer CreatePlayerState
|
||||||
deriving (Eq, Show)
|
|
||||||
|
instance Show ProgMode where
|
||||||
|
show MainMenu = "MainMenu"
|
||||||
|
show NewSeason = "NewSeason"
|
||||||
|
show (NewGame _) = "NewGame"
|
||||||
|
show (CreatePlayer _) = "CreatePlayer"
|
||||||
|
|
||||||
-- | The game state
|
-- | The game state
|
||||||
data GameState = GameState
|
data GameState = GameState
|
||||||
|
@ -197,13 +204,17 @@ data GameType
|
||||||
|
|
||||||
-- | Player creation status
|
-- | Player creation status
|
||||||
data CreatePlayerState = CreatePlayerState
|
data CreatePlayerState = CreatePlayerState
|
||||||
{ _cpsNumber :: Maybe Int
|
{ _cpsNumber :: Maybe Int
|
||||||
-- ^ The player's number
|
-- ^ The player's number
|
||||||
, _cpsName :: String
|
, _cpsName :: String
|
||||||
-- ^ The player's name
|
-- ^ The player's name
|
||||||
, _cpsPosition :: String
|
, _cpsPosition :: String
|
||||||
-- ^ The player's position
|
-- ^ The player's position
|
||||||
} deriving (Eq, Show)
|
, _cpsSuccessCallback :: Action ()
|
||||||
|
-- ^ The function to call on success
|
||||||
|
, _cpsFailureCallback :: Action ()
|
||||||
|
-- ^ The function to call on failure
|
||||||
|
}
|
||||||
|
|
||||||
-- | Represents the database
|
-- | Represents the database
|
||||||
data Database = Database
|
data Database = Database
|
||||||
|
@ -473,9 +484,11 @@ newGameState = GameState
|
||||||
-- | Constructor for a 'CreatePlayerState'
|
-- | Constructor for a 'CreatePlayerState'
|
||||||
newCreatePlayerState :: CreatePlayerState
|
newCreatePlayerState :: CreatePlayerState
|
||||||
newCreatePlayerState = CreatePlayerState
|
newCreatePlayerState = CreatePlayerState
|
||||||
{ _cpsNumber = Nothing
|
{ _cpsNumber = Nothing
|
||||||
, _cpsName = ""
|
, _cpsName = ""
|
||||||
, _cpsPosition = ""
|
, _cpsPosition = ""
|
||||||
|
, _cpsSuccessCallback = return ()
|
||||||
|
, _cpsFailureCallback = return ()
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Constructor for a 'Database'
|
-- | Constructor for a 'Database'
|
||||||
|
|
|
@ -50,7 +50,7 @@ startNewSeasonSpec = describe "startNewSeason" $ do
|
||||||
& startNewSeason
|
& startNewSeason
|
||||||
|
|
||||||
it "should set the progState to NewSeason" $
|
it "should set the progState to NewSeason" $
|
||||||
s ^. progMode `shouldBe` NewSeason
|
show (s^.progMode) `shouldBe` "NewSeason"
|
||||||
|
|
||||||
it "should set the number of games to 0" $
|
it "should set the number of games to 0" $
|
||||||
s ^. database . dbGames `shouldBe` 0
|
s ^. database . dbGames `shouldBe` 0
|
||||||
|
@ -63,7 +63,7 @@ startNewGameSpec = describe "startNewGame" $ do
|
||||||
s ^. database . dbGames `shouldBe` 1
|
s ^. database . dbGames `shouldBe` 1
|
||||||
|
|
||||||
it "should set the mode to NewGame" $
|
it "should set the mode to NewGame" $
|
||||||
s ^. progMode `shouldBe` NewGame newGameState
|
show (s^.progMode) `shouldBe` "NewGame"
|
||||||
|
|
||||||
resetYtdSpec :: Spec
|
resetYtdSpec :: Spec
|
||||||
resetYtdSpec = describe "resetYtd" $
|
resetYtdSpec = describe "resetYtd" $
|
||||||
|
@ -254,23 +254,27 @@ updateGameStatsSpec = describe "updateGameStats" $ do
|
||||||
|
|
||||||
context "missing game type" $
|
context "missing game type" $
|
||||||
it "should not change anything" $ let
|
it "should not change anything" $ let
|
||||||
s' = s Nothing (Just 1) (Just 2) (Just True)
|
s' = s Nothing (Just 1) (Just 2) (Just True)
|
||||||
in updateGameStats s' `shouldBe` s'
|
db' = updateGameStats s' ^. database
|
||||||
|
in db' `shouldBe` db 1 1 1 1 1 1
|
||||||
|
|
||||||
context "missing home score" $
|
context "missing home score" $
|
||||||
it "should not change anything" $ let
|
it "should not change anything" $ let
|
||||||
s' = s (Just HomeGame) Nothing (Just 1) (Just True)
|
s' = s (Just HomeGame) Nothing (Just 1) (Just True)
|
||||||
in updateGameStats s' `shouldBe` s'
|
db' = updateGameStats s' ^. database
|
||||||
|
in db' `shouldBe` db 1 1 1 1 1 1
|
||||||
|
|
||||||
context "missing away score" $
|
context "missing away score" $
|
||||||
it "should not change anything" $ let
|
it "should not change anything" $ let
|
||||||
s' = s (Just HomeGame) (Just 1) Nothing (Just True)
|
s' = s (Just HomeGame) (Just 1) Nothing (Just True)
|
||||||
in updateGameStats s' `shouldBe` s'
|
db' = updateGameStats s' ^. database
|
||||||
|
in db' `shouldBe` db 1 1 1 1 1 1
|
||||||
|
|
||||||
context "missing overtime flag" $
|
context "missing overtime flag" $
|
||||||
it "should not change anything" $ let
|
it "should not change anything" $ let
|
||||||
s' = s (Just HomeGame) (Just 1) (Just 2) Nothing
|
s' = s (Just HomeGame) (Just 1) (Just 2) Nothing
|
||||||
in updateGameStats s' `shouldBe` s'
|
db' = updateGameStats s' ^. database
|
||||||
|
in db' `shouldBe` db 1 1 1 1 1 1
|
||||||
|
|
||||||
validateGameDateSpec :: Spec
|
validateGameDateSpec :: Spec
|
||||||
validateGameDateSpec = describe "validateGameDate" $ do
|
validateGameDateSpec = describe "validateGameDate" $ do
|
||||||
|
@ -321,7 +325,7 @@ createPlayerSpec :: Spec
|
||||||
createPlayerSpec = describe "createPlayer" $
|
createPlayerSpec = describe "createPlayer" $
|
||||||
it "should change the mode appropriately" $ let
|
it "should change the mode appropriately" $ let
|
||||||
s = createPlayer newProgState
|
s = createPlayer newProgState
|
||||||
in s^.progMode `shouldBe` CreatePlayer newCreatePlayerState
|
in show (s^.progMode) `shouldBe` "CreatePlayer"
|
||||||
|
|
||||||
addPlayerSpec :: Spec
|
addPlayerSpec :: Spec
|
||||||
addPlayerSpec = describe "addPlayer" $ do
|
addPlayerSpec = describe "addPlayer" $ do
|
||||||
|
|
|
@ -83,21 +83,32 @@ gameStateLSpec = describe "gameStateL" $ lensSpec gameStateL
|
||||||
where gs t = newGameState & gameType ?~ t
|
where gs t = newGameState & gameType ?~ t
|
||||||
|
|
||||||
createPlayerStateLSpec :: Spec
|
createPlayerStateLSpec :: Spec
|
||||||
createPlayerStateLSpec = describe "createPlayerStateL" $
|
createPlayerStateLSpec = describe "createPlayerStateL" $ do
|
||||||
lensSpec createPlayerStateL
|
context "getters" $ do
|
||||||
-- getters
|
context "state missing" $ let
|
||||||
[ ( MainMenu, newCreatePlayerState )
|
pm = MainMenu
|
||||||
, ( CreatePlayer $ cps 1 , cps 1 )
|
cps = pm^.createPlayerStateL
|
||||||
]
|
in it "should not have a number" $
|
||||||
-- setters
|
cps^.cpsNumber `shouldBe` Nothing
|
||||||
[ ( MainMenu, cps 1 )
|
|
||||||
, ( CreatePlayer $ cps 1, cps 2 )
|
context "existing state" $ let
|
||||||
]
|
pm = CreatePlayer $ newCreatePlayerState & cpsNumber ?~ 1
|
||||||
where
|
cps = pm^.createPlayerStateL
|
||||||
cps n = newCreatePlayerState
|
in it "should have a number of 1" $
|
||||||
& cpsNumber ?~ n
|
cps^.cpsNumber `shouldBe` Just 1
|
||||||
& cpsName .~ "foo"
|
|
||||||
& cpsPosition .~ "bar"
|
context "setters" $ do
|
||||||
|
context "state missing" $ let
|
||||||
|
pm = MainMenu
|
||||||
|
pm' = pm & createPlayerStateL.cpsNumber ?~ 1
|
||||||
|
in it "should set the player number to 1" $
|
||||||
|
pm'^.createPlayerStateL.cpsNumber `shouldBe` Just 1
|
||||||
|
|
||||||
|
context "existing state" $ let
|
||||||
|
pm = CreatePlayer $ newCreatePlayerState & cpsNumber ?~ 1
|
||||||
|
pm' = pm & createPlayerStateL.cpsNumber ?~ 2
|
||||||
|
in it "should set the player number to 2" $
|
||||||
|
pm'^.createPlayerStateL.cpsNumber `shouldBe` Just 2
|
||||||
|
|
||||||
teamScoreSpec :: Spec
|
teamScoreSpec :: Spec
|
||||||
teamScoreSpec = describe "teamScore" $ do
|
teamScoreSpec = describe "teamScore" $ do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user