💄 Improve copy child selection and test robustness

This commit is contained in:
Andrés Moya 2024-05-07 18:07:03 +02:00
parent caefaf6016
commit 8b4e52a2be
5 changed files with 140 additions and 94 deletions

View file

@ -129,6 +129,7 @@
(when children-labels (when children-labels
(dotimes [idx (count children-labels)] (dotimes [idx (count children-labels)]
(set-child-label file' copy-root-label idx (nth children-labels idx)))) (set-child-label file' copy-root-label idx (nth children-labels idx))))
file')) file'))
(defn component-swap (defn component-swap

View file

@ -140,8 +140,8 @@
component2-params))) component2-params)))
(defn add-nested-component-with-copy (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 [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-params]}] & {:keys [component1-params root1-params main1-child-params component2-params main2-root-params nested-head-params copy2-root-params]}]
;; Generated shape tree: ;; Generated shape tree:
;; {:main1-root-label} [:name: Frame1] # [Component :component1-label] ;; {:main1-root-label} [:name: Frame1] # [Component :component1-label]
;; :main1-child-label [:name: Rect1] ;; :main1-child-label [:name: Rect1]
@ -166,4 +166,4 @@
:component2-params component2-params :component2-params component2-params
:main2-root-params main2-root-params :main2-root-params main2-root-params
:nested-head-params nested-head-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)))

View file

