mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
♻️ Make test helpers globally usable
This commit is contained in:
@@ -1,156 +0,0 @@
|
||||
;; 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
|
||||
|
||||
[path name] (cfh/parse-path-name (:name updated-root))]
|
||||
(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
|
||||
:path path
|
||||
:main-instance-id (:id updated-root)
|
||||
:main-instance-page (:id page)
|
||||
:shapes updated-shapes))))))))
|
||||
|
||||
(defn get-component
|
||||
[file label & {:keys [include-deleted?] :or {include-deleted? false}}]
|
||||
(ctkl/get-component (:data file) (thi/id label) include-deleted?))
|
||||
|
||||
(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)))
|
||||
@@ -1,169 +0,0 @@
|
||||
;; 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.compositions
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[common-tests.helpers.components :as thc]
|
||||
[common-tests.helpers.shapes :as ths]))
|
||||
|
||||
(defn add-rect
|
||||
[file rect-label & {:keys [] :as params}]
|
||||
;; Generated shape tree:
|
||||
;; :rect-label [:type :rect :name: Rect1]
|
||||
(ths/add-sample-shape file rect-label
|
||||
(merge {:type :rect
|
||||
:name "Rect1"}
|
||||
params)))
|
||||
|
||||
(defn add-frame
|
||||
[file frame-label & {:keys [] :as params}]
|
||||
;; Generated shape tree:
|
||||
;; :frame-label [:type :frame :name: Frame1]
|
||||
(ths/add-sample-shape file frame-label
|
||||
(merge {:type :frame
|
||||
:name "Frame1"}
|
||||
params)))
|
||||
|
||||
(defn add-frame-with-child
|
||||
[file frame-label child-label & {:keys [frame-params child-params]}]
|
||||
;; Generated shape tree:
|
||||
;; :frame-label [:name: Frame1]
|
||||
;; :child-label [:name: Rect1]
|
||||
(-> file
|
||||
(add-frame frame-label frame-params)
|
||||
(ths/add-sample-shape child-label
|
||||
(merge {:type :rect
|
||||
:name "Rect1"
|
||||
:parent-label frame-label}
|
||||
child-params))))
|
||||
|
||||
(defn add-simple-component
|
||||
[file component-label root-label child-label
|
||||
& {:keys [component-params root-params child-params]}]
|
||||
;; Generated shape tree:
|
||||
;; {:root-label} [:name: Frame1] # [Component :component-label]
|
||||
;; :child-label [:name: Rect1]
|
||||
(-> file
|
||||
(add-frame-with-child root-label child-label :frame-params root-params :child-params child-params)
|
||||
(thc/make-component component-label root-label component-params)))
|
||||
|
||||
(defn add-simple-component-with-copy
|
||||
[file component-label main-root-label main-child-label copy-root-label
|
||||
& {:keys [component-params main-root-params main-child-params copy-root-params]}]
|
||||
;; Generated shape tree:
|
||||
;; {:main-root-label} [:name: Frame1] # [Component :component-label]
|
||||
;; :main-child-label [:name: Rect1]
|
||||
;;
|
||||
;; :copy-root-label [:name: Frame1] #--> [Component :component-label] :main-root-label
|
||||
;; <no-label> [:name: Rect1] ---> :main-child-label
|
||||
(-> file
|
||||
(add-simple-component component-label
|
||||
main-root-label
|
||||
main-child-label
|
||||
:component-params component-params
|
||||
:root-params main-root-params
|
||||
:child-params main-child-params)
|
||||
(thc/instantiate-component component-label copy-root-label copy-root-params)))
|
||||
|
||||
(defn add-component-with-many-children
|
||||
[file component-label root-label child-labels
|
||||
& {:keys [component-params root-params child-params-list]}]
|
||||
;; Generated shape tree:
|
||||
;; {:root-label} [:name: Frame1] # [Component :component-label]
|
||||
;; :child1-label [:name: Rect1]
|
||||
;; :child2-label [:name: Rect2]
|
||||
;; :child3-label [:name: Rect3]
|
||||
(as-> file $
|
||||
(add-frame $ root-label root-params)
|
||||
(reduce (fn [file [index [label params]]]
|
||||
(ths/add-sample-shape file
|
||||
label
|
||||
(merge {:type :rect
|
||||
:name (str "Rect" (inc index))
|
||||
:parent-label root-label}
|
||||
params)))
|
||||
$
|
||||
(d/enumerate (d/zip-all child-labels child-params-list)))
|
||||
(thc/make-component $ component-label root-label component-params)))
|
||||
|
||||
(defn add-component-with-many-children-and-copy
|
||||
[file component-label main-root-label main-child-labels copy-root-label
|
||||
& {:keys [component-params main-root-params main-child-params-list copy-root-params]}]
|
||||
;; Generated shape tree:
|
||||
;; {:root-label} [:name: Frame1] # [Component :component-label]
|
||||
;; :child1-label [:name: Rect1]
|
||||
;; :child2-label [:name: Rect2]
|
||||
;; :child3-label [:name: Rect3]
|
||||
;;
|
||||
;; :copy-root-label [:name: Frame1] #--> [Component :component-label] :root-label
|
||||
;; <no-label> [:name: Rect1] ---> :child1-label
|
||||
;; <no-label> [:name: Rect2] ---> :child2-label
|
||||
;; <no-label> [:name: Rect3] ---> :child3-label
|
||||
(-> file
|
||||
(add-component-with-many-children component-label
|
||||
main-root-label
|
||||
main-child-labels
|
||||
:component-params component-params
|
||||
:root-params main-root-params
|
||||
:child-params-list main-child-params-list)
|
||||
(thc/instantiate-component component-label copy-root-label copy-root-params)))
|
||||
|
||||
(defn add-nested-component
|
||||
[file component1-label main1-root-label main1-child-label component2-label main2-root-label nested-head-label
|
||||
& {:keys [component1-params root1-params main1-child-params component2-params main2-root-params nested-head-params]}]
|
||||
;; Generated shape tree:
|
||||
;; {:main1-root-label} [:name: Frame1] # [Component :component1-label]
|
||||
;; :main1-child-label [:name: Rect1]
|
||||
;;
|
||||
;; {:main2-root-label} [:name: Frame2] # [Component :component2-label]
|
||||
;; :nested-head-label [:name: Frame1] @--> [Component :component1-label] :main1-root-label
|
||||
;; <no-label> [:name: Rect1] ---> :main1-child-label
|
||||
(-> file
|
||||
(add-simple-component component1-label
|
||||
main1-root-label
|
||||
main1-child-label
|
||||
:component-params component1-params
|
||||
:root-params root1-params
|
||||
:child-params main1-child-params)
|
||||
(add-frame main2-root-label (merge {:name "Frame2"}
|
||||
main2-root-params))
|
||||
(thc/instantiate-component component1-label
|
||||
nested-head-label
|
||||
(assoc nested-head-params
|
||||
:parent-label main2-root-label))
|
||||
(thc/make-component component2-label
|
||||
main2-root-label
|
||||
component2-params)))
|
||||
|
||||
(defn add-nested-component-with-copy
|
||||
[file component1-label main1-root-label main1-child-label component2-label main2-root-label nested-head-label copy2-root-label
|
||||
& {:keys [component1-params root1-params main1-child-params component2-params main2-root-params nested-head-params copy2-root-params]}]
|
||||
;; Generated shape tree:
|
||||
;; {:main1-root-label} [:name: Frame1] # [Component :component1-label]
|
||||
;; :main1-child-label [:name: Rect1]
|
||||
;;
|
||||
;; {:main2-root-label} [:name: Frame2] # [Component :component2-label]
|
||||
;; :nested-head-label [:name: Frame1] @--> [Component :component1-label] :main1-root-label
|
||||
;; <no-label> [:name: Rect1] ---> :main1-child-label
|
||||
;;
|
||||
;; :copy2-label [:name: Frame2] #--> [Component :component2-label] :main2-root-label
|
||||
;; <no-label> [:name: Frame1] @--> [Component :component1-label] :nested-head-label
|
||||
;; <no-label> [:name: Rect1] ---> <no-label>
|
||||
(-> file
|
||||
(add-nested-component component1-label
|
||||
main1-root-label
|
||||
main1-child-label
|
||||
component2-label
|
||||
main2-root-label
|
||||
nested-head-label
|
||||
:component1-params component1-params
|
||||
:root1-params root1-params
|
||||
:main1-child-params main1-child-params
|
||||
:component2-params component2-params
|
||||
:main2-root-params main2-root-params
|
||||
:nested-head-params nested-head-params)
|
||||
(thc/instantiate-component component2-label copy2-root-label copy2-root-params)))
|
||||
@@ -1,189 +0,0 @@
|
||||
;; 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.files
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.features :as ffeat]
|
||||
[app.common.files.changes :as cfc]
|
||||
[app.common.files.validate :as cfv]
|
||||
[app.common.pprint :refer [pprint]]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.types.page :as ctp]
|
||||
[app.common.types.pages-list :as ctpl]
|
||||
[app.common.uuid :as uuid]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
;; ----- Files
|
||||
|
||||
(defn sample-file
|
||||
[label & {:keys [page-label name] :as params}]
|
||||
(binding [ffeat/*current* #{"components/v2"}]
|
||||
(let [params (cond-> params
|
||||
label
|
||||
(assoc :id (thi/new-id! label))
|
||||
|
||||
page-label
|
||||
(assoc :page-id (thi/new-id! page-label))
|
||||
|
||||
(nil? name)
|
||||
(assoc :name "Test file"))
|
||||
|
||||
file (-> (ctf/make-file (dissoc params :page-label))
|
||||
(assoc :features #{"components/v2"}))
|
||||
|
||||
page (-> file
|
||||
:data
|
||||
(ctpl/pages-seq)
|
||||
(first))]
|
||||
|
||||
(with-meta file
|
||||
{:current-page-id (:id page)}))))
|
||||
|
||||
(defn validate-file!
|
||||
([file] (validate-file! file {}))
|
||||
([file libraries]
|
||||
(cfv/validate-file-schema! file)
|
||||
(cfv/validate-file! file libraries)))
|
||||
|
||||
(defn apply-changes
|
||||
[file changes]
|
||||
(let [file' (ctf/update-file-data file #(cfc/process-changes % (:redo-changes changes) true))]
|
||||
(validate-file! file')
|
||||
file'))
|
||||
|
||||
;; ----- Pages
|
||||
|
||||
(defn sample-page
|
||||
[label & {:keys [] :as params}]
|
||||
(ctp/make-empty-page (assoc params :id (thi/new-id! label))))
|
||||
|
||||
(defn add-sample-page
|
||||
[file label & {:keys [] :as params}]
|
||||
(let [page (sample-page label params)]
|
||||
(-> file
|
||||
(ctf/update-file-data #(ctpl/add-page % page))
|
||||
(vary-meta assoc :current-page-id (:id page)))))
|
||||
|
||||
(defn get-page
|
||||
[file label]
|
||||
(ctpl/get-page (:data file) (thi/id label)))
|
||||
|
||||
(defn current-page-id
|
||||
[file]
|
||||
(:current-page-id (meta file)))
|
||||
|
||||
(defn current-page
|
||||
[file]
|
||||
(ctpl/get-page (:data file) (current-page-id file)))
|
||||
|
||||
(defn switch-to-page
|
||||
[file label]
|
||||
(vary-meta file assoc :current-page-id (thi/id label)))
|
||||
|
||||
;; ----- Debug
|
||||
|
||||
(defn dump-tree
|
||||
"Dump a file using dump-tree function in common.types.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
|
||||
"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 dump-shape
|
||||
"Dump 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]
|
||||
(let [kv (-> (select-keys m keys)
|
||||
(assoc :swap-slot (when ((set keys) :swap-slot)
|
||||
(ctk/get-swap-slot m)))
|
||||
(assoc :swap-slot-label (when ((set keys) :swap-slot-label)
|
||||
(when-let [slot (ctk/get-swap-slot m)]
|
||||
(thi/label slot))))
|
||||
(d/without-nils))
|
||||
|
||||
pretty-uuid (fn [id]
|
||||
(let [id (str id)]
|
||||
(str "#" (subs id (- (count id) 6)))))
|
||||
|
||||
format-kv (fn [[k v]]
|
||||
(cond
|
||||
(uuid? v)
|
||||
(str k " " (pretty-uuid v))
|
||||
|
||||
:else
|
||||
(str k " " v)))]
|
||||
|
||||
(when (seq kv)
|
||||
(str " [" (apply str (interpose ", " (map format-kv kv))) "]"))))
|
||||
|
||||
(defn- dump-page-shape
|
||||
[shape keys padding show-refs?]
|
||||
(println (str/pad (str padding
|
||||
(when (and (:main-instance shape) show-refs?) "{")
|
||||
(thi/label (:id shape))
|
||||
(when (and (:main-instance shape) show-refs?) "}")
|
||||
(when (seq keys)
|
||||
(stringify-keys shape keys)))
|
||||
{:length 50 :type :right})
|
||||
(if (nil? (:shape-ref shape))
|
||||
(if (and (:component-root shape) show-refs?)
|
||||
(str "# [Component " (thi/label (:component-id shape)) "]")
|
||||
"")
|
||||
(if show-refs?
|
||||
(str/format "%s--> %s%s"
|
||||
(cond (:component-root shape) "#"
|
||||
(:component-id shape) "@"
|
||||
:else "-")
|
||||
(if (:component-root shape)
|
||||
(str "[Component " (thi/label (:component-id shape)) "] ")
|
||||
"")
|
||||
(thi/label (:shape-ref shape)))
|
||||
""))))
|
||||
|
||||
(defn dump-page
|
||||
"Dump the layer tree of the page, showing labels of the shapes.
|
||||
- keys: a list of attributes of the shapes you want to show. In addition, you
|
||||
can add :swap-slot to show the slot id (if any) or :swap-slot-label
|
||||
to show the corresponding label.
|
||||
- show-refs?: if true, the component references will be shown."
|
||||
[page & {:keys [keys root-id padding show-refs?]
|
||||
:or {keys [:name :swap-slot-label] root-id uuid/zero padding "" show-refs? true}}]
|
||||
(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 show-refs?)
|
||||
(dump-page page
|
||||
:keys keys
|
||||
:root-id (:id shape)
|
||||
:padding (str padding " ")
|
||||
:show-refs? show-refs?))))
|
||||
|
||||
(defn dump-file
|
||||
"Dump the current page of the file, using dump-page above.
|
||||
Example: (thf/dump-file file :keys [:name :swap-slot-label] :show-refs? false)"
|
||||
[file & {:keys [] :as params}]
|
||||
(dump-page (current-page file) params))
|
||||
@@ -1,43 +0,0 @@
|
||||
;; 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.ids-map
|
||||
(:require
|
||||
[app.common.uuid :as uuid]))
|
||||
|
||||
;; ---- Helpers to manage ids as known identifiers
|
||||
|
||||
(def ^:private idmap (atom {}))
|
||||
|
||||
(defn reset-idmap! []
|
||||
(reset! idmap {}))
|
||||
|
||||
(defn set-id!
|
||||
[label id]
|
||||
(swap! idmap assoc label id))
|
||||
|
||||
(defn new-id!
|
||||
[label]
|
||||
(let [id (uuid/next)]
|
||||
(set-id! label id)
|
||||
id))
|
||||
|
||||
(defn id
|
||||
[label]
|
||||
(get @idmap label))
|
||||
|
||||
(defn test-fixture
|
||||
;; Ensure that each test starts with a clean ids map
|
||||
[f]
|
||||
(reset-idmap!)
|
||||
(f))
|
||||
|
||||
(defn label [id]
|
||||
(or (->> @idmap
|
||||
(filter #(= id (val %)))
|
||||
(map key)
|
||||
(first))
|
||||
(str "<no-label #" (subs (str id) (- (count (str id)) 6)) ">")))
|
||||
@@ -1,101 +0,0 @@
|
||||
;; 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))))
|
||||
@@ -6,21 +6,16 @@
|
||||
|
||||
(ns common-tests.logic.chained-propagation-test
|
||||
(:require
|
||||
[app.common.files.changes :as ch]
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.pprint :as pp]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.components :as thc]
|
||||
[common-tests.helpers.compositions :as tho]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[common-tests.helpers.shapes :as ths]))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
@@ -55,8 +50,6 @@
|
||||
|
||||
(step-update-color-comp-2 [file]
|
||||
(let [page (thf/current-page file)
|
||||
file-id (:id file)
|
||||
page-id (:id page)
|
||||
|
||||
;; Changes to update the color of the contained rectangle in component comp-2
|
||||
changes-update-color-comp-1
|
||||
@@ -75,7 +68,6 @@
|
||||
(step-propagate-comp-2 [file]
|
||||
(let [page (thf/current-page file)
|
||||
file-id (:id file)
|
||||
page-id (:id page)
|
||||
|
||||
;; Changes to propagate the color changes of component comp-1
|
||||
changes-sync-comp-1 (-> (pcb/empty-changes)
|
||||
@@ -108,8 +100,7 @@
|
||||
(:objects page)
|
||||
{})
|
||||
|
||||
file' (thf/apply-changes file changes-update-color-comp-3)
|
||||
page' (thf/current-page file')]
|
||||
file' (thf/apply-changes file changes-update-color-comp-3)]
|
||||
|
||||
(t/is (= (first-child-fill-color file' :comp-1-comp-2) "#00FF00"))
|
||||
file'))
|
||||
@@ -168,7 +159,6 @@
|
||||
|
||||
(step-update-color-comp-4 [file]
|
||||
(let [page (thf/current-page file)
|
||||
file-id (:id file)
|
||||
;; Changes to update the color of the contained rectangle in component comp-4
|
||||
changes-update-color-comp-4
|
||||
(cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
@@ -184,8 +174,7 @@
|
||||
file'))
|
||||
|
||||
(step-propagate-comp-4 [file]
|
||||
(let [page (thf/current-page file)
|
||||
file-id (:id file)
|
||||
(let [file-id (:id file)
|
||||
;; Changes to propagate the color changes of component comp-4
|
||||
changes-sync-comp-4 (-> (pcb/empty-changes)
|
||||
(cll/generate-sync-file-changes
|
||||
|
||||
@@ -12,15 +12,15 @@
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.components :as thc]
|
||||
[common-tests.helpers.compositions :as tho]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[common-tests.helpers.shapes :as ths]))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
||||
@@ -10,19 +10,18 @@
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.components :as thc]
|
||||
[common-tests.helpers.compositions :as tho]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[common-tests.helpers.shapes :as ths]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
||||
;; Related .penpot file: common/test/cases/remove-swap-slots.penpot
|
||||
(defn- setup-file
|
||||
[]
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.components :as thc]
|
||||
[common-tests.helpers.compositions :as tho]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[common-tests.helpers.shapes :as ths]))
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
||||
@@ -8,19 +8,16 @@
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.files.shapes-helpers :as cfsh]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.components :as thc]
|
||||
[common-tests.helpers.compositions :as tho]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[common-tests.helpers.shapes :as ths]))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.components :as thc]
|
||||
[common-tests.helpers.compositions :as tho]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[common-tests.helpers.shapes :as ths]))
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.file :as ctf]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.components :as thc]
|
||||
[common-tests.helpers.compositions :as tho]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[common-tests.helpers.shapes :as ths]))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
(ns common-tests.types.types-libraries-test
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.text :as txt]
|
||||
[app.common.types.colors-list :as ctcl]
|
||||
[app.common.types.component :as ctk]
|
||||
@@ -14,12 +19,7 @@
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.types.pages-list :as ctpl]
|
||||
[app.common.types.typographies-list :as ctyl]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.components :as thc]
|
||||
[common-tests.helpers.compositions :as tho]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[common-tests.helpers.shapes :as ths]))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user