33 lines
1.7 KiB
Clojure
33 lines
1.7 KiB
Clojure
(ns arthur.events.vertex-test
|
|
(:require [cljs.test :refer [deftest is]]
|
|
[arthur.domain.clip :as clip]
|
|
[arthur.domain.paint :as paint]
|
|
[arthur.events.ui :as ui]
|
|
[arthur.footage.store :as store]
|
|
[re-frame.core :as rf]
|
|
[re-frame.db :as rf-db]))
|
|
|
|
(deftest delete-takes-the-picked-point-and-then-the-one-before
|
|
(let [doc (paint/new-shape (clip/blank) :main :s 0 [0 0 10 0 20 10 10 20 0 20] 1)
|
|
id (store/install! {:clip doc :store {}} "vertex-delete")
|
|
pts #(-> (store/entry id) :clip
|
|
(get-in [:symbols :main :nodes :s :channels paint/geometry :keys 0]))
|
|
n #(quot (count (pts)) 2)]
|
|
(reset! rf-db/app-db {:clip/current id :paint/revision 0
|
|
:ui {:open :main :tool :pen :selection [:node :main :s [:s]]}
|
|
:playback {:frame 0}})
|
|
(let [before (pts)]
|
|
(rf/dispatch-sync [::ui/pick-vertex :main :s 2])
|
|
(rf/dispatch-sync [::ui/delete-selected])
|
|
(is (= 4 (n)))
|
|
(is (= (into (subvec before 0 4) (subvec before 6)) (pts)) "point 2 is the one gone")
|
|
(is (= [:main :s 1] (get-in @rf-db/app-db [:ui :vertex])) "the one before it is picked"))
|
|
(rf/dispatch-sync [::ui/delete-selected])
|
|
(rf/dispatch-sync [::ui/delete-selected])
|
|
(is (= 3 (n)) "a triangle keeps its three")
|
|
(is (some? (get-in (:clip (store/entry id)) [:symbols :main :nodes :s]))
|
|
"and Delete never falls through to the shape")
|
|
(swap! rf-db/app-db assoc-in [:ui :tool] :select)
|
|
(rf/dispatch-sync [::ui/delete-selected])
|
|
(is (nil? (get-in (:clip (store/entry id)) [:symbols :main :nodes :s]))
|
|
"off the pen, Delete is the shape's")))
|