@ -4,7 +4,7 @@
;; ;;
;; Copyright (c) KALEIDOS INC ;; Copyright (c) KALEIDOS INC
(ns common-tests.logic.component-creation-test (ns common-tests.logic.comp-creation-test
(:require (:require
[app.common.files.changes-builder :as pcb] [app.common.files.changes-builder :as pcb]
[app.common.logic.libraries :as cll] [app.common.logic.libraries :as cll]

View file

@ -26,16 +26,18 @@
:main-child :main-child
:copy-root :copy-root
:main-child-params {:fills (ths/sample-fills-color :main-child-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")})) :fill-color "#abcdef")}
:copy-root-params {:children-labels [:copy-child]}))
page (thf/current-page file) page (thf/current-page file)
copy-root (ths/get-shape file :copy-root) copy-root (ths/get-shape file :copy-root)
copy-child (ths/get-shape file :copy-child)
;; ==== Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy-root) #{(:id copy-child)}
update-fn update-fn
(:objects page) (:objects page)
{}) {})
@ -54,11 +56,13 @@
;; ==== Get ;; ==== Get
copy-root' (ths/get-shape file' :copy-root) 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') fills' (:fills copy-child')
fill' (first fills')] fill' (first fills')]
;; ==== Check ;; ==== Check
(t/is (some? copy-root'))
(t/is (some? copy-child'))
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#abcdef")) (t/is (= (:fill-color fill') "#abcdef"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))
@ -73,17 +77,20 @@
:fill-color "#abcdef")})) :fill-color "#abcdef")}))
file (-> (thf/sample-file :file) file (-> (thf/sample-file :file)
(thc/instantiate-component :component1 :copy-root :library library)) (thc/instantiate-component :component1 :copy-root
:library library
:children-labels [:copy-child]))
page (thf/current-page file) page (thf/current-page file)
copy-root (ths/get-shape file :copy-root) copy-root (ths/get-shape file :copy-root)
copy-child (ths/get-shape file :copy-child)
;; ==== Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy-root) #{(:id copy-child)}
update-fn update-fn
(:objects page) (:objects page)
{}) {})
@ -103,11 +110,13 @@
;; ==== Get ;; ==== Get
copy-root' (ths/get-shape file' :copy-root) 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') fills' (:fills copy-child')
fill' (first fills')] fill' (first fills')]
;; ==== Check ;; ==== Check
(t/is (some? copy-root'))
(t/is (some? copy-child'))
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#abcdef")) (t/is (= (:fill-color fill') "#abcdef"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))
@ -120,7 +129,8 @@
(tho/add-simple-component-with-copy :component1 (tho/add-simple-component-with-copy :component1
:main-root :main-root
:main-child :main-child
:copy-root) :copy-root
:copy-root-params {:children-labels [:copy-child]})
(ths/add-sample-shape :free-shape)) (ths/add-sample-shape :free-shape))
page (thf/current-page file) page (thf/current-page file)
@ -152,9 +162,11 @@
;; ==== Get ;; ==== Get
copy-root' (ths/get-shape file' :copy-root) 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 ;; ==== Check
(t/is (some? copy-root'))
(t/is (some? copy-child'))
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil)))) (t/is (= (:touched copy-child') nil))))
@ -164,10 +176,12 @@
(tho/add-simple-component-with-copy :component1 (tho/add-simple-component-with-copy :component1
:main-root :main-root
:main-child :main-child
:copy-root)) :copy-root
:copy-root-params {:children-labels [:copy-child]}))
page (thf/current-page file) page (thf/current-page file)
copy-root (ths/get-shape file :copy-root) copy-root (ths/get-shape file :copy-root)
copy-child (ths/get-shape file :copy-child)
;; ==== Action ;; ==== Action
@ -178,7 +192,7 @@
file file
page page
(:objects page) (:objects page)
(set (:shapes copy-root)) #{(:id copy-child)}
{:components-v2 true}) {:components-v2 true})
file-mdf (thf/apply-changes file changes) file-mdf (thf/apply-changes file changes)
@ -195,9 +209,11 @@
;; ==== Get ;; ==== Get
copy-root' (ths/get-shape file' :copy-root) 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 ;; ==== Check
(t/is (some? copy-root'))
(t/is (some? copy-child'))
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil)))) (t/is (= (:touched copy-child') nil))))
@ -207,12 +223,13 @@
(tho/add-component-with-many-children-and-copy :component1 (tho/add-component-with-many-children-and-copy :component1
:main-root :main-root
[:main-child1 :main-child2 :main-child3] [:main-child1 :main-child2 :main-child3]
:copy-root) :copy-root
:copy-root-params {:children-labels [:copy-child]})
(ths/add-sample-shape :free-shape)) (ths/add-sample-shape :free-shape))
page (thf/current-page file) page (thf/current-page file)
copy-root (ths/get-shape file :copy-root) 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 ;; ==== Action
@ -240,9 +257,11 @@
;; ==== Get ;; ==== Get
copy-root' (ths/get-shape file' :copy-root) 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 ;; ==== Check
(t/is (some? copy-root'))
(t/is (some? copy-child'))
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil)))) (t/is (= (:touched copy-child') nil))))
@ -289,6 +308,7 @@
fill' (first fills')] fill' (first fills')]
;; ==== Check ;; ==== Check
(t/is (some? copy2-root'))
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#abcdef")) (t/is (= (:fill-color fill') "#abcdef"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))
@ -303,16 +323,18 @@
:component2 :component2
:main2-root :main2-root
:main2-nested-head :main2-nested-head
:copy2-root)) :copy2-root
:copy2-root-params {:children-labels [:copy2-child]}))
page (thf/current-page file) page (thf/current-page file)
copy2-root (ths/get-shape file :copy2-root) copy2-root (ths/get-shape file :copy2-root)
copy2-child (ths/get-shape file :copy2-child)
;; ==== Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy2-root) #{(:id copy2-child)}
update-fn update-fn
(:objects page) (:objects page)
{}) {})
@ -331,11 +353,13 @@
;; ==== Get ;; ==== Get
copy2-root' (ths/get-shape file' :copy2-root) 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') fills' (:fills copy2-child')
fill' (first fills')] fill' (first fills')]
;; ==== Check ;; ==== Check
(t/is (some? copy2-root'))
(t/is (some? copy2-child'))
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#FFFFFF")) (t/is (= (:fill-color fill') "#FFFFFF"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))

View file

@ -4,7 +4,7 @@
;; ;;
;; Copyright (c) KALEIDOS INC ;; Copyright (c) KALEIDOS INC
(ns common-tests.logic.components-touched-test (ns common-tests.logic.comp-touched-test
(:require (:require
[app.common.files.changes-builder :as pcb] [app.common.files.changes-builder :as pcb]
[app.common.logic.shapes :as cls] [app.common.logic.shapes :as cls]
@ -25,16 +25,17 @@
:main-child :main-child
:copy-root :copy-root
:main-child-params {:fills (ths/sample-fills-color :main-child-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")})) :fill-color "#abcdef")}
:copy-root-params {:children-labels [:copy-child]}))
page (thf/current-page file) page (thf/current-page file)
copy-root (ths/get-shape file :copy-root) copy-child (ths/get-shape file :copy-child)
;; ==== Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy-root) #{(:id copy-child)}
update-fn update-fn
(:objects page) (:objects page)
{}) {})
@ -43,11 +44,13 @@
;; ==== Get ;; ==== Get
copy-root' (ths/get-shape file' :copy-root) 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') fills' (:fills copy-child')
fill' (first fills')] fill' (first fills')]
;; ==== Check ;; ==== Check
(t/is (some? copy-root'))
(t/is (some? copy-child'))
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#fabada")) (t/is (= (:fill-color fill') "#fabada"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))
@ -62,17 +65,19 @@
:fill-color "#abcdef")})) :fill-color "#abcdef")}))
file (-> (thf/sample-file :file) file (-> (thf/sample-file :file)
(thc/instantiate-component :component1 :copy-root :library library)) (thc/instantiate-component :component1 :copy-root
:library library
:children-labels [:copy-child]))
page (thf/current-page file) page (thf/current-page file)
copy-root (ths/get-shape file :copy-root) copy-child (ths/get-shape file :copy-child)
;; ==== Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy-root) #{(:id copy-child)}
update-fn update-fn
(:objects page) (:objects page)
{}) {})
@ -81,11 +86,13 @@
;; ==== Get ;; ==== Get
copy-root' (ths/get-shape file' :copy-root) 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') fills' (:fills copy-child')
fill' (first fills')] fill' (first fills')]
;; ==== Check ;; ==== Check
(t/is (some? copy-root'))
(t/is (some? copy-child'))
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#fabada")) (t/is (= (:fill-color fill') "#fabada"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))
@ -98,7 +105,8 @@
(tho/add-simple-component-with-copy :component1 (tho/add-simple-component-with-copy :component1
:main-root :main-root
:main-child :main-child
:copy-root) :copy-root
:copy-root-params {:children-labels [:copy-child]})
(ths/add-sample-shape :free-shape)) (ths/add-sample-shape :free-shape))
page (thf/current-page file) page (thf/current-page file)
@ -120,9 +128,11 @@
;; ==== Get ;; ==== Get
copy-root' (ths/get-shape file' :copy-root) 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 ;; ==== Check
(t/is (some? copy-root'))
(t/is (some? copy-child'))
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil)))) (t/is (= (:touched copy-child') nil))))
@ -132,10 +142,11 @@
(tho/add-simple-component-with-copy :component1 (tho/add-simple-component-with-copy :component1
:main-root :main-root
:main-child :main-child
:copy-root)) :copy-root
:copy-root-params {:children-labels [:copy-child]}))
page (thf/current-page file) page (thf/current-page file)
copy-root (ths/get-shape file :copy-root) copy-child (ths/get-shape file :copy-child)
;; ==== Action ;; ==== Action
@ -146,16 +157,18 @@
file file
page page
(:objects page) (:objects page)
(set (:shapes copy-root)) #{(:id copy-child)}
{:components-v2 true}) {:components-v2 true})
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ==== Get ;; ==== Get
copy-root' (ths/get-shape file' :copy-root) 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 ;; ==== Check
(t/is (some? copy-root'))
(t/is (some? copy-child'))
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') #{:visibility-group})))) (t/is (= (:touched copy-child') #{:visibility-group}))))
@ -165,12 +178,14 @@
(tho/add-component-with-many-children-and-copy :component1 (tho/add-component-with-many-children-and-copy :component1
:main-root :main-root
[:main-child1 :main-child2 :main-child3] [: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)) (ths/add-sample-shape :free-shape))
page (thf/current-page file) page (thf/current-page file)
copy-root (ths/get-shape file :copy-root) copy-child1 (ths/get-shape file :copy-child1)
copy-child1 (ths/get-shape-by-id file (first (:shapes copy-root)))
;; ==== Action ;; ==== Action
@ -188,9 +203,11 @@
;; ==== Get ;; ==== Get
copy-root' (ths/get-shape file' :copy-root) 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 ;; ==== Check
(t/is (some? copy-root'))
(t/is (some? copy-child'))
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil)))) (t/is (= (:touched copy-child') nil))))
@ -227,6 +244,7 @@
fill' (first fills')] fill' (first fills')]
;; ==== Check ;; ==== Check
(t/is (some? copy2-root'))
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#fabada")) (t/is (= (:fill-color fill') "#fabada"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))
@ -241,16 +259,17 @@
:component2 :component2
:main2-root :main2-root
:main2-nested-head :main2-nested-head
:copy2-root)) :copy2-root
:copy2-root-params {:children-labels [:copy2-child]}))
page (thf/current-page file) page (thf/current-page file)
copy2-root (ths/get-shape file :copy2-root) copy2-child (ths/get-shape file :copy2-child)
;; ==== Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy2-root) #{(:id copy2-child)}
update-fn update-fn
(:objects page) (:objects page)
{}) {})
@ -259,11 +278,13 @@
;; ==== Get ;; ==== Get
copy2-root' (ths/get-shape file' :copy2-root) 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') fills' (:fills copy2-child')
fill' (first fills')] fill' (first fills')]
;; ==== Check ;; ==== Check
(t/is (some? copy2-root'))
(t/is (some? copy2-child'))
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#fabada")) (t/is (= (:fill-color fill') "#fabada"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))