1
0
Fork 0
mirror of https://github.com/heyarne/airsonic-ui.git synced 2026-05-06 18:33:38 +02:00

Add tests for helper functions

This commit is contained in:
Arne Schlüter 2018-07-16 12:29:26 +02:00
commit 84450479ae
3 changed files with 26 additions and 12 deletions

View file

@ -1,6 +1,7 @@
(ns airsonic-ui.events-test
(:require [cljs.test :refer [deftest testing is]]
[clojure.string :as str]
[airsonic-ui.test-helpers :refer [dispatches?]]
[airsonic-ui.fixtures :refer [responses]]
[airsonic-ui.db :as db]
[airsonic-ui.routes :as routes]
@ -8,18 +9,6 @@
(enable-console-print!)
(into [] (conj [[:foo :bar :baz]] nil))
(defn dispatches?
"Helper to see whether an event is dispatched in a coeffect; `ev` can either
be a whole vector or a keyword which is interpreted as the event name."
[cofx ev]
(let [all-events (conj (or (:dispatch-n cofx) []) (:dispatch cofx))]
(some #(if (vector? ev)
(= ev %)
(= ev (first %)))
all-events)))
(deftest session-restoration
(letfn [(no-previous-session []
(events/restore-previous-session {} [:_]))

View file

@ -0,0 +1,8 @@
(ns airsonic-ui.test-helpers)
(defn dispatches?
"Helper to see whether an event is dispatched in a coeffect; `ev` can either
be a whole vector or a keyword which is interpreted as the event name."
[cofx ev]
(let [all-events (conj (get cofx :dispatch-n []) (:dispatch cofx))]
(some #(= ev (if (vector? ev) % (first %))) all-events)))

View file

@ -0,0 +1,17 @@
(ns airsonic-ui.test-helpers-test
(:require [cljs.test :refer [deftest testing is]]
[airsonic-ui.test-helpers :refer [dispatches?]]))
(deftest dispatch-helper
(testing "single dispatch"
(is (not (dispatches? {} :foo)))
(is (dispatches? {:dispatch [:foo 1 2 3]} :foo))
(is (not (dispatches? {:dispatch [:foo 1 2 3]} :bar)))
(is (dispatches? {:dispatch [:foo 1 2 3]} [:foo 1 2 3]))
(is (not (dispatches? {:dispatch [:foo 1 2 3]} [:bar 2 3]))))
(testing "multiple dispatch"
(is (not (dispatches? {:dispatch-n [[:bar]]} :foo)))
(is (dispatches? {:dispatch-n [[:foo 1 2 3]]} :foo))
(is (not (dispatches? {:dispatch-n [[:foo 1 2 3]]} :bar)))
(is (dispatches? {:dispatch-n [[:foo 1 2 3]]} [:foo 1 2 3]))
(is (not (dispatches? {:dispatch-n [[:foo 1 2 3]]} [:bar 2 3])))))