💄 Split helpers in separated files

This commit is contained in:
Andrés Moya 2024-05-07 12:50:32 +02:00
parent 97e34d6e28
commit c937d49ce9
10 changed files with 459 additions and 429 deletions

View file

@ -0,0 +1,153 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS INC
(ns common-tests.helpers.components
(:require
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.logic.libraries :as cll]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
[app.common.types.container :as ctn]
[app.common.types.file :as ctf]
[app.common.types.pages-list :as ctpl]
[app.common.types.shape-tree :as ctst]
[common-tests.helpers.files :as thf]
[common-tests.helpers.ids-map :as thi]
[common-tests.helpers.shapes :as ths]))
(defn make-component
[file label root-label & {:keys [] :as params}]
(let [page (thf/current-page file)
root (ths/get-shape file root-label)]
(dm/assert!
"Need that root is already a frame"
(cfh/frame-shape? root))
(let [[_new-root _new-shapes updated-shapes]
(ctn/convert-shape-in-component root (:objects page) (:id file))
updated-root (first updated-shapes)] ; Can't use new-root because it has a new id
(thi/set-id! label (:component-id updated-root))
(ctf/update-file-data
file
(fn [file-data]
(as-> file-data $
(reduce (fn [file-data shape]
(ctpl/update-page file-data
(:id page)
#(update % :objects assoc (:id shape) shape)))
$
updated-shapes)
(ctkl/add-component $ (assoc params
:id (:component-id updated-root)
:name (:name updated-root)
:main-instance-id (:id updated-root)
:main-instance-page (:id page)
:shapes updated-shapes))))))))
(defn get-component
[file label]
(ctkl/get-component (:data file) (thi/id label)))
(defn get-component-by-id
[file id]
(ctkl/get-component (:data file) id))
(defn set-child-label
[file shape-label child-idx label]
(let [id (-> (ths/get-shape file shape-label)
:shapes
(nth child-idx))]
(when id
(thi/set-id! label id))))
(defn instantiate-component
[file component-label copy-root-label & {:keys [parent-label library children-labels] :as params}]
(let [page (thf/current-page file)
library (or library file)
component (get-component library component-label)
parent-id (when parent-label
(thi/id parent-label))
parent (when parent-id
(ctst/get-shape page parent-id))
frame-id (if (cfh/frame-shape? parent)
(:id parent)
(:frame-id parent))
[copy-root copy-shapes]
(ctn/make-component-instance page
component
(:data library)
(gpt/point 100 100)
true
{:force-id (thi/new-id! copy-root-label)
:force-frame-id frame-id})
copy-root' (cond-> copy-root
(some? parent)
(assoc :parent-id parent-id)
(some? frame-id)
(assoc :frame-id frame-id)
(and (some? parent) (ctn/in-any-component? (:objects page) parent))
(dissoc :component-root))
file' (ctf/update-file-data
file
(fn [file-data]
(as-> file-data $
(ctpl/update-page $
(:id page)
#(ctst/add-shape (:id copy-root')
copy-root'
%
frame-id
parent-id
nil
true))
(reduce (fn [file-data shape]
(ctpl/update-page file-data
(:id page)
#(ctst/add-shape (:id shape)
shape
%
(:parent-id shape)
(:frame-id shape)
nil
true)))
$
(remove #(= (:id %) (:did copy-root')) copy-shapes)))))]
(when children-labels
(dotimes [idx (count children-labels)]
(set-child-label file' copy-root-label idx (nth children-labels idx))))
file'))
(defn component-swap
[file shape-label new-component-label new-shape-label & {:keys [library] :as params}]
(let [shape (ths/get-shape file shape-label)
library (or library file)
libraries {(:id library) library}
page (thf/current-page file)
objects (:objects page)
id-new-component (-> (get-component library new-component-label)
:id)
;; Store the properties that need to be maintained when the component is swapped
keep-props-values (select-keys shape ctk/swap-keep-attrs)
[new_shape _ changes]
(-> (pcb/empty-changes nil (:id page))
(cll/generate-component-swap objects shape (:data file) page libraries id-new-component 0 nil keep-props-values))]
(thi/set-id! new-shape-label (:id new_shape))
(thf/apply-changes file changes)))

View file

@ -7,13 +7,14 @@
(ns common-tests.helpers.compositions (ns common-tests.helpers.compositions
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[common-tests.helpers.files :as thf])) [common-tests.helpers.components :as thc]
[common-tests.helpers.shapes :as ths]))
(defn add-rect (defn add-rect
[file rect-label & {:keys [] :as params}] [file rect-label & {:keys [] :as params}]
;; Generated shape tree: ;; Generated shape tree:
;; :rect-label [:type :rect :name: Rect1] ;; :rect-label [:type :rect :name: Rect1]
(thf/add-sample-shape file rect-label (ths/add-sample-shape file rect-label
(merge {:type :rect (merge {:type :rect
:name "Rect1"} :name "Rect1"}
params))) params)))
@ -22,7 +23,7 @@
[file frame-label & {:keys [] :as params}] [file frame-label & {:keys [] :as params}]
;; Generated shape tree: ;; Generated shape tree:
;; :frame-label [:type :frame :name: Frame1] ;; :frame-label [:type :frame :name: Frame1]
(thf/add-sample-shape file frame-label (ths/add-sample-shape file frame-label
(merge {:type :frame (merge {:type :frame
:name "Frame1"} :name "Frame1"}
params))) params)))
@ -34,7 +35,7 @@
;; :child-label [:name: Rect1] ;; :child-label [:name: Rect1]
(-> file (-> file
(add-frame frame-label frame-params) (add-frame frame-label frame-params)
(thf/add-sample-shape child-label (ths/add-sample-shape child-label
(merge {:type :rect (merge {:type :rect
:name "Rect1" :name "Rect1"
:parent-label frame-label} :parent-label frame-label}
@ -48,7 +49,7 @@
;; :child-label [:name: Rect1] ;; :child-label [:name: Rect1]
(-> file (-> file
(add-frame-with-child root-label child-label :frame-params root-params :child-params child-params) (add-frame-with-child root-label child-label :frame-params root-params :child-params child-params)
(thf/make-component component-label root-label component-params))) (thc/make-component component-label root-label component-params)))
(defn add-simple-component-with-copy (defn add-simple-component-with-copy
[file component-label main-root-label main-child-label copy-root-label [file component-label main-root-label main-child-label copy-root-label
@ -66,7 +67,7 @@
:component-params component-params :component-params component-params
:root-params main-root-params :root-params main-root-params
:child-params main-child-params) :child-params main-child-params)
(thf/instantiate-component component-label copy-root-label copy-root-params))) (thc/instantiate-component component-label copy-root-label copy-root-params)))
(defn add-component-with-many-children (defn add-component-with-many-children
[file component-label root-label child-labels [file component-label root-label child-labels
@ -79,7 +80,7 @@
(as-> file $ (as-> file $
(add-frame $ root-label root-params) (add-frame $ root-label root-params)
(reduce (fn [file [index [label params]]] (reduce (fn [file [index [label params]]]
(thf/add-sample-shape file (ths/add-sample-shape file
label label
(merge {:type :rect (merge {:type :rect
:name (str "Rect" (inc index)) :name (str "Rect" (inc index))
@ -87,7 +88,7 @@
params))) params)))
$ $
(d/enumerate (d/zip-all child-labels child-params-list))) (d/enumerate (d/zip-all child-labels child-params-list)))
(thf/make-component $ component-label root-label component-params))) (thc/make-component $ component-label root-label component-params)))
(defn add-component-with-many-children-and-copy (defn add-component-with-many-children-and-copy
[file component-label main-root-label main-child-labels copy-root-label [file component-label main-root-label main-child-labels copy-root-label
@ -109,7 +110,7 @@
:component-params component-params :component-params component-params
:root-params main-root-params :root-params main-root-params
:child-params-list main-child-params-list) :child-params-list main-child-params-list)
(thf/instantiate-component component-label copy-root-label copy-root-params))) (thc/instantiate-component component-label copy-root-label copy-root-params)))
(defn add-nested-component (defn add-nested-component
[file component1-label main1-root-label main1-child-label component2-label main2-root-label nested-head-label [file component1-label main1-root-label main1-child-label component2-label main2-root-label nested-head-label
@ -130,11 +131,11 @@
:child-params main1-child-params) :child-params main1-child-params)
(add-frame main2-root-label (merge {:name "Frame2"} (add-frame main2-root-label (merge {:name "Frame2"}
main2-root-params)) main2-root-params))
(thf/instantiate-component component1-label (thc/instantiate-component component1-label
nested-head-label nested-head-label
(assoc nested-head-params (assoc nested-head-params
:parent-label main2-root-label)) :parent-label main2-root-label))
(thf/make-component component2-label (thc/make-component component2-label
main2-root-label main2-root-label
component2-params))) component2-params)))
@ -165,4 +166,4 @@
:component2-params component2-params :component2-params component2-params
:main2-root-params main2-root-params :main2-root-params main2-root-params
:nested-head-params nested-head-params) :nested-head-params nested-head-params)
(thf/instantiate-component component2-label copy2-label copy2-params))) (thc/instantiate-component component2-label copy2-label copy2-params)))

View file

@ -1,53 +0,0 @@
(ns common-tests.helpers.debug
(:require
[app.common.data :as d]
[app.common.uuid :as uuid]
[common-tests.helpers.ids-map :as thi]
[cuerdas.core :as str]))
(defn dump-shape
"Dumps a shape, with each attribute in a line"
[shape]
(println "{")
(doseq [[k v] (sort shape)]
(when (some? v)
(println (str " " k " : " v))))
(println "}"))
(defn- stringify-keys [m keys]
(apply str (interpose ", " (map #(str % ": " (get m %)) keys))))
(defn- dump-page-shape
[shape keys padding]
(println (str/pad (str padding
(when (:main-instance shape) "{")
(or (thi/label (:id shape)) "<no-label>")
(when (:main-instance shape) "}")
(when keys
(str " [" (stringify-keys shape keys) "]")))
{:length 40 :type :right})
(if (nil? (:shape-ref shape))
(if (:component-root shape)
(str "# [Component " (or (thi/label (:component-id shape)) "<no-label>") "]")
"")
(str/format "%s--> %s%s"
(cond (:component-root shape) "#"
(:component-id shape) "@"
:else "-")
(if (:component-root shape)
(str "[Component " (or (thi/label (:component-id shape)) "<no-label>") "] ")
"")
(or (thi/label (:shape-ref shape)) "<no-label>")))))
(defn dump-page
"Dumps the layer tree of the page. Prints the label of each shape, and the specified keys.
Example: (thd/dump-page (thf/current-page file) [:id :touched])"
([page keys]
(dump-page page uuid/zero "" keys))
([page root-id padding keys]
(let [lookupf (d/getf (:objects page))
root-shape (lookupf root-id)
shapes (map lookupf (:shapes root-shape))]
(doseq [shape shapes]
(dump-page-shape shape keys padding)
(dump-page page (:id shape) (str padding " ") keys)))))

View file

@ -6,29 +6,17 @@
(ns common-tests.helpers.files (ns common-tests.helpers.files
(:require (:require
[app.common.colors :as clr] [app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.features :as ffeat] [app.common.features :as ffeat]
[app.common.files.changes :as cfc] [app.common.files.changes :as cfc]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.files.validate :as cfv] [app.common.files.validate :as cfv]
[app.common.geom.point :as gpt]
[app.common.logic.libraries :as cll]
[app.common.pprint :refer [pprint]] [app.common.pprint :refer [pprint]]
[app.common.types.color :as ctc]
[app.common.types.colors-list :as ctcl]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
[app.common.types.container :as ctn]
[app.common.types.file :as ctf] [app.common.types.file :as ctf]
[app.common.types.page :as ctp] [app.common.types.page :as ctp]
[app.common.types.pages-list :as ctpl] [app.common.types.pages-list :as ctpl]
[app.common.types.shape :as cts] [app.common.uuid :as uuid]
[app.common.types.shape-tree :as ctst] [common-tests.helpers.ids-map :as thi]
[app.common.types.typographies-list :as cttl] [cuerdas.core :as str]))
[app.common.types.typography :as ctt]
[common-tests.helpers.ids-map :as thi]))
;; ----- Files ;; ----- Files
@ -68,25 +56,6 @@
(validate-file! file') (validate-file! file')
file')) file'))
(declare current-page-id)
(declare get-page)
(defn dump-file
[file & {:keys [page-label libraries] :as params}]
(let [params (-> params
(or {:show-ids true :show-touched true})
(dissoc page-label libraries))
page (if (some? page-label)
(:id (get-page file page-label))
(current-page-id file))
libraries (or libraries {})]
(ctf/dump-tree file page libraries params)))
(defn pprint-file
[file & {:keys [level length] :or {level 10 length 1000}}]
(pprint file {:level level :length length}))
;; ----- Pages ;; ----- Pages
(defn sample-page (defn sample-page
@ -116,221 +85,74 @@
[file label] [file label]
(vary-meta file assoc :current-page-id (thi/id label))) (vary-meta file assoc :current-page-id (thi/id label)))
;; ----- Shapes ;; ----- Debug
(defn sample-shape (defn dump-file-type
[label & {:keys [type] :as params}] "Dump a file using dump-tree function in common.types.file."
(let [params (cond-> params [file & {:keys [page-label libraries] :as params}]
label (let [params (-> params
(assoc :id (thi/new-id! label)) (or {:show-ids true :show-touched true})
(dissoc page-label libraries))
page (if (some? page-label)
(:id (get-page file page-label))
(current-page-id file))
libraries (or libraries {})]
(nil? type) (ctf/dump-tree file page libraries params)))
(assoc :type :rect))]
(cts/setup-shape params))) (defn pprint-file
"Pretry print a file trying to limit the quantity of info shown."
[file & {:keys [level length] :or {level 10 length 1000}}]
(pprint file {:level level :length length}))
(defn add-sample-shape (defn dump-shape
[file label & {:keys [parent-label] :as params}] "Dump a shape, with each attribute in a line."
(let [page (current-page file) [shape]
shape (sample-shape label (dissoc params :parent-label)) (println "{")
parent-id (when parent-label (doseq [[k v] (sort shape)]
(thi/id parent-label)) (when (some? v)
parent (when parent-id (println (str " " k " : " v))))
(ctst/get-shape page parent-id)) (println "}"))
frame-id (if (cfh/frame-shape? parent)
(:id parent)
(:frame-id parent))]
(ctf/update-file-data
file
(fn [file-data]
(ctpl/update-page file-data
(:id page)
#(ctst/add-shape (:id shape)
shape
%
frame-id
parent-id
nil
true))))))
(defn get-shape (defn- stringify-keys [m keys]
[file label & {:keys [page-label]}] (apply str (interpose ", " (map #(str % ": " (get m %)) keys))))
(let [page (if page-label
(get-page file page-label)
(current-page file))]
(ctst/get-shape page (thi/id label))))
(defn get-shape-by-id (defn- dump-page-shape
[file id & {:keys [page-label]}] [shape keys padding]
(let [page (if page-label (println (str/pad (str padding
(get-page file page-label) (when (:main-instance shape) "{")
(current-page file))] (or (thi/label (:id shape)) "<no-label>")
(ctst/get-shape page id))) (when (:main-instance shape) "}")
(when keys
(str " [" (stringify-keys shape keys) "]")))
{:length 40 :type :right})
(if (nil? (:shape-ref shape))
(if (:component-root shape)
(str "# [Component " (or (thi/label (:component-id shape)) "<no-label>") "]")
"")
(str/format "%s--> %s%s"
(cond (:component-root shape) "#"
(:component-id shape) "@"
:else "-")
(if (:component-root shape)
(str "[Component " (or (thi/label (:component-id shape)) "<no-label>") "] ")
"")
(or (thi/label (:shape-ref shape)) "<no-label>")))))
;; ----- Components (defn dump-page
"Dump the layer tree of the page. Print the label of each shape, and the specified keys."
([page keys]
(dump-page page uuid/zero "" keys))
([page root-id padding keys]
(let [lookupf (d/getf (:objects page))
root-shape (lookupf root-id)
shapes (map lookupf (:shapes root-shape))]
(doseq [shape shapes]
(dump-page-shape shape keys padding)
(dump-page page (:id shape) (str padding " ") keys)))))
(defn make-component (defn dump-file
[file label root-label & {:keys [] :as params}] "Dump the current page of the file, using dump-page above.
(let [page (current-page file) Example: (thf/dump-file file [:id :touched])"
root (get-shape file root-label)] ([file] (dump-file file []))
([file keys] (dump-page (current-page file) keys)))
(dm/assert!
"Need that root is already a frame"
(cfh/frame-shape? root))
(let [[_new-root _new-shapes updated-shapes]
(ctn/convert-shape-in-component root (:objects page) (:id file))
updated-root (first updated-shapes)] ; Can't use new-root because it has a new id
(thi/set-id! label (:component-id updated-root))
(ctf/update-file-data
file
(fn [file-data]
(as-> file-data $
(reduce (fn [file-data shape]
(ctpl/update-page file-data
(:id page)
#(update % :objects assoc (:id shape) shape)))
$
updated-shapes)
(ctkl/add-component $ (assoc params
:id (:component-id updated-root)
:name (:name updated-root)
:main-instance-id (:id updated-root)
:main-instance-page (:id page)
:shapes updated-shapes))))))))
(defn get-component
[file label]
(ctkl/get-component (:data file) (thi/id label)))
(defn get-component-by-id
[file id]
(ctkl/get-component (:data file) id))
(defn set-child-label
[file shape-label child-idx label]
(let [id (-> (get-shape file shape-label)
:shapes
(nth child-idx))]
(when id
(thi/set-id! label id))))
(defn instantiate-component
[file component-label copy-root-label & {:keys [parent-label library children-labels] :as params}]
(let [page (current-page file)
library (or library file)
component (get-component library component-label)
parent-id (when parent-label
(thi/id parent-label))
parent (when parent-id
(ctst/get-shape page parent-id))
frame-id (if (cfh/frame-shape? parent)
(:id parent)
(:frame-id parent))
[copy-root copy-shapes]
(ctn/make-component-instance page
component
(:data library)
(gpt/point 100 100)
true
{:force-id (thi/new-id! copy-root-label)
:force-frame-id frame-id})
copy-root' (cond-> copy-root
(some? parent)
(assoc :parent-id parent-id)
(some? frame-id)
(assoc :frame-id frame-id)
(and (some? parent) (ctn/in-any-component? (:objects page) parent))
(dissoc :component-root))
file' (ctf/update-file-data
file
(fn [file-data]
(as-> file-data $
(ctpl/update-page $
(:id page)
#(ctst/add-shape (:id copy-root')
copy-root'
%
frame-id
parent-id
nil
true))
(reduce (fn [file-data shape]
(ctpl/update-page file-data
(:id page)
#(ctst/add-shape (:id shape)
shape
%
(:parent-id shape)
(:frame-id shape)
nil
true)))
$
(remove #(= (:id %) (:did copy-root')) copy-shapes)))))]
(when children-labels
(dotimes [idx (count children-labels)]
(set-child-label file' copy-root-label idx (nth children-labels idx))))
file'))
(defn component-swap
[file shape-label new-component-label new-shape-label & {:keys [library] :as params}]
(let [shape (get-shape file shape-label)
library (or library file)
libraries {(:id library) library}
page (current-page file)
objects (:objects page)
id-new-component (-> (get-component library new-component-label)
:id)
;; Store the properties that need to be maintained when the component is swapped
keep-props-values (select-keys shape ctk/swap-keep-attrs)
[new_shape _ changes]
(-> (pcb/empty-changes nil (:id page))
(cll/generate-component-swap objects shape (:data file) page libraries id-new-component 0 nil keep-props-values))]
(thi/set-id! new-shape-label (:id new_shape))
(apply-changes file changes)))
(defn sample-color
[label & {:keys [] :as params}]
(ctc/make-color (assoc params :id (thi/new-id! label))))
(defn sample-fill-color
[& {:keys [fill-color fill-opacity] :as params}]
(let [params (cond-> params
(nil? fill-color)
(assoc :fill-color clr/black)
(nil? fill-opacity)
(assoc :fill-opacity 1))]
params))
(defn sample-fills-color
[& {:keys [] :as params}]
[(sample-fill-color params)])
(defn add-sample-library-color
[file label & {:keys [] :as params}]
(let [color (sample-color label params)]
(ctf/update-file-data file #(ctcl/add-color % color))))
(defn sample-typography
[label & {:keys [] :as params}]
(ctt/make-typography (assoc params :id (thi/new-id! label))))
(defn add-sample-typography
[file label & {:keys [] :as params}]
(let [typography (sample-typography label params)]
(ctf/update-file-data file #(cttl/add-typography % typography))))

View file

@ -0,0 +1,101 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS INC
(ns common-tests.helpers.shapes
(:require
[app.common.colors :as clr]
[app.common.files.helpers :as cfh]
[app.common.types.color :as ctc]
[app.common.types.colors-list :as ctcl]
[app.common.types.file :as ctf]
[app.common.types.pages-list :as ctpl]
[app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst]
[app.common.types.typographies-list :as cttl]
[app.common.types.typography :as ctt]
[common-tests.helpers.files :as thf]
[common-tests.helpers.ids-map :as thi]))
(defn sample-shape
[label & {:keys [type] :as params}]
(let [params (cond-> params
label
(assoc :id (thi/new-id! label))
(nil? type)
(assoc :type :rect))]
(cts/setup-shape params)))
(defn add-sample-shape
[file label & {:keys [parent-label] :as params}]
(let [page (thf/current-page file)
shape (sample-shape label (dissoc params :parent-label))
parent-id (when parent-label
(thi/id parent-label))
parent (when parent-id
(ctst/get-shape page parent-id))
frame-id (if (cfh/frame-shape? parent)
(:id parent)
(:frame-id parent))]
(ctf/update-file-data
file
(fn [file-data]
(ctpl/update-page file-data
(:id page)
#(ctst/add-shape (:id shape)
shape
%
frame-id
parent-id
nil
true))))))
(defn get-shape
[file label & {:keys [page-label]}]
(let [page (if page-label
(thf/get-page file page-label)
(thf/current-page file))]
(ctst/get-shape page (thi/id label))))
(defn get-shape-by-id
[file id & {:keys [page-label]}]
(let [page (if page-label
(thf/get-page file page-label)
(thf/current-page file))]
(ctst/get-shape page id)))
(defn sample-color
[label & {:keys [] :as params}]
(ctc/make-color (assoc params :id (thi/new-id! label))))
(defn sample-fill-color
[& {:keys [fill-color fill-opacity] :as params}]
(let [params (cond-> params
(nil? fill-color)
(assoc :fill-color clr/black)
(nil? fill-opacity)
(assoc :fill-opacity 1))]
params))
(defn sample-fills-color
[& {:keys [] :as params}]
[(sample-fill-color params)])
(defn add-sample-library-color
[file label & {:keys [] :as params}]
(let [color (sample-color label params)]
(ctf/update-file-data file #(ctcl/add-color % color))))
(defn sample-typography
[label & {:keys [] :as params}]
(ctt/make-typography (assoc params :id (thi/new-id! label))))
(defn add-sample-typography
[file label & {:keys [] :as params}]
(let [typography (sample-typography label params)]
(ctf/update-file-data file #(cttl/add-typography % typography))))

View file

@ -11,9 +11,11 @@
[app.common.types.component :as ctk] [app.common.types.component :as ctk]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[clojure.test :as t] [clojure.test :as t]
[common-tests.helpers.components :as thc]
[common-tests.helpers.compositions :as tho] [common-tests.helpers.compositions :as tho]
[common-tests.helpers.files :as thf] [common-tests.helpers.files :as thf]
[common-tests.helpers.ids-map :as thi])) [common-tests.helpers.ids-map :as thi]
[common-tests.helpers.shapes :as ths]))
(t/use-fixtures :each thi/test-fixture) (t/use-fixtures :each thi/test-fixture)
@ -34,28 +36,28 @@
(-> (thf/sample-file :file1) (-> (thf/sample-file :file1)
(tho/add-frame :frame-red) (tho/add-frame :frame-red)
(thf/make-component :red :frame-red) (thc/make-component :red :frame-red)
(tho/add-frame :frame-blue) (tho/add-frame :frame-blue)
(thf/make-component :blue :frame-blue) (thc/make-component :blue :frame-blue)
(tho/add-frame :frame-green) (tho/add-frame :frame-green)
(thf/make-component :green :frame-green) (thc/make-component :green :frame-green)
(thf/instantiate-component :red :red-copy-green :parent-label :frame-green) (thc/instantiate-component :red :red-copy-green :parent-label :frame-green)
(tho/add-frame :frame-b1) (tho/add-frame :frame-b1)
(thf/make-component :b1 :frame-b1) (thc/make-component :b1 :frame-b1)
(tho/add-frame :frame-yellow :parent-label :frame-b1) (tho/add-frame :frame-yellow :parent-label :frame-b1)
(thf/instantiate-component :red :red-copy :parent-label :frame-b1) (thc/instantiate-component :red :red-copy :parent-label :frame-b1)
(thf/component-swap :red-copy :blue :blue1) (thc/component-swap :red-copy :blue :blue1)
(thf/instantiate-component :green :green-copy :parent-label :frame-b1 :children-labels [:red-copy-in-green-copy]) (thc/instantiate-component :green :green-copy :parent-label :frame-b1 :children-labels [:red-copy-in-green-copy])
(thf/component-swap :red-copy-in-green-copy :blue :blue-copy-in-green-copy) (thc/component-swap :red-copy-in-green-copy :blue :blue-copy-in-green-copy)
(tho/add-frame :frame-b2) (tho/add-frame :frame-b2)
(thf/make-component :b2 :frame-b2))) (thc/make-component :b2 :frame-b2)))
(t/deftest test-keep-swap-slot-relocating-blue1-to-root (t/deftest test-keep-swap-slot-relocating-blue1-to-root
(let [;; ==== Setup (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (ths/get-shape file :blue1)
;; ==== Action ;; ==== Action
changes (cls/generate-relocate-shapes (pcb/empty-changes nil) changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
@ -68,7 +70,7 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
blue1' (thf/get-shape file' :blue1)] blue1' (ths/get-shape file' :blue1)]
;; ==== Check ;; ==== Check
@ -83,7 +85,7 @@
(let [;; ==== Setup (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (ths/get-shape file :blue1)
;; ==== Action ;; ==== Action
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
@ -97,7 +99,7 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
blue1' (thf/get-shape file' :blue1)] blue1' (ths/get-shape file' :blue1)]
;; ==== Check ;; ==== Check
@ -113,8 +115,8 @@
(let [;; ==== Setup (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (ths/get-shape file :blue1)
b2 (thf/get-shape file :frame-b2) b2 (ths/get-shape file :frame-b2)
;; ==== Action ;; ==== Action
@ -128,7 +130,7 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
blue1' (thf/get-shape file' :blue1)] blue1' (ths/get-shape file' :blue1)]
;; ==== Check ;; ==== Check
@ -143,8 +145,8 @@
(let [;; ==== Setup (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (ths/get-shape file :blue1)
b2 (thf/get-shape file :frame-b2) b2 (ths/get-shape file :frame-b2)
;; ==== Action ;; ==== Action
@ -159,7 +161,7 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
blue1' (thf/get-shape file' :blue1)] blue1' (ths/get-shape file' :blue1)]
;; ==== Check ;; ==== Check
@ -174,8 +176,8 @@
(let [;; ==== Setup (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (ths/get-shape file :blue1)
yellow (thf/get-shape file :frame-yellow) yellow (ths/get-shape file :frame-yellow)
;; ==== Action ;; ==== Action
;; Move blue1 into yellow ;; Move blue1 into yellow
@ -189,7 +191,7 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
page' (thf/current-page file') page' (thf/current-page file')
yellow' (thf/get-shape file' :frame-yellow) yellow' (ths/get-shape file' :frame-yellow)
;; Move yellow into root ;; Move yellow into root
changes' (cls/generate-relocate-shapes (pcb/empty-changes nil) changes' (cls/generate-relocate-shapes (pcb/empty-changes nil)
@ -202,7 +204,7 @@
file'' (thf/apply-changes file' changes') file'' (thf/apply-changes file' changes')
;; ==== Get ;; ==== Get
blue1'' (thf/get-shape file'' :blue1)] blue1'' (ths/get-shape file'' :blue1)]
;; ==== Check ;; ==== Check
@ -217,11 +219,10 @@
(let [;; ==== Setup (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (ths/get-shape file :blue1)
yellow (thf/get-shape file :frame-yellow) yellow (ths/get-shape file :frame-yellow)
;; ==== Action ;; ==== Action
;; Move blue1 into yellow ;; Move blue1 into yellow
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids #{(:id blue1)} ;; ids
@ -233,7 +234,7 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
page' (thf/current-page file') page' (thf/current-page file')
yellow' (thf/get-shape file' :frame-yellow) yellow' (ths/get-shape file' :frame-yellow)
;; Move yellow into root ;; Move yellow into root
changes' (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) changes' (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
@ -246,7 +247,7 @@
file'' (thf/apply-changes file' changes') file'' (thf/apply-changes file' changes')
;; ==== Get ;; ==== Get
blue1'' (thf/get-shape file'' :blue1)] blue1'' (ths/get-shape file'' :blue1)]
;; ==== Check ;; ==== Check
@ -262,11 +263,10 @@
(let [;; ==== Setup (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (ths/get-shape file :blue1)
yellow (thf/get-shape file :frame-yellow) yellow (ths/get-shape file :frame-yellow)
;; ==== Action ;; ==== Action
;; Move blue1 into yellow ;; Move blue1 into yellow
changes (cls/generate-relocate-shapes (pcb/empty-changes nil) changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page) (:objects page)
@ -278,8 +278,8 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
page' (thf/current-page file') page' (thf/current-page file')
yellow' (thf/get-shape file' :frame-yellow) yellow' (ths/get-shape file' :frame-yellow)
b2' (thf/get-shape file' :frame-b2) b2' (ths/get-shape file' :frame-b2)
;; Move yellow into b2 ;; Move yellow into b2
changes' (cls/generate-relocate-shapes (pcb/empty-changes nil) changes' (cls/generate-relocate-shapes (pcb/empty-changes nil)
@ -292,7 +292,7 @@
file'' (thf/apply-changes file' changes') file'' (thf/apply-changes file' changes')
;; ==== Get ;; ==== Get
blue1'' (thf/get-shape file'' :blue1)] blue1'' (ths/get-shape file'' :blue1)]
;; ==== Check ;; ==== Check
@ -307,11 +307,10 @@
(let [;; ==== Setup (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (ths/get-shape file :blue1)
yellow (thf/get-shape file :frame-yellow) yellow (ths/get-shape file :frame-yellow)
;; ==== Action ;; ==== Action
;; Move blue1 into yellow ;; Move blue1 into yellow
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids #{(:id blue1)} ;; ids
@ -323,8 +322,8 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
page' (thf/current-page file') page' (thf/current-page file')
yellow' (thf/get-shape file' :frame-yellow) yellow' (ths/get-shape file' :frame-yellow)
b2' (thf/get-shape file' :frame-b2) b2' (ths/get-shape file' :frame-b2)
;; Move yellow into b2 ;; Move yellow into b2
changes' (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) changes' (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
@ -338,7 +337,7 @@
file'' (thf/apply-changes file' changes') file'' (thf/apply-changes file' changes')
;; ==== Get ;; ==== Get
blue1'' (thf/get-shape file'' :blue1)] blue1'' (ths/get-shape file'' :blue1)]
;; ==== Check ;; ==== Check

View file

@ -9,18 +9,20 @@
[app.common.files.changes-builder :as pcb] [app.common.files.changes-builder :as pcb]
[app.common.logic.libraries :as cll] [app.common.logic.libraries :as cll]
[clojure.test :as t] [clojure.test :as t]
[common-tests.helpers.components :as thc]
[common-tests.helpers.files :as thf] [common-tests.helpers.files :as thf]
[common-tests.helpers.ids-map :as thi])) [common-tests.helpers.ids-map :as thi]
[common-tests.helpers.shapes :as ths]))
(t/use-fixtures :each thi/test-fixture) (t/use-fixtures :each thi/test-fixture)
(t/deftest test-add-component-from-single-shape (t/deftest test-add-component-from-single-shape
(let [;; ==== Setup (let [;; ==== Setup
file (-> (thf/sample-file :file1) file (-> (thf/sample-file :file1)
(thf/add-sample-shape :shape1 :type :frame)) (ths/add-sample-shape :shape1 :type :frame))
page (thf/current-page file) page (thf/current-page file)
shape1 (thf/get-shape file :shape1) shape1 (ths/get-shape file :shape1)
;; ==== Action ;; ==== Action
[_ component-id changes] [_ component-id changes]
@ -36,8 +38,8 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
component (thf/get-component-by-id file' component-id) component (thc/get-component-by-id file' component-id)
root (thf/get-shape-by-id file' (:main-instance-id component))] root (ths/get-shape-by-id file' (:main-instance-id component))]
;; ==== Check ;; ==== Check
(t/is (some? component)) (t/is (some? component))

View file

@ -11,7 +11,8 @@
[clojure.test :as t] [clojure.test :as t]
[common-tests.helpers.compositions :as tho] [common-tests.helpers.compositions :as tho]
[common-tests.helpers.files :as thf] [common-tests.helpers.files :as thf]
[common-tests.helpers.ids-map :as thi])) [common-tests.helpers.ids-map :as thi]
[common-tests.helpers.shapes :as ths]))
(t/use-fixtures :each thi/test-fixture) (t/use-fixtures :each thi/test-fixture)
@ -22,14 +23,14 @@
:main-root :main-root
:main-child :main-child
:copy-root :copy-root
:main-child-params {:fills (thf/sample-fills-color :main-child-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")})) :fill-color "#abcdef")}))
page (thf/current-page file) page (thf/current-page file)
copy-root (thf/get-shape file :copy-root) copy-root (ths/get-shape file :copy-root)
;; ==== Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (thf/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy-root) (:shapes copy-root)
@ -40,8 +41,8 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
copy-root' (thf/get-shape file' :copy-root) copy-root' (ths/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root'))) copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))
fills' (:fills copy-child') fills' (:fills copy-child')
fill' (first fills')] fill' (first fills')]
@ -59,10 +60,10 @@
:main-root :main-root
:main-child :main-child
:copy-root) :copy-root)
(thf/add-sample-shape :free-shape)) (ths/add-sample-shape :free-shape))
page (thf/current-page file) page (thf/current-page file)
copy-root (thf/get-shape file :copy-root) copy-root (ths/get-shape file :copy-root)
;; ==== Action ;; ==== Action
@ -79,8 +80,8 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
copy-root' (thf/get-shape file' :copy-root) copy-root' (ths/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))] copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
;; ==== Check ;; ==== Check
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
@ -95,7 +96,7 @@
:copy-root)) :copy-root))
page (thf/current-page file) page (thf/current-page file)
copy-root (thf/get-shape file :copy-root) copy-root (ths/get-shape file :copy-root)
;; ==== Action ;; ==== Action
@ -112,8 +113,8 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
copy-root' (thf/get-shape file' :copy-root) copy-root' (ths/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))] copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
;; ==== Check ;; ==== Check
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
@ -126,11 +127,11 @@
:main-root :main-root
[:main-child1 :main-child2 :main-child3] [:main-child1 :main-child2 :main-child3]
:copy-root) :copy-root)
(thf/add-sample-shape :free-shape)) (ths/add-sample-shape :free-shape))
page (thf/current-page file) page (thf/current-page file)
copy-root (thf/get-shape file :copy-root) copy-root (ths/get-shape file :copy-root)
copy-child1 (thf/get-shape-by-id file (first (:shapes copy-root))) copy-child1 (ths/get-shape-by-id file (first (:shapes copy-root)))
;; ==== Action ;; ==== Action
@ -147,8 +148,8 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
copy-root' (thf/get-shape file' :copy-root) copy-root' (ths/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))] copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
;; ==== Check ;; ==== Check
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
@ -164,14 +165,14 @@
:main2-root :main2-root
:main2-nested-head :main2-nested-head
:copy2-root :copy2-root
:root2-params {:fills (thf/sample-fills-color :root2-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")})) :fill-color "#abcdef")}))
page (thf/current-page file) page (thf/current-page file)
copy2-root (thf/get-shape file :copy2-root) copy2-root (ths/get-shape file :copy2-root)
;; ==== Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (thf/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
#{(:id copy2-root)} #{(:id copy2-root)}
@ -182,7 +183,7 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
copy2-root' (thf/get-shape file' :copy2-root) copy2-root' (ths/get-shape file' :copy2-root)
fills' (:fills copy2-root') fills' (:fills copy2-root')
fill' (first fills')] fill' (first fills')]
@ -202,14 +203,14 @@
:main2-root :main2-root
:main2-nested-head :main2-nested-head
:copy2-root :copy2-root
:nested-head-params {:fills (thf/sample-fills-color :nested-head-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")})) :fill-color "#abcdef")}))
page (thf/current-page file) page (thf/current-page file)
copy2-root (thf/get-shape file :copy2-root) copy2-root (ths/get-shape file :copy2-root)
;; ==== Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (thf/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy2-root) (:shapes copy2-root)
@ -220,8 +221,8 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
copy2-root' (thf/get-shape file' :copy2-root) copy2-root' (ths/get-shape file' :copy2-root)
copy2-child' (thf/get-shape-by-id file' (first (:shapes copy2-root'))) copy2-child' (ths/get-shape-by-id file' (first (:shapes copy2-root')))
fills' (:fills copy2-child') fills' (:fills copy2-child')
fill' (first fills')] fill' (first fills')]

