Improved logic to run once for all shapes

This commit is contained in:
Florian Schroedl
2024-07-08 14:38:19 +02:00
parent 90618ec89a
commit da0389e304
2 changed files with 37 additions and 23 deletions

View File

@@ -29,34 +29,35 @@
(t/is (= #{:x} (wtt/token-applied-attributes {:id :a}
{:applied-tokens {:x :a :y :b}}
#{:x :missing}))))
(t/deftest token-context-menu
(t/testing "Returns :all when token is applied to every shape"
(let [shapes [{:applied-tokens {:x 1 :y 1}}
{:applied-tokens {:x 1 :y 1}}]
expected (wtt/group-shapes-by-all-applied {:id 1} shapes #{:x :y})]
(t/is (true? (wtt/group-shapes-by-all-applied-all? expected)))
(t/is (= (:all expected) shapes))
(t/is (empty? (:other expected)))
(t/is (empty? (:some expected)))))
(t/deftest shapes-ids-by-applied-attributes
(t/testing "Returns set of matched attributes that fit the applied token"
(let [attributes #{:x :y :z}
shape-applied-x {:applied-tokens {:x 1}}
shape-applied-y {:applied-tokens {:y 1}}
shape-applied-x-y {:applied-tokens {:x 1 :y 1}}
shape-applied-none {:applied-tokens {}}
shape-applied-all {:applied-tokens {:x 1 :y 1 :z 1}}
shape-applied-x {:id :shape-applied-x
:applied-tokens {:x 1}}
shape-applied-y {:id :shape-applied-y
:applied-tokens {:y 1}}
shape-applied-x-y {:id :shape-applied-x-y
:applied-tokens {:x 1 :y 1}}
shape-applied-none {:id :shape-applied-none
:applied-tokens {}}
shape-applied-all {:id :shape-applied-all
:applied-tokens {:x 1 :y 1 :z 1}}
ids-set (fn [& xs] (into #{} (map :id xs)))
shapes [shape-applied-x
shape-applied-y
shape-applied-x-y
shape-applied-all
shape-applied-none]
expected (wtt/group-shapes-by-all-applied {:id 1} shapes attributes)]
(t/is (= (:all expected) [shape-applied-all]))
(t/is (= (:none expected) [shape-applied-none]))
(t/is (= (get-in expected [:some :x]) [shape-applied-x shape-applied-x-y]))
(t/is (= (get-in expected [:some :y]) [shape-applied-y shape-applied-x-y]))
(t/is (nil? (get-in expected [:some :z]))))))
expected (wtt/shapes-ids-by-applied-attributes {:id 1} shapes attributes)]
(t/is (= (:x expected) (ids-set shape-applied-x
shape-applied-x-y
shape-applied-all)))
(t/is (= (:y expected) (ids-set shape-applied-y
shape-applied-x-y
shape-applied-all)))
(t/is (= (:z expected) (ids-set shape-applied-all)))
(t/is (true? (wtt/shapes-applied-all? expected (ids-set shape-applied-all) attributes)))
(t/is (false? (wtt/shapes-applied-all? expected (apply ids-set shapes) attributes))))))
(t/deftest tokens-applied-test
(t/testing "is true when single shape matches the token and attributes"