mirror of
https://github.com/penpot/penpot.git
synced 2025-03-15 01:01:30 -05:00
✅ Add new helper functions for common tests
This commit is contained in:
parent
1026f5b972
commit
dde89e60dd
12 changed files with 556 additions and 452 deletions
|
@ -6,13 +6,10 @@
|
||||||
|
|
||||||
(ns app.rpc.commands.files-create
|
(ns app.rpc.commands.files-create
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.features :as cfeat]
|
[app.common.features :as cfeat]
|
||||||
[app.common.files.defaults :refer [version]]
|
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.types.file :as ctf]
|
[app.common.types.file :as ctf]
|
||||||
[app.common.uuid :as uuid]
|
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.features.fdata :as feat.fdata]
|
[app.features.fdata :as feat.fdata]
|
||||||
|
@ -40,7 +37,7 @@
|
||||||
(defn create-file
|
(defn create-file
|
||||||
[{:keys [::db/conn] :as cfg}
|
[{:keys [::db/conn] :as cfg}
|
||||||
{:keys [id name project-id is-shared revn
|
{:keys [id name project-id is-shared revn
|
||||||
modified-at deleted-at create-page
|
modified-at deleted-at create-page page-id
|
||||||
ignore-sync-until features]
|
ignore-sync-until features]
|
||||||
:or {is-shared false revn 0 create-page true}
|
:or {is-shared false revn 0 create-page true}
|
||||||
:as params}]
|
:as params}]
|
||||||
|
@ -51,23 +48,17 @@
|
||||||
|
|
||||||
(binding [pmap/*tracked* (pmap/create-tracked)
|
(binding [pmap/*tracked* (pmap/create-tracked)
|
||||||
cfeat/*current* features]
|
cfeat/*current* features]
|
||||||
(let [id (or id (uuid/next))
|
(let [file (ctf/make-file {:id id
|
||||||
|
:project-id project-id
|
||||||
data (if create-page
|
:name name
|
||||||
(ctf/make-file-data id)
|
:revn revn
|
||||||
(ctf/make-file-data id nil))
|
:is-shared is-shared
|
||||||
|
:features features
|
||||||
file {:id id
|
:ignore-sync-until ignore-sync-until
|
||||||
:project-id project-id
|
:modified-at modified-at
|
||||||
:name name
|
:deleted-at deleted-at
|
||||||
:revn revn
|
:create-page create-page
|
||||||
:is-shared is-shared
|
:page-id page-id})
|
||||||
:version version
|
|
||||||
:data data
|
|
||||||
:features features
|
|
||||||
:ignore-sync-until ignore-sync-until
|
|
||||||
:modified-at modified-at
|
|
||||||
:deleted-at deleted-at}
|
|
||||||
|
|
||||||
file (if (contains? features "fdata/objects-map")
|
file (if (contains? features "fdata/objects-map")
|
||||||
(feat.fdata/enable-objects-map file)
|
(feat.fdata/enable-objects-map file)
|
||||||
|
@ -75,9 +66,7 @@
|
||||||
|
|
||||||
file (if (contains? features "fdata/pointer-map")
|
file (if (contains? features "fdata/pointer-map")
|
||||||
(feat.fdata/enable-pointer-map file)
|
(feat.fdata/enable-pointer-map file)
|
||||||
file)
|
file)]
|
||||||
|
|
||||||
file (d/without-nils file)]
|
|
||||||
|
|
||||||
(db/insert! conn :file
|
(db/insert! conn :file
|
||||||
(-> file
|
(-> file
|
||||||
|
@ -86,9 +75,9 @@
|
||||||
{::db/return-keys false})
|
{::db/return-keys false})
|
||||||
|
|
||||||
(when (contains? features "fdata/pointer-map")
|
(when (contains? features "fdata/pointer-map")
|
||||||
(feat.fdata/persist-pointers! cfg id))
|
(feat.fdata/persist-pointers! cfg (:id file)))
|
||||||
|
|
||||||
(->> (assoc params :file-id id :role :owner)
|
(->> (assoc params :file-id (:id file) :role :owner)
|
||||||
(create-file-role! conn))
|
(create-file-role! conn))
|
||||||
|
|
||||||
(db/update! conn :project
|
(db/update! conn :project
|
||||||
|
|
|
@ -147,7 +147,7 @@
|
||||||
[file data]
|
[file data]
|
||||||
(dm/assert! (nil? (:current-component-id file)))
|
(dm/assert! (nil? (:current-component-id file)))
|
||||||
(let [page-id (or (:id data) (uuid/next))
|
(let [page-id (or (:id data) (uuid/next))
|
||||||
page (-> (ctp/make-empty-page page-id "Page 1")
|
page (-> (ctp/make-empty-page {:id page-id :name "Page 1"})
|
||||||
(d/deep-merge data))]
|
(d/deep-merge data))]
|
||||||
(-> file
|
(-> file
|
||||||
(commit-change
|
(commit-change
|
||||||
|
|
|
@ -578,7 +578,7 @@
|
||||||
(ex/raise :type :conflict
|
(ex/raise :type :conflict
|
||||||
:hint "id+name or page should be provided, never both"))
|
:hint "id+name or page should be provided, never both"))
|
||||||
(let [page (if (and (string? name) (uuid? id))
|
(let [page (if (and (string? name) (uuid? id))
|
||||||
(ctp/make-empty-page id name)
|
(ctp/make-empty-page {:id id :name name})
|
||||||
page)]
|
page)]
|
||||||
(ctpl/add-page data page)))
|
(ctpl/add-page data page)))
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
[app.common.types.color.generic :as-alias color-generic]
|
[app.common.types.color.generic :as-alias color-generic]
|
||||||
[app.common.types.color.gradient :as-alias color-gradient]
|
[app.common.types.color.gradient :as-alias color-gradient]
|
||||||
[app.common.types.color.gradient.stop :as-alias color-gradient-stop]
|
[app.common.types.color.gradient.stop :as-alias color-gradient-stop]
|
||||||
|
[app.common.uuid :as uuid]
|
||||||
[clojure.test.check.generators :as tgen]))
|
[clojure.test.check.generators :as tgen]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -105,6 +106,22 @@
|
||||||
;; HELPERS
|
;; HELPERS
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
;; --- factory
|
||||||
|
|
||||||
|
(defn make-color
|
||||||
|
[{:keys [id name path value color opacity ref-id ref-file gradient image]}]
|
||||||
|
(-> {:id (or id (uuid/next))
|
||||||
|
:name (or name color "Black")
|
||||||
|
:path path
|
||||||
|
:value value
|
||||||
|
:color (or color "#000000")
|
||||||
|
:opacity (or opacity 1)
|
||||||
|
:ref-id ref-id
|
||||||
|
:ref-file ref-file
|
||||||
|
:gradient gradient
|
||||||
|
:image image}
|
||||||
|
(d/without-nils)))
|
||||||
|
|
||||||
;; --- fill
|
;; --- fill
|
||||||
|
|
||||||
(defn fill->shape-color
|
(defn fill->shape-color
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.features :as cfeat]
|
[app.common.features :as cfeat]
|
||||||
|
[app.common.files.defaults :refer [version]]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
|
@ -78,7 +79,7 @@
|
||||||
|
|
||||||
([file-id page-id]
|
([file-id page-id]
|
||||||
(let [page (when (some? page-id)
|
(let [page (when (some? page-id)
|
||||||
(ctp/make-empty-page page-id "Page 1"))]
|
(ctp/make-empty-page {:id page-id :name "Page 1"}))]
|
||||||
|
|
||||||
(cond-> (assoc empty-file-data :id file-id)
|
(cond-> (assoc empty-file-data :id file-id)
|
||||||
(some? page-id)
|
(some? page-id)
|
||||||
|
@ -87,6 +88,34 @@
|
||||||
(contains? cfeat/*current* "components/v2")
|
(contains? cfeat/*current* "components/v2")
|
||||||
(assoc-in [:options :components-v2] true)))))
|
(assoc-in [:options :components-v2] true)))))
|
||||||
|
|
||||||
|
(defn make-file
|
||||||
|
[{:keys [id project-id name revn is-shared features
|
||||||
|
ignore-sync-until modified-at deleted-at
|
||||||
|
create-page page-id]
|
||||||
|
:or {is-shared false revn 0 create-page true}}]
|
||||||
|
|
||||||
|
(let [id (or id (uuid/next))
|
||||||
|
|
||||||
|
data (if create-page
|
||||||
|
(if page-id
|
||||||
|
(make-file-data id page-id)
|
||||||
|
(make-file-data id))
|
||||||
|
(make-file-data id nil))
|
||||||
|
|
||||||
|
file {:id id
|
||||||
|
:project-id project-id
|
||||||
|
:name name
|
||||||
|
:revn revn
|
||||||
|
:is-shared is-shared
|
||||||
|
:version version
|
||||||
|
:data data
|
||||||
|
:features features
|
||||||
|
:ignore-sync-until ignore-sync-until
|
||||||
|
:modified-at modified-at
|
||||||
|
:deleted-at deleted-at}]
|
||||||
|
|
||||||
|
(d/without-nils file)))
|
||||||
|
|
||||||
;; Helpers
|
;; Helpers
|
||||||
|
|
||||||
(defn file-data
|
(defn file-data
|
||||||
|
@ -457,7 +486,7 @@
|
||||||
(gpt/point 0 0)
|
(gpt/point 0 0)
|
||||||
(ctn/shapes-seq library-page))]
|
(ctn/shapes-seq library-page))]
|
||||||
[file-data (:id library-page) position])
|
[file-data (:id library-page) position])
|
||||||
(let [library-page (ctp/make-empty-page (uuid/next) "Main components")]
|
(let [library-page (ctp/make-empty-page {:id (uuid/next) :name "Main components"})]
|
||||||
[(ctpl/add-page file-data library-page) (:id library-page) (gpt/point 0 0)]))))
|
[(ctpl/add-page file-data library-page) (:id library-page) (gpt/point 0 0)]))))
|
||||||
|
|
||||||
(defn- absorb-components
|
(defn- absorb-components
|
||||||
|
|
|
@ -69,10 +69,10 @@
|
||||||
:name "Root Frame"})}})
|
:name "Root Frame"})}})
|
||||||
|
|
||||||
(defn make-empty-page
|
(defn make-empty-page
|
||||||
[id name]
|
[{:keys [id name]}]
|
||||||
(-> empty-page-data
|
(-> empty-page-data
|
||||||
(assoc :id id)
|
(assoc :id (or id (uuid/next)))
|
||||||
(assoc :name name)))
|
(assoc :name (or name "Page 1"))))
|
||||||
|
|
||||||
;; --- Helpers for flow
|
;; --- Helpers for flow
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
|
|
||||||
(ns app.common.types.typography
|
(ns app.common.types.typography
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data :as d]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.text :as txt]))
|
[app.common.text :as txt]
|
||||||
|
[app.common.uuid :as uuid]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; SCHEMA
|
;; SCHEMA
|
||||||
|
@ -36,6 +38,23 @@
|
||||||
;; HELPERS
|
;; HELPERS
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defn make-typography
|
||||||
|
[{:keys [id name path font-id font-family font-variant-id font-size
|
||||||
|
font-weight font-style line-height letter-spacing text-transform]}]
|
||||||
|
(-> {:id (or id (uuid/next))
|
||||||
|
:name (or name "Typography 1")
|
||||||
|
:path path
|
||||||
|
:font-id (or font-id "sourcesanspro")
|
||||||
|
:font-family (or font-family "sourcesanspro")
|
||||||
|
:font-variant-id (or font-variant-id "regular")
|
||||||
|
:font-size (or font-size "14")
|
||||||
|
:font-weight (or font-weight "480")
|
||||||
|
:font-style (or font-style "normal")
|
||||||
|
:line-height (or line-height "1.2")
|
||||||
|
:letter-spacing (or letter-spacing "0")
|
||||||
|
:text-transform (or text-transform "none")}
|
||||||
|
(d/without-nils)))
|
||||||
|
|
||||||
(defn uses-library-typographies?
|
(defn uses-library-typographies?
|
||||||
"Check if the shape uses any typography in the given library."
|
"Check if the shape uses any typography in the given library."
|
||||||
[shape library-id]
|
[shape library-id]
|
||||||
|
|
|
@ -1,146 +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.files.helpers :as cfh]
|
|
||||||
[app.common.types.component :as ctk]
|
|
||||||
[app.common.types.container :as ctn]
|
|
||||||
[app.common.types.file :as ctf]
|
|
||||||
[clojure.test :as t]))
|
|
||||||
|
|
||||||
;; ---- Helpers to manage libraries and synchronization
|
|
||||||
|
|
||||||
(defn check-instance-root
|
|
||||||
[shape]
|
|
||||||
(t/is (some? (:shape-ref shape)))
|
|
||||||
(t/is (some? (:component-id shape)))
|
|
||||||
(t/is (= (:component-root shape) true)))
|
|
||||||
|
|
||||||
(defn check-instance-subroot
|
|
||||||
[shape]
|
|
||||||
(t/is (some? (:shape-ref shape)))
|
|
||||||
(t/is (some? (:component-id shape)))
|
|
||||||
(t/is (nil? (:component-root shape))))
|
|
||||||
|
|
||||||
(defn check-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 check-instance-inner
|
|
||||||
[shape]
|
|
||||||
(if (some? (:component-id shape))
|
|
||||||
(check-instance-subroot shape)
|
|
||||||
(check-instance-child shape)))
|
|
||||||
|
|
||||||
(defn check-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 check-from-file
|
|
||||||
[shape file]
|
|
||||||
(t/is (= (:component-file shape)
|
|
||||||
(:id file))))
|
|
||||||
|
|
||||||
(defn resolve-instance
|
|
||||||
"Get the shape with the given id and all its children, and
|
|
||||||
verify that they are a well constructed instance tree."
|
|
||||||
[page root-inst-id]
|
|
||||||
(let [root-inst (ctn/get-shape page root-inst-id)
|
|
||||||
shapes-inst (cfh/get-children-with-self (:objects page)
|
|
||||||
root-inst-id)]
|
|
||||||
(check-instance-root (first shapes-inst))
|
|
||||||
(run! check-instance-inner (rest shapes-inst))
|
|
||||||
|
|
||||||
shapes-inst))
|
|
||||||
|
|
||||||
(defn resolve-noninstance
|
|
||||||
"Get the shape with the given id and all its children, and
|
|
||||||
verify that they are not a component instance."
|
|
||||||
[page root-inst-id]
|
|
||||||
(let [root-inst (ctn/get-shape page root-inst-id)
|
|
||||||
shapes-inst (cfh/get-children-with-self (:objects page)
|
|
||||||
root-inst-id)]
|
|
||||||
(run! check-noninstance shapes-inst)
|
|
||||||
|
|
||||||
shapes-inst))
|
|
||||||
|
|
||||||
(defn resolve-instance-and-main
|
|
||||||
"Get the shape with the given id and all its children, and also
|
|
||||||
the main component and all its shapes."
|
|
||||||
[page root-inst-id libraries]
|
|
||||||
(let [root-inst (ctn/get-shape page root-inst-id)
|
|
||||||
|
|
||||||
component (ctf/get-component libraries (:component-file root-inst) (:component-id root-inst))
|
|
||||||
|
|
||||||
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
|
|
||||||
shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst))
|
|
||||||
|
|
||||||
unique-refs (into #{} (map :shape-ref) shapes-inst)
|
|
||||||
|
|
||||||
main-exists? (fn [shape]
|
|
||||||
(let [component-shape
|
|
||||||
(ctn/get-component-shape (:objects page) shape)
|
|
||||||
|
|
||||||
component
|
|
||||||
(ctf/get-component libraries (:component-file component-shape) (:component-id component-shape))
|
|
||||||
|
|
||||||
main-shape
|
|
||||||
(ctn/get-shape component (:shape-ref shape))]
|
|
||||||
|
|
||||||
(t/is (some? main-shape))))]
|
|
||||||
|
|
||||||
;; Validate that the instance tree is well constructed
|
|
||||||
(check-instance-root (first shapes-inst))
|
|
||||||
(run! check-instance-inner (rest shapes-inst))
|
|
||||||
(t/is (= (count shapes-inst)
|
|
||||||
(count shapes-main)
|
|
||||||
(count unique-refs)))
|
|
||||||
(run! main-exists? shapes-inst)
|
|
||||||
|
|
||||||
[shapes-inst shapes-main component]))
|
|
||||||
|
|
||||||
(defn resolve-instance-and-main-allow-dangling
|
|
||||||
"Get the shape with the given id and all its children, and also
|
|
||||||
the main component and all its shapes. Allows shapes with the
|
|
||||||
corresponding component shape missing."
|
|
||||||
[page root-inst-id libraries]
|
|
||||||
(let [root-inst (ctn/get-shape page root-inst-id)
|
|
||||||
|
|
||||||
component (ctf/get-component libraries (:component-file root-inst) (:component-id root-inst))
|
|
||||||
|
|
||||||
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
|
|
||||||
shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst))
|
|
||||||
|
|
||||||
unique-refs (into #{} (map :shape-ref) shapes-inst)
|
|
||||||
|
|
||||||
main-exists? (fn [shape]
|
|
||||||
(let [component-shape
|
|
||||||
(ctn/get-component-shape (:objects page) shape)
|
|
||||||
|
|
||||||
component
|
|
||||||
(ctf/get-component libraries (:component-file component-shape) (:component-id component-shape))
|
|
||||||
|
|
||||||
main-shape
|
|
||||||
(ctn/get-shape component (:shape-ref shape))]
|
|
||||||
|
|
||||||
(t/is (some? main-shape))))]
|
|
||||||
|
|
||||||
;; Validate that the instance tree is well constructed
|
|
||||||
(check-instance-root (first shapes-inst))
|
|
||||||
|
|
||||||
[shapes-inst shapes-main component]))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,150 +6,278 @@
|
||||||
|
|
||||||
(ns common-tests.helpers.files
|
(ns common-tests.helpers.files
|
||||||
(:require
|
(:require
|
||||||
|
[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.helpers :as cfh]
|
||||||
|
[app.common.files.validate :as cfv]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
[app.common.pprint :refer [pprint]]
|
||||||
|
[app.common.types.color :as ctc]
|
||||||
[app.common.types.colors-list :as ctcl]
|
[app.common.types.colors-list :as ctcl]
|
||||||
[app.common.types.components-list :as ctkl]
|
[app.common.types.components-list :as ctkl]
|
||||||
[app.common.types.container :as ctn]
|
[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.pages-list :as ctpl]
|
[app.common.types.pages-list :as ctpl]
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
[app.common.types.shape-tree :as ctst]
|
[app.common.types.shape-tree :as ctst]
|
||||||
[app.common.types.typographies-list :as ctyl]
|
[app.common.types.typographies-list :as cttl]
|
||||||
[app.common.uuid :as uuid]))
|
[app.common.types.typography :as ctt]
|
||||||
|
[common-tests.helpers.ids-map :as thi]))
|
||||||
|
|
||||||
(defn- make-file-data
|
;; ----- Files
|
||||||
[file-id page-id]
|
|
||||||
(binding [ffeat/*current* #{"components/v2"}]
|
|
||||||
(ctf/make-file-data file-id page-id)))
|
|
||||||
|
|
||||||
(def ^:private idmap (atom {}))
|
|
||||||
|
|
||||||
(defn reset-idmap!
|
|
||||||
[next]
|
|
||||||
(reset! idmap {})
|
|
||||||
(next))
|
|
||||||
|
|
||||||
(defn id
|
|
||||||
[label]
|
|
||||||
(get @idmap label))
|
|
||||||
|
|
||||||
(defn sample-file
|
(defn sample-file
|
||||||
([file-id page-id] (sample-file file-id page-id nil))
|
[label & {:keys [page-label name] :as params}]
|
||||||
([file-id page-id props]
|
(binding [ffeat/*current* #{"components/v2"}]
|
||||||
(merge {:id file-id
|
(let [params (cond-> params
|
||||||
:name (get props :name "File1")
|
label
|
||||||
:data (make-file-data file-id page-id)}
|
(assoc :id (thi/new-id! label))
|
||||||
props)))
|
|
||||||
|
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'))
|
||||||
|
|
||||||
|
(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
|
||||||
|
|
||||||
|
(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)))
|
||||||
|
|
||||||
|
;; ----- Shapes
|
||||||
|
|
||||||
(defn sample-shape
|
(defn sample-shape
|
||||||
[file label type page-id props]
|
[label & {:keys [type] :as params}]
|
||||||
(ctf/update-file-data
|
(let [params (cond-> params
|
||||||
file
|
label
|
||||||
(fn [file-data]
|
(assoc :id (thi/new-id! label))
|
||||||
(let [frame-id (get props :frame-id uuid/zero)
|
|
||||||
parent-id (get props :parent-id uuid/zero)
|
|
||||||
shape (cts/setup-shape
|
|
||||||
(-> {:type type
|
|
||||||
:width 1
|
|
||||||
:height 1}
|
|
||||||
(merge props)))]
|
|
||||||
|
|
||||||
(swap! idmap assoc label (:id shape))
|
(nil? type)
|
||||||
|
(assoc :type :rect))]
|
||||||
|
|
||||||
|
(cts/setup-shape params)))
|
||||||
|
|
||||||
|
(defn add-sample-shape
|
||||||
|
[file label & {:keys [parent-label] :as params}]
|
||||||
|
(let [page (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
|
(ctpl/update-page file-data
|
||||||
page-id
|
(:id page)
|
||||||
#(ctst/add-shape (:id shape)
|
#(ctst/add-shape (:id shape)
|
||||||
shape
|
shape
|
||||||
%
|
%
|
||||||
frame-id
|
frame-id
|
||||||
parent-id
|
parent-id
|
||||||
0
|
nil
|
||||||
true))))))
|
true))))))
|
||||||
|
|
||||||
(defn sample-component
|
(defn get-shape
|
||||||
[file label page-id shape-id]
|
[file label & {:keys [page-label]}]
|
||||||
(ctf/update-file-data
|
(let [page (if page-label
|
||||||
file
|
(get-page file page-label)
|
||||||
(fn [file-data]
|
(current-page file))]
|
||||||
(let [page (ctpl/get-page file-data page-id)
|
(ctst/get-shape page (thi/id label))))
|
||||||
|
|
||||||
[component-shape component-shapes updated-shapes]
|
(defn get-shape-by-id
|
||||||
(ctn/make-component-shape (ctn/get-shape page shape-id)
|
[file id & {:keys [page-label]}]
|
||||||
(:objects page)
|
(let [page (if page-label
|
||||||
(:id file)
|
(get-page file page-label)
|
||||||
true)]
|
(current-page file))]
|
||||||
|
(ctst/get-shape page id)))
|
||||||
|
|
||||||
(swap! idmap assoc label (:id component-shape))
|
;; ----- Components
|
||||||
(-> file-data
|
|
||||||
(ctpl/update-page page-id
|
|
||||||
#(reduce (fn [page shape] (ctst/set-shape page shape))
|
|
||||||
%
|
|
||||||
updated-shapes))
|
|
||||||
(ctkl/add-component {:id (:id component-shape)
|
|
||||||
:name (:name component-shape)
|
|
||||||
:path ""
|
|
||||||
:main-instance-id shape-id
|
|
||||||
:main-instance-page page-id
|
|
||||||
:shapes component-shapes}))))))
|
|
||||||
|
|
||||||
(defn sample-instance
|
(defn make-component
|
||||||
[file label page-id library component-id]
|
[file label root-label]
|
||||||
(ctf/update-file-data
|
(let [page (current-page file)
|
||||||
file
|
root (get-shape file root-label)]
|
||||||
(fn [file-data]
|
|
||||||
(let [[instance-shape instance-shapes]
|
|
||||||
(ctn/make-component-instance (ctpl/get-page file-data page-id)
|
|
||||||
(ctkl/get-component (:data library) component-id)
|
|
||||||
(:data library)
|
|
||||||
(gpt/point 0 0)
|
|
||||||
true)]
|
|
||||||
|
|
||||||
(swap! idmap assoc label (:id instance-shape))
|
(dm/assert!
|
||||||
(-> file-data
|
"Need that root is already a frame"
|
||||||
(ctpl/update-page page-id
|
(cfh/frame-shape? root))
|
||||||
#(reduce (fn [page shape]
|
|
||||||
(ctst/add-shape (:id shape)
|
(let [[_new-root _new-shapes updated-shapes]
|
||||||
shape
|
(ctn/convert-shape-in-component root (:objects page) (:id file))
|
||||||
page
|
|
||||||
uuid/zero
|
updated-root (first updated-shapes)] ; Can't use new-root because it has a new id
|
||||||
(:parent-id shape)
|
|
||||||
0
|
(thi/set-id! label (:component-id updated-root))
|
||||||
true))
|
|
||||||
%
|
(ctf/update-file-data
|
||||||
instance-shapes)))))))
|
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 $
|
||||||
|
{: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 instantiate-component
|
||||||
|
[file component-label copy-root-label & {:keys [parent-label library] :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))]
|
||||||
|
|
||||||
|
(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)))))))
|
||||||
|
|
||||||
(defn sample-color
|
(defn sample-color
|
||||||
[file label props]
|
[label & {:keys [] :as params}]
|
||||||
(ctf/update-file-data
|
(ctc/make-color (assoc params :id (thi/new-id! label))))
|
||||||
file
|
|
||||||
(fn [file-data]
|
(defn add-sample-color
|
||||||
(let [id (uuid/next)
|
[file label & {:keys [] :as params}]
|
||||||
props (merge {:id id
|
(let [color (sample-color label params)]
|
||||||
:name "Color 1"
|
(ctf/update-file-data file #(ctcl/add-color % color))))
|
||||||
:color "#000000"
|
|
||||||
:opacity 1}
|
|
||||||
props)]
|
|
||||||
(swap! idmap assoc label id)
|
|
||||||
(ctcl/add-color file-data props)))))
|
|
||||||
|
|
||||||
(defn sample-typography
|
(defn sample-typography
|
||||||
[file label props]
|
[label & {:keys [] :as params}]
|
||||||
(ctf/update-file-data
|
(ctt/make-typography (assoc params :id (thi/new-id! label))))
|
||||||
file
|
|
||||||
(fn [file-data]
|
|
||||||
(let [id (uuid/next)
|
|
||||||
props (merge {:id id
|
|
||||||
:name "Typography 1"
|
|
||||||
:font-id "sourcesanspro"
|
|
||||||
:font-family "sourcesanspro"
|
|
||||||
:font-size "14"
|
|
||||||
:font-style "normal"
|
|
||||||
:font-variant-id "regular"
|
|
||||||
:font-weight "400"
|
|
||||||
:line-height "1.2"
|
|
||||||
:letter-spacing "0"
|
|
||||||
:text-transform "none"}
|
|
||||||
props)]
|
|
||||||
(swap! idmap assoc label id)
|
|
||||||
(ctyl/add-typography file-data props)))))
|
|
||||||
|
|
||||||
|
(defn add-sample-typography
|
||||||
|
[file label & {:keys [] :as params}]
|
||||||
|
(let [typography (sample-typography label params)]
|
||||||
|
(ctf/update-file-data file #(cttl/add-typography % typography))))
|
||||||
|
|
36
common/test/common_tests/helpers/ids_map.cljc
Normal file
36
common/test/common_tests/helpers/ids_map.cljc
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
;; 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))
|
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
(t/testing "unknown assoc"
|
(t/testing "unknown assoc"
|
||||||
(let [o (assoc o :c 176)]
|
(let [o (assoc o :c 176)]
|
||||||
(prn o)
|
|
||||||
(t/is (= 1 (:a o)))
|
(t/is (= 1 (:a o)))
|
||||||
(t/is (= 2 (:b o)))
|
(t/is (= 2 (:b o)))
|
||||||
(t/is (= 176 (:c o)))))
|
(t/is (= 176 (:c o)))))
|
||||||
|
|
|
@ -7,201 +7,234 @@
|
||||||
(ns common-tests.types-file-test
|
(ns common-tests.types-file-test
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.files.changes-builder :as pcb]
|
||||||
|
[app.common.files.libraries-helpers :as cflh]
|
||||||
[app.common.text :as txt]
|
[app.common.text :as txt]
|
||||||
[app.common.types.colors-list :as ctcl]
|
[app.common.types.colors-list :as ctcl]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
[app.common.types.components-list :as ctkl]
|
[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.pages-list :as ctpl]
|
[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 ctyl]
|
[app.common.types.typographies-list :as ctyl]
|
||||||
[app.common.uuid :as uuid]
|
|
||||||
[clojure.pprint :refer [pprint]]
|
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[common-tests.helpers.components :as thk]
|
|
||||||
[common-tests.helpers.files :as thf]
|
[common-tests.helpers.files :as thf]
|
||||||
[cuerdas.core :as str]))
|
[common-tests.helpers.ids-map :as thi]))
|
||||||
|
|
||||||
(t/use-fixtures :each thf/reset-idmap!)
|
(t/use-fixtures :each thi/test-fixture)
|
||||||
|
|
||||||
#_(t/deftest test-absorb-components
|
(t/deftest test-create-file
|
||||||
(let [library-id (uuid/custom 1 1)
|
(let [f1 (thf/sample-file :file1)
|
||||||
library-page-id (uuid/custom 2 2)
|
f2 (thf/sample-file :file2 :page-label :page1)
|
||||||
file-id (uuid/custom 3 3)
|
f3 (thf/sample-file :file3 :name "testing file")
|
||||||
file-page-id (uuid/custom 4 4)
|
f4 (-> (thf/sample-file :file4 :page-label :page2)
|
||||||
|
(thf/add-sample-page :page3 :name "testing page")
|
||||||
|
(thf/add-sample-shape :shape1))
|
||||||
|
f5 (-> f4
|
||||||
|
(thf/add-sample-shape :shape2)
|
||||||
|
(thf/switch-to-page :page2)
|
||||||
|
(thf/add-sample-shape :shape3 :name "testing shape" :width 100))
|
||||||
|
s1 (thf/get-shape f4 :shape1)
|
||||||
|
s2 (thf/get-shape f5 :shape2 :page-label :page3)
|
||||||
|
s3 (thf/get-shape f5 :shape3)]
|
||||||
|
|
||||||
library (-> (thf/sample-file library-id library-page-id {:is-shared true})
|
;; (thf/pprint-file f4)
|
||||||
(thf/sample-shape :group1
|
|
||||||
:group
|
|
||||||
library-page-id
|
|
||||||
{:name "Group1"})
|
|
||||||
(thf/sample-shape :shape1
|
|
||||||
:rect
|
|
||||||
library-page-id
|
|
||||||
{:name "Rect1"
|
|
||||||
:parent-id (thf/id :group1)})
|
|
||||||
(thf/sample-component :component1
|
|
||||||
library-page-id
|
|
||||||
(thf/id :group1)))
|
|
||||||
|
|
||||||
file (-> (thf/sample-file file-id file-page-id)
|
(t/is (= (:name f1) "Test file"))
|
||||||
(thf/sample-instance :instance1
|
(t/is (= (:name f3) "testing file"))
|
||||||
file-page-id
|
(t/is (= (:id f2) (thi/id :file2)))
|
||||||
library
|
(t/is (= (:id f4) (thi/id :file4)))
|
||||||
(thf/id :component1)))
|
(t/is (= (-> f4 :data :pages-index vals first :id) (thi/id :page2)))
|
||||||
|
(t/is (= (-> f4 :data :pages-index vals first :name) "Page 1"))
|
||||||
|
(t/is (= (-> f4 :data :pages-index vals second :id) (thi/id :page3)))
|
||||||
|
(t/is (= (-> f4 :data :pages-index vals second :name) "testing page"))
|
||||||
|
|
||||||
absorbed-file (ctf/update-file-data
|
(t/is (= (:id (thf/current-page f2)) (thi/id :page1)))
|
||||||
file
|
(t/is (= (:id (thf/current-page f4)) (thi/id :page3)))
|
||||||
#(ctf/absorb-assets % (:data library)))
|
(t/is (= (:id (thf/current-page f5)) (thi/id :page2)))
|
||||||
|
|
||||||
pages (ctpl/pages-seq (ctf/file-data absorbed-file))
|
(t/is (= (:id s1) (thi/id :shape1)))
|
||||||
components (ctkl/components-seq (ctf/file-data absorbed-file))
|
(t/is (= (:name s1) "Rectangle"))
|
||||||
shapes-1 (ctn/shapes-seq (first pages))
|
(t/is (= (:id s2) (thi/id :shape2)))
|
||||||
shapes-2 (ctn/shapes-seq (second pages))
|
(t/is (= (:name s2) "Rectangle"))
|
||||||
|
(t/is (= (:id s3) (thi/id :shape3)))
|
||||||
|
(t/is (= (:name s3) "testing shape"))
|
||||||
|
(t/is (= (:width s3) 100))
|
||||||
|
(t/is (= (:width (:selrect s3)) 100))))
|
||||||
|
|
||||||
[[p-group p-shape] [c-group1 c-shape1] component1]
|
(t/deftest test-create-components
|
||||||
(thk/resolve-instance-and-main
|
(let [f1 (-> (thf/sample-file :file1)
|
||||||
(first pages)
|
(thf/add-sample-shape :main-root :type :frame)
|
||||||
(:id (second shapes-1))
|
(thf/add-sample-shape :main-child :parent-label :main-root)
|
||||||
{file-id absorbed-file})
|
(thf/make-component :component1 :main-root)
|
||||||
|
(thf/instantiate-component :component1 :copy-root))]
|
||||||
|
|
||||||
[[lp-group lp-shape] [c-group2 c-shape2] component2]
|
#_(thf/dump-file f1)
|
||||||
(thk/resolve-instance-and-main
|
#_(thf/pprint-file f4)
|
||||||
(second pages)
|
|
||||||
(:id (second shapes-2))
|
|
||||||
{file-id absorbed-file})]
|
|
||||||
|
|
||||||
;; Uncomment to debug
|
(t/is (= (:name f1) "Test file"))))
|
||||||
|
|
||||||
;; (println "\n===== library")
|
(t/deftest test-add-component-from-single-shape
|
||||||
;; (ctf/dump-tree (:data library)
|
(let [; Setup
|
||||||
;; library-page-id
|
file (-> (thf/sample-file :file1)
|
||||||
;; {}
|
(thf/add-sample-shape :shape1 :type :frame))
|
||||||
;; true)
|
|
||||||
|
|
||||||
;; (println "\n===== file")
|
page (thf/current-page file)
|
||||||
;; (ctf/dump-tree (:data file)
|
shape1 (thf/get-shape file :shape1)
|
||||||
;; file-page-id
|
|
||||||
;; {library-id library}
|
|
||||||
;; true)
|
|
||||||
|
|
||||||
;; (println "\n===== absorbed file")
|
; Action
|
||||||
;; (println (str "\n<" (:name (first pages)) ">"))
|
[_ component-id changes]
|
||||||
;; (ctf/dump-tree (:data absorbed-file)
|
(cflh/generate-add-component (pcb/empty-changes)
|
||||||
;; (:id (first pages))
|
[shape1]
|
||||||
;; {file-id absorbed-file}
|
(:objects page)
|
||||||
;; false)
|
(:id page)
|
||||||
;; (println (str "\n<" (:name (second pages)) ">"))
|
(:id file)
|
||||||
;; (ctf/dump-tree (:data absorbed-file)
|
true
|
||||||
;; (:id (second pages))
|
nil
|
||||||
;; {file-id absorbed-file}
|
nil)
|
||||||
;; false)
|
|
||||||
|
|
||||||
(t/is (= (count pages) 2))
|
file' (thf/apply-changes file changes)
|
||||||
(t/is (= (:name (first pages)) "Page 1"))
|
|
||||||
(t/is (= (:name (second pages)) "Main components"))
|
|
||||||
|
|
||||||
(t/is (= (count components) 1))
|
; Get
|
||||||
|
component (thf/get-component-by-id file' component-id)
|
||||||
|
root (thf/get-shape-by-id file' (:main-instance-id component))]
|
||||||
|
|
||||||
(t/is (= (:name p-group) "Group1"))
|
; Check
|
||||||
(t/is (ctk/instance-of? p-group file-id (:id component1)))
|
(t/is (some? component))
|
||||||
(t/is (not (:main-instance? p-group)))
|
(t/is (some? root))
|
||||||
(t/is (not (ctk/main-instance-of? (:id p-group) file-page-id component1)))
|
(t/is (= (:component-id root) (:id component)))))
|
||||||
(t/is (ctk/is-main-of? c-group1 p-group))
|
|
||||||
|
|
||||||
(t/is (= (:name p-shape) "Rect1"))
|
(t/deftest test-absorb-components
|
||||||
(t/is (ctk/is-main-of? c-shape1 p-shape))))
|
(let [; Setup
|
||||||
|
library (-> (thf/sample-file :library
|
||||||
|
:is-shared true)
|
||||||
|
(thf/add-sample-shape :main-root
|
||||||
|
:type :frame
|
||||||
|
:name "Frame1")
|
||||||
|
(thf/add-sample-shape :rect1
|
||||||
|
:type :rect
|
||||||
|
:name "Rect1"
|
||||||
|
:parent-label :main-root)
|
||||||
|
(thf/make-component :component1 :main-root))
|
||||||
|
|
||||||
|
file (-> (thf/sample-file :file)
|
||||||
|
(thf/instantiate-component :component1
|
||||||
|
:copy-root
|
||||||
|
:library library))
|
||||||
|
|
||||||
|
; Action
|
||||||
|
file' (ctf/update-file-data
|
||||||
|
file
|
||||||
|
#(ctf/absorb-assets % (:data library)))
|
||||||
|
|
||||||
|
_ (thf/validate-file! file')
|
||||||
|
|
||||||
|
; Get
|
||||||
|
pages' (ctpl/pages-seq (ctf/file-data file'))
|
||||||
|
components' (ctkl/components-seq (ctf/file-data file'))
|
||||||
|
component' (first components')
|
||||||
|
|
||||||
|
copy-root' (thf/get-shape file' :copy-root)
|
||||||
|
main-root' (ctf/get-ref-shape (ctf/file-data file') component' copy-root')]
|
||||||
|
|
||||||
|
; Check
|
||||||
|
(t/is (= (count pages') 2))
|
||||||
|
(t/is (= (:name (first pages')) "Page 1"))
|
||||||
|
(t/is (= (:name (second pages')) "Main components"))
|
||||||
|
|
||||||
|
(t/is (= (count components') 1))
|
||||||
|
|
||||||
|
(t/is (ctk/instance-of? copy-root' (:id file') (:id component')))
|
||||||
|
(t/is (ctk/is-main-of? main-root' copy-root' true))
|
||||||
|
(t/is (ctk/main-instance-of? (:id main-root') (:id (second pages')) component'))))
|
||||||
|
|
||||||
(t/deftest test-absorb-colors
|
(t/deftest test-absorb-colors
|
||||||
(let [library-id (uuid/custom 1 1)
|
(let [; Setup
|
||||||
library-page-id (uuid/custom 2 2)
|
library (-> (thf/sample-file :library
|
||||||
file-id (uuid/custom 3 3)
|
:name "Test library"
|
||||||
file-page-id (uuid/custom 4 4)
|
:is-shared true)
|
||||||
|
(thf/add-sample-color :color1 {:name "Test color"
|
||||||
|
:color "#abcdef"}))
|
||||||
|
|
||||||
library (-> (thf/sample-file library-id library-page-id {:is-shared true})
|
file (-> (thf/sample-file :file
|
||||||
(thf/sample-color :color1 {:name "Test color"
|
:name "Test file")
|
||||||
:color "#abcdef"}))
|
(thf/add-sample-shape :shape1
|
||||||
|
:type :rect
|
||||||
|
:name "Rect1"
|
||||||
|
:fills [{:fill-color "#abcdef"
|
||||||
|
:fill-opacity 1
|
||||||
|
:fill-color-ref-id (thi/id :color1)
|
||||||
|
:fill-color-ref-file (thi/id :library)}]))
|
||||||
|
|
||||||
file (-> (thf/sample-file file-id file-page-id)
|
; Action
|
||||||
(thf/sample-shape :shape1
|
file' (ctf/update-file-data
|
||||||
:rect
|
file
|
||||||
file-page-id
|
#(ctf/absorb-assets % (:data library)))
|
||||||
{:name "Rect1"
|
|
||||||
:fills [{:fill-color "#abcdef"
|
|
||||||
:fill-opacity 1
|
|
||||||
:fill-color-ref-id (thf/id :color1)
|
|
||||||
:fill-color-ref-file library-id}]}))
|
|
||||||
|
|
||||||
absorbed-file (ctf/update-file-data
|
_ (thf/validate-file! file')
|
||||||
file
|
|
||||||
#(ctf/absorb-assets % (:data library)))
|
|
||||||
|
|
||||||
colors (ctcl/colors-seq (ctf/file-data absorbed-file))
|
; Get
|
||||||
page (ctpl/get-page (ctf/file-data absorbed-file) file-page-id)
|
colors' (ctcl/colors-seq (ctf/file-data file'))
|
||||||
shape1 (ctn/get-shape page (thf/id :shape1))
|
shape1' (thf/get-shape file' :shape1)
|
||||||
fill (first (:fills shape1))]
|
fill' (first (:fills shape1'))]
|
||||||
|
|
||||||
(t/is (= (count colors) 1))
|
; Check
|
||||||
(t/is (= (:id (first colors)) (thf/id :color1)))
|
(t/is (= (count colors') 1))
|
||||||
(t/is (= (:name (first colors)) "Test color"))
|
(t/is (= (:id (first colors')) (thi/id :color1)))
|
||||||
(t/is (= (:color (first colors)) "#abcdef"))
|
(t/is (= (:name (first colors')) "Test color"))
|
||||||
|
(t/is (= (:color (first colors')) "#abcdef"))
|
||||||
|
|
||||||
(t/is (= (:fill-color fill) "#abcdef"))
|
(t/is (= (:fill-color fill') "#abcdef"))
|
||||||
(t/is (= (:fill-color-ref-id fill) (thf/id :color1)))
|
(t/is (= (:fill-color-ref-id fill') (thi/id :color1)))
|
||||||
(t/is (= (:fill-color-ref-file fill) file-id))))
|
(t/is (= (:fill-color-ref-file fill') (:id file')))))
|
||||||
|
|
||||||
(t/deftest test-absorb-typographies
|
(t/deftest test-absorb-typographies
|
||||||
(let [library-id (uuid/custom 1 1)
|
(let [; Setup
|
||||||
library-page-id (uuid/custom 2 2)
|
library (-> (thf/sample-file :library
|
||||||
file-id (uuid/custom 3 3)
|
:name "Test library"
|
||||||
file-page-id (uuid/custom 4 4)
|
:is-shared true)
|
||||||
|
(thf/add-sample-typography :typography1 {:name "Test typography"}))
|
||||||
|
|
||||||
library (-> (thf/sample-file library-id library-page-id {:is-shared true})
|
file (-> (thf/sample-file :file
|
||||||
(thf/sample-typography :typography1 {:name "Test typography"}))
|
:name "Test file")
|
||||||
|
(thf/add-sample-shape :shape1
|
||||||
|
:type :text
|
||||||
|
:name "Text1"
|
||||||
|
:content {:type "root"
|
||||||
|
:children [{:type "paragraph-set"
|
||||||
|
:children [{:type "paragraph"
|
||||||
|
:key "67uep"
|
||||||
|
:children [{:text "Example text"
|
||||||
|
:typography-ref-id (thi/id :typography1)
|
||||||
|
:typography-ref-file (thi/id :library)
|
||||||
|
:line-height "1.2"
|
||||||
|
:font-style "normal"
|
||||||
|
:text-transform "none"
|
||||||
|
:text-align "left"
|
||||||
|
:font-id "sourcesanspro"
|
||||||
|
:font-family "sourcesanspro"
|
||||||
|
:font-size "14"
|
||||||
|
:font-weight "400"
|
||||||
|
:font-variant-id "regular"
|
||||||
|
:text-decoration "none"
|
||||||
|
:letter-spacing "0"
|
||||||
|
:fills [{:fill-color "#000000"
|
||||||
|
:fill-opacity 1}]}]}]}]}))
|
||||||
|
; Action
|
||||||
|
file' (ctf/update-file-data
|
||||||
|
file
|
||||||
|
#(ctf/absorb-assets % (:data library)))
|
||||||
|
|
||||||
file (-> (thf/sample-file file-id file-page-id)
|
_ (thf/validate-file! file')
|
||||||
(thf/sample-shape :shape1
|
|
||||||
:text
|
|
||||||
file-page-id
|
|
||||||
{:name "Text1"
|
|
||||||
:content {:type "root"
|
|
||||||
:children [{:type "paragraph-set"
|
|
||||||
:children [{:type "paragraph"
|
|
||||||
:key "67uep"
|
|
||||||
:children [{:text "Example text"
|
|
||||||
:typography-ref-id (thf/id :typography1)
|
|
||||||
:typography-ref-file library-id
|
|
||||||
:line-height "1.2"
|
|
||||||
:font-style "normal"
|
|
||||||
:text-transform "none"
|
|
||||||
:text-align "left"
|
|
||||||
:font-id "sourcesanspro"
|
|
||||||
:font-family "sourcesanspro"
|
|
||||||
:font-size "14"
|
|
||||||
:font-weight "400"
|
|
||||||
:font-variant-id "regular"
|
|
||||||
:text-decoration "none"
|
|
||||||
:letter-spacing "0"
|
|
||||||
:fills [{:fill-color "#000000"
|
|
||||||
:fill-opacity 1}]}]}]}]}}))
|
|
||||||
absorbed-file (ctf/update-file-data
|
|
||||||
file
|
|
||||||
#(ctf/absorb-assets % (:data library)))
|
|
||||||
|
|
||||||
typographies (ctyl/typographies-seq (ctf/file-data absorbed-file))
|
; Get
|
||||||
page (ctpl/get-page (ctf/file-data absorbed-file) file-page-id)
|
typographies' (ctyl/typographies-seq (ctf/file-data file'))
|
||||||
|
shape1' (thf/get-shape file' :shape1)
|
||||||
|
text-node' (d/seek #(some? (:text %)) (txt/node-seq (:content shape1')))]
|
||||||
|
|
||||||
shape1 (ctn/get-shape page (thf/id :shape1))
|
(t/is (= (count typographies') 1))
|
||||||
text-node (d/seek #(some? (:text %)) (txt/node-seq (:content shape1)))]
|
(t/is (= (:id (first typographies')) (thi/id :typography1)))
|
||||||
|
(t/is (= (:name (first typographies')) "Test typography"))
|
||||||
|
|
||||||
(t/is (= (count typographies) 1))
|
(t/is (= (:typography-ref-id text-node') (thi/id :typography1)))
|
||||||
(t/is (= (:id (first typographies)) (thf/id :typography1)))
|
(t/is (= (:typography-ref-file text-node') (:id file')))))
|
||||||
(t/is (= (:name (first typographies)) "Test typography"))
|
|
||||||
|
|
||||||
(t/is (= (:typography-ref-id text-node) (thf/id :typography1)))
|
|
||||||
(t/is (= (:typography-ref-file text-node) file-id))))
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue