mirror of
https://github.com/penpot/penpot.git
synced 2025-02-25 00:06:09 -05:00
Merge pull request #4580 from penpot/hiru-refactor-frontend-tests
Refactor frontend test helpers
This commit is contained in:
commit
cddc50036f
16 changed files with 170 additions and 80 deletions
|
@ -4,22 +4,22 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.helpers.components
|
||||
(ns app.common.test-helpers.components
|
||||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.types.pages-list :as ctpl]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[common-tests.helpers.shapes :as ths]))
|
||||
[app.common.types.shape-tree :as ctst]))
|
||||
|
||||
(defn make-component
|
||||
[file label root-label & {:keys [] :as params}]
|
|
@ -4,11 +4,11 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.helpers.compositions
|
||||
(ns app.common.test-helpers.compositions
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[common-tests.helpers.components :as thc]
|
||||
[common-tests.helpers.shapes :as ths]))
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.shapes :as ths]))
|
||||
|
||||
(defn add-rect
|
||||
[file rect-label & {:keys [] :as params}]
|
|
@ -4,19 +4,19 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.helpers.files
|
||||
(ns app.common.test-helpers.files
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.features :as ffeat]
|
||||
[app.common.files.changes :as cfc]
|
||||
[app.common.files.validate :as cfv]
|
||||
[app.common.pprint :refer [pprint]]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.types.page :as ctp]
|
||||
[app.common.types.pages-list :as ctpl]
|
||||
[app.common.uuid :as uuid]
|
||||
[common-tests.helpers.ids-map :as thi]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
;; ----- Files
|
|
@ -4,7 +4,7 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.helpers.ids-map
|
||||
(ns app.common.test-helpers.ids-map
|
||||
(:require
|
||||
[app.common.uuid :as uuid]))
|
||||
|
|
@ -4,10 +4,12 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.helpers.shapes
|
||||
(ns app.common.test-helpers.shapes
|
||||
(:require
|
||||
[app.common.colors :as clr]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.types.color :as ctc]
|
||||
[app.common.types.colors-list :as ctcl]
|
||||
[app.common.types.file :as ctf]
|
||||
|
@ -15,9 +17,7 @@
|
|||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[app.common.types.typographies-list :as cttl]
|
||||
[app.common.types.typography :as ctt]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]))
|
||||
[app.common.types.typography :as ctt]))
|
||||
|
||||
(defn sample-shape
|
||||
[label & {:keys [type] :as params}]
|
|
@ -6,21 +6,16 @@
|
|||
|
||||
(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.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]
|
||||
[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]))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
@ -55,8 +50,6 @@
|
|||
|
||||
(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
|
||||
|
@ -75,7 +68,6 @@
|
|||
(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)
|
||||
|
@ -108,8 +100,7 @@
|
|||
(:objects page)
|
||||
{})
|
||||
|
||||
file' (thf/apply-changes file changes-update-color-comp-3)
|
||||
page' (thf/current-page file')]
|
||||
file' (thf/apply-changes file changes-update-color-comp-3)]
|
||||
|
||||
(t/is (= (first-child-fill-color file' :comp-1-comp-2) "#00FF00"))
|
||||
file'))
|
||||
|
@ -168,7 +159,6 @@
|
|||
|
||||
(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))
|
||||
|
@ -184,8 +174,7 @@
|
|||
file'))
|
||||
|
||||
(step-propagate-comp-4 [file]
|
||||
(let [page (thf/current-page file)
|
||||
file-id (:id file)
|
||||
(let [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
|
||||
|
|
|
@ -12,15 +12,15 @@
|
|||
[app.common.geom.point :as gpt]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[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]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[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]))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
|
|
@ -10,19 +10,18 @@
|
|||
[app.common.geom.point :as gpt]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[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]
|
||||
[app.common.types.component :as ctk]
|
||||
[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]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
||||
;; Related .penpot file: common/test/cases/remove-swap-slots.penpot
|
||||
(defn- setup-file
|
||||
[]
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[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]))
|
||||
[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)
|
||||
|
||||
|
|
|
@ -8,19 +8,16 @@
|
|||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.files.shapes-helpers :as cfsh]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[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]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[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]))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[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]))
|
||||
[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)
|
||||
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[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]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.file :as ctf]
|
||||
[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]))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
|
|
@ -7,6 +7,11 @@
|
|||
(ns common-tests.types.types-libraries-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]
|
||||
[app.common.text :as txt]
|
||||
[app.common.types.colors-list :as ctcl]
|
||||
[app.common.types.component :as ctk]
|
||||
|
@ -14,12 +19,7 @@
|
|||
[app.common.types.file :as ctf]
|
||||
[app.common.types.pages-list :as ctpl]
|
||||
[app.common.types.typographies-list :as ctyl]
|
||||
[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]))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
|
|
49
frontend/test/frontend_tests/basic_shapes_test.cljs
Normal file
49
frontend/test/frontend_tests/basic_shapes_test.cljs
Normal file
|
@ -0,0 +1,49 @@
|
|||
;; 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 frontend-tests.basic-shapes-test
|
||||
(:require
|
||||
[app.common.test-helpers.files :as cthf]
|
||||
[app.common.test-helpers.ids-map :as cthi]
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[frontend-tests.helpers.state :as ths]))
|
||||
|
||||
(t/deftest test-update-shape
|
||||
(t/async
|
||||
done
|
||||
(let [;; ==== Setup
|
||||
store
|
||||
(ths/setup-store
|
||||
(-> (cthf/sample-file :file1 :page-label :page1)
|
||||
(cths/add-sample-shape :shape1)))
|
||||
|
||||
;; ==== Action
|
||||
events
|
||||
[(dch/update-shapes [(cthi/id :shape1)]
|
||||
#(assoc % :fills
|
||||
(cths/sample-fills-color :fill-color
|
||||
"#fabada")))]]
|
||||
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
shape1' (get-in new-state [:workspace-data
|
||||
:pages-index
|
||||
(cthi/id :page1)
|
||||
:objects
|
||||
(cthi/id :shape1)])
|
||||
fills' (:fills shape1')
|
||||
fill' (first fills')]
|
||||
|
||||
(cthf/dump-shape shape1')
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? shape1'))
|
||||
(t/is (= (count fills') 1))
|
||||
(t/is (= (:fill-color fill') "#fabada"))
|
||||
(t/is (= (:fill-opacity fill') 1))))))))
|
|
@ -97,7 +97,7 @@
|
|||
(if (empty? shapes)
|
||||
state
|
||||
(let [[group changes]
|
||||
(dwg/prepare-create-group nil (:objects page) (:id page) shapes prefix true)]
|
||||
(dwg/prepare-create-group (pcb/empty-changes) nil (:objects page) (:id page) shapes prefix true)]
|
||||
|
||||
(swap! idmap assoc label (:id group))
|
||||
(update state :workspace-data
|
||||
|
|
56
frontend/test/frontend_tests/helpers/state.cljs
Normal file
56
frontend/test/frontend_tests/helpers/state.cljs
Normal file
|
@ -0,0 +1,56 @@
|
|||
;; 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 frontend-tests.helpers.state
|
||||
(:require
|
||||
[app.common.pprint :refer [pprint]]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.test-helpers.files :as cthf]
|
||||
[app.main.data.workspace.layout :as layout]
|
||||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(def ^private initial-state
|
||||
{:workspace-layout layout/default-layout
|
||||
:workspace-global layout/default-global
|
||||
:current-file-id nil
|
||||
:current-page-id nil
|
||||
:workspace-data nil
|
||||
:workspace-libraries {}
|
||||
:features/team #{"components/v2"}})
|
||||
|
||||
(defn- on-error
|
||||
[cause]
|
||||
(js/console.log "STORE ERROR" (.-stack cause))
|
||||
(when-let [data (some-> cause ex-data ::sm/explain)]
|
||||
(pprint (sm/humanize-explain data))))
|
||||
|
||||
(defn setup-store
|
||||
[file]
|
||||
(let [state (-> initial-state
|
||||
(assoc :current-file-id (:id file)
|
||||
:current-page-id (cthf/current-page-id file)
|
||||
:workspace-file (dissoc file :data)
|
||||
:workspace-data (:data file)))
|
||||
store (ptk/store {:state state :on-error on-error})]
|
||||
store))
|
||||
|
||||
(defn run-store
|
||||
[store done events completed-cb]
|
||||
(let [stream (ptk/input-stream store)]
|
||||
(->> stream
|
||||
(rx/take-until (rx/filter #(= :the/end %) stream))
|
||||
(rx/last)
|
||||
(rx/tap (fn []
|
||||
(completed-cb @store)))
|
||||
(rx/subs! (fn [_] (done))
|
||||
(fn [cause]
|
||||
(js/console.log "[error]:" cause))
|
||||
(fn [_]
|
||||
(js/console.log "[complete]"))))
|
||||
(doall (for [event events]
|
||||
(ptk/emit! store event)))
|
||||
(ptk/emit! store :the/end)))
|
Loading…
Add table
Reference in a new issue