https://github.com/bensu/facilier
Transform user actions into test cases
(view state)
;; => html
(step state action)
;; => state'
(event-handler state dom-event)
;; => action
(defmulti step (fn [_ [k _]] k))
(defmethod step :session/load
[state [_ {:keys [session/all]}]]
(-> state
(assoc :app/name (first (keys all)))
(update :session/all #(merge % all))))
;; Handle DOM Events
{:onClick (handle [e]
(f/raise! [:session/close nil]))}
;; Handle XHR Events
(http-request! (str test-url "/session/" id)
(handle [e]
(let [{:keys [session]} e]
(cb {:session/full session}))))
;; Manual test cases
(is (= expected-result (tested-fn test-data)))
;; Generated test cases
(is (invariant? test-data (tested-fn test-data)))
;; The current session is displayed
(when-let [current (:session/current state)]
(let [n (tu/find-one-by-class html "session-title")]
(is (= current (.-innerText n)))))
;; Closing turns the current session nil
(let [[type load] action]
(when (= :session/close type)
(is (nil? (:session/current state)))))
;; A click event either closes or selects a session
(let [[type _] action]
(when (= "click" (.-type dom-event))
(is (contains? #{:session/close :session/select}
type))))