🎉 Add drag components in or out a variant container

This commit is contained in:
Pablo Alba 2025-02-20 10:05:01 +01:00 committed by GitHub
parent 6277db8d45
commit 014c297458
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 613 additions and 206 deletions

View file

@ -61,10 +61,10 @@
blue1 (ths/get-shape file :blue1)
;; ==== Action
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
uuid/zero ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
@ -91,10 +91,10 @@
;; ==== Action
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(:id b2) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
@ -121,10 +121,10 @@
;; ==== Action
;; Move blue1 into yellow
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
@ -134,10 +134,10 @@
yellow' (ths/get-shape file' :frame-yellow)
;; Move yellow into root
changes' (cls/generate-relocate (pcb/empty-changes nil)
(:objects page')
changes' (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page'))
(pcb/with-objects (:objects page')))
uuid/zero ;; parent-id
(:id page') ;; page-id
0 ;; to-index
#{(:id yellow')}) ;; ids
@ -164,10 +164,10 @@
;; ==== Action
;; Move blue1 into yellow
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
@ -178,10 +178,10 @@
b2' (ths/get-shape file' :frame-b2)
;; Move yellow into b2
changes' (cls/generate-relocate (pcb/empty-changes nil)
(:objects page')
changes' (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page'))
(pcb/with-objects (:objects page')))
(:id b2') ;; parent-id
(:id page') ;; page-id
0 ;; to-index
#{(:id yellow')}) ;; ids
@ -254,10 +254,10 @@
;; ==== Action
;; Move blue1 into yellow
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
@ -308,10 +308,10 @@
blue1 (ths/get-shape file :blue1)
;; ==== Action
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(:parent-id blue1) ;; parent-id
(:id page) ;; page-id
2 ;; to-index
#{(:id blue1)}) ;; ids
@ -338,10 +338,10 @@
;; ==== Action
;; Move blue1 into yellow
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
@ -351,10 +351,10 @@
page' (thf/current-page file')
blue1' (ths/get-shape file' :blue1)
b1' (ths/get-shape file' :frame-b1)
changes' (cls/generate-relocate (pcb/empty-changes nil)
(:objects page')
changes' (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page'))
(pcb/with-objects (:objects page')))
(:id b1') ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1')}) ;; ids
@ -382,10 +382,10 @@
;; ==== Action
;; Relocate blue1 into yellow
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
@ -396,10 +396,10 @@
page' (thf/current-page file')
blue1' (ths/get-shape file' :blue1)
b1' (ths/get-shape file' :frame-b1)
changes' (cls/generate-relocate (pcb/empty-changes nil)
(:objects page')
changes' (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page'))
(pcb/with-objects (:objects page')))
(:id b1') ;; parent-id
(:id page') ;; page-id
0 ;; to-index
#{(:id blue1')}) ;; ids
@ -428,10 +428,10 @@
green-copy (ths/get-shape file :green-copy)
;; ==== Action
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
uuid/zero ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id green-copy)}) ;; ids
@ -459,10 +459,10 @@
b2 (ths/get-shape file :frame-b2)
;; ==== Action
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(:id b2) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id green-copy)}) ;; ids

View file

@ -136,10 +136,10 @@
;; IMPORTANT: as modifying copies structure is now forbidden, this action
;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate (pcb/empty-changes)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
0 ; to-index
#{(thi/id :free-shape)}) ; ids
@ -231,10 +231,10 @@
;; IMPORTANT: as modifying copies structure is now forbidden, this action
;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate (pcb/empty-changes)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
2 ; to-index
#{(:id copy-child1)}) ; ids

View file

@ -195,10 +195,10 @@
page (thf/current-page file)
;; ==== Action
changes1 (cls/generate-relocate (pcb/empty-changes)
(:objects page)
changes1 (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(thi/id :main-root) ; parent-id
(:id page) ; page-id
0 ; to-index
#{(thi/id :free-shape)}) ; ids
@ -292,10 +292,10 @@
main-child1 (ths/get-shape file :main-child1)
;; ==== Action
changes1 (cls/generate-relocate (pcb/empty-changes)
(:objects page)
changes1 (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(thi/id :main-root) ; parent-id
(:id page) ; page-id
2 ; to-index
#{(:id main-child1)}) ; ids

View file

@ -112,10 +112,10 @@
;; IMPORTANT: as modifying copies structure is now forbidden, this action
;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate (pcb/empty-changes)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
0 ; to-index
#{(thi/id :free-shape)}) ; ids
@ -187,10 +187,10 @@
;; IMPORTANT: as modifying copies structure is now forbidden, this action
;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate (pcb/empty-changes)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
2 ; to-index
#{(:id copy-child1)}) ; ids

View file

@ -29,10 +29,10 @@
;; ==== Action
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
(:id frame-parent) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id frame-to-move)}) ;; ids
@ -61,10 +61,10 @@
;; ==== Action
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
changes (cls/generate-relocate (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-objects (:objects page)))
uuid/zero ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id circle)}) ;; ids

