simplify. remove tick

This commit is contained in:
2026-01-22 22:22:19 -05:00
parent 8cb4c82daa
commit 8c7cb24171
9 changed files with 133 additions and 88 deletions
+39 -26
View File
@@ -102,40 +102,53 @@
(is (vector? tui/quit))
(is (= :quit (first tui/quit)))))
(deftest tick-command-test
(testing "from timer: tick with 1000ms"
(is (= [:tick 1000] (tui/tick 1000))))
(deftest after-command-test
(testing "from timer: after creates function"
(let [cmd (tui/after 1000 :timer-tick)]
(is (fn? cmd))))
(testing "from spinner: tick with 80ms"
(is (= [:tick 80] (tui/tick 80))))
(testing "from spinner: after creates function"
(let [cmd (tui/after 80 :spinner-frame)]
(is (fn? cmd))))
(testing "tick with various intervals"
(are [ms] (= [:tick ms] (tui/tick ms))
0 1 10 100 500 1000 5000 60000)))
(testing "after with zero delay returns message immediately"
(is (= :timer-tick ((tui/after 0 :timer-tick))))
(is (= [:my-tick {:id 1}] ((tui/after 0 [:my-tick {:id 1}]))))))
(deftest batch-command-test
(testing "batch two commands"
(let [cmd (tui/batch (tui/tick 100) tui/quit)]
(is (= [:batch [:tick 100] [:quit]] cmd))))
(let [cmd (tui/batch (tui/after 100 :tick1) tui/quit)]
(is (= :batch (first cmd)))
(is (= 3 (count cmd)))
(is (fn? (second cmd)))
(is (= [:quit] (last cmd)))))
(testing "batch three commands"
(let [cmd (tui/batch (tui/tick 50) (tui/tick 100) tui/quit)]
(is (= [:batch [:tick 50] [:tick 100] [:quit]] cmd))))
(let [cmd (tui/batch (tui/after 50 :t1) (tui/after 100 :t2) tui/quit)]
(is (= :batch (first cmd)))
(is (= 4 (count cmd)))))
(testing "batch filters nil"
(is (= [:batch [:tick 100]] (tui/batch nil (tui/tick 100) nil)))
(let [cmd (tui/batch nil (tui/send-msg :msg1) nil)]
(is (= :batch (first cmd)))
(is (= 2 (count cmd))))
(is (= [:batch] (tui/batch nil nil nil))))
(testing "batch with single command"
(is (= [:batch tui/quit] (tui/batch tui/quit)))))
(is (= [:batch [:quit]] (tui/batch tui/quit)))))
(deftest sequentially-command-test
(testing "sequentially two commands"
(let [cmd (tui/sequentially (tui/tick 100) tui/quit)]
(is (= [:seq [:tick 100] [:quit]] cmd))))
(let [cmd (tui/sequentially (tui/after 100 :tick1) tui/quit)]
(is (= :seq (first cmd)))
(is (= 3 (count cmd)))
(is (fn? (second cmd)))
(is (= [:quit] (last cmd)))))
(testing "sequentially filters nil"
(is (= [:seq [:tick 100]] (tui/sequentially nil (tui/tick 100) nil))))
(let [cmd (tui/sequentially nil (tui/send-msg :msg1) nil)]
(is (= :seq (first cmd)))
(is (= 2 (count cmd)))))
(testing "sequentially with functions"
(let [f (fn [] :msg)
@@ -231,31 +244,31 @@
(testing "timer tick handling pattern"
(let [update-fn (fn [{:keys [seconds running] :as model} msg]
(cond
(= (first msg) :tick)
(= msg :timer-tick)
(if running
(let [new-seconds (dec seconds)]
(if (<= new-seconds 0)
[(assoc model :seconds 0 :done true :running false) nil]
[(assoc model :seconds new-seconds) (tui/tick 1000)]))
[(assoc model :seconds new-seconds) (tui/after 1000 :timer-tick)]))
[model nil])
(tui/key= msg " ")
(let [new-running (not running)]
[(assoc model :running new-running)
(when new-running (tui/tick 1000))])
(when new-running (tui/after 1000 :timer-tick))])
:else
[model nil]))]
;; Test tick countdown
(let [m0 {:seconds 3 :running true :done false}
[m1 c1] (update-fn m0 [:tick 123])
[m2 c2] (update-fn m1 [:tick 123])
[m3 c3] (update-fn m2 [:tick 123])]
[m1 c1] (update-fn m0 :timer-tick)
[m2 c2] (update-fn m1 :timer-tick)
[m3 c3] (update-fn m2 :timer-tick)]
(is (= 2 (:seconds m1)))
(is (= [:tick 1000] c1))
(is (fn? c1))
(is (= 1 (:seconds m2)))
(is (= [:tick 1000] c2))
(is (fn? c2))
(is (= 0 (:seconds m3)))
(is (:done m3))
(is (not (:running m3)))
@@ -268,7 +281,7 @@
(is (not (:running m1)))
(is (nil? c1))
(is (:running m2))
(is (= [:tick 1000] c2))))))
(is (fn? c2))))))
(deftest list-selection-update-pattern-test
(testing "cursor navigation with bounds"