-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move tests to separate directory; fix build errors
- Loading branch information
Showing
7 changed files
with
154 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(ns ulysses.db-test | ||
(:require [cljs.test :refer-macros [deftest testing are is]] | ||
[ulysses.db :as db])) | ||
|
||
(deftest test-refresh-keys | ||
(testing "refresh-keys" | ||
(are [keys db-state] (= db/default-db (db/refresh-keys db-state keys)) | ||
[:active-page] (assoc db/default-db :active-page :builder) | ||
[:page-current] (assoc db/default-db :page-current 2)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
(ns ulysses.runner | ||
(:require [doo.runner :refer-macros [doo-tests doo-all-tests]] | ||
[ulysses.core-test])) | ||
(:require [doo.runner :refer-macros [doo-all-tests]] | ||
[ulysses.core-test] | ||
[ulysses.utils-test] | ||
[ulysses.db-test])) | ||
|
||
;; run all tests in all namespaces matching ulysses.* | ||
(doo.runner/doo-all-tests #"ulysses.*") | ||
(doo-all-tests #"ulysses.*") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
(ns ulysses.utils-test | ||
(:require [cljs.test :refer-macros [deftest testing are is]] | ||
[ulysses.utils :as utils])) | ||
|
||
(deftest test-noop | ||
(is (nil? (utils/noop))) | ||
(is (nil? (utils/noop 1))) | ||
(is (nil? (utils/noop 1 2)))) | ||
|
||
(deftest test-boolean? | ||
(is (= true (utils/boolean? true))) | ||
(is (= true (utils/boolean? false))) | ||
(is (not (utils/boolean? nil))) | ||
(is (not (utils/boolean? ""))) | ||
(is (not (utils/boolean? 0)))) | ||
|
||
; missing: ptr | ||
|
||
; missing: ptr-first | ||
|
||
(deftest test-metas-equal? | ||
(is (utils/metas-equal? [(with-meta {:a 1} {:key 1})] | ||
[(with-meta {:a 2} {:key 1})])) | ||
(is (not (utils/metas-equal? [(with-meta {:a 1} {:key 1})] | ||
[(with-meta {:a 2} {:key 2})])))) | ||
|
||
(deftest test-remap-and-variations | ||
(let [from {:a 1 :b 2 :c 3}] | ||
(testing "remap" | ||
(is (= {:a 2 :b 4 :c 6} (utils/remap (partial * 2) from)))) | ||
(testing "remap-k" | ||
(is (= {:a1 1 :b2 2 :c3 3} | ||
(utils/remap-k | ||
(fn [k v] (keyword (str (name k) v))) | ||
from)))) | ||
(testing "remap-v" | ||
(is (= {:a :a1 :b :b2 :c :c3} | ||
(utils/remap-v | ||
(fn [k v] (keyword (str (name k) v))) | ||
from)))))) | ||
|
||
(deftest test-hyphenate-keys | ||
(is (= {:a-b 1 :c-d 2} (utils/hyphenate-keys {:a_b 1 :c_d 2})))) | ||
|
||
(deftest test-map-subels | ||
(testing "when values have ids" | ||
(let [in [{:id 23 :value 3} {:id 95 :value 4}] | ||
out (utils/map-subels :div in) | ||
expected (list (with-meta [:div (first in)] {:key 23}) | ||
(with-meta [:div (second in)] {:key 95}))] | ||
(is (= out expected)) | ||
(is (utils/metas-equal? out expected)))) | ||
(testing "when values don't have ids" | ||
(let [in [3 4] | ||
out (utils/map-subels :div in) | ||
expected (list (with-meta [:div (first in)] {:key "default-key-0"}) | ||
(with-meta [:div (second in)] {:key "default-key-1"}))] | ||
(is (= out expected)) | ||
(is (utils/metas-equal? out expected)))) | ||
(testing "when values have ids sometimes" | ||
(let [in [{:id 23 :value 3} 4] | ||
out (utils/map-subels :div in) | ||
expected (list (with-meta [:div (first in)] {:key 23}) | ||
(with-meta [:div (second in)] {:key "default-key-1"}))] | ||
(is (= out expected)) | ||
(is (utils/metas-equal? out expected))))) | ||
|
||
(deftest test-str->int | ||
(testing "successful cases" | ||
(is (= 0 (utils/str->int "0"))) | ||
(is (= -5 (utils/str->int "-5"))) | ||
(is (= 1 (utils/str->int "1"))) | ||
(is (= 20003018 (utils/str->int "20003018"))) | ||
(is (= 0 (utils/str->int 0))) | ||
(is (= -5 (utils/str->int -5))) | ||
(is (= 1 (utils/str->int 1))) | ||
(is (= 20003018 (utils/str->int 20003018)))) | ||
(testing "unsuccessful cases" | ||
(is (nil? (utils/str->int ""))) | ||
(is (nil? (utils/str->int "0.0"))) | ||
(is (nil? (utils/str->int "1.0"))) | ||
(is (nil? (utils/str->int "123.123"))) | ||
(is (nil? (utils/str->int "garbage"))) | ||
(is (nil? (utils/str->int "12moregarbage12"))) | ||
(is (nil? (utils/str->int 123.123))) | ||
(is (nil? (utils/str->int nil))))) | ||
|
||
(deftest test-clj->json | ||
(is (= "null" (utils/clj->json nil))) | ||
(is (= "true" (utils/clj->json true))) | ||
(is (= "-3" (utils/clj->json -3))) | ||
(is (= "[1,2,3]" (utils/clj->json [1 2 3]))) | ||
(is (= "[\"one\",\"three\",\"two\"]" (utils/clj->json (sorted-set :one :two :three))))) | ||
|
||
(deftest test-json->clj | ||
(testing "basic values" | ||
(is (= nil (utils/json->clj "null"))) | ||
(is (= true (utils/json->clj "true"))) | ||
(is (= -3 (utils/json->clj "-3"))) | ||
(is (= [1 2 3] (utils/json->clj "[1,2,3]"))) | ||
(is (= ["one" "two" "three"] (utils/json->clj "[\"one\",\"two\",\"three\"]")))) | ||
(testing "maps: no keywordizing" | ||
(is (= {"a" 1 "b" 2} (utils/json->clj "{\"a\": 1, \"b\": 2}")))) | ||
(testing "maps: keywordizing" | ||
(is (= {:a 1 :b 2} (utils/json->clj "{\"a\": 1, \"b\": 2}" :keywords)))) | ||
(testing "exception throwing" | ||
(is (thrown? js/SyntaxError (utils/json->clj "asdf"))) | ||
(is (thrown? js/SyntaxError (utils/json->clj "[1,2"))))) | ||
|
||
(deftest test-url-encode-component | ||
(is (= "foo" (utils/url-encode-component "foo"))) | ||
(is (= "foo%20bar" (utils/url-encode-component "foo bar"))) | ||
(is (= "%3F%26%3F%26" (utils/url-encode-component "?&?&")))) | ||
|
||
(deftest test-truncate-with-ellipsis | ||
(testing "normal" | ||
(is (= "foo..." (utils/truncate-with-ellipsis "foo bar" 3)))) | ||
(testing "custom ellipsis" | ||
(is (= "foo[..]" (utils/truncate-with-ellipsis "foo bar" 3 "[..]"))))) | ||
|
||
(deftest test-find-by-id | ||
(let [ms [{:id 1} {:id 2} {:id 94}]] | ||
(testing "found (type int)" | ||
(is (= (first ms) (utils/find-by-id 1 ms))) | ||
(is (= (second ms) (utils/find-by-id 2 ms))) | ||
(is (= (last ms) (utils/find-by-id 94 ms)))) | ||
(testing "found (type int-string)" | ||
(is (= (first ms) (utils/find-by-id "1" ms))) | ||
(is (= (second ms) (utils/find-by-id "2" ms))) | ||
(is (= (last ms) (utils/find-by-id "94" ms)))) | ||
(testing "not found" | ||
(is (nil? (utils/find-by-id 33 ms))) | ||
(is (nil? (utils/find-by-id "33" ms))) | ||
(is (nil? (utils/find-by-id "1.0" ms)))))) |