2019-09-06 23:25:13 -04:00
|
|
|
{-
|
|
|
|
|
|
|
|
mtlstats
|
2023-05-23 17:22:14 -04:00
|
|
|
Copyright (C) Rhéal Lamothe
|
2019-09-06 23:25:13 -04:00
|
|
|
<rheal.lamothe@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or (at
|
|
|
|
your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
module HandlersSpec (spec) where
|
|
|
|
|
|
|
|
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
2023-05-25 19:36:03 -04:00
|
|
|
|
|
|
|
import Brick.Types (BrickEvent (VtyEvent))
|
|
|
|
import Graphics.Vty.Input.Events (Event (EvKey, EvResize), Key (KChar))
|
2019-09-06 23:25:13 -04:00
|
|
|
|
|
|
|
import Mtlstats.Handlers
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = describe "Mtlstats.Handlers"
|
|
|
|
ynHandlerSpec
|
|
|
|
|
|
|
|
ynHandlerSpec :: Spec
|
|
|
|
ynHandlerSpec = describe "ynHandler" $ mapM_
|
|
|
|
(\(desc, event, expected) ->
|
|
|
|
context desc $
|
|
|
|
it ("should be " ++ show expected) $
|
|
|
|
ynHandler event `shouldBe` expected)
|
|
|
|
-- description, event, expected
|
2023-05-25 19:36:03 -04:00
|
|
|
[ ( "Y pressed", capitalY, Just True )
|
|
|
|
, ( "y pressed", lowerY, Just True )
|
|
|
|
, ( "N pressed", capitalN, Just False )
|
|
|
|
, ( "n pressed", lowerN, Just False )
|
|
|
|
, ( "x pressed", lowerX, Nothing )
|
|
|
|
, ( "other event", otherEvent, Nothing )
|
2019-09-06 23:25:13 -04:00
|
|
|
]
|
2023-05-25 19:36:03 -04:00
|
|
|
where
|
|
|
|
capitalY = chE 'Y'
|
|
|
|
lowerY = chE 'y'
|
|
|
|
capitalN = chE 'N'
|
|
|
|
lowerN = chE 'n'
|
|
|
|
lowerX = chE 'x'
|
|
|
|
otherEvent = VtyEvent $ EvResize 0 0
|
|
|
|
chE c = VtyEvent $ EvKey (KChar c) []
|