|
| 1 | +(ns notification-test |
| 2 | + (:require |
| 3 | + [cljs.test :refer-macros [deftest is testing]] |
| 4 | + [day8.re-frame.test :as rf-test] |
| 5 | + [re-frame.core :as rf] |
| 6 | + [renderer.app.events :as app.e] |
| 7 | + [renderer.notification.events :as e] |
| 8 | + [renderer.notification.subs :as s])) |
| 9 | + |
| 10 | +(deftest add-and-remove |
| 11 | + (rf-test/run-test-sync |
| 12 | + (rf/dispatch [::app.e/initialize-db]) |
| 13 | + |
| 14 | + (let [notifications (rf/subscribe [::s/entities])] |
| 15 | + (testing "intial" |
| 16 | + (is (= @notifications []))) |
| 17 | + |
| 18 | + (testing "add" |
| 19 | + (rf/dispatch [::e/add [:div "test"]]) |
| 20 | + (is (= (count @notifications) 1)) |
| 21 | + (is (= (first @notifications) {:content [:div "test"] |
| 22 | + :count 1}))) |
| 23 | + |
| 24 | + (testing "merge identical" |
| 25 | + (rf/dispatch [::e/add [:div "test"]]) |
| 26 | + (is (= (count @notifications) 1)) |
| 27 | + (is (= (first @notifications) {:content [:div "test"] |
| 28 | + :count 2}))) |
| 29 | + |
| 30 | + (testing "add different" |
| 31 | + (rf/dispatch [::e/add [:div "test 2"]]) |
| 32 | + (is (= (count @notifications) 2)) |
| 33 | + (is (= (second @notifications) {:content [:div "test 2"] |
| 34 | + :count 1}))) |
| 35 | + |
| 36 | + (testing "remove nth" |
| 37 | + (rf/dispatch [::e/remove-nth 1]) |
| 38 | + (is (= (count @notifications) 1))) |
| 39 | + |
| 40 | + (testing "clear all" |
| 41 | + (rf/dispatch [::e/clear-all]) |
| 42 | + (is (= (count @notifications) 0)))))) |
| 43 | + |
| 44 | +(deftest exception |
| 45 | + (rf-test/run-test-sync |
| 46 | + (rf/dispatch [::app.e/initialize-db]) |
| 47 | + |
| 48 | + (let [notifications (rf/subscribe [::s/entities])] |
| 49 | + (testing "string exception" |
| 50 | + (try |
| 51 | + (throw (js/Error. "Error message")) |
| 52 | + (catch js/Error e |
| 53 | + (rf/dispatch [::e/exception e]) |
| 54 | + (is (= (:content (first @notifications)) |
| 55 | + [:div |
| 56 | + [:h2.font-bold.text-error "Error"] |
| 57 | + [:div.mt-4 "Error message"]])))))))) |
0 commit comments