From 42acdbd135df83b69ddefd2fe0583d60204e6deb Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 16 Jan 2025 17:55:28 +0100 Subject: [PATCH] :recycle: Reorganize common types tests --- common/test/common_tests/helpers_test.cljc | 65 +++++++++++++++++++ common/test/common_tests/runner.cljc | 16 ++--- ...ries_test.cljc => absorb_assets_test.cljc} | 56 ++-------------- ...mponent_test.cljc => components_test.cljc} | 2 +- .../modifiers_test.cljc} | 4 +- .../shape_interactions_test.cljc} | 3 +- 6 files changed, 81 insertions(+), 65 deletions(-) create mode 100644 common/test/common_tests/helpers_test.cljc rename common/test/common_tests/types/{types_libraries_test.cljc => absorb_assets_test.cljc} (76%) rename common/test/common_tests/types/{types_component_test.cljc => components_test.cljc} (97%) rename common/test/common_tests/{types_modifiers_test.cljc => types/modifiers_test.cljc} (92%) rename common/test/common_tests/{types_shape_interactions_test.cljc => types/shape_interactions_test.cljc} (99%) diff --git a/common/test/common_tests/helpers_test.cljc b/common/test/common_tests/helpers_test.cljc new file mode 100644 index 000000000..7f478207d --- /dev/null +++ b/common/test/common_tests/helpers_test.cljc @@ -0,0 +1,65 @@ +;; 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-test + (:require + [app.common.data :as d] + [app.common.test-helpers.components :as thc] + [app.common.test-helpers.compositions :as tho] + [app.common.test-helpers.files :as thf] + [app.common.test-helpers.ids-map :as thi] + [app.common.test-helpers.shapes :as ths] + [clojure.test :as t])) + +(t/use-fixtures :each thi/test-fixture) + +(t/deftest create-file + (let [f1 (thf/sample-file :file1) + f2 (thf/sample-file :file2 :page-label :page1) + f3 (thf/sample-file :file3 :name "testing file") + f4 (-> (thf/sample-file :file4 :page-label :page2) + (thf/add-sample-page :page3 :name "testing page") + (ths/add-sample-shape :shape1)) + f5 (-> f4 + (ths/add-sample-shape :shape2) + (thf/switch-to-page :page2) + (ths/add-sample-shape :shape3 :name "testing shape" :width 100)) + s1 (ths/get-shape f4 :shape1) + s2 (ths/get-shape f5 :shape2 :page-label :page3) + s3 (ths/get-shape f5 :shape3)] + + ;; (thf/pprint-file f4) + + (t/is (= (:name f1) "Test file")) + (t/is (= (:name f3) "testing file")) + (t/is (= (:id f2) (thi/id :file2))) + (t/is (= (:id f4) (thi/id :file4))) + (t/is (= (-> f4 :data :pages-index vals first :id) (thi/id :page2))) + (t/is (= (-> f4 :data :pages-index vals first :name) "Page 1")) + (t/is (= (-> f4 :data :pages-index vals second :id) (thi/id :page3))) + (t/is (= (-> f4 :data :pages-index vals second :name) "testing page")) + + (t/is (= (:id (thf/current-page f2)) (thi/id :page1))) + (t/is (= (:id (thf/current-page f4)) (thi/id :page3))) + (t/is (= (:id (thf/current-page f5)) (thi/id :page2))) + + (t/is (= (:id s1) (thi/id :shape1))) + (t/is (= (:name s1) "Rectangle")) + (t/is (= (:id s2) (thi/id :shape2))) + (t/is (= (:name s2) "Rectangle")) + (t/is (= (:id s3) (thi/id :shape3))) + (t/is (= (:name s3) "testing shape")) + (t/is (= (:width s3) 100)) + (t/is (= (:width (:selrect s3)) 100)))) + +(t/deftest create-components + (let [f1 (-> (thf/sample-file :file1) + (tho/add-simple-component-with-copy :component1 :main-root :main-child :copy-root))] + + #_(thf/dump-file f1) + #_(thf/pprint-file f4) + + (t/is (= (:name f1) "Test file")))) diff --git a/common/test/common_tests/runner.cljc b/common/test/common_tests/runner.cljc index 443bce779..6b30a8886 100644 --- a/common/test/common_tests/runner.cljc +++ b/common/test/common_tests/runner.cljc @@ -35,12 +35,12 @@ [common-tests.svg-test] [common-tests.text-test] [common-tests.time-test] - [common-tests.types-modifiers-test] - [common-tests.types-shape-interactions-test] + [common-tests.types.absorb-assets-test] + [common-tests.types.components-test] + [common-tests.types.modifiers-test] [common-tests.types.shape-decode-encode-test] + [common-tests.types.shape-interactions-test] [common-tests.types.tokens-lib-test] - [common-tests.types.types-component-test] - [common-tests.types.types-libraries-test] [common-tests.uuid-test])) #?(:cljs (enable-console-print!)) @@ -82,10 +82,10 @@ 'common-tests.svg-test 'common-tests.text-test 'common-tests.time-test - 'common-tests.types-modifiers-test - 'common-tests.types-shape-interactions-test + 'common-tests.types.modifiers-test + 'common-tests.types.shape-interactions-test 'common-tests.types.shape-decode-encode-test 'common-tests.types.tokens-lib-test - 'common-tests.types.types-component-test - 'common-tests.types.types-libraries-test + 'common-tests.types.components-test + 'common-tests.types.absorb-assets-test 'common-tests.uuid-test)) diff --git a/common/test/common_tests/types/types_libraries_test.cljc b/common/test/common_tests/types/absorb_assets_test.cljc similarity index 76% rename from common/test/common_tests/types/types_libraries_test.cljc rename to common/test/common_tests/types/absorb_assets_test.cljc index ab13cf868..790d029b0 100644 --- a/common/test/common_tests/types/types_libraries_test.cljc +++ b/common/test/common_tests/types/absorb_assets_test.cljc @@ -4,7 +4,7 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns common-tests.types.types-libraries-test +(ns common-tests.types.absorb-assets-test (:require [app.common.data :as d] [app.common.test-helpers.components :as thc] @@ -23,55 +23,7 @@ (t/use-fixtures :each thi/test-fixture) -(t/deftest test-create-file - (let [f1 (thf/sample-file :file1) - f2 (thf/sample-file :file2 :page-label :page1) - f3 (thf/sample-file :file3 :name "testing file") - f4 (-> (thf/sample-file :file4 :page-label :page2) - (thf/add-sample-page :page3 :name "testing page") - (ths/add-sample-shape :shape1)) - f5 (-> f4 - (ths/add-sample-shape :shape2) - (thf/switch-to-page :page2) - (ths/add-sample-shape :shape3 :name "testing shape" :width 100)) - s1 (ths/get-shape f4 :shape1) - s2 (ths/get-shape f5 :shape2 :page-label :page3) - s3 (ths/get-shape f5 :shape3)] - - ;; (thf/pprint-file f4) - - (t/is (= (:name f1) "Test file")) - (t/is (= (:name f3) "testing file")) - (t/is (= (:id f2) (thi/id :file2))) - (t/is (= (:id f4) (thi/id :file4))) - (t/is (= (-> f4 :data :pages-index vals first :id) (thi/id :page2))) - (t/is (= (-> f4 :data :pages-index vals first :name) "Page 1")) - (t/is (= (-> f4 :data :pages-index vals second :id) (thi/id :page3))) - (t/is (= (-> f4 :data :pages-index vals second :name) "testing page")) - - (t/is (= (:id (thf/current-page f2)) (thi/id :page1))) - (t/is (= (:id (thf/current-page f4)) (thi/id :page3))) - (t/is (= (:id (thf/current-page f5)) (thi/id :page2))) - - (t/is (= (:id s1) (thi/id :shape1))) - (t/is (= (:name s1) "Rectangle")) - (t/is (= (:id s2) (thi/id :shape2))) - (t/is (= (:name s2) "Rectangle")) - (t/is (= (:id s3) (thi/id :shape3))) - (t/is (= (:name s3) "testing shape")) - (t/is (= (:width s3) 100)) - (t/is (= (:width (:selrect s3)) 100)))) - -(t/deftest test-create-components - (let [f1 (-> (thf/sample-file :file1) - (tho/add-simple-component-with-copy :component1 :main-root :main-child :copy-root))] - - #_(thf/dump-file f1) - #_(thf/pprint-file f4) - - (t/is (= (:name f1) "Test file")))) - -(t/deftest test-absorb-components +(t/deftest absorb-components (let [;; Setup library (-> (thf/sample-file :library :is-shared true) (tho/add-simple-component :component1 :main-root :rect1)) @@ -105,7 +57,7 @@ (t/is (ctk/is-main-of? main-root' copy-root' true)) (t/is (ctk/main-instance-of? (:id main-root') (:id (second pages')) component')))) -(t/deftest test-absorb-colors +(t/deftest absorb-colors (let [;; Setup library (-> (thf/sample-file :library :is-shared true) (ths/add-sample-library-color :color1 {:name "Test color" @@ -142,7 +94,7 @@ (t/is (= (:fill-color-ref-id fill') (thi/id :color1))) (t/is (= (:fill-color-ref-file fill') (:id file'))))) -(t/deftest test-absorb-typographies +(t/deftest absorb-typographies (let [;; Setup library (-> (thf/sample-file :library :is-shared true) (ths/add-sample-typography :typography1 {:name "Test typography"})) diff --git a/common/test/common_tests/types/types_component_test.cljc b/common/test/common_tests/types/components_test.cljc similarity index 97% rename from common/test/common_tests/types/types_component_test.cljc rename to common/test/common_tests/types/components_test.cljc index d46480bf7..36394f29a 100644 --- a/common/test/common_tests/types/types_component_test.cljc +++ b/common/test/common_tests/types/components_test.cljc @@ -4,7 +4,7 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns common-tests.types.types-component-test +(ns common-tests.types.components-test (:require [app.common.test-helpers.ids-map :as thi] [app.common.test-helpers.shapes :as ths] diff --git a/common/test/common_tests/types_modifiers_test.cljc b/common/test/common_tests/types/modifiers_test.cljc similarity index 92% rename from common/test/common_tests/types_modifiers_test.cljc rename to common/test/common_tests/types/modifiers_test.cljc index 740d49628..264b3e71e 100644 --- a/common/test/common_tests/types_modifiers_test.cljc +++ b/common/test/common_tests/types/modifiers_test.cljc @@ -4,14 +4,14 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns common-tests.types-modifiers-test +(ns common-tests.types.modifiers-test (:require [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] [app.common.types.modifiers :as ctm] [clojure.test :as t])) -(t/deftest test-modifiers->transform +(t/deftest modifiers->transform (let [modifiers (-> (ctm/empty) (ctm/move (gpt/point 100 200)) diff --git a/common/test/common_tests/types_shape_interactions_test.cljc b/common/test/common_tests/types/shape_interactions_test.cljc similarity index 99% rename from common/test/common_tests/types_shape_interactions_test.cljc rename to common/test/common_tests/types/shape_interactions_test.cljc index 5a699278d..853a68ba8 100644 --- a/common/test/common_tests/types_shape_interactions_test.cljc +++ b/common/test/common_tests/types/shape_interactions_test.cljc @@ -4,7 +4,7 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns common-tests.types-shape-interactions-test +(ns common-tests.types.shape-interactions-test (:require [app.common.exceptions :as ex] [app.common.geom.point :as gpt] @@ -50,7 +50,6 @@ (t/is (= :after-delay (:event-type new-interaction))) (t/is (= 300 (:delay new-interaction))))))) - (t/deftest set-action-type (let [interaction ctsi/default-interaction]