mirror of
https://github.com/penpot/penpot.git
synced 2025-02-08 16:18:11 -05:00
✅ Add test for touched shapes
This commit is contained in:
parent
5611fcfc2c
commit
a40afd5b63
8 changed files with 122 additions and 111 deletions
|
@ -10,35 +10,44 @@
|
||||||
[common-tests.helpers.ids-map :as thi]))
|
[common-tests.helpers.ids-map :as thi]))
|
||||||
|
|
||||||
(defn add-rect
|
(defn add-rect
|
||||||
[file rect-label]
|
[file rect-label & {:keys [] :as params}]
|
||||||
(thf/add-sample-shape file rect-label
|
(thf/add-sample-shape file rect-label
|
||||||
:type :rect
|
(merge {:type :rect
|
||||||
:name "Rect1"))
|
:name "Rect1"}
|
||||||
|
params)))
|
||||||
|
|
||||||
(defn add-frame
|
(defn add-frame
|
||||||
([file frame-label & {:keys [parent-label]}]
|
[file frame-label & {:keys [] :as params}]
|
||||||
(thf/add-sample-shape file frame-label
|
(thf/add-sample-shape file frame-label
|
||||||
:type :frame
|
(merge {:type :frame
|
||||||
:name "Frame1"
|
:name "Frame1"}
|
||||||
:parent-label parent-label)))
|
params)))
|
||||||
|
|
||||||
(defn add-frame-with-child
|
(defn add-frame-with-child
|
||||||
[file frame-label child-label]
|
[file frame-label child-label & {:keys [frame-params child-params]}]
|
||||||
(-> file
|
(-> file
|
||||||
(add-frame frame-label)
|
(add-frame frame-label frame-params)
|
||||||
(thf/add-sample-shape child-label
|
(thf/add-sample-shape child-label
|
||||||
:type :rect
|
(merge {:type :rect
|
||||||
:name "Rect1"
|
:name "Rect1"
|
||||||
:parent-label frame-label)))
|
:parent-label frame-label}
|
||||||
|
child-params))))
|
||||||
|
|
||||||
(defn add-simple-component
|
(defn add-simple-component
|
||||||
[file component-label root-label child-label]
|
[file component-label root-label child-label
|
||||||
|
& {:keys [component-params root-params child-params]}]
|
||||||
(-> file
|
(-> file
|
||||||
(add-frame-with-child root-label child-label)
|
(add-frame-with-child root-label child-label :frame-params root-params :child-params child-params)
|
||||||
(thf/make-component component-label root-label)))
|
(thf/make-component component-label root-label component-params)))
|
||||||
|
|
||||||
(defn add-simple-component-with-copy
|
(defn add-simple-component-with-copy
|
||||||
[file component-label main-root-label main-child-label copy-root-label]
|
[file component-label main-root-label main-child-label copy-root-label
|
||||||
|
& {:keys [component-params main-root-params main-child-params copy-root-params]}]
|
||||||
(-> file
|
(-> file
|
||||||
(add-simple-component component-label main-root-label main-child-label)
|
(add-simple-component component-label
|
||||||
(thf/instantiate-component component-label copy-root-label)))
|
main-root-label
|
||||||
|
main-child-label
|
||||||
|
:component-params component-params
|
||||||
|
:root-params main-root-params
|
||||||
|
:child-params main-child-params)
|
||||||
|
(thf/instantiate-component component-label copy-root-label copy-root-params)))
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
(ns common-tests.helpers.files
|
(ns common-tests.helpers.files
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.colors :as clr]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.features :as ffeat]
|
[app.common.features :as ffeat]
|
||||||
[app.common.files.changes :as cfc]
|
[app.common.files.changes :as cfc]
|
||||||
|
@ -169,7 +170,7 @@
|
||||||
;; ----- Components
|
;; ----- Components
|
||||||
|
|
||||||
(defn make-component
|
(defn make-component
|
||||||
[file label root-label]
|
[file label root-label & {:keys [] :as params}]
|
||||||
(let [page (current-page file)
|
(let [page (current-page file)
|
||||||
root (get-shape file root-label)]
|
root (get-shape file root-label)]
|
||||||
|
|
||||||
|
@ -194,12 +195,12 @@
|
||||||
#(update % :objects assoc (:id shape) shape)))
|
#(update % :objects assoc (:id shape) shape)))
|
||||||
$
|
$
|
||||||
updated-shapes)
|
updated-shapes)
|
||||||
(ctkl/add-component $
|
(ctkl/add-component $ (assoc params
|
||||||
{:id (:component-id updated-root)
|
:id (:component-id updated-root)
|
||||||
:name (:name updated-root)
|
:name (:name updated-root)
|
||||||
:main-instance-id (:id updated-root)
|
:main-instance-id (:id updated-root)
|
||||||
:main-instance-page (:id page)
|
:main-instance-page (:id page)
|
||||||
:shapes updated-shapes})))))))
|
:shapes updated-shapes))))))))
|
||||||
|
|
||||||
(defn get-component
|
(defn get-component
|
||||||
[file label]
|
[file label]
|
||||||
|
@ -306,7 +307,21 @@
|
||||||
[label & {:keys [] :as params}]
|
[label & {:keys [] :as params}]
|
||||||
(ctc/make-color (assoc params :id (thi/new-id! label))))
|
(ctc/make-color (assoc params :id (thi/new-id! label))))
|
||||||
|
|
||||||
(defn add-sample-color
|
(defn sample-fill-color
|
||||||
|
[& {:keys [fill-color fill-opacity] :as params}]
|
||||||
|
(let [params (cond-> params
|
||||||
|
(nil? fill-color)
|
||||||
|
(assoc :fill-color clr/black)
|
||||||
|
|
||||||
|
(nil? fill-opacity)
|
||||||
|
(assoc :fill-opacity 1))]
|
||||||
|
params))
|
||||||
|
|
||||||
|
(defn sample-fills-color
|
||||||
|
[& {:keys [] :as params}]
|
||||||
|
[(sample-fill-color params)])
|
||||||
|
|
||||||
|
(defn add-sample-library-color
|
||||||
[file label & {:keys [] :as params}]
|
[file label & {:keys [] :as params}]
|
||||||
(let [color (sample-color label params)]
|
(let [color (sample-color label params)]
|
||||||
(ctf/update-file-data file #(ctcl/add-color % color))))
|
(ctf/update-file-data file #(ctcl/add-color % color))))
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) KALEIDOS INC
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
(ns common-tests.logic.logic-comp-creation-test
|
(ns common-tests.logic.component-creation-test
|
||||||
(:require
|
(:require
|
||||||
[app.common.files.changes-builder :as pcb]
|
[app.common.files.changes-builder :as pcb]
|
||||||
[app.common.files.libraries-helpers :as cflh]
|
[app.common.files.libraries-helpers :as cflh]
|
||||||
|
@ -15,14 +15,14 @@
|
||||||
(t/use-fixtures :each thi/test-fixture)
|
(t/use-fixtures :each thi/test-fixture)
|
||||||
|
|
||||||
(t/deftest test-add-component-from-single-shape
|
(t/deftest test-add-component-from-single-shape
|
||||||
(let [; Setup
|
(let [;; Setup
|
||||||
file (-> (thf/sample-file :file1)
|
file (-> (thf/sample-file :file1)
|
||||||
(thf/add-sample-shape :shape1 :type :frame))
|
(thf/add-sample-shape :shape1 :type :frame))
|
||||||
|
|
||||||
page (thf/current-page file)
|
page (thf/current-page file)
|
||||||
shape1 (thf/get-shape file :shape1)
|
shape1 (thf/get-shape file :shape1)
|
||||||
|
|
||||||
; Action
|
;; Action
|
||||||
[_ component-id changes]
|
[_ component-id changes]
|
||||||
(cflh/generate-add-component (pcb/empty-changes)
|
(cflh/generate-add-component (pcb/empty-changes)
|
||||||
[shape1]
|
[shape1]
|
||||||
|
@ -35,11 +35,11 @@
|
||||||
|
|
||||||
file' (thf/apply-changes file changes)
|
file' (thf/apply-changes file changes)
|
||||||
|
|
||||||
; Get
|
;; Get
|
||||||
component (thf/get-component-by-id file' component-id)
|
component (thf/get-component-by-id file' component-id)
|
||||||
root (thf/get-shape-by-id file' (:main-instance-id component))]
|
root (thf/get-shape-by-id file' (:main-instance-id component))]
|
||||||
|
|
||||||
; Check
|
;; Check
|
||||||
(t/is (some? component))
|
(t/is (some? component))
|
||||||
(t/is (some? root))
|
(t/is (some? root))
|
||||||
(t/is (= (:component-id root) (:id component)))))
|
(t/is (= (:component-id root) (:id component)))))
|
51
common/test/common_tests/logic/components_touched_test.cljc
Normal file
51
common/test/common_tests/logic/components_touched_test.cljc
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
;; 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.components-touched-test
|
||||||
|
(:require
|
||||||
|
[app.common.files.changes-builder :as pcb]
|
||||||
|
[app.common.files.libraries-helpers :as cflh]
|
||||||
|
[clojure.test :as t]
|
||||||
|
[common-tests.helpers.compositions :as tho]
|
||||||
|
[common-tests.helpers.files :as thf]
|
||||||
|
[common-tests.helpers.ids-map :as thi]))
|
||||||
|
|
||||||
|
(t/use-fixtures :each thi/test-fixture)
|
||||||
|
|
||||||
|
(t/deftest test-touched-when-changing-attribute
|
||||||
|
(let [;; Setup
|
||||||
|
file (-> (thf/sample-file :file1)
|
||||||
|
(tho/add-simple-component-with-copy :component1
|
||||||
|
:main-root
|
||||||
|
:main-child
|
||||||
|
:copy-root
|
||||||
|
:main-child-params {:fills (thf/sample-fills-color
|
||||||
|
:fill-color "#abcdef")}))
|
||||||
|
page (thf/current-page file)
|
||||||
|
copy-root (thf/get-shape file :copy-root)
|
||||||
|
|
||||||
|
;; Action
|
||||||
|
changes (cflh/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||||
|
(:shapes copy-root)
|
||||||
|
#(assoc % :fills (thf/sample-fills-color
|
||||||
|
:fill-color "#fabada"))
|
||||||
|
(:objects page)
|
||||||
|
{})
|
||||||
|
|
||||||
|
file' (thf/apply-changes file changes)
|
||||||
|
|
||||||
|
;; Get
|
||||||
|
copy-root' (thf/get-shape file' :copy-root)
|
||||||
|
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))
|
||||||
|
fills' (:fills copy-child')
|
||||||
|
fill' (first fills')]
|
||||||
|
|
||||||
|
;; Check
|
||||||
|
(t/is (= (count fills') 1))
|
||||||
|
(t/is (= (:fill-color fill') "#fabada"))
|
||||||
|
(t/is (= (:fill-opacity fill') 1))
|
||||||
|
(t/is (= (:touched copy-root') nil))
|
||||||
|
(t/is (= (:touched copy-child') #{:fill-group}))))
|
|
@ -70,21 +70,21 @@
|
||||||
(t/is (= (:name f1) "Test file"))))
|
(t/is (= (:name f1) "Test file"))))
|
||||||
|
|
||||||
(t/deftest test-absorb-components
|
(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))
|
||||||
|
|
||||||
file (-> (thf/sample-file :file)
|
file (-> (thf/sample-file :file)
|
||||||
(thf/instantiate-component :component1 :copy-root :library library))
|
(thf/instantiate-component :component1 :copy-root :library library))
|
||||||
|
|
||||||
; Action
|
;; Action
|
||||||
file' (ctf/update-file-data
|
file' (ctf/update-file-data
|
||||||
file
|
file
|
||||||
#(ctf/absorb-assets % (:data library)))
|
#(ctf/absorb-assets % (:data library)))
|
||||||
|
|
||||||
_ (thf/validate-file! file')
|
_ (thf/validate-file! file')
|
||||||
|
|
||||||
; Get
|
;; Get
|
||||||
pages' (ctpl/pages-seq (ctf/file-data file'))
|
pages' (ctpl/pages-seq (ctf/file-data file'))
|
||||||
components' (ctkl/components-seq (ctf/file-data file'))
|
components' (ctkl/components-seq (ctf/file-data file'))
|
||||||
component' (first components')
|
component' (first components')
|
||||||
|
@ -92,7 +92,7 @@
|
||||||
copy-root' (thf/get-shape file' :copy-root)
|
copy-root' (thf/get-shape file' :copy-root)
|
||||||
main-root' (ctf/get-ref-shape (ctf/file-data file') component' copy-root')]
|
main-root' (ctf/get-ref-shape (ctf/file-data file') component' copy-root')]
|
||||||
|
|
||||||
; Check
|
;; Check
|
||||||
(t/is (= (count pages') 2))
|
(t/is (= (count pages') 2))
|
||||||
(t/is (= (:name (first pages')) "Page 1"))
|
(t/is (= (:name (first pages')) "Page 1"))
|
||||||
(t/is (= (:name (second pages')) "Main components"))
|
(t/is (= (:name (second pages')) "Main components"))
|
||||||
|
@ -104,9 +104,9 @@
|
||||||
(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 test-absorb-colors
|
||||||
(let [; Setup
|
(let [;; Setup
|
||||||
library (-> (thf/sample-file :library :is-shared true)
|
library (-> (thf/sample-file :library :is-shared true)
|
||||||
(thf/add-sample-color :color1 {:name "Test color"
|
(thf/add-sample-library-color :color1 {:name "Test color"
|
||||||
:color "#abcdef"}))
|
:color "#abcdef"}))
|
||||||
|
|
||||||
file (-> (thf/sample-file :file)
|
file (-> (thf/sample-file :file)
|
||||||
|
@ -118,19 +118,19 @@
|
||||||
:fill-color-ref-id (thi/id :color1)
|
:fill-color-ref-id (thi/id :color1)
|
||||||
:fill-color-ref-file (thi/id :library)}]))
|
:fill-color-ref-file (thi/id :library)}]))
|
||||||
|
|
||||||
; Action
|
;; Action
|
||||||
file' (ctf/update-file-data
|
file' (ctf/update-file-data
|
||||||
file
|
file
|
||||||
#(ctf/absorb-assets % (:data library)))
|
#(ctf/absorb-assets % (:data library)))
|
||||||
|
|
||||||
_ (thf/validate-file! file')
|
_ (thf/validate-file! file')
|
||||||
|
|
||||||
; Get
|
;; Get
|
||||||
colors' (ctcl/colors-seq (ctf/file-data file'))
|
colors' (ctcl/colors-seq (ctf/file-data file'))
|
||||||
shape1' (thf/get-shape file' :shape1)
|
shape1' (thf/get-shape file' :shape1)
|
||||||
fill' (first (:fills shape1'))]
|
fill' (first (:fills shape1'))]
|
||||||
|
|
||||||
; Check
|
;; Check
|
||||||
(t/is (= (count colors') 1))
|
(t/is (= (count colors') 1))
|
||||||
(t/is (= (:id (first colors')) (thi/id :color1)))
|
(t/is (= (:id (first colors')) (thi/id :color1)))
|
||||||
(t/is (= (:name (first colors')) "Test color"))
|
(t/is (= (:name (first colors')) "Test color"))
|
||||||
|
@ -141,7 +141,7 @@
|
||||||
(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 test-absorb-typographies
|
||||||
(let [; Setup
|
(let [;; Setup
|
||||||
library (-> (thf/sample-file :library :is-shared true)
|
library (-> (thf/sample-file :library :is-shared true)
|
||||||
(thf/add-sample-typography :typography1 {:name "Test typography"}))
|
(thf/add-sample-typography :typography1 {:name "Test typography"}))
|
||||||
|
|
||||||
|
@ -169,18 +169,19 @@
|
||||||
:letter-spacing "0"
|
:letter-spacing "0"
|
||||||
:fills [{:fill-color "#000000"
|
:fills [{:fill-color "#000000"
|
||||||
:fill-opacity 1}]}]}]}]}))
|
:fill-opacity 1}]}]}]}]}))
|
||||||
; Action
|
;; Action
|
||||||
file' (ctf/update-file-data
|
file' (ctf/update-file-data
|
||||||
file
|
file
|
||||||
#(ctf/absorb-assets % (:data library)))
|
#(ctf/absorb-assets % (:data library)))
|
||||||
|
|
||||||
_ (thf/validate-file! file')
|
_ (thf/validate-file! file')
|
||||||
|
|
||||||
; Get
|
;; Get
|
||||||
typographies' (ctyl/typographies-seq (ctf/file-data file'))
|
typographies' (ctyl/typographies-seq (ctf/file-data file'))
|
||||||
shape1' (thf/get-shape file' :shape1)
|
shape1' (thf/get-shape file' :shape1)
|
||||||
text-node' (d/seek #(some? (:text %)) (txt/node-seq (:content shape1')))]
|
text-node' (d/seek #(some? (:text %)) (txt/node-seq (:content shape1')))]
|
||||||
|
|
||||||
|
;; Check
|
||||||
(t/is (= (count typographies') 1))
|
(t/is (= (count typographies') 1))
|
||||||
(t/is (= (:id (first typographies')) (thi/id :typography1)))
|
(t/is (= (:id (first typographies')) (thi/id :typography1)))
|
||||||
(t/is (= (:name (first typographies')) "Test typography"))
|
(t/is (= (:name (first typographies')) "Test typography"))
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
[app.common.logging :as log]
|
[app.common.logging :as log]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.types.shape-tree :as ctst]
|
[app.common.types.shape-tree :as ctst]
|
||||||
[app.common.types.shape.layout :as ctl]
|
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.workspace.state-helpers :as wsh]
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.data.workspace.undo :as dwu]
|
[app.main.data.workspace.undo :as dwu]
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
(ns frontend-tests.state-components-sync-test
|
(ns frontend-tests.state-components-sync-test
|
||||||
(:require
|
(:require
|
||||||
[app.common.colors :as clr]
|
[app.common.colors :as clr]
|
||||||
[app.common.types.file :as ctf]
|
|
||||||
[app.main.data.workspace :as dw]
|
[app.main.data.workspace :as dw]
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
[app.main.data.workspace.libraries :as dwl]
|
[app.main.data.workspace.libraries :as dwl]
|
||||||
|
@ -24,69 +23,6 @@
|
||||||
|
|
||||||
;; === Test touched ======================
|
;; === Test touched ======================
|
||||||
|
|
||||||
(t/deftest test-touched
|
|
||||||
(t/async done
|
|
||||||
(let [state (-> thp/initial-state
|
|
||||||
(thp/sample-page)
|
|
||||||
(thp/sample-shape :shape1 :rect
|
|
||||||
{:name "Rect 1"
|
|
||||||
:fill-color clr/white
|
|
||||||
:fill-opacity 1})
|
|
||||||
(thp/make-component :main1 :component1
|
|
||||||
[(thp/id :shape1)])
|
|
||||||
(thp/instantiate-component :instance1
|
|
||||||
(thp/id :component1)))
|
|
||||||
|
|
||||||
[_group1 shape1']
|
|
||||||
(thl/resolve-instance state (thp/id :instance1))
|
|
||||||
|
|
||||||
store (the/prepare-store state done
|
|
||||||
(fn [new-state]
|
|
||||||
;; Uncomment to debug
|
|
||||||
;; (ctf/dump-tree (get new-state :workspace-data)
|
|
||||||
;; (get new-state :current-page-id)
|
|
||||||
;; (get new-state :workspace-libraries)
|
|
||||||
;; false true)
|
|
||||||
;; Expected shape tree:
|
|
||||||
;;;
|
|
||||||
;; [Page]
|
|
||||||
;; Root Frame
|
|
||||||
;; Rect 1
|
|
||||||
;; Rect 1
|
|
||||||
;; Rect 1 #--> Rect 1
|
|
||||||
;; Rect 1* ---> Rect 1
|
|
||||||
;; #{:fill-group}
|
|
||||||
;;;
|
|
||||||
;; [Rect 1]
|
|
||||||
;; page1 / Rect 1
|
|
||||||
;;;
|
|
||||||
(let [[[group shape1] [c-group c-shape1] _component]
|
|
||||||
(thl/resolve-instance-and-main
|
|
||||||
new-state
|
|
||||||
(thp/id :instance1))]
|
|
||||||
|
|
||||||
(t/is (= (:name group) "Rect 1"))
|
|
||||||
(t/is (= (:touched group) nil))
|
|
||||||
(t/is (= (:name shape1) "Rect 1"))
|
|
||||||
(t/is (= (:touched shape1) #{:fill-group}))
|
|
||||||
(t/is (= (:fill-color shape1) clr/test))
|
|
||||||
(t/is (= (:fill-opacity shape1) 0.5))
|
|
||||||
|
|
||||||
(t/is (= (:name c-group) "Rect 1"))
|
|
||||||
(t/is (= (:touched c-group) nil))
|
|
||||||
(t/is (= (:name c-shape1) "Rect 1"))
|
|
||||||
(t/is (= (:touched c-shape1) nil))
|
|
||||||
(t/is (= (:fill-color c-shape1) clr/white))
|
|
||||||
(t/is (= (:fill-opacity c-shape1) 1)))))]
|
|
||||||
|
|
||||||
(ptk/emit!
|
|
||||||
store
|
|
||||||
(dch/update-shapes [(:id shape1')]
|
|
||||||
(fn [shape]
|
|
||||||
(merge shape {:fill-color clr/test
|
|
||||||
:fill-opacity 0.5})))
|
|
||||||
:the/end))))
|
|
||||||
|
|
||||||
(t/deftest test-touched-children-add
|
(t/deftest test-touched-children-add
|
||||||
(t/async done
|
(t/async done
|
||||||
(let [state (-> thp/initial-state
|
(let [state (-> thp/initial-state
|
||||||
|
|
Loading…
Add table
Reference in a new issue