diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-21 22:18:50 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-21 22:25:42 +0530 |
| commit | f51fbc728e4b731372e39ba19c38a35ef58fe71a (patch) | |
| tree | ada2dbc2a16b6df46d446cfd9fc787d4c5a18879 /specs | |
| parent | 1ade68e7252dda79c365cc9ec187c2bea3513cae (diff) | |
| download | chelleport-f51fbc728e4b731372e39ba19c38a35ef58fe71a.tar.gz chelleport-f51fbc728e4b731372e39ba19c38a35ef58fe71a.zip | |
Add action repetition
Diffstat (limited to 'specs')
| -rw-r--r-- | specs/Specs/AppEventSpec.hs | 6 | ||||
| -rw-r--r-- | specs/Specs/AppStateUpdateSpec.hs | 82 | ||||
| -rw-r--r-- | specs/Specs/ViewSpec.hs | 1 |
3 files changed, 80 insertions, 9 deletions
diff --git a/specs/Specs/AppEventSpec.hs b/specs/Specs/AppEventSpec.hs index 390fbc2..db292a7 100644 --- a/specs/Specs/AppEventSpec.hs +++ b/specs/Specs/AppEventSpec.hs @@ -86,7 +86,6 @@ test = do it "calls key input handler" $ do eventHandler (mkKeyboardEvent SDL.KeycodeA SDL.Pressed defaultMod) `shouldBe` Just (HandleKeyInput SDL.KeycodeA) eventHandler (mkKeyboardEvent SDL.KeycodeQ SDL.Pressed defaultMod) `shouldBe` Just (HandleKeyInput SDL.KeycodeQ) - eventHandler (mkKeyboardEvent SDL.Keycode9 SDL.Pressed defaultMod) `shouldBe` Just (HandleKeyInput SDL.Keycode9) context "when shift key is pressed" $ do it "enables shift" $ do @@ -97,3 +96,8 @@ test = do it "disabled shift" $ do let action = eventHandler $ mkKeyboardEvent SDL.KeycodeRShift SDL.Released defaultMod action `shouldBe` Just (UpdateShiftState False) + + context "when digit is pressed" $ do + it "sets repetition count" $ do + let action = eventHandler $ mkKeyboardEvent SDL.Keycode9 SDL.Pressed defaultMod + action `shouldBe` Just (UpdateRepetition 9) diff --git a/specs/Specs/AppStateUpdateSpec.hs b/specs/Specs/AppStateUpdateSpec.hs index 7c03f1a..59b686a 100644 --- a/specs/Specs/AppStateUpdateSpec.hs +++ b/specs/Specs/AppStateUpdateSpec.hs @@ -34,6 +34,7 @@ test = do stateIsShiftPressed = False, stateIsMatched = False, stateGrid = [["ABC", "DEF"], ["DJK", "JKL"]], + stateRepetition = 1, stateIsDragging = False } @@ -77,6 +78,29 @@ test = do action `shouldBe` Just ShutdownApp nextState `shouldBe` currentState + context "when repetition is more than 1" $ do + let currentState = defaultState {stateRepetition = 3} + + it "resets repetition back to 1" $ do + ((nextState, _), _) <- runWithMocks $ update currentState $ TriggerMouseClick LeftClick + nextState `shouldBe` currentState {stateRepetition = 1} + + it "clicks multiple times" $ do + (_, mock) <- runWithMocks $ update currentState $ TriggerMouseClick LeftClick + calls mock + `shouldBe` [ CallHideWindow, + CallClickMouseButton LeftClick, + CallClickMouseButton LeftClick, + CallClickMouseButton LeftClick + ] + + context "when repetition is 0" $ do + let currentState = defaultState {stateRepetition = 0} + + it "clicks just once" $ do + (_, mock) <- runWithMocks $ update currentState $ TriggerMouseClick LeftClick + calls mock `shouldBe` [CallHideWindow, CallClickMouseButton LeftClick] + context "with action ChainMouseClick" $ do let currentState = defaultState @@ -89,6 +113,30 @@ test = do action `shouldBe` Just ResetKeys nextState `shouldBe` currentState + context "when repetition is more than 1" $ do + let currentState = defaultState {stateRepetition = 3} + + it "resets repetition back to 1" $ do + ((nextState, _), _) <- runWithMocks $ update currentState $ ChainMouseClick LeftClick + nextState `shouldBe` currentState {stateRepetition = 1} + + it "clicks multiple times" $ do + (_, mock) <- runWithMocks $ update currentState $ ChainMouseClick LeftClick + calls mock + `shouldBe` [ CallHideWindow, + CallClickMouseButton LeftClick, + CallClickMouseButton LeftClick, + CallClickMouseButton LeftClick, + CallShowWindow + ] + + context "when repetition is 0" $ do + let currentState = defaultState {stateRepetition = 0} + + it "clicks just once" $ do + (_, mock) <- runWithMocks $ update currentState $ ChainMouseClick LeftClick + calls mock `shouldBe` [CallHideWindow, CallClickMouseButton LeftClick, CallShowWindow] + context "with action MouseDragToggle" $ do context "when is dragging is true" $ do let currentState = defaultState {stateIsDragging = True} @@ -142,10 +190,6 @@ test = do -- TODO: Test with inline mocked values it "moves mouse pointer to center of cell of given coordinates" $ do (_, mock) <- runWithMocks $ update currentState $ MoveMousePosition (0, 0) - -- handleMocks - -- [ CallClickMouseButton LeftClick `returns` (1, 2), - -- CallHideWindow `returns` () - -- ] mock `shouldHaveCalled` CallMoveMousePosition (mockWindowOffsetX + mockWindowWidth `div` columns `div` 2) @@ -156,25 +200,39 @@ test = do result `shouldBe` (currentState, Nothing) context "with action ResetKeys" $ do - let currentState = defaultState + let currentState = defaultState {stateRepetition = 5} it "resets state without any action" $ do ((nextState, action), _) <- runWithMocks $ update currentState ResetKeys action `shouldBe` Nothing - nextState `shouldBe` currentState {stateKeySequence = [], stateIsMatched = False} + nextState `shouldBe` currentState {stateKeySequence = [], stateIsMatched = False, stateRepetition = 1} context "with action IncrementMouseCursor" $ do let currentState = defaultState -- TODO: Test with inline mocked values it "increments mouse position relative to current position" $ do - (_, mock) <- runWithMocks $ update currentState $ IncrementMouseCursor (10, -20) - mock `shouldHaveCalled` CallMoveMousePosition 52 22 + (_, mock) <- runWithMocks $ update currentState $ IncrementMouseCursor (10, -5) + mock `shouldHaveCalled` CallMoveMousePosition 52 37 it "does not continue or update state" $ do (result, _) <- runWithMocks $ update currentState $ IncrementMouseCursor (0, 0) result `shouldBe` (currentState, Nothing) + context "when repetition is more than 1" $ do + let currentState = defaultState {stateRepetition = 5} + + it "multiplies increment" $ do + (_, mock) <- runWithMocks $ update currentState $ IncrementMouseCursor (10, -5) + mock `shouldHaveCalled` CallMoveMousePosition 92 17 + + context "when repetition is 0" $ do + let currentState = defaultState {stateRepetition = 0} + + it "increments just once" $ do + (_, mock) <- runWithMocks $ update currentState $ IncrementMouseCursor (10, -5) + mock `shouldHaveCalled` CallMoveMousePosition 52 37 + context "with action ShutdownApp" $ do let currentState = defaultState @@ -186,6 +244,14 @@ test = do (result, _) <- runWithMocks $ update currentState ShutdownApp result `shouldBe` (currentState, Nothing) + context "with action UpdateRepetition" $ do + let currentState = defaultState + + it "updates shift state without any action" $ do + ((nextState, action), _) <- runWithMocks $ update currentState $ UpdateRepetition 7 + action `shouldBe` Nothing + nextState `shouldBe` currentState {stateRepetition = 7} + context "with action UpdateShiftState" $ do let currentState = defaultState diff --git a/specs/Specs/ViewSpec.hs b/specs/Specs/ViewSpec.hs index 62b49fd..285c297 100644 --- a/specs/Specs/ViewSpec.hs +++ b/specs/Specs/ViewSpec.hs @@ -14,6 +14,7 @@ test = do stateIsShiftPressed = False, stateIsMatched = False, stateGrid = [["ABC", "DEF"], ["DJK", "JKL"]], + stateRepetition = 1, stateIsDragging = False } let drawTextCalls = filter (\case CallDrawText {} -> True; _ -> False) . calls |
