0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 10:38:13 -05:00

Tests are coming.

This commit is contained in:
Andrey Antukh 2016-02-02 21:33:32 +02:00
parent e8b46229ee
commit 787a31ac4d
3 changed files with 155 additions and 5 deletions

View file

@ -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})

View file

@ -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])))))
)

View file

@ -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)