Add tests for undo behaviour
Inspired by #149, this adds tests to cover the change that was made. It also tests the redo logic.
This commit is contained in:
parent
bb78981e1d
commit
41cf9951d8
|
@ -164,7 +164,7 @@
|
|||
|
||||
|
||||
(handlers/register-base ;; not a pure handler
|
||||
:purge-redos ;; usage: (dispatch [:purge-redo])
|
||||
:purge-redos ;; usage: (dispatch [:purge-redos])
|
||||
(fn handler
|
||||
[_ _]
|
||||
(if-not (redos?)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
(ns re-frame.test.runner
|
||||
(:require [jx.reporter.karma :as karma :include-macros true]
|
||||
[re-frame.test.middleware]))
|
||||
[re-frame.test.middleware]
|
||||
[re-frame.test.undo]))
|
||||
|
||||
|
||||
(defn ^:export run [karma]
|
||||
(karma/run-tests
|
||||
karma
|
||||
're-frame.test.middleware))
|
||||
're-frame.test.middleware
|
||||
're-frame.test.undo))
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
(ns re-frame.test.undo
|
||||
(:require [cljs.test :refer-macros [is deftest]]
|
||||
[re-frame.undo :as undo]
|
||||
[re-frame.db :as db]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(deftest test-undos
|
||||
;; Create undo history
|
||||
(undo/set-max-undos! 5)
|
||||
(doseq [i (range 10)]
|
||||
(reset! db/app-db i)
|
||||
(undo/store-now! i))
|
||||
|
||||
;; Check the undo state is correct
|
||||
(is (undo/undos?))
|
||||
(is (not (undo/redos?)))
|
||||
(is (= [4 5 6 7 8 9] (undo/undo-explanations)))
|
||||
(is (= [5 6 7 8 9] @undo/undo-list))
|
||||
|
||||
;; Undo the actions
|
||||
(re-frame/dispatch-sync [:undo])
|
||||
(is (= @db/app-db 9))
|
||||
(is (undo/redos?))
|
||||
(re-frame/dispatch-sync [:undo])
|
||||
(is (= @db/app-db 8))
|
||||
(re-frame/dispatch-sync [:undo])
|
||||
(is (= @db/app-db 7))
|
||||
(re-frame/dispatch-sync [:undo])
|
||||
(is (= @db/app-db 6))
|
||||
(re-frame/dispatch-sync [:undo])
|
||||
(is (= @db/app-db 5))
|
||||
(is (not (undo/undos?)))
|
||||
(is (undo/redos?))
|
||||
|
||||
;; Redo them again
|
||||
(re-frame/dispatch-sync [:redo 5])
|
||||
(is (= @db/app-db 9))
|
||||
(is (not (undo/redos?)))
|
||||
(is (undo/undos?))
|
||||
(is (= [5 6 7 8 9] @undo/undo-list))
|
||||
|
||||
;; Clear history
|
||||
(undo/clear-history!)
|
||||
(is (not (undo/undos?)))
|
||||
(is (not (undo/redos?))))
|
Loading…
Reference in New Issue