arthur/frontend/test/arthur/events/export_test.cljs
Olive Vaughn fbcbcd0321 The pool is a tree of what places what, and deletes
A drawing is named by where it is drawn, `body 12`, until it is given a
name of its own. The pool lists each symbol under what places it, with
the root's lanes always showing and anything placed nowhere at the top,
where it wants looking at. Delete or the cross removes a symbol and its
placements, asking first when it is used anywhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 21:38:35 -04:00

93 lines
4.7 KiB
Clojure

(ns arthur.events.export-test
"The picker's round trip, which is the whole of a bug that read as a hung tab.
An export target is a timeline or a placement inside one. A symbol timeline's id
is NAMESPACED (`:sym/face-8625`) and a placement's is a UUID, and the panel puts
both into `<option value>`s and reads them back out of a change event. Writing
that value with `name` drops the `sym`, the id comes back `:face-8625`, it
matches no key in `:symbols`, and `export/run!` throws from inside re-frame's
`:do-fx` where nothing catches it: `:busy?` latches on and the readout sits at
\"frame 0 /\" forever with nothing in the status line.
So the pair is asserted directly, on both kinds, because `name` and `keyword`
are individually reasonable-looking and only wrong together."
(:require [cljs.test :refer [deftest is testing]]
[arthur.events.export :as export]))
(def ^:private a-uuid #uuid "8f594d72-a97f-4a32-82fd-08d1670a2218")
(deftest every-kind-of-target-survives-the-round-trip
(doseq [t [{:symbol :main}
{:symbol :sym/face-8625}
{:symbol :main :isolate a-uuid}
{:symbol :sym/face-8625 :isolate a-uuid}]]
(let [back (export/target-id (export/target-value t))]
(is (= (:symbol t) (:symbol back))
(str (pr-str t) " -> " (pr-str (export/target-value t))))
(is (= (:isolate t) (:isolate back)))
(testing "and a placement comes back a uuid, not a string or a keyword"
(when (:isolate t)
(is (uuid? (:isolate back))))))))
(deftest the-value-keeps-the-namespace-and-marks-the-two-kinds
;; Spelled out, because these are the strings that end up in the DOM.
(is (= "s:main" (export/target-value {:symbol :main})))
(is (= "s:sym/face-8625" (export/target-value {:symbol :sym/face-8625})))
(is (= (str "n:main:" a-uuid)
(export/target-value {:symbol :main :isolate a-uuid}))))
(deftest a-whole-symbol-has-no-isolate
;; Switching from a placement back to the clip must clear it, or the new target
;; would still be filtered down to one node that may not even be in it.
(is (nil? (:isolate (export/target-id "s:main")))))
(deftest the-old-encoding-is-the-bug
;; A guard against someone "simplifying" this back to `name`. `name` is lossy on
;; exactly the ids the stage produces, and this states what that costs.
(is (not= :sym/face-8625 (keyword (name :sym/face-8625)))
"name/keyword loses the namespace, which is what broke the export")
(is (thrown? js/Error (name a-uuid))
"and a placement's id is not something `name` can take at all"))
;; ---- what the picker offers ----
(def ^:private clip
"A clip with one symbol in its library, placed twice, plus a decoy: a node that
is not a symbol must not show up as a face."
{:fps 30 :width 320 :height 200
:symbols
{:main {:frames 280
:nodes {:root {:id :root :kind :group :z "a1"}
#uuid "22222222-2222-4222-8222-222222222222"
{:id #uuid "22222222-2222-4222-8222-222222222222"
:kind :instance :parent :root :z "a2"
:source {:symbol :sym/face}}
#uuid "11111111-1111-4111-8111-111111111111"
{:id #uuid "11111111-1111-4111-8111-111111111111"
:kind :instance :parent :root :z "a1"
:source {:symbol :sym/face}}
:a-rect {:id :a-rect :kind :rect :parent :root :z "a3"}}}
:sym/face {:name "head" :frames 40 :nodes {:root {:id :root :kind :group :z "a1"}}}}})
(deftest the-picker-offers-every-symbol-then-every-instance-in-the-open-one
(let [ts (export/targets clip :main)]
(is (= ["main" "face" "head 1" "head 2"] (mapv :label ts))
"every symbol, then the instances in the open one")
(testing "the instances isolate a node in the open symbol and the symbols do not"
(is (= [nil nil] (mapv :isolate (take 2 ts))))
(is (every? uuid? (mapv :isolate (drop 2 ts))))
(is (every? #(= :main (:symbol %)) (drop 2 ts))))
(testing "one symbol placed twice is numbered in stacking order, because a uuid sorts at random"
(is (= [#uuid "11111111-1111-4111-8111-111111111111"
#uuid "22222222-2222-4222-8222-222222222222"]
(mapv :isolate (drop 2 ts)))))
(testing "and a node that is not an instance is not offered"
(is (not-any? #{"a-rect"} (map :label ts))))))
(deftest every-offered-target-round-trips
;; The picker and the encoding asserted against each other, so neither can drift
;; into offering something that cannot be selected.
(doseq [t (export/targets clip :main)]
(let [norm #(merge {:isolate nil} (select-keys % [:symbol :isolate]))
back (export/target-id (export/target-value t))]
(is (= (norm t) (norm back)) (pr-str t)))))