View file

@ -0,0 +1,194 @@
;; 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.logic.variants-test
(:require
[app.common.files.changes-builder :as pcb]
[app.common.logic.variants :as clv]
[app.common.test-helpers.components :as thc]
[app.common.test-helpers.files :as thf]
[app.common.test-helpers.ids-map :as thi]
[app.common.test-helpers.shapes :as ths]
[app.common.test-helpers.variants :as thv]
[clojure.test :as t]))
(t/use-fixtures :each thi/test-fixture)
(t/deftest test-update-property-name
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02))
v-id (-> (ths/get-shape file :v01) :id)
page (thf/current-page file)
;; ==== Action
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-update-property-name v-id 0 "NewName1")
(clv/generate-update-property-name v-id 1 "NewName2"))
file' (thf/apply-changes file changes)
;; ==== Get
comp01' (thc/get-component file' :c01)
comp02' (thc/get-component file' :c02)]
;; ==== Check
(t/is (= (-> comp01' :variant-properties first :name) "NewName1"))
(t/is (= (-> comp01' :variant-properties last :name) "NewName2"))
(t/is (= (-> comp02' :variant-properties first :name) "NewName1"))
(t/is (= (-> comp02' :variant-properties last :name) "NewName2"))))
(t/deftest test-add-new-property-without-values
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02))
v-id (-> (ths/get-shape file :v01) :id)
page (thf/current-page file)
comp01 (thc/get-component file :c01)
comp02 (thc/get-component file :c02)
;; ==== Action
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-add-new-property v-id))
file' (thf/apply-changes file changes)
;; ==== Get
comp01' (thc/get-component file' :c01)
comp02' (thc/get-component file' :c02)]
;; ==== Check
(t/is (= (count (:variant-properties comp01)) 1))
(t/is (= (count (:variant-properties comp01')) 2))
(t/is (= (count (:variant-properties comp02)) 1))
(t/is (= (count (:variant-properties comp02')) 2))
(t/is (= (-> comp01' :variant-properties last :value) ""))))
(t/deftest test-add-new-property-with-values
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02))
v-id (-> (ths/get-shape file :v01) :id)
page (thf/current-page file)
comp01 (thc/get-component file :c01)
comp02 (thc/get-component file :c02)
;; ==== Action
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-add-new-property v-id {:fill-values? true}))
file' (thf/apply-changes file changes)
;; ==== Get
comp01' (thc/get-component file' :c01)
comp02' (thc/get-component file' :c02)]
;; ==== Check
(t/is (= (count (:variant-properties comp01)) 1))
(t/is (= (count (:variant-properties comp01')) 2))
(t/is (= (count (:variant-properties comp02)) 1))
(t/is (= (count (:variant-properties comp02')) 2))
(t/is (= (-> comp01' :variant-properties last :value) "Value1"))))
(t/deftest test-remove-property
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02))
v-id (-> (ths/get-shape file :v01) :id)
page (thf/current-page file)
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-add-new-property v-id))
file (thf/apply-changes file changes)
page (thf/current-page file)
comp01 (thc/get-component file :c01)
comp02 (thc/get-component file :c02)
;; ==== Action
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-remove-property v-id 0))
file' (thf/apply-changes file changes)
;; ==== Get
comp01' (thc/get-component file' :c01)
comp02' (thc/get-component file' :c02)]
;; ==== Check
(t/is (= (count (:variant-properties comp01)) 2))
(t/is (= (count (:variant-properties comp01')) 1))
(t/is (= (count (:variant-properties comp02)) 2))
(t/is (= (count (:variant-properties comp02')) 1))
(t/is (= (-> comp01' :variant-properties first :name) "Property2"))))
(t/deftest test-update-property-value
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02))
page (thf/current-page file)
comp01 (thc/get-component file :c01)
comp02 (thc/get-component file :c02)
;; ==== Action
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clv/generate-update-property-value (:id comp01) 0 "NewValue1")
(clv/generate-update-property-value (:id comp02) 0 "NewValue2"))
file' (thf/apply-changes file changes)
;; ==== Get
comp01' (thc/get-component file' :c01)
comp02' (thc/get-component file' :c02)]
;; ==== Check
(t/is (= (-> comp01' :variant-properties first :value) "NewValue1"))
(t/is (= (-> comp02' :variant-properties first :value) "NewValue2"))))