0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-23 07:16:07 -05:00

♻️ Reorganize common types tests

This commit is contained in:
Andrey Antukh 2025-01-16 17:55:28 +01:00
parent 6b3f70e94b
commit 42acdbd135
6 changed files with 81 additions and 65 deletions

View file

@ -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"))))

View file

@ -35,12 +35,12 @@
[common-tests.svg-test] [common-tests.svg-test]
[common-tests.text-test] [common-tests.text-test]
[common-tests.time-test] [common-tests.time-test]
[common-tests.types-modifiers-test] [common-tests.types.absorb-assets-test]
[common-tests.types-shape-interactions-test] [common-tests.types.components-test]
[common-tests.types.modifiers-test]
[common-tests.types.shape-decode-encode-test] [common-tests.types.shape-decode-encode-test]
[common-tests.types.shape-interactions-test]
[common-tests.types.tokens-lib-test] [common-tests.types.tokens-lib-test]
[common-tests.types.types-component-test]
[common-tests.types.types-libraries-test]
[common-tests.uuid-test])) [common-tests.uuid-test]))
#?(:cljs (enable-console-print!)) #?(:cljs (enable-console-print!))
@ -82,10 +82,10 @@
'common-tests.svg-test 'common-tests.svg-test
'common-tests.text-test 'common-tests.text-test
'common-tests.time-test 'common-tests.time-test
'common-tests.types-modifiers-test 'common-tests.types.modifiers-test
'common-tests.types-shape-interactions-test 'common-tests.types.shape-interactions-test
'common-tests.types.shape-decode-encode-test 'common-tests.types.shape-decode-encode-test
'common-tests.types.tokens-lib-test 'common-tests.types.tokens-lib-test
'common-tests.types.types-component-test 'common-tests.types.components-test
'common-tests.types.types-libraries-test 'common-tests.types.absorb-assets-test
'common-tests.uuid-test)) 'common-tests.uuid-test))

View file

@ -4,7 +4,7 @@
;; ;;
;; Copyright (c) KALEIDOS INC ;; Copyright (c) KALEIDOS INC
(ns common-tests.types.types-libraries-test (ns common-tests.types.absorb-assets-test
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.test-helpers.components :as thc] [app.common.test-helpers.components :as thc]
@ -23,55 +23,7 @@
(t/use-fixtures :each thi/test-fixture) (t/use-fixtures :each thi/test-fixture)
(t/deftest test-create-file (t/deftest absorb-components
(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
(let [;; Setup (let [;; Setup
library (-> (thf/sample-file :library :is-shared true) library (-> (thf/sample-file :library :is-shared true)
(tho/add-simple-component :component1 :main-root :rect1)) (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/is-main-of? main-root' copy-root' true))
(t/is (ctk/main-instance-of? (:id main-root') (:id (second pages')) component')))) (t/is (ctk/main-instance-of? (:id main-root') (:id (second pages')) component'))))
(t/deftest test-absorb-colors (t/deftest absorb-colors
(let [;; Setup (let [;; Setup
library (-> (thf/sample-file :library :is-shared true) library (-> (thf/sample-file :library :is-shared true)
(ths/add-sample-library-color :color1 {:name "Test color" (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-id fill') (thi/id :color1)))
(t/is (= (:fill-color-ref-file fill') (:id file'))))) (t/is (= (:fill-color-ref-file fill') (:id file')))))
(t/deftest test-absorb-typographies (t/deftest absorb-typographies
(let [;; Setup (let [;; Setup
library (-> (thf/sample-file :library :is-shared true) library (-> (thf/sample-file :library :is-shared true)
(ths/add-sample-typography :typography1 {:name "Test typography"})) (ths/add-sample-typography :typography1 {:name "Test typography"}))

View file

@ -4,7 +4,7 @@
;; ;;
;; Copyright (c) KALEIDOS INC ;; Copyright (c) KALEIDOS INC
(ns common-tests.types.types-component-test (ns common-tests.types.components-test
(:require (:require
[app.common.test-helpers.ids-map :as thi] [app.common.test-helpers.ids-map :as thi]
[app.common.test-helpers.shapes :as ths] [app.common.test-helpers.shapes :as ths]

View file

@ -4,14 +4,14 @@
;; ;;
;; Copyright (c) KALEIDOS INC ;; Copyright (c) KALEIDOS INC
(ns common-tests.types-modifiers-test (ns common-tests.types.modifiers-test
(:require (:require
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.types.modifiers :as ctm] [app.common.types.modifiers :as ctm]
[clojure.test :as t])) [clojure.test :as t]))
(t/deftest test-modifiers->transform (t/deftest modifiers->transform
(let [modifiers (let [modifiers
(-> (ctm/empty) (-> (ctm/empty)
(ctm/move (gpt/point 100 200)) (ctm/move (gpt/point 100 200))

View file

@ -4,7 +4,7 @@
;; ;;
;; Copyright (c) KALEIDOS INC ;; Copyright (c) KALEIDOS INC
(ns common-tests.types-shape-interactions-test (ns common-tests.types.shape-interactions-test
(:require (:require
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
@ -50,7 +50,6 @@
(t/is (= :after-delay (:event-type new-interaction))) (t/is (= :after-delay (:event-type new-interaction)))
(t/is (= 300 (:delay new-interaction))))))) (t/is (= 300 (:delay new-interaction)))))))
(t/deftest set-action-type (t/deftest set-action-type
(let [interaction ctsi/default-interaction] (let [interaction ctsi/default-interaction]