mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -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.typographies-list :as ctyl]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.compositions :as tho]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]))
|
||||
|
||||
|
@ -63,10 +64,7 @@
|
|||
|
||||
(t/deftest test-create-components
|
||||
(let [f1 (-> (thf/sample-file :file1)
|
||||
(thf/add-sample-shape :main-root :type :frame)
|
||||
(thf/add-sample-shape :main-child :parent-label :main-root)
|
||||
(thf/make-component :component1 :main-root)
|
||||
(thf/instantiate-component :component1 :copy-root))]
|
||||
(tho/add-simple-component-with-copy :component1 :main-root :main-child :copy-root))]
|
||||
|
||||
#_(thf/dump-file f1)
|
||||
#_(thf/pprint-file f4)
|
||||
|
@ -105,21 +103,11 @@
|
|||
|
||||
(t/deftest test-absorb-components
|
||||
(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))
|
||||
library (-> (thf/sample-file :library :is-shared true)
|
||||
(tho/add-simple-component :component1 :main-root :rect1))
|
||||
|
||||
file (-> (thf/sample-file :file)
|
||||
(thf/instantiate-component :component1
|
||||
:copy-root
|
||||
:library library))
|
||||
(thf/instantiate-component :component1 :copy-root :library library))
|
||||
|
||||
; Action
|
||||
file' (ctf/update-file-data
|
||||
|
@ -149,14 +137,11 @@
|
|||
|
||||
(t/deftest test-absorb-colors
|
||||
(let [; Setup
|
||||
library (-> (thf/sample-file :library
|
||||
:name "Test library"
|
||||
:is-shared true)
|
||||
library (-> (thf/sample-file :library :is-shared true)
|
||||
(thf/add-sample-color :color1 {:name "Test color"
|
||||
:color "#abcdef"}))
|
||||
|
||||
file (-> (thf/sample-file :file
|
||||
:name "Test file")
|
||||
file (-> (thf/sample-file :file)
|
||||
(thf/add-sample-shape :shape1
|
||||
:type :rect
|
||||
:name "Rect1"
|
||||
|
@ -189,13 +174,10 @@
|
|||
|
||||
(t/deftest test-absorb-typographies
|
||||
(let [; Setup
|
||||
library (-> (thf/sample-file :library
|
||||
:name "Test library"
|
||||
:is-shared true)
|
||||
library (-> (thf/sample-file :library :is-shared true)
|
||||
(thf/add-sample-typography :typography1 {:name "Test typography"}))
|
||||
|
||||
file (-> (thf/sample-file :file
|
||||
:name "Test file")
|
||||
file (-> (thf/sample-file :file)
|
||||
(thf/add-sample-shape :shape1
|
||||
:type :text
|
||||
:name "Text1"
|
||||
|
@ -237,4 +219,3 @@
|
|||
|
||||
(t/is (= (:typography-ref-id text-node') (thi/id :typography1)))
|
||||
(t/is (= (:typography-ref-file text-node') (:id file')))))
|
||||
|
||||
|
|
Loading…
Reference in a new issue