insert players at end of list (preserve index numbers)
This commit is contained in:
parent
767c9b9221
commit
ac92182b20
|
@ -149,7 +149,7 @@ addPlayer s = fromMaybe s $ do
|
|||
pos = cps^.cpsPosition
|
||||
player = newPlayer num name pos
|
||||
Just $ s & database.dbPlayers
|
||||
%~ (player:)
|
||||
%~ (++[player])
|
||||
|
||||
-- | Awards the goal and assists to the players
|
||||
recordGoalAssists :: ProgState -> ProgState
|
||||
|
|
|
@ -182,7 +182,8 @@ selectPlayerPrompt pStr callback = Prompt
|
|||
& cpsName .~ sStr
|
||||
& cpsSuccessCallback .~ do
|
||||
modify $ progMode .~ mode
|
||||
callback (Just 0)
|
||||
pIndex <- pred . length <$> gets (view $ database.dbPlayers)
|
||||
callback $ Just pIndex
|
||||
& cpsFailureCallback .~ do
|
||||
modify $ progMode .~ mode
|
||||
callback Nothing
|
||||
|
|
|
@ -342,7 +342,7 @@ addPlayerSpec = describe "addPlayer" $ do
|
|||
p1 = newPlayer 1 "Joe" "centre"
|
||||
p2 = newPlayer 2 "Bob" "defense"
|
||||
db = newDatabase
|
||||
& dbPlayers .~ [p2]
|
||||
& dbPlayers .~ [p1]
|
||||
s pm = newProgState
|
||||
& progMode .~ pm
|
||||
& database .~ db
|
||||
|
@ -350,15 +350,15 @@ addPlayerSpec = describe "addPlayer" $ do
|
|||
context "data available" $
|
||||
it "should create the player" $ let
|
||||
s' = addPlayer $ s $ CreatePlayer $ newCreatePlayerState
|
||||
& cpsNumber ?~ 1
|
||||
& cpsName .~ "Joe"
|
||||
& cpsPosition .~ "centre"
|
||||
& cpsNumber ?~ 2
|
||||
& cpsName .~ "Bob"
|
||||
& cpsPosition .~ "defense"
|
||||
in s'^.database.dbPlayers `shouldBe` [p1, p2]
|
||||
|
||||
context "data unavailable" $
|
||||
it "should not create the player" $ let
|
||||
s' = addPlayer $ s MainMenu
|
||||
in s'^.database.dbPlayers `shouldBe` [p2]
|
||||
in s'^.database.dbPlayers `shouldBe` [p1]
|
||||
|
||||
recordGoalAssistsSpec :: Spec
|
||||
recordGoalAssistsSpec = describe "recordGoalAssists" $ do
|
||||
|
|
Loading…
Reference in New Issue
Block a user