From 84450479aee6376e2071b63347b944bde28454d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20Schl=C3=BCter?= Date: Mon, 16 Jul 2018 12:29:26 +0200 Subject: [PATCH] Add tests for helper functions --- test/cljs/airsonic_ui/events_test.cljs | 13 +------------ test/cljs/airsonic_ui/test_helpers.cljs | 8 ++++++++ test/cljs/airsonic_ui/test_helpers_test.cljs | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 test/cljs/airsonic_ui/test_helpers.cljs create mode 100644 test/cljs/airsonic_ui/test_helpers_test.cljs diff --git a/test/cljs/airsonic_ui/events_test.cljs b/test/cljs/airsonic_ui/events_test.cljs index 9f6de0f..c68b679 100644 --- a/test/cljs/airsonic_ui/events_test.cljs +++ b/test/cljs/airsonic_ui/events_test.cljs @@ -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 {} [:_])) diff --git a/test/cljs/airsonic_ui/test_helpers.cljs b/test/cljs/airsonic_ui/test_helpers.cljs new file mode 100644 index 0000000..18f8718 --- /dev/null +++ b/test/cljs/airsonic_ui/test_helpers.cljs @@ -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))) diff --git a/test/cljs/airsonic_ui/test_helpers_test.cljs b/test/cljs/airsonic_ui/test_helpers_test.cljs new file mode 100644 index 0000000..e4abf52 --- /dev/null +++ b/test/cljs/airsonic_ui/test_helpers_test.cljs @@ -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])))))