datepicker

An fzf-like tool to interactively select a date in a provided format

git clone https://git.8pit.net/datepicker.git

  1{-# LANGUAGE OverloadedStrings #-}
  2
  3module Tmux (tmuxTests) where
  4
  5import Control.Monad (replicateM_)
  6import Test.Tasty
  7import Test.Tasty.Tmux
  8import Util
  9
 10selectDateSpatially :: TestCase sharedEnv
 11selectDateSpatially =
 12  withTmuxSession' "select date using spatial movement" $ \_ -> do
 13    startApplication ["--date-only"] "dec 2024"
 14
 15    -- selection: 2024-12-01
 16    sendKeys_ "Up" Unconditional
 17    sendKeys_ "Left" Unconditional
 18    -- selection: 2024-12-01
 19    sendKeys_ "Down" Unconditional
 20    -- selection: 2024-12-08
 21    sendKeys_ "Right" Unconditional
 22    -- selection: 2024-12-09
 23    sendKeys_ "Right" Unconditional
 24    -- selection: 2024-12-10
 25    sendKeys_ "Down" Unconditional
 26    -- selection: 2024-12-17
 27    sendKeys_ "Down" Unconditional
 28    -- selection: 2024-12-24
 29    sendKeys_ "Left" Unconditional
 30    -- selection: 2024-12-23
 31
 32    sendKeys_ "Enter" Unconditional
 33    captureDate >>= assertDate "Mon, 23 Dec 2024 00:00:00 CET"
 34
 35selectDateLogically :: TestCase sharedEnv
 36selectDateLogically =
 37  withTmuxSession' "select date using logical movement" $ \_ -> do
 38    startApplication ["--date-only", "--logical-move"] "02 2020"
 39
 40    -- 2020-02-01 is a Saturday, so moving right, in logical mode, will
 41    -- directly go to the next week. Hence moving up after should do nothing.
 42    sendKeys_ "Right" Unconditional
 43    -- selection: 2020-02-02
 44    sendKeys_ "Up" Unconditional
 45    -- selection: 2020-02-02
 46    sendKeys_ "Down" Unconditional
 47    -- selection: 2020-02-09
 48    sendKeys_ "Left" Unconditional
 49    -- selection: 2020-02-08
 50
 51    sendKeys_ "Enter" Unconditional
 52    captureDate >>= assertDate "Sat, 08 Feb 2020 00:00:00 CET"
 53
 54selectDateWithCustomFormat :: TestCase sharedEnv
 55selectDateWithCustomFormat =
 56  withTmuxSession' "custom date format" $ \_ -> do
 57    startApplication ["--date-only", "--format", "'%0Y%m%d %Z'"] "July 1998"
 58
 59    sendKeys_ "Enter" Unconditional
 60    captureDate >>= assertDate "19980701 CET"
 61
 62selectDateMondayWeekstart :: TestCase sharedEnv
 63selectDateMondayWeekstart =
 64  withTmuxSession' "--monday option" $ \_ -> do
 65    startApplication ["--date-only", "--monday"] "Jan 2025"
 66
 67    sendKeys_ "Down" Unconditional
 68    -- selection: 2025-08-01
 69    sendKeys_ "Left" Unconditional
 70    -- selection: 2025-07-01
 71    sendKeys_ "Left" Unconditional
 72    sendKeys_ "Left" Unconditional
 73    sendKeys_ "Left" Unconditional
 74    sendKeys_ "Left" Unconditional
 75    -- selection: 2025-06-01
 76
 77    sendKeys_ "Enter" Unconditional
 78    captureDate >>= assertDate "Mon, 06 Jan 2025 00:00:00 CET"
 79
 80selectDateTwelveMonths :: TestCase sharedEnv
 81selectDateTwelveMonths =
 82  withTmuxSession' "--twelve option" $ \_ -> do
 83    startApplication ["--date-only", "--twelve"] "sep 2025"
 84
 85    replicateM_ 17 (sendKeys_ "Down" Unconditional)
 86    -- selection: 2025-09-15
 87    replicateM_ 15 (sendKeys_ "Right" Unconditional)
 88    -- selection: 2025-08-11
 89
 90    sendKeys_ "Enter" Unconditional
 91    captureDate >>= assertDate "Tue, 11 Aug 2026 00:00:00 CET"
 92
 93selectTime :: TestCase sharedEnv
 94selectTime =
 95  withTmuxSession' "select date and time" $ \_ -> do
 96    startApplication [] "03 1900"
 97
 98    sendKeys_ "Enter" Unconditional
 99    sendKeys_ "2342" Unconditional
100    sendKeys_ "Enter" Unconditional
101
102    captureDate >>= assertDate "Thu, 01 Mar 1900 23:42:00 CET"
103
104selectTimeAndOverflow :: TestCase sharedEnv
105selectTimeAndOverflow =
106  withTmuxSession' "select time, delete, and re-enter" $ \_ -> do
107    startApplication [] "03 1900"
108
109    sendKeys_ "Enter" (Substring "March")
110    sendKeys_ "1111 2222" Unconditional
111
112    sendKeys_ "Enter" Unconditional
113    captureDate >>= assertDate "Thu, 01 Mar 1900 22:22:00 CET"
114
115selectTimeBackspace :: TestCase sharedEnv
116selectTimeBackspace =
117  withTmuxSession' "select time, delete, and re-enter" $ \_ -> do
118    startApplication [] "03 1900"
119
120    sendKeys_ "Enter" (Substring "March")
121    sendKeys_ "1 2 3 4" Unconditional
122    sendKeys_ "c-h" Unconditional
123    sendKeys_ "5" Unconditional
124    sendKeys_ "c-h" Unconditional
125    sendKeys_ "c-h" Unconditional
126    sendKeys_ "c-h" Unconditional
127    sendKeys_ "4" Unconditional
128
129    sendKeys_ "Enter" Unconditional
130    captureDate >>= assertDate "Thu, 01 Mar 1900 14:35:00 CET"
131
132moveSpatiallyVertAcrossMonths :: TestCase sharedEnv
133moveSpatiallyVertAcrossMonths =
134  withTmuxSession' "move spatially across month boundary" $ \_ -> do
135    startApplication ["-d", "-3"] "Jan 2030"
136
137    -- selection: 2030-01-01
138    sendKeys_ "Left" (Substring "January")
139    -- selection: 2029-12-01
140    sendKeys_ "Down" Unconditional
141    sendKeys_ "Down" Unconditional
142    sendKeys_ "Down" Unconditional
143    sendKeys_ "Down" Unconditional
144    -- selection: 2029-12-29
145    sendKeys_ "Right" Unconditional
146    -- selection: 2030-01-27
147
148    sendKeys_ "Enter" Unconditional
149    captureDate >>= assertDate "Sun, 27 Jan 2030 00:00:00 CET"
150
151moveSpatiallyVertBoundary :: TestCase sharedEnv
152moveSpatiallyVertBoundary =
153  withTmuxSession' "move spatially across month boundary" $ \_ -> do
154    startApplication ["-d", "--three"] "nov 2029"
155
156    -- selection: 2029-11-01
157    sendKeys_ "Down" (Substring "November")
158    -- selection: 2029-11-08
159    replicateM_ 3 (sendKeys_ "Right" Unconditional)
160    -- selection: 2029-12-02
161    replicateM_ 4 (sendKeys_ "Down" Unconditional)
162    -- selection: 2029-12-30
163    replicateM_ 4 (sendKeys_ "Left" Unconditional)
164    replicateM_ 4 (sendKeys_ "Down" Unconditional)
165    replicateM_ 4 (sendKeys_ "Down" Unconditional)
166    replicateM_ 4 (sendKeys_ "Right" Unconditional)
167    replicateM_ 4 (sendKeys_ "Right" Unconditional)
168    -- selection: 2029-12-31
169
170    sendKeys_ "Enter" Unconditional
171    captureDate >>= assertDate "Mon, 31 Dec 2029 00:00:00 CET"
172
173moveSpatiallyHorizAcrossMonths :: TestCase sharedEnv
174moveSpatiallyHorizAcrossMonths =
175  withTmuxSession' "move horizontally across months" $ \_ -> do
176    startApplication ["-d", "-y"] "jun 2065"
177
178    -- selection: 2065-06-01
179    sendKeys_ "Up" (Substring "December")
180    -- selection: 2065-03-30
181    sendKeys_ "Up" Unconditional
182    -- selection: 2065-03-23
183    sendKeys_ "Left" Unconditional
184    sendKeys_ "Left" Unconditional
185    -- selection: 2065-02-28
186    replicateM_ 14 (sendKeys_ "Down" Unconditional)
187    -- selection: 2065-11-28
188
189    sendKeys_ "Enter" Unconditional
190    captureDate >>= assertDate "Sat, 28 Nov 2065 00:00:00 CET"
191
192tmuxTests :: TestTree
193tmuxTests =
194  testTmux'
195    [ selectDateSpatially,
196      selectDateLogically,
197      selectDateWithCustomFormat,
198      selectDateMondayWeekstart,
199      selectDateTwelveMonths,
200      selectTime,
201      selectTimeAndOverflow,
202      selectTimeBackspace,
203      moveSpatiallyVertAcrossMonths,
204      moveSpatiallyVertBoundary,
205      moveSpatiallyHorizAcrossMonths
206    ]