From a3e750ed0af732359b5f42a5d120fd0a06a95e0f Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Tue, 30 Apr 2024 16:37:52 +0200 Subject: [PATCH] :sparkles: Tests for chained components changes propagation --- ...ined-components-changes-propagation.penpot | Bin 0 -> 5393 bytes .../logic/chained_propagation_test.cljc | 223 ++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 common/test/cases/chained-components-changes-propagation.penpot create mode 100644 common/test/common_tests/logic/chained_propagation_test.cljc diff --git a/common/test/cases/chained-components-changes-propagation.penpot b/common/test/cases/chained-components-changes-propagation.penpot new file mode 100644 index 0000000000000000000000000000000000000000..368e9a0bc50ef157d1e19960e5b97f9a6614a577 GIT binary patch literal 5393 zcmV+s74GT*3mS${W1(Ng0000000001D77#B0AQr209xzdHBKN_I(nrP%(Ha4GHfiX zP|A3fS>tT@1Bbc$t)65-A`~8E{rb4$9xis;mer4D8QEnIbpcj0AH&^pyi|Y77g8*u z3kW8r9=#AOu(V)zHUlgJRRisLRCe$w{IXm;yqn{f8OpxcezdOG%X zm_5@ww+;Nk9yr1PR(ynsV1f=apzXp%z>1_(89yxAU&2oJDD8RP_1sTUWHfso%6|BB zyCLf%*;Fmhusxi^w8*BMyeq?|6I8YT^&wcdyGw%(4A4cRDa78iFcOU_D9P|aC{7Sp zmzf^c=nkyS8g}6>t+FXvSB$n~;B(Ju(xU#LcxA`xT2xKlD?20|6cq%|6lKrVceS7H z&`^5A9Mp@7m^oH7F@cnh5tyQuE5*@QW5~9KwE-Pq%e^>%zOLJXm8u}1c!APp1|5zc z#;|K{GCVPQVk08PM(k{JtM7b`5TZ&6609!HC=mb@3}B3I6&~190~5s6Wd)nxPQ0+w zFIX)~EsC3CbF6#wtr@ar2+pUsmBn=^{+0q&ZQaOH#)>997UrkOTSs$dyZW4&TXpYy-drbsyRd1up2;`! z@Z7&{dj+wH;V%1xO+dTHl!=~}XV~t)KAh=cS^J;dfo)m3UWPjmsWeMp_qMca-%D>V z>@q2b;A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zFTVhpAj7wA zX*X0X@tG#07+t`-p7-CecBEf~tbRjyc%MVw`_U9-Y+sl6ST(MV9?a!mVB8=1G?+=M#Db zK}0Tb68FtO0LYyrp-71KEzuVd-g#@RQuz$^p8_uKHvBsGnL@+Ag>oXyM_T#2+Gjl= zZzkK2@Zsd09|n6U;F+KnC2dQf_35*jX2b+21pjnV)X@h8t_7_3@=)cTiQ^cz1sZfR zQb~j=vRFwQXEI;#_kf6{^MIkAZLH|{T|`J~rm_gZ@#yb{j2x3_0qn?+U1z!mkYVNImR9qN&L(CBAi`Wj)+JMyEs z9P0)w8@-(U_6XY4HbH-BiM&Y90~{6 zL#{*BCF$}vpwz~dCq(@)KU!P(FfJf#2>y|M5v52LHU6zGpkTqlQ4DZEA;@O%mUzO= zO$QYcuMg%;ax`}{n+KVUkZw}yyjMd-(85m2_PZRP1F0Sv^(n^Fm1K&yJ6G2EosrC>xUU5(%g>Ja%s*DnPI;3Y?er47)WdpS**?C~{#?VZx2lKg zOhSr<$1>gYU~AM%?Fj{n$1T4r!4hcan8uEr(g8*Z#Z&u+zH(RZtt=tLPE#a0m()!t viZuH+$gpWlMd+-LeqqUB^g+CC)68f!{NE%_lPHXLpJsKStK)jZ9{~UW+{$9- literal 0 HcmV?d00001 diff --git a/common/test/common_tests/logic/chained_propagation_test.cljc b/common/test/common_tests/logic/chained_propagation_test.cljc new file mode 100644 index 000000000..f1db114a7 --- /dev/null +++ b/common/test/common_tests/logic/chained_propagation_test.cljc @@ -0,0 +1,223 @@ +;; 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.chained-propagation-test + (:require + [app.common.files.changes :as ch] + [app.common.files.changes-builder :as pcb] + [app.common.logic.libraries :as cll] + [app.common.logic.shapes :as cls] + [app.common.pprint :as pp] + [app.common.types.component :as ctk] + [app.common.types.container :as ctn] + [app.common.types.file :as ctf] + [app.common.uuid :as uuid] + [clojure.test :as t] + [common-tests.helpers.components :as thc] + [common-tests.helpers.compositions :as tho] + [common-tests.helpers.files :as thf] + [common-tests.helpers.ids-map :as thi] + [common-tests.helpers.shapes :as ths])) + +(t/use-fixtures :each thi/test-fixture) + +(defn- first-fill-color [file tag] + (-> (ths/get-shape file tag) + (:fills) + first + :fill-color)) + +(defn- first-child-fill-color [file tag] + (let [shape (ths/get-shape file tag)] + (-> (ths/get-shape-by-id file (first (:shapes shape))) + (:fills) + first + :fill-color))) + +;; Related .penpot file: common/test/cases/chained-components-changes-propagation.penpot +(t/deftest test-propagation-with-anidated-components + (letfn [(setup [] + (-> (thf/sample-file :file1) + (tho/add-frame :frame-comp-1) + (ths/add-sample-shape :rectangle :parent-label :frame-comp-1) + (thc/make-component :comp-1 :frame-comp-1) + + (tho/add-frame :frame-comp-2) + (thc/instantiate-component :comp-1 :copy-comp-1 :parent-label :frame-comp-2 :children-labels [:rect-comp-2]) + (thc/make-component :comp-2 :frame-comp-2) + + (tho/add-frame :frame-comp-3) + (thc/instantiate-component :comp-2 :copy-comp-2 :parent-label :frame-comp-3 :children-labels [:comp-1-comp-2]) + (thc/make-component :comp-3 :frame-comp-3))) + + (step-update-color-comp-2 [file] + (let [page (thf/current-page file) + file-id (:id file) + page-id (:id page) + + ;; Changes to update the color of the contained rectangle in component comp-2 + changes-update-color-comp-1 + (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + (:shapes (ths/get-shape file :copy-comp-1)) + (fn [shape] + (assoc shape :fills (ths/sample-fills-color :fill-color "#FF0000"))) + (:objects page) + {}) + + file' (thf/apply-changes file changes-update-color-comp-1)] + + (t/is (= (first-child-fill-color file' :comp-1-comp-2) "#B1B2B5")) + file')) + + (step-propagate-comp-2 [file] + (let [page (thf/current-page file) + file-id (:id file) + page-id (:id page) + + ;; Changes to propagate the color changes of component comp-1 + changes-sync-comp-1 (-> (pcb/empty-changes) + (cll/generate-sync-file-changes + nil + :components + file-id + (:id (thc/get-component file :comp-2)) + file-id + {file-id file} + file-id)) + + file' (thf/apply-changes file changes-sync-comp-1)] + + (t/is (= (first-fill-color file' :rect-comp-2) "#FF0000")) + (t/is (= (first-child-fill-color file' :comp-1-comp-2) "#FF0000")) + file')) + + (step-update-color-comp-3 [file] + (let [page (thf/current-page file) + page-id (:id page) + comp-1-comp-2 (ths/get-shape file :comp-1-comp-2) + rect-comp-3 (ths/get-shape-by-id file (first (:shapes comp-1-comp-2))) + ;; Changes to update the color of the contained rectangle in component comp-3 + changes-update-color-comp-3 + (cls/generate-update-shapes (pcb/empty-changes nil page-id) + [(:id rect-comp-3)] + (fn [shape] + (assoc shape :fills (ths/sample-fills-color :fill-color "#00FF00"))) + (:objects page) + {}) + + file' (thf/apply-changes file changes-update-color-comp-3) + page' (thf/current-page file')] + + (t/is (= (first-child-fill-color file' :comp-1-comp-2) "#00FF00")) + file')) + + (step-reset [file] + (let [page (thf/current-page file) + file-id (:id file) + comp-1-comp-2 (ths/get-shape file :comp-1-comp-2) + ;; Changes to reset the changes on comp-1 inside comp-3 + changes-reset (cll/generate-reset-component (pcb/empty-changes) + file + {file-id file} + (ctn/make-container page :page) + (:id comp-1-comp-2) + true) + file' (thf/apply-changes file changes-reset)] + + (t/is (= (first-child-fill-color file' :comp-1-comp-2) "#FF0000")) + file'))] + + (-> (setup) + step-update-color-comp-2 + step-propagate-comp-2 + step-update-color-comp-3 + step-reset))) + +(t/deftest test-propagation-with-deleted-component + (letfn [(setup [] + (-> (thf/sample-file :file1) + (tho/add-frame :frame-comp-4) + (ths/add-sample-shape :rectangle :parent-label :frame-comp-4) + (thc/make-component :comp-4 :frame-comp-4) + + (tho/add-frame :frame-comp-5) + (thc/instantiate-component :comp-4 :copy-comp-4 :parent-label :frame-comp-5 :children-labels [:rect-comp-5]) + (thc/make-component :comp-5 :frame-comp-5) + + (tho/add-frame :frame-comp-6) + (thc/instantiate-component :comp-5 :copy-comp-5 :parent-label :frame-comp-6 :children-labels [:comp-4-comp-5]) + (thc/make-component :comp-6 :frame-comp-6))) + + (step-delete-comp-5 [file] + (let [page (thf/current-page file) + ;; Changes to delete comp-5 + [_ changes-delete] (cls/generate-delete-shapes (pcb/empty-changes nil (:id page)) + file + page + (:objects page) + #{(-> (ths/get-shape file :frame-comp-5) + :id)} + {:components-v2 true}) + + file' (thf/apply-changes file changes-delete)] + (t/is (= (first-child-fill-color file' :comp-4-comp-5) "#B1B2B5")) + file')) + + (step-update-color-comp-4 [file] + (let [page (thf/current-page file) + file-id (:id file) + ;; Changes to update the color of the contained rectangle in component comp-4 + changes-update-color-comp-4 + (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + [(-> (ths/get-shape file :rectangle) + :id)] + (fn [shape] + (assoc shape :fills (ths/sample-fills-color :fill-color "#FF0000"))) + (:objects page) + {}) + + file' (thf/apply-changes file changes-update-color-comp-4)] + (t/is (= (first-fill-color file' :rectangle) "#FF0000")) + file')) + + (step-propagate-comp-4 [file] + (let [page (thf/current-page file) + file-id (:id file) + ;; Changes to propagate the color changes of component comp-4 + changes-sync-comp-4 (-> (pcb/empty-changes) + (cll/generate-sync-file-changes + nil + :components + file-id + (:id (thc/get-component file :comp-4)) + file-id + {file-id file} + file-id)) + + file' (thf/apply-changes file changes-sync-comp-4)] + file')) + + (step-propagate-comp-5 [file] + (let [file-id (:id file) + ;; Changes to propagate the color changes of component comp-5 + changes-sync-comp-5 (-> (pcb/empty-changes) + (cll/generate-sync-file-changes + nil + :components + file-id + (:id (thc/get-component file :comp-5)) + file-id + {file-id file} + file-id)) + file' (thf/apply-changes file changes-sync-comp-5)] + (t/is (= (first-child-fill-color file' :comp-4-comp-5) "#FF0000")) + file'))] + + (-> (setup) + step-delete-comp-5 + step-update-color-comp-4 + step-propagate-comp-4 + step-propagate-comp-5)))