aboutsummaryrefslogtreecommitdiff
path: root/specs/Specs
diff options
context:
space:
mode:
Diffstat (limited to 'specs/Specs')
-rw-r--r--specs/Specs/AppStateSpec.hs67
-rw-r--r--specs/Specs/ViewSpec.hs8
2 files changed, 54 insertions, 21 deletions
diff --git a/specs/Specs/AppStateSpec.hs b/specs/Specs/AppStateSpec.hs
index 96ff9ee..39b8437 100644
--- a/specs/Specs/AppStateSpec.hs
+++ b/specs/Specs/AppStateSpec.hs
@@ -17,19 +17,17 @@ test = do
it "returns the initial state of the app" $ do
((initState, _), _) <- runWithMocks $ initialState config
- stateKeySequence initState `shouldBe` []
- stateIsMatched initState `shouldBe` False
stateIsShiftPressed initState `shouldBe` False
+ case stateMode initState of
+ ModeHints hintsData -> do
+ stateKeySequence hintsData `shouldBe` []
+ stateIsMatched hintsData `shouldBe` False
+ _ -> undefined
it "returns grid with 16x9 key sequences" $ do
((initState, _), _) <- runWithMocks $ initialState config
- length (stateGrid initState) `shouldBe` 9
- stateGrid initState `shouldSatisfy` all ((== 16) . length)
- stateGrid initState `shouldSatisfy` all (all ((== 2) . length))
-
- it "returns grid with all unique key sequences" $ do
- ((initState, _), _) <- runWithMocks $ initialState config
- join (stateGrid initState) `shouldBe` uniq (join $ stateGrid initState)
+ stateGridRows initState `shouldBe` 9
+ stateGridCols initState `shouldBe` 16
context "when config specifies mode" $ do
let currentConfig = config {configMode = ModeSearch def}
@@ -39,7 +37,13 @@ test = do
action `shouldBe` Just (SetMode $ ModeSearch def)
describe "#update" $ do
- let defaultState = def {stateGrid = [["ABC", "DEF"], ["DJK", "JKL"]]}
+ let defaultHintModeData = def {stateGrid = [["ABC", "DEF"], ["DJK", "JKL"]]}
+ let defaultState =
+ def
+ { stateGridRows = 2,
+ stateGridCols = 2,
+ stateMode = ModeHints defaultHintModeData
+ }
context "with action ChainMouseClick" $ do
context "when repetition is 1" $ do
@@ -152,7 +156,7 @@ test = do
context "when mode is ModeHints" $ do
context "when there are no matches" $ do
- let currentState = defaultState {stateKeySequence = "D", stateMode = ModeHints def}
+ let currentState = defaultState {stateMode = ModeHints $ defaultHintModeData {stateKeySequence = "D"}}
context "when input key sequence has matching values in grid" $ do
it "does not update" $ do
@@ -164,15 +168,15 @@ test = do
it "adds key to key sequence" $ do
((nextState, action), _) <- runWithMocks $ update flush currentState $ HandleKeyInput SDL.KeycodeE
action `shouldBe` Nothing
- nextState `shouldBe` currentState {stateKeySequence = "DE"}
+ nextState `shouldBe` currentState {stateMode = ModeHints defaultHintModeData {stateKeySequence = "DE"}}
context "when there are matches" $ do
- let currentState = defaultState {stateKeySequence = "DE", stateMode = ModeHints def}
+ let currentState = defaultState {stateMode = ModeHints $ defaultHintModeData {stateKeySequence = "DE"}}
context "when input key sequence does not have matching values in grid" $ do
it "adds key to key sequence and enables isMatched" $ do
((nextState, _), _) <- runWithMocks $ update flush currentState $ HandleKeyInput SDL.KeycodeF
- nextState `shouldBe` currentState {stateKeySequence = "DEF", stateIsMatched = True}
+ nextState `shouldBe` currentState {stateMode = ModeHints defaultHintModeData {stateKeySequence = "DEF", stateIsMatched = True}}
it "continues with MoveMousePosition action at center of matched cell" $ do
((_, action), _) <- runWithMocks $ do
@@ -229,7 +233,11 @@ test = do
it "resets state without any action" $ do
((nextState, action), _) <- runWithMocks $ update flush currentState ResetKeys
action `shouldBe` Nothing
- nextState `shouldBe` currentState {stateKeySequence = [], stateIsMatched = False, stateRepetition = 1}
+ nextState
+ `shouldBe` currentState
+ { stateMode = ModeHints $ defaultHintModeData {stateKeySequence = [], stateIsMatched = False},
+ stateRepetition = 1
+ }
context "with action SetMode" $ do
let currentState = defaultState
@@ -241,13 +249,38 @@ test = do
context "with action InitializeMode" $ do
context "when mode is ModeHints" $ do
- let currentState = defaultState {stateMode = ModeHints def, stateIsModeInitialized = False}
+ let rows = 13
+ let cols = 11
+ let currentState =
+ defaultState
+ { stateGridRows = rows,
+ stateGridCols = cols,
+ stateMode = ModeHints defaultHintModeData,
+ stateIsModeInitialized = False
+ }
it "updates initialization state to true" $ do
((nextState, action), _) <- runWithMocks $ update flush currentState InitializeMode
- nextState `shouldBe` currentState {stateIsModeInitialized = True}
+ stateIsModeInitialized nextState `shouldBe` True
action `shouldBe` Nothing
+ it "returns grid with 16x9 key sequences" $ do
+ ((nextState, _), _) <- runWithMocks $ update flush currentState InitializeMode
+ case stateMode nextState of
+ ModeHints hintsData -> do
+ length (stateGrid hintsData) `shouldBe` rows
+ stateGrid hintsData `shouldSatisfy` all ((== cols) . length)
+ stateGrid hintsData `shouldSatisfy` all (all ((== 2) . length))
+ _ -> undefined
+
+ it "returns grid with all unique key sequences" $ do
+ ((nextState, _), _) <- runWithMocks $ update flush currentState InitializeMode
+ case stateMode nextState of
+ ModeHints hintsData -> do
+ join (stateGrid hintsData) `shouldSatisfy` (not . null)
+ join (stateGrid hintsData) `shouldBe` uniq (join $ stateGrid hintsData)
+ _ -> undefined
+
context "when mode is ModeSearch" $ do
let currentState = defaultState {stateMode = ModeSearch def, stateIsModeInitialized = False}
diff --git a/specs/Specs/ViewSpec.hs b/specs/Specs/ViewSpec.hs
index f3cfdf2..a5a67c9 100644
--- a/specs/Specs/ViewSpec.hs
+++ b/specs/Specs/ViewSpec.hs
@@ -9,11 +9,11 @@ import TestUtils
test :: SpecWith ()
test = do
- let defaultState = def {stateGrid = [["ABC", "DEF"], ["DJK", "JKL"]]}
+ let defaultState = def {stateGridRows = 2, stateGridCols = 2, stateMode = ModeHints def {stateGrid = [["ABC", "DEF"], ["DJK", "JKL"]]}}
describe "#render" $ do
context "when key sequence is empty" $ do
- let currentState = defaultState {stateKeySequence = ""}
+ let currentState = defaultState {stateMode = ModeHints (modeHintsData $ stateMode defaultState) {stateKeySequence = ""}}
it "draws matching text labels" $ do
(_, mock) <- runWithMocks $ do
@@ -25,7 +25,7 @@ test = do
mock `shouldHaveCalled` Mock_drawText (1420, 550) colorWhite FontLG "JKL"
context "when there is a partial match" $ do
- let currentState = defaultState {stateKeySequence = "D"}
+ let currentState = defaultState {stateMode = ModeHints (modeHintsData $ stateMode defaultState) {stateKeySequence = "D"}}
it "draws matching text labels" $ do
(_, mock) <- runWithMocks $ do
@@ -39,7 +39,7 @@ test = do
mock `shouldHaveCalled` Mock_drawText (470, 550) colorAccent FontLG "JK"
context "when key sequence is complete match" $ do
- let currentState = defaultState {stateKeySequence = "DEF"}
+ let currentState = defaultState {stateMode = ModeHints (modeHintsData $ stateMode defaultState) {stateKeySequence = "DEF"}}
it "draws only the matching label" $ do
(_, mock) <- runWithMocks $ do