mirror of
https://github.com/penpot/penpot.git
synced 2025-03-10 14:51:37 -05:00
💄 Improve copy child selection and test robustness
This commit is contained in:
parent
caefaf6016
commit
8b4e52a2be
5 changed files with 140 additions and 94 deletions
|
@ -129,6 +129,7 @@
|
|||
(when children-labels
|
||||
(dotimes [idx (count children-labels)]
|
||||
(set-child-label file' copy-root-label idx (nth children-labels idx))))
|
||||
|
||||
file'))
|
||||
|
||||
(defn component-swap
|
||||
|
|
|
@ -140,8 +140,8 @@
|
|||
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-label
|
||||
& {:keys [component1-params root1-params main1-child-params component2-params main2-root-params nested-head-params copy2-params]}]
|
||||
[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]
|
||||
|
@ -166,4 +166,4 @@
|
|||
:component2-params component2-params
|
||||
:main2-root-params main2-root-params
|
||||
:nested-head-params nested-head-params)
|
||||
(thc/instantiate-component component2-label copy2-label copy2-params)))
|
||||
(thc/instantiate-component component2-label copy2-root-label copy2-root-params)))
|
|
@ -4,7 +4,7 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.logic.component-creation-test
|
||||
(ns common-tests.logic.comp-creation-test
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.libraries :as cll]
|
|
@ -20,22 +20,24 @@
|
|||
|
||||
(t/deftest test-reset-after-changing-attribute
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component-with-copy :component1
|
||||
:main-root
|
||||
:main-child
|
||||
:copy-root
|
||||
:main-child-params {:fills (ths/sample-fills-color
|
||||
:fill-color "#abcdef")}))
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component-with-copy :component1
|
||||
:main-root
|
||||
:main-child
|
||||
:copy-root
|
||||
:main-child-params {:fills (ths/sample-fills-color
|
||||
:fill-color "#abcdef")}
|
||||
:copy-root-params {:children-labels [:copy-child]}))
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
copy-child (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action
|
||||
update-fn (fn [shape]
|
||||
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
(:shapes copy-root)
|
||||
#{(:id copy-child)}
|
||||
update-fn
|
||||
(:objects page)
|
||||
{})
|
||||
|
@ -54,11 +56,13 @@
|
|||
|
||||
;; ==== Get
|
||||
copy-root' (ths/get-shape file' :copy-root)
|
||||
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))
|
||||
copy-child' (ths/get-shape file' :copy-child)
|
||||
fills' (:fills copy-child')
|
||||
fill' (first fills')]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy-root'))
|
||||
(t/is (some? copy-child'))
|
||||
(t/is (= (count fills') 1))
|
||||
(t/is (= (:fill-color fill') "#abcdef"))
|
||||
(t/is (= (:fill-opacity fill') 1))
|
||||
|
@ -67,23 +71,26 @@
|
|||
|
||||
(t/deftest test-reset-from-library
|
||||
(let [;; ==== Setup
|
||||
library (-> (thf/sample-file :library :is-shared true)
|
||||
(tho/add-simple-component :component1 :main-root :main-child
|
||||
:child-params {:fills (ths/sample-fills-color
|
||||
:fill-color "#abcdef")}))
|
||||
library (-> (thf/sample-file :library :is-shared true)
|
||||
(tho/add-simple-component :component1 :main-root :main-child
|
||||
:child-params {:fills (ths/sample-fills-color
|
||||
:fill-color "#abcdef")}))
|
||||
|
||||
file (-> (thf/sample-file :file)
|
||||
(thc/instantiate-component :component1 :copy-root :library library))
|
||||
file (-> (thf/sample-file :file)
|
||||
(thc/instantiate-component :component1 :copy-root
|
||||
:library library
|
||||
:children-labels [:copy-child]))
|
||||
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
copy-child (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action
|
||||
update-fn (fn [shape]
|
||||
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
(:shapes copy-root)
|
||||
#{(:id copy-child)}
|
||||
update-fn
|
||||
(:objects page)
|
||||
{})
|
||||
|
@ -103,11 +110,13 @@
|
|||
|
||||
;; ==== Get
|
||||
copy-root' (ths/get-shape file' :copy-root)
|
||||
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))
|
||||
copy-child' (ths/get-shape file' :copy-child)
|
||||
fills' (:fills copy-child')
|
||||
fill' (first fills')]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy-root'))
|
||||
(t/is (some? copy-child'))
|
||||
(t/is (= (count fills') 1))
|
||||
(t/is (= (:fill-color fill') "#abcdef"))
|
||||
(t/is (= (:fill-opacity fill') 1))
|
||||
|
@ -120,7 +129,8 @@
|
|||
(tho/add-simple-component-with-copy :component1
|
||||
:main-root
|
||||
:main-child
|
||||
:copy-root)
|
||||
:copy-root
|
||||
:copy-root-params {:children-labels [:copy-child]})
|
||||
(ths/add-sample-shape :free-shape))
|
||||
|
||||
page (thf/current-page file)
|
||||
|
@ -152,9 +162,11 @@
|
|||
|
||||
;; ==== Get
|
||||
copy-root' (ths/get-shape file' :copy-root)
|
||||
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy-root'))
|
||||
(t/is (some? copy-child'))
|
||||
(t/is (= (:touched copy-root') nil))
|
||||
(t/is (= (:touched copy-child') nil))))
|
||||
|
||||
|
@ -164,10 +176,12 @@
|
|||
(tho/add-simple-component-with-copy :component1
|
||||
:main-root
|
||||
:main-child
|
||||
:copy-root))
|
||||
:copy-root
|
||||
:copy-root-params {:children-labels [:copy-child]}))
|
||||
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
copy-child (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action
|
||||
|
||||
|
@ -178,7 +192,7 @@
|
|||
file
|
||||
page
|
||||
(:objects page)
|
||||
(set (:shapes copy-root))
|
||||
#{(:id copy-child)}
|
||||
{:components-v2 true})
|
||||
|
||||
file-mdf (thf/apply-changes file changes)
|
||||
|
@ -195,9 +209,11 @@
|
|||
|
||||
;; ==== Get
|
||||
copy-root' (ths/get-shape file' :copy-root)
|
||||
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy-root'))
|
||||
(t/is (some? copy-child'))
|
||||
(t/is (= (:touched copy-root') nil))
|
||||
(t/is (= (:touched copy-child') nil))))
|
||||
|
||||
|
@ -207,12 +223,13 @@
|
|||
(tho/add-component-with-many-children-and-copy :component1
|
||||
:main-root
|
||||
[:main-child1 :main-child2 :main-child3]
|
||||
:copy-root)
|
||||
:copy-root
|
||||
:copy-root-params {:children-labels [:copy-child]})
|
||||
(ths/add-sample-shape :free-shape))
|
||||
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
copy-child1 (ths/get-shape-by-id file (first (:shapes copy-root)))
|
||||
copy-child1 (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action
|
||||
|
||||
|
@ -240,9 +257,11 @@
|
|||
|
||||
;; ==== Get
|
||||
copy-root' (ths/get-shape file' :copy-root)
|
||||
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy-root'))
|
||||
(t/is (some? copy-child'))
|
||||
(t/is (= (:touched copy-root') nil))
|
||||
(t/is (= (:touched copy-child') nil))))
|
||||
|
||||
|
@ -289,6 +308,7 @@
|
|||
fill' (first fills')]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy2-root'))
|
||||
(t/is (= (count fills') 1))
|
||||
(t/is (= (:fill-color fill') "#abcdef"))
|
||||
(t/is (= (:fill-opacity fill') 1))
|
||||
|
@ -296,23 +316,25 @@
|
|||
|
||||
(t/deftest test-reset-after-changing-lower
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component-with-copy :component1
|
||||
:main1-root
|
||||
:main1-child
|
||||
:component2
|
||||
:main2-root
|
||||
:main2-nested-head
|
||||
:copy2-root))
|
||||
page (thf/current-page file)
|
||||
copy2-root (ths/get-shape file :copy2-root)
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component-with-copy :component1
|
||||
:main1-root
|
||||
:main1-child
|
||||
:component2
|
||||
:main2-root
|
||||
:main2-nested-head
|
||||
:copy2-root
|
||||
:copy2-root-params {:children-labels [:copy2-child]}))
|
||||
page (thf/current-page file)
|
||||
copy2-root (ths/get-shape file :copy2-root)
|
||||
copy2-child (ths/get-shape file :copy2-child)
|
||||
|
||||
;; ==== Action
|
||||
update-fn (fn [shape]
|
||||
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
(:shapes copy2-root)
|
||||
#{(:id copy2-child)}
|
||||
update-fn
|
||||
(:objects page)
|
||||
{})
|
||||
|
@ -331,11 +353,13 @@
|
|||
|
||||
;; ==== Get
|
||||
copy2-root' (ths/get-shape file' :copy2-root)
|
||||
copy2-child' (ths/get-shape-by-id file' (first (:shapes copy2-root')))
|
||||
copy2-child' (ths/get-shape file' :copy2-child)
|
||||
fills' (:fills copy2-child')
|
||||
fill' (first fills')]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy2-root'))
|
||||
(t/is (some? copy2-child'))
|
||||
(t/is (= (count fills') 1))
|
||||
(t/is (= (:fill-color fill') "#FFFFFF"))
|
||||
(t/is (= (:fill-opacity fill') 1))
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.logic.components-touched-test
|
||||
(ns common-tests.logic.comp-touched-test
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.shapes :as cls]
|
||||
|
@ -19,22 +19,23 @@
|
|||
|
||||
(t/deftest test-touched-when-changing-attribute
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component-with-copy :component1
|
||||
:main-root
|
||||
:main-child
|
||||
:copy-root
|
||||
:main-child-params {:fills (ths/sample-fills-color
|
||||
:fill-color "#abcdef")}))
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component-with-copy :component1
|
||||
:main-root
|
||||
:main-child
|
||||
:copy-root
|
||||
:main-child-params {:fills (ths/sample-fills-color
|
||||
:fill-color "#abcdef")}
|
||||
:copy-root-params {:children-labels [:copy-child]}))
|
||||
page (thf/current-page file)
|
||||
copy-child (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action
|
||||
update-fn (fn [shape]
|
||||
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
(:shapes copy-root)
|
||||
#{(:id copy-child)}
|
||||
update-fn
|
||||
(:objects page)
|
||||
{})
|
||||
|
@ -43,11 +44,13 @@
|
|||
|
||||
;; ==== Get
|
||||
copy-root' (ths/get-shape file' :copy-root)
|
||||
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))
|
||||
copy-child' (ths/get-shape file' :copy-child)
|
||||
fills' (:fills copy-child')
|
||||
fill' (first fills')]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy-root'))
|
||||
(t/is (some? copy-child'))
|
||||
(t/is (= (count fills') 1))
|
||||
(t/is (= (:fill-color fill') "#fabada"))
|
||||
(t/is (= (:fill-opacity fill') 1))
|
||||
|
@ -56,23 +59,25 @@
|
|||
|
||||
(t/deftest test-touched-from-library
|
||||
(let [;; ==== Setup
|
||||
library (-> (thf/sample-file :library :is-shared true)
|
||||
(tho/add-simple-component :component1 :main-root :main-child
|
||||
:child-params {:fills (ths/sample-fills-color
|
||||
:fill-color "#abcdef")}))
|
||||
library (-> (thf/sample-file :library :is-shared true)
|
||||
(tho/add-simple-component :component1 :main-root :main-child
|
||||
:child-params {:fills (ths/sample-fills-color
|
||||
:fill-color "#abcdef")}))
|
||||
|
||||
file (-> (thf/sample-file :file)
|
||||
(thc/instantiate-component :component1 :copy-root :library library))
|
||||
file (-> (thf/sample-file :file)
|
||||
(thc/instantiate-component :component1 :copy-root
|
||||
:library library
|
||||
:children-labels [:copy-child]))
|
||||
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
page (thf/current-page file)
|
||||
copy-child (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action
|
||||
update-fn (fn [shape]
|
||||
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
(:shapes copy-root)
|
||||
#{(:id copy-child)}
|
||||
update-fn
|
||||
(:objects page)
|
||||
{})
|
||||
|
@ -81,11 +86,13 @@
|
|||
|
||||
;; ==== Get
|
||||
copy-root' (ths/get-shape file' :copy-root)
|
||||
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))
|
||||
copy-child' (ths/get-shape file' :copy-child)
|
||||
fills' (:fills copy-child')
|
||||
fill' (first fills')]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy-root'))
|
||||
(t/is (some? copy-child'))
|
||||
(t/is (= (count fills') 1))
|
||||
(t/is (= (:fill-color fill') "#fabada"))
|
||||
(t/is (= (:fill-opacity fill') 1))
|
||||
|
@ -94,12 +101,13 @@
|
|||
|
||||
(t/deftest test-not-touched-when-adding-shape
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component-with-copy :component1
|
||||
:main-root
|
||||
:main-child
|
||||
:copy-root)
|
||||
(ths/add-sample-shape :free-shape))
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component-with-copy :component1
|
||||
:main-root
|
||||
:main-child
|
||||
:copy-root
|
||||
:copy-root-params {:children-labels [:copy-child]})
|
||||
(ths/add-sample-shape :free-shape))
|
||||
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
|
@ -120,9 +128,11 @@
|
|||
|
||||
;; ==== Get
|
||||
copy-root' (ths/get-shape file' :copy-root)
|
||||
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy-root'))
|
||||
(t/is (some? copy-child'))
|
||||
(t/is (= (:touched copy-root') nil))
|
||||
(t/is (= (:touched copy-child') nil))))
|
||||
|
||||
|
@ -132,10 +142,11 @@
|
|||
(tho/add-simple-component-with-copy :component1
|
||||
:main-root
|
||||
:main-child
|
||||
:copy-root))
|
||||
:copy-root
|
||||
:copy-root-params {:children-labels [:copy-child]}))
|
||||
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
copy-child (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action
|
||||
|
||||
|
@ -146,16 +157,18 @@
|
|||
file
|
||||
page
|
||||
(:objects page)
|
||||
(set (:shapes copy-root))
|
||||
#{(:id copy-child)}
|
||||
{:components-v2 true})
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
;; ==== Get
|
||||
copy-root' (ths/get-shape file' :copy-root)
|
||||
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy-root'))
|
||||
(t/is (some? copy-child'))
|
||||
(t/is (= (:touched copy-root') nil))
|
||||
(t/is (= (:touched copy-child') #{:visibility-group}))))
|
||||
|
||||
|
@ -165,12 +178,14 @@
|
|||
(tho/add-component-with-many-children-and-copy :component1
|
||||
:main-root
|
||||
[:main-child1 :main-child2 :main-child3]
|
||||
:copy-root)
|
||||
:copy-root
|
||||
:copy-root-params {:children-labels [:copy-child1
|
||||
:copy-child2
|
||||
:copy-child3]})
|
||||
(ths/add-sample-shape :free-shape))
|
||||
|
||||
page (thf/current-page file)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
copy-child1 (ths/get-shape-by-id file (first (:shapes copy-root)))
|
||||
copy-child1 (ths/get-shape file :copy-child1)
|
||||
|
||||
;; ==== Action
|
||||
|
||||
|
@ -188,9 +203,11 @@
|
|||
|
||||
;; ==== Get
|
||||
copy-root' (ths/get-shape file' :copy-root)
|
||||
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
|
||||
copy-child' (ths/get-shape file' :copy-child1)]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy-root'))
|
||||
(t/is (some? copy-child'))
|
||||
(t/is (= (:touched copy-root') nil))
|
||||
(t/is (= (:touched copy-child') nil))))
|
||||
|
||||
|
@ -227,6 +244,7 @@
|
|||
fill' (first fills')]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy2-root'))
|
||||
(t/is (= (count fills') 1))
|
||||
(t/is (= (:fill-color fill') "#fabada"))
|
||||
(t/is (= (:fill-opacity fill') 1))
|
||||
|
@ -234,23 +252,24 @@
|
|||
|
||||
(t/deftest test-touched-when-changing-lower
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component-with-copy :component1
|
||||
:main1-root
|
||||
:main1-child
|
||||
:component2
|
||||
:main2-root
|
||||
:main2-nested-head
|
||||
:copy2-root))
|
||||
page (thf/current-page file)
|
||||
copy2-root (ths/get-shape file :copy2-root)
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component-with-copy :component1
|
||||
:main1-root
|
||||
:main1-child
|
||||
:component2
|
||||
:main2-root
|
||||
:main2-nested-head
|
||||
:copy2-root
|
||||
:copy2-root-params {:children-labels [:copy2-child]}))
|
||||
page (thf/current-page file)
|
||||
copy2-child (ths/get-shape file :copy2-child)
|
||||
|
||||
;; ==== Action
|
||||
update-fn (fn [shape]
|
||||
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
(:shapes copy2-root)
|
||||
#{(:id copy2-child)}
|
||||
update-fn
|
||||
(:objects page)
|
||||
{})
|
||||
|
@ -259,11 +278,13 @@
|
|||
|
||||
;; ==== Get
|
||||
copy2-root' (ths/get-shape file' :copy2-root)
|
||||
copy2-child' (ths/get-shape-by-id file' (first (:shapes copy2-root')))
|
||||
copy2-child' (ths/get-shape file' :copy2-child)
|
||||
fills' (:fills copy2-child')
|
||||
fill' (first fills')]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? copy2-root'))
|
||||
(t/is (some? copy2-child'))
|
||||
(t/is (= (count fills') 1))
|
||||
(t/is (= (:fill-color fill') "#fabada"))
|
||||
(t/is (= (:fill-opacity fill') 1))
|
Loading…
Add table
Reference in a new issue