mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 06:58:58 -05:00
✅ Add composition helpers
This commit is contained in:
parent
dde89e60dd
commit
ff4e27a1d5
2 changed files with 51 additions and 28 deletions
42
common/test/common_tests/helpers/compositions.cljc
Normal file
42
common/test/common_tests/helpers/compositions.cljc
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
;; 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
|
||||||
|
[common-tests.helpers.files :as thf]))
|
||||||
|
|
||||||
|
(defn add-rect
|
||||||
|
[file rect-label]
|
||||||
|
(thf/add-sample-shape file rect-label
|
||||||
|
:type :rect
|
||||||
|
:name "Rect1"))
|
||||||
|
|
||||||
|
(defn add-frame
|
||||||
|
[file frame-label]
|
||||||
|
(thf/add-sample-shape file frame-label
|
||||||
|
:type :frame
|
||||||
|
:name "Frame1"))
|
||||||
|
|
||||||
|
(defn add-frame-with-child
|
||||||
|
[file frame-label child-label]
|
||||||
|
(-> file
|
||||||
|
(add-frame frame-label)
|
||||||
|
(thf/add-sample-shape child-label
|
||||||
|
:type :rect
|
||||||
|
:name "Rect1"
|
||||||
|
:parent-label frame-label)))
|
||||||
|
|
||||||
|
(defn add-simple-component
|
||||||
|
[file component-label root-label child-label]
|
||||||
|
(-> file
|
||||||
|
(add-frame-with-child root-label child-label)
|
||||||
|
(thf/make-component component-label root-label)))
|
||||||
|
|
||||||
|
(defn add-simple-component-with-copy
|
||||||
|
[file component-label main-root-label main-child-label copy-root-label]
|
||||||
|
(-> file
|
||||||
|
(add-simple-component component-label main-root-label main-child-label)
|
||||||
|
(thf/instantiate-component component-label copy-root-label)))
|
|
@ -17,6 +17,7 @@
|
||||||
[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.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]))
|
||||||
|
|
||||||
|
@ -63,10 +64,7 @@
|
||||||
|
|
||||||
(t/deftest test-create-components
|
(t/deftest test-create-components
|
||||||
(let [f1 (-> (thf/sample-file :file1)
|
(let [f1 (-> (thf/sample-file :file1)
|
||||||
(thf/add-sample-shape :main-root :type :frame)
|
(tho/add-simple-component-with-copy :component1 :main-root :main-child :copy-root))]
|
||||||
(thf/add-sample-shape :main-child :parent-label :main-root)
|
|
||||||
(thf/make-component :component1 :main-root)
|
|
||||||
(thf/instantiate-component :component1 :copy-root))]
|
|
||||||
|
|
||||||
#_(thf/dump-file f1)
|
#_(thf/dump-file f1)
|
||||||
#_(thf/pprint-file f4)
|
#_(thf/pprint-file f4)
|
||||||
|
@ -105,21 +103,11 @@
|
||||||
|
|
||||||
(t/deftest test-absorb-components
|
(t/deftest test-absorb-components
|
||||||
(let [; Setup
|
(let [; Setup
|
||||||
library (-> (thf/sample-file :library
|
library (-> (thf/sample-file :library :is-shared true)
|
||||||
:is-shared true)
|
(tho/add-simple-component :component1 :main-root :rect1))
|
||||||
(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)
|
file (-> (thf/sample-file :file)
|
||||||
(thf/instantiate-component :component1
|
(thf/instantiate-component :component1 :copy-root :library library))
|
||||||
:copy-root
|
|
||||||
:library library))
|
|
||||||
|
|
||||||
; Action
|
; Action
|
||||||
file' (ctf/update-file-data
|
file' (ctf/update-file-data
|
||||||
|
@ -149,14 +137,11 @@
|
||||||
|
|
||||||
(t/deftest test-absorb-colors
|
(t/deftest test-absorb-colors
|
||||||
(let [; Setup
|
(let [; Setup
|
||||||
library (-> (thf/sample-file :library
|
library (-> (thf/sample-file :library :is-shared true)
|
||||||
:name "Test library"
|
|
||||||
:is-shared true)
|
|
||||||
(thf/add-sample-color :color1 {:name "Test color"
|
(thf/add-sample-color :color1 {:name "Test color"
|
||||||
:color "#abcdef"}))
|
:color "#abcdef"}))
|
||||||
|
|
||||||
file (-> (thf/sample-file :file
|
file (-> (thf/sample-file :file)
|
||||||
:name "Test file")
|
|
||||||
(thf/add-sample-shape :shape1
|
(thf/add-sample-shape :shape1
|
||||||
:type :rect
|
:type :rect
|
||||||
:name "Rect1"
|
:name "Rect1"
|
||||||
|
@ -189,13 +174,10 @@
|
||||||
|
|
||||||
(t/deftest test-absorb-typographies
|
(t/deftest test-absorb-typographies
|
||||||
(let [; Setup
|
(let [; Setup
|
||||||
library (-> (thf/sample-file :library
|
library (-> (thf/sample-file :library :is-shared true)
|
||||||
:name "Test library"
|
|
||||||
:is-shared true)
|
|
||||||
(thf/add-sample-typography :typography1 {:name "Test typography"}))
|
(thf/add-sample-typography :typography1 {:name "Test typography"}))
|
||||||
|
|
||||||
file (-> (thf/sample-file :file
|
file (-> (thf/sample-file :file)
|
||||||
:name "Test file")
|
|
||||||
(thf/add-sample-shape :shape1
|
(thf/add-sample-shape :shape1
|
||||||
:type :text
|
:type :text
|
||||||
:name "Text1"
|
:name "Text1"
|
||||||
|
@ -237,4 +219,3 @@
|
||||||
|
|
||||||
(t/is (= (:typography-ref-id text-node') (thi/id :typography1)))
|
(t/is (= (:typography-ref-id text-node') (thi/id :typography1)))
|
||||||
(t/is (= (:typography-ref-file text-node') (:id file')))))
|
(t/is (= (:typography-ref-file text-node') (:id file')))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue