From 787a31ac4dc5e94d2379657f9d039e25acda86a4 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 2 Feb 2016 21:33:32 +0200 Subject: [PATCH] Tests are coming. --- scripts/watch.clj | 10 +-- test/uxbox/data/workspace_tests.cljs | 130 +++++++++++++++++++++++++++ test/uxbox/test_runner.cljs | 20 +++++ 3 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 test/uxbox/data/workspace_tests.cljs create mode 100644 test/uxbox/test_runner.cljs diff --git a/scripts/watch.clj b/scripts/watch.clj index 7b9d362727..c073cc75bf 100644 --- a/scripts/watch.clj +++ b/scripts/watch.clj @@ -4,14 +4,14 @@ (alter-var-root #'cljs.tagged-literals/*cljs-data-readers* assoc 'ux/tr (fn [v] `(uxbox.locales/tr ~v))) -(b/watch (b/inputs "src") - {:main 'uxbox.core - :output-to "resources/public/js/main.js" - :output-dir "resources/public/js" +(b/watch (b/inputs "src" "test") + {:main 'uxbox.test-runner + :output-to "out/tests.js" + :output-dir "out" :parallel-build false - :asset-path "/js" :optimizations :none :pretty-print true + :target :nodejs :language-in :ecmascript5 :language-out :ecmascript5 :verbose true}) diff --git a/test/uxbox/data/workspace_tests.cljs b/test/uxbox/data/workspace_tests.cljs new file mode 100644 index 0000000000..4a0ca7c593 --- /dev/null +++ b/test/uxbox/data/workspace_tests.cljs @@ -0,0 +1,130 @@ +(ns uxbox.data.workspace-tests + (:require [cljs.test :as t :include-macros true] + [cljs.pprint :refer (pprint)] + [uxbox.rstore :as rs] + [uxbox.data.workspace :as dw])) + +(t/deftest transfer-shape-test + (t/testing "case 1: move shape before other shape" + (let [initial {:pages-by-id {1 {:id 1 :shapes [1 2 3]}} + :shapes-by-id {1 {:id 1 :page 1} + 2 {:id 2 :page 1} + 3 {:id 3 :page 1}}} + expected (assoc-in initial [:pages-by-id 1 :shapes] [3 1 2]) + event (dw/transfer-shape 3 1 :before) + result (rs/-apply-update event initial)] + ;; (pprint expected) + ;; (pprint result) + (t/is (= result expected)) + (t/is (vector? (get-in result [:pages-by-id 1 :shapes]))))) + + (t/testing "case 2: move shape after other shape" + (let [initial {:pages-by-id {1 {:id 1 :shapes [1 2 3]}} + :shapes-by-id {1 {:id 1 :page 1} + 2 {:id 2 :page 1} + 3 {:id 3 :page 1}}} + expected (assoc-in initial [:pages-by-id 1 :shapes] [1 3 2]) + event (dw/transfer-shape 3 1 :after) + result (rs/-apply-update event initial)] + (t/is (= result expected)) + (t/is (vector? (get-in result [:pages-by-id 1 :shapes]))))) + + (t/testing "case 3: move shape before other shape that is part of group." + (let [initial {:pages-by-id {1 {:id 1 :shapes [1 3 4]}} + :shapes-by-id {1 {:id 1 :page 1 + :type :builtin/group + :items [2]} + 2 {:id 2 :page 1 :group 1} + 3 {:id 3 :page 1} + 4 {:id 4 :page 1}}} + event (dw/transfer-shape 3 2 :before) + expected (-> initial + (assoc-in [:pages-by-id 1 :shapes] [1 4]) + (assoc-in [:shapes-by-id 1 :items] [3 2]) + (assoc-in [:shapes-by-id 3 :group] 1)) + result (rs/-apply-update event initial)] + (t/is (= result expected)) + (t/is (vector? (get-in result [:pages-by-id 1 :shapes]))))) + + (t/testing "case 4: move shape inside group" + (let [initial {:pages-by-id {1 {:id 1 :shapes [1 3 4]}} + :shapes-by-id {1 {:id 1 :page 1 + :type :builtin/group + :items [2]} + 2 {:id 2 :page 1 :group 1} + 3 {:id 3 :page 1} + 4 {:id 4 :page 1}}} + event (dw/transfer-shape 3 1 :inside) + expected (-> initial + (assoc-in [:pages-by-id 1 :shapes] [1 4]) + (assoc-in [:shapes-by-id 1 :items] [2 3]) + (assoc-in [:shapes-by-id 3 :group] 1)) + result (rs/-apply-update event initial)] + ;; (pprint expected) + ;; (pprint result) + (t/is (= result expected)) + (t/is (vector? (get-in result [:pages-by-id 1 :shapes]))))) + + (t/testing "case 5: move shape outside of group" + (let [initial {:pages-by-id {1 {:id 1 :shapes [1 4]}} + :shapes-by-id {1 {:id 1 :page 1 + :type :builtin/group + :items [2 3]} + 2 {:id 2 :page 1 :group 1} + 3 {:id 3 :page 1 :group 1} + 4 {:id 4 :page 1}}} + event (dw/transfer-shape 3 4 :after) + expected (-> initial + (assoc-in [:pages-by-id 1 :shapes] [1 4 3]) + (assoc-in [:shapes-by-id 1 :items] [2]) + (update-in [:shapes-by-id 3] dissoc :group)) + result (rs/-apply-update event initial)] + (t/is (= result expected)) + (t/is (vector? (get-in result [:pages-by-id 1 :shapes]))))) + + (t/testing "case 6: move group inside group" + (let [initial {:pages-by-id {1 {:id 1 :shapes [1 2]}} + :shapes-by-id {1 {:id 1 :page 1 + :type :builtin/group + :items [3]} + 2 {:id 2 :page 1 + :type :builtin/group + :items [4]} + 3 {:id 3 :page 1 :group 1} + 4 {:id 4 :page 1 :group 2}}} + event (dw/transfer-shape 2 3 :after) + expected (-> initial + (assoc-in [:pages-by-id 1 :shapes] [1]) + (assoc-in [:shapes-by-id 1 :items] [3 2]) + (assoc-in [:shapes-by-id 2 :group] 1)) + + result (rs/-apply-update event initial)] + ;; (pprint expected) + ;; (pprint result) + (t/is (= result expected)) + (t/is (vector? (get-in result [:pages-by-id 1 :shapes]))))) + + (t/testing "case 7: move group outside group" + (let [initial {:pages-by-id {1 {:id 1 :shapes [1 3]}} + :shapes-by-id {1 {:id 1 :page 1 + :type :builtin/group + :items [2]} + 2 {:id 2 :page 1 + :group 1 + :type :builtin/group + :items [4]} + 3 {:id 3 :page 1} + 4 {:id 4 :page 1 :group 2}}} + event (dw/transfer-shape 2 1 :after) + expected (-> initial + (assoc-in [:pages-by-id 1 :shapes] [2 3]) + (update-in [:shapes-by-id] dissoc 1) + (update-in [:shapes-by-id 2] dissoc :group)) + result (rs/-apply-update event initial)] + ;; (pprint expected) + ;; (pprint result) + (t/is (= result expected)) + (t/is (vector? (get-in result [:pages-by-id 1 :shapes]))))) +) + + diff --git a/test/uxbox/test_runner.cljs b/test/uxbox/test_runner.cljs new file mode 100644 index 0000000000..175684aca9 --- /dev/null +++ b/test/uxbox/test_runner.cljs @@ -0,0 +1,20 @@ +(ns uxbox.test-runner + (:require [cljs.test :as test] + [uxbox.data.workspace-tests])) + +(enable-console-print!) + +(defn main + [] + (test/run-tests + (test/empty-env) + 'uxbox.data.workspace-tests + )) + +(defmethod test/report [:cljs.test/default :end-run-tests] + [m] + (if (test/successful? m) + (set! (.-exitCode js/process) 0) + (set! (.-exitCode js/process) 1))) + +(set! *main-cli-fn* main)