From ff4e27a1d5154ad7f671ba3a19f253f6fe7da7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 25 Apr 2024 16:57:37 +0200 Subject: [PATCH] :white_check_mark: Add composition helpers --- .../common_tests/helpers/compositions.cljc | 42 +++++++++++++++++++ common/test/common_tests/types_file_test.cljc | 37 ++++------------ 2 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 common/test/common_tests/helpers/compositions.cljc diff --git a/common/test/common_tests/helpers/compositions.cljc b/common/test/common_tests/helpers/compositions.cljc new file mode 100644 index 000000000..6306fc51a --- /dev/null +++ b/common/test/common_tests/helpers/compositions.cljc @@ -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))) diff --git a/common/test/common_tests/types_file_test.cljc b/common/test/common_tests/types_file_test.cljc index 1e316bc78..04b76b565 100644 --- a/common/test/common_tests/types_file_test.cljc +++ b/common/test/common_tests/types_file_test.cljc @@ -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'))))) -