2021-01-28 07:09:59 -05:00
|
|
|
(ns app.test-helpers.libraries
|
2021-05-28 06:50:42 -05:00
|
|
|
(:require
|
|
|
|
[cljs.test :as t :include-macros true]
|
|
|
|
[cljs.pprint :refer [pprint]]
|
|
|
|
[beicon.core :as rx]
|
|
|
|
[potok.core :as ptk]
|
|
|
|
[app.common.uuid :as uuid]
|
|
|
|
[app.common.geom.point :as gpt]
|
|
|
|
[app.common.geom.shapes :as gsh]
|
|
|
|
[app.common.pages :as cp]
|
|
|
|
[app.common.pages.helpers :as cph]
|
|
|
|
[app.main.data.workspace :as dw]
|
|
|
|
[app.main.data.workspace.libraries-helpers :as dwlh]
|
|
|
|
[app.test-helpers.pages :as thp]))
|
2021-01-28 07:09:59 -05:00
|
|
|
|
|
|
|
;; ---- Helpers to manage libraries and synchronization
|
|
|
|
|
|
|
|
(defn is-instance-root
|
|
|
|
[shape]
|
|
|
|
(t/is (some? (:shape-ref shape)))
|
|
|
|
(t/is (some? (:component-id shape)))
|
|
|
|
(t/is (= (:component-root? shape) true)))
|
|
|
|
|
|
|
|
(defn is-instance-subroot
|
|
|
|
[shape]
|
|
|
|
(t/is (some? (:shape-ref shape)))
|
|
|
|
(t/is (some? (:component-id shape)))
|
|
|
|
(t/is (nil? (:component-root? shape))))
|
|
|
|
|
|
|
|
(defn is-instance-head
|
|
|
|
[shape]
|
|
|
|
(t/is (some? (:shape-ref shape)))
|
|
|
|
(t/is (some? (:component-id shape))))
|
|
|
|
|
|
|
|
(defn is-instance-child
|
|
|
|
[shape]
|
|
|
|
(t/is (some? (:shape-ref shape)))
|
|
|
|
(t/is (nil? (:component-id shape)))
|
|
|
|
(t/is (nil? (:component-file shape)))
|
|
|
|
(t/is (nil? (:component-root? shape))))
|
|
|
|
|
|
|
|
(defn is-noninstance
|
|
|
|
[shape]
|
|
|
|
(t/is (nil? (:shape-ref shape)))
|
|
|
|
(t/is (nil? (:component-id shape)))
|
|
|
|
(t/is (nil? (:component-file shape)))
|
|
|
|
(t/is (nil? (:component-root? shape)))
|
|
|
|
(t/is (nil? (:remote-synced? shape)))
|
|
|
|
(t/is (nil? (:touched shape))))
|
|
|
|
|
|
|
|
(defn is-from-file
|
|
|
|
[shape file]
|
|
|
|
(t/is (= (:component-file shape)
|
|
|
|
(:id file))))
|
|
|
|
|
2021-02-04 11:29:12 -05:00
|
|
|
(defn resolve-instance
|
|
|
|
[state root-inst-id]
|
|
|
|
(let [page (thp/current-page state)
|
|
|
|
root-inst (cph/get-shape page root-inst-id)
|
|
|
|
shapes-inst (cph/get-object-with-children
|
|
|
|
root-inst-id
|
|
|
|
(:objects page))]
|
|
|
|
|
|
|
|
;; Validate that the instance tree is well constructed
|
|
|
|
(t/is (is-instance-root (first shapes-inst)))
|
|
|
|
(run! is-instance-child (rest shapes-inst))
|
|
|
|
|
|
|
|
shapes-inst))
|
|
|
|
|
|
|
|
(defn resolve-noninstance
|
|
|
|
[state root-inst-id]
|
|
|
|
(let [page (thp/current-page state)
|
|
|
|
root-inst (cph/get-shape page root-inst-id)
|
|
|
|
shapes-inst (cph/get-object-with-children
|
|
|
|
root-inst-id
|
|
|
|
(:objects page))]
|
|
|
|
|
|
|
|
;; Validate that the tree is not an instance
|
|
|
|
(run! is-noninstance shapes-inst)
|
|
|
|
|
|
|
|
shapes-inst))
|
|
|
|
|
2021-03-18 07:36:25 -05:00
|
|
|
(defn resolve-instance-and-main
|
2021-01-28 07:09:59 -05:00
|
|
|
[state root-inst-id]
|
|
|
|
(let [page (thp/current-page state)
|
|
|
|
root-inst (cph/get-shape page root-inst-id)
|
|
|
|
|
2021-02-03 07:09:38 -05:00
|
|
|
file (dwlh/get-local-file state)
|
2021-01-28 07:09:59 -05:00
|
|
|
component (cph/get-component
|
|
|
|
(:component-id root-inst)
|
|
|
|
(:id file)
|
|
|
|
file
|
|
|
|
nil)
|
|
|
|
|
|
|
|
shapes-inst (cph/get-object-with-children
|
|
|
|
root-inst-id
|
|
|
|
(:objects page))
|
2021-03-18 07:36:25 -05:00
|
|
|
shapes-main (cph/get-object-with-children
|
2021-01-28 07:09:59 -05:00
|
|
|
(:shape-ref root-inst)
|
|
|
|
(:objects component))
|
|
|
|
|
|
|
|
unique-refs (into #{} (map :shape-ref shapes-inst))
|
|
|
|
|
2021-03-18 07:36:25 -05:00
|
|
|
main-exists? (fn [shape]
|
|
|
|
(t/is (some #(= (:id %) (:shape-ref shape))
|
|
|
|
shapes-main)))]
|
2021-01-28 07:09:59 -05:00
|
|
|
|
|
|
|
;; Validate that the instance tree is well constructed
|
|
|
|
(t/is (is-instance-root (first shapes-inst)))
|
|
|
|
(run! is-instance-child (rest shapes-inst))
|
2021-03-18 07:36:25 -05:00
|
|
|
(run! is-noninstance shapes-main)
|
2021-01-28 07:09:59 -05:00
|
|
|
(t/is (= (count shapes-inst)
|
2021-03-18 07:36:25 -05:00
|
|
|
(count shapes-main)
|
2021-01-28 07:09:59 -05:00
|
|
|
(count unique-refs)))
|
2021-03-18 07:36:25 -05:00
|
|
|
(run! main-exists? shapes-inst)
|
2021-01-28 07:09:59 -05:00
|
|
|
|
2021-03-18 07:36:25 -05:00
|
|
|
[shapes-inst shapes-main component]))
|
2021-01-28 07:09:59 -05:00
|
|
|
|
2021-02-03 07:09:38 -05:00
|
|
|
(defn resolve-component
|
|
|
|
[state component-id]
|
|
|
|
(let [page (thp/current-page state)
|
|
|
|
|
|
|
|
file (dwlh/get-local-file state)
|
|
|
|
component (cph/get-component
|
|
|
|
component-id
|
|
|
|
(:id file)
|
|
|
|
file
|
|
|
|
nil)
|
|
|
|
|
2021-03-18 07:36:25 -05:00
|
|
|
root-main (cph/get-component-root
|
|
|
|
component)
|
|
|
|
shapes-main (cph/get-object-with-children
|
|
|
|
(:id root-main)
|
|
|
|
(:objects component))]
|
2021-02-03 07:09:38 -05:00
|
|
|
|
|
|
|
;; Validate that the component tree is well constructed
|
2021-03-18 07:36:25 -05:00
|
|
|
(run! is-noninstance shapes-main)
|
2021-02-03 07:09:38 -05:00
|
|
|
|
2021-03-18 07:36:25 -05:00
|
|
|
[shapes-main component]))
|
2021-02-03 07:09:38 -05:00
|
|
|
|