View file

@ -11,9 +11,11 @@
[app.common.types.component :as ctk] [app.common.types.component :as ctk]
[app.common.types.file :as ctf] [app.common.types.file :as ctf]
[clojure.test :as t] [clojure.test :as t]
[common-tests.helpers.compositions :as thc] [common-tests.helpers.components :as thc]
[common-tests.helpers.compositions :as tho]
[common-tests.helpers.files :as thf] [common-tests.helpers.files :as thf]
[common-tests.helpers.ids-map :as thi])) [common-tests.helpers.ids-map :as thi]
[common-tests.helpers.shapes :as ths]))
(t/use-fixtures :each thi/test-fixture) (t/use-fixtures :each thi/test-fixture)
@ -21,16 +23,16 @@
(t/deftest test-simple-swap (t/deftest test-simple-swap
(let [;; ==== Setup (let [;; ==== Setup
file (-> (thf/sample-file :file1) file (-> (thf/sample-file :file1)
(thc/add-simple-component-with-copy :component-1 (tho/add-simple-component-with-copy :component-1
:component-1-main-root :component-1-main-root
:component-1-main-child :component-1-main-child
:component-1-copy-root) :component-1-copy-root)
(thc/add-simple-component :component-2 (tho/add-simple-component :component-2
:component-2-root :component-2-root
:component-2-child)) :component-2-child))
component-1-copy-root (thf/get-shape file :component-1-copy-root) component-1-copy-root (ths/get-shape file :component-1-copy-root)
component-2 (thf/get-component file :component-2) component-2 (thc/get-component file :component-2)
page (thf/current-page file) page (thf/current-page file)
;; ==== Action ;; ==== Action
@ -49,7 +51,7 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
swapped (thf/get-shape-by-id file' (:id new-shape))] swapped (ths/get-shape-by-id file' (:id new-shape))]
;; ==== Check ;; ==== Check
(t/is (not= (:component-id component-1-copy-root) (:component-id swapped))) (t/is (not= (:component-id component-1-copy-root) (:component-id swapped)))
@ -60,22 +62,22 @@
(let [;; ==== Setup (let [;; ==== Setup
file file
(-> (thf/sample-file :file1) (-> (thf/sample-file :file1)
(thc/add-simple-component :component-1 :component-1-main-root :component-1-main-child) (tho/add-simple-component :component-1 :component-1-main-root :component-1-main-child)
(thc/add-frame :component-container) (tho/add-frame :component-container)
(thf/instantiate-component :component-1 :component-1-copy-root :parent-label :component-container) (thc/instantiate-component :component-1 :component-1-copy-root :parent-label :component-container)
(thf/make-component :component-container-main :component-container) (thc/make-component :component-container-main :component-container)
(thf/instantiate-component :component-container-main :component-container-instance) (thc/instantiate-component :component-container-main :component-container-instance)
(thc/add-simple-component :component-2 :component-2-main-root :component-2-main-child)) (tho/add-simple-component :component-2 :component-2-main-root :component-2-main-child))
page (thf/current-page file) page (thf/current-page file)
component-2 (thf/get-component file :component-2) component-2 (thc/get-component file :component-2)
copy copy
(->> (->>
(thf/get-shape file :component-container-instance) (ths/get-shape file :component-container-instance)
:shapes :shapes
first first
(thf/get-shape-by-id file)) (ths/get-shape-by-id file))
libraries {(:id file) file} libraries {(:id file) file}
@ -97,8 +99,8 @@
page' (thf/current-page file') page' (thf/current-page file')
;; ==== Get ;; ==== Get
swapped (thf/get-shape-by-id file' (:id new-shape)) swapped (ths/get-shape-by-id file' (:id new-shape))
component-1-copy-root (thf/get-shape file' :component-1-copy-root) component-1-copy-root (ths/get-shape file' :component-1-copy-root)
slot (-> (ctf/find-swap-slot swapped slot (-> (ctf/find-swap-slot swapped
page' page'
file' file'
@ -116,23 +118,23 @@
(let [;; ==== Setup (let [;; ==== Setup
file file
(-> (thf/sample-file :file1) (-> (thf/sample-file :file1)
(thc/add-simple-component :component-1 :component-1-main-root :component-1-main-child) (tho/add-simple-component :component-1 :component-1-main-root :component-1-main-child)
(thc/add-frame :component-container) (tho/add-frame :component-container)
(thf/instantiate-component :component-1 :component-1-copy-root :parent-label :component-container) (thc/instantiate-component :component-1 :component-1-copy-root :parent-label :component-container)
(thf/make-component :component-container-main :component-container) (thc/make-component :component-container-main :component-container)
(thf/instantiate-component :component-container-main :component-container-instance) (thc/instantiate-component :component-container-main :component-container-instance)
(thc/add-simple-component :component-2 :component-2-main-root :component-2-main-child)) (tho/add-simple-component :component-2 :component-2-main-root :component-2-main-child))
page (thf/current-page file) page (thf/current-page file)
component-1 (thf/get-component file :component-1) component-1 (thc/get-component file :component-1)
component-2 (thf/get-component file :component-2) component-2 (thc/get-component file :component-2)
copy copy
(->> (->>
(thf/get-shape file :component-container-instance) (ths/get-shape file :component-container-instance)
:shapes :shapes
first first
(thf/get-shape-by-id file)) (ths/get-shape-by-id file))
;; ==== Action ;; ==== Action
[new-shape _all-parents changes-swap] [new-shape _all-parents changes-swap]
@ -163,10 +165,10 @@
;; ==== Get ;; ==== Get
reset reset
(->> (->>
(thf/get-shape file' :component-container-instance) (ths/get-shape file' :component-container-instance)
:shapes :shapes
first first
(thf/get-shape-by-id file'))] (ths/get-shape-by-id file'))]
;; ==== Check ;; ==== Check
(t/is (= (:id component-1) (:component-id reset))) (t/is (= (:id component-1) (:component-id reset)))

View file

@ -15,9 +15,11 @@
[app.common.types.pages-list :as ctpl] [app.common.types.pages-list :as ctpl]
[app.common.types.typographies-list :as ctyl] [app.common.types.typographies-list :as ctyl]
[clojure.test :as t] [clojure.test :as t]
[common-tests.helpers.components :as thc]
[common-tests.helpers.compositions :as tho] [common-tests.helpers.compositions :as tho]
[common-tests.helpers.files :as thf] [common-tests.helpers.files :as thf]
[common-tests.helpers.ids-map :as thi])) [common-tests.helpers.ids-map :as thi]
[common-tests.helpers.shapes :as ths]))
(t/use-fixtures :each thi/test-fixture) (t/use-fixtures :each thi/test-fixture)
@ -27,14 +29,14 @@
f3 (thf/sample-file :file3 :name "testing file") f3 (thf/sample-file :file3 :name "testing file")
f4 (-> (thf/sample-file :file4 :page-label :page2) f4 (-> (thf/sample-file :file4 :page-label :page2)
(thf/add-sample-page :page3 :name "testing page") (thf/add-sample-page :page3 :name "testing page")
(thf/add-sample-shape :shape1)) (ths/add-sample-shape :shape1))
f5 (-> f4 f5 (-> f4
(thf/add-sample-shape :shape2) (ths/add-sample-shape :shape2)
(thf/switch-to-page :page2) (thf/switch-to-page :page2)
(thf/add-sample-shape :shape3 :name "testing shape" :width 100)) (ths/add-sample-shape :shape3 :name "testing shape" :width 100))
s1 (thf/get-shape f4 :shape1) s1 (ths/get-shape f4 :shape1)
s2 (thf/get-shape f5 :shape2 :page-label :page3) s2 (ths/get-shape f5 :shape2 :page-label :page3)
s3 (thf/get-shape f5 :shape3)] s3 (ths/get-shape f5 :shape3)]
;; (thf/pprint-file f4) ;; (thf/pprint-file f4)
@ -75,7 +77,7 @@
(tho/add-simple-component :component1 :main-root :rect1)) (tho/add-simple-component :component1 :main-root :rect1))
file (-> (thf/sample-file :file) file (-> (thf/sample-file :file)
(thf/instantiate-component :component1 :copy-root :library library)) (thc/instantiate-component :component1 :copy-root :library library))
;; Action ;; Action
file' (ctf/update-file-data file' (ctf/update-file-data
@ -89,7 +91,7 @@
components' (ctkl/components-seq (ctf/file-data file')) components' (ctkl/components-seq (ctf/file-data file'))
component' (first components') component' (first components')
copy-root' (thf/get-shape file' :copy-root) copy-root' (ths/get-shape file' :copy-root)
main-root' (ctf/get-ref-shape (ctf/file-data file') component' copy-root')] main-root' (ctf/get-ref-shape (ctf/file-data file') component' copy-root')]
;; Check ;; Check
@ -106,11 +108,11 @@
(t/deftest test-absorb-colors (t/deftest test-absorb-colors
(let [;; Setup (let [;; Setup
library (-> (thf/sample-file :library :is-shared true) library (-> (thf/sample-file :library :is-shared true)
(thf/add-sample-library-color :color1 {:name "Test color" (ths/add-sample-library-color :color1 {:name "Test color"
:color "#abcdef"})) :color "#abcdef"}))
file (-> (thf/sample-file :file) file (-> (thf/sample-file :file)
(thf/add-sample-shape :shape1 (ths/add-sample-shape :shape1
:type :rect :type :rect
:name "Rect1" :name "Rect1"
:fills [{:fill-color "#abcdef" :fills [{:fill-color "#abcdef"
@ -127,7 +129,7 @@
;; Get ;; Get
colors' (ctcl/colors-seq (ctf/file-data file')) colors' (ctcl/colors-seq (ctf/file-data file'))
shape1' (thf/get-shape file' :shape1) shape1' (ths/get-shape file' :shape1)
fill' (first (:fills shape1'))] fill' (first (:fills shape1'))]
;; Check ;; Check
@ -143,10 +145,10 @@
(t/deftest test-absorb-typographies (t/deftest test-absorb-typographies
(let [;; Setup (let [;; Setup
library (-> (thf/sample-file :library :is-shared true) library (-> (thf/sample-file :library :is-shared true)
(thf/add-sample-typography :typography1 {:name "Test typography"})) (ths/add-sample-typography :typography1 {:name "Test typography"}))
file (-> (thf/sample-file :file) file (-> (thf/sample-file :file)
(thf/add-sample-shape :shape1 (ths/add-sample-shape :shape1
:type :text :type :text
:name "Text1" :name "Text1"
:content {:type "root" :content {:type "root"
@ -178,7 +180,7 @@
;; Get ;; Get
typographies' (ctyl/typographies-seq (ctf/file-data file')) typographies' (ctyl/typographies-seq (ctf/file-data file'))
shape1' (thf/get-shape file' :shape1) shape1' (ths/get-shape file' :shape1)
text-node' (d/seek #(some? (:text %)) (txt/node-seq (:content shape1')))] text-node' (d/seek #(some? (:text %)) (txt/node-seq (:content shape1')))]
;; Check ;; Check