♻️ Move app.common.pages to app.common.files

This commit is contained in:
Andrey Antukh 2023-11-15 16:35:52 +01:00
parent 8345548a7a
commit 52fbc678f3
139 changed files with 1459 additions and 1510 deletions

View file

@ -8,7 +8,6 @@
(:require
[app.common.data :as d]
[app.common.files.migrations :as cpm]
[app.common.pages :as cp]
[app.common.uuid :as uuid]
[clojure.pprint :refer [pprint]]
[clojure.test :as t]))

View file

@ -7,7 +7,7 @@
(ns common-tests.helpers.components
(:require
[clojure.test :as t]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.file :as ctf]))
@ -58,7 +58,7 @@
verify that they are a well constructed instance tree."
[page root-inst-id]
(let [root-inst (ctn/get-shape page root-inst-id)
shapes-inst (cph/get-children-with-self (:objects page)
shapes-inst (cfh/get-children-with-self (:objects page)
root-inst-id)]
(check-instance-root (first shapes-inst))
(run! check-instance-inner (rest shapes-inst))
@ -70,7 +70,7 @@
verify that they are not a component instance."
[page root-inst-id]
(let [root-inst (ctn/get-shape page root-inst-id)
shapes-inst (cph/get-children-with-self (:objects page)
shapes-inst (cfh/get-children-with-self (:objects page)
root-inst-id)]
(run! check-noninstance shapes-inst)
@ -84,8 +84,8 @@
component (ctf/find-component libraries (:component-id root-inst))
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst))
unique-refs (into #{} (map :shape-ref) shapes-inst)
@ -120,8 +120,8 @@
component (ctf/find-component libraries (:component-id root-inst))
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst))
unique-refs (into #{} (map :shape-ref) shapes-inst)
@ -147,7 +147,7 @@
[page component-id libraries]
(let [component (ctf/find-component libraries component-id)
root-main (ctk/get-component-root component)
shapes-main (cph/get-children-with-self (:objects component) (:id root-main))]
shapes-main (cfh/get-children-with-self (:objects component) (:id root-main))]
;; Validate that the component tree is well constructed
(run! check-noninstance shapes-main)

View file

@ -8,12 +8,12 @@
(:require
[clojure.test :as t]
[clojure.pprint :refer [pprint]]
[app.common.pages.helpers :as cph]))
[app.common.files.helpers :as cfh]))
(t/deftest parse-path-name
(t/is (= ["foo" "bar"] (cph/parse-path-name "foo/bar")))
(t/is (= ["" "foo"] (cph/parse-path-name "foo")))
(t/is (= ["" "foo"] (cph/parse-path-name "/foo")))
(t/is (= ["" ""] (cph/parse-path-name "")))
(t/is (= ["" ""] (cph/parse-path-name nil))))
(t/is (= ["foo" "bar"] (cfh/parse-path-name "foo/bar")))
(t/is (= ["" "foo"] (cfh/parse-path-name "foo")))
(t/is (= ["" "foo"] (cfh/parse-path-name "/foo")))
(t/is (= ["" ""] (cfh/parse-path-name "")))
(t/is (= ["" ""] (cfh/parse-path-name nil))))

View file

@ -7,7 +7,7 @@
(ns common-tests.pages-test
(:require
[app.common.features :as ffeat]
[app.common.pages :as cp]
[app.common.files.changes :as ch]
[app.common.types.file :as ctf]
[app.common.types.shape :as cts]
[app.common.uuid :as uuid]
@ -28,7 +28,7 @@
:page-id page-id
:option :test
:value "test"}
res (cp/process-changes data [chg])]
res (ch/process-changes data [chg])]
(t/is (= "test" (get-in res [:pages-index page-id :options :test])))))
(t/testing "Sets option nested"
@ -40,7 +40,7 @@
:page-id page-id
:option [:values :test :b]
:value "b"}]
res (cp/process-changes data chgs)]
res (ch/process-changes data chgs)]
(t/is (= {:a "a" :b "b"}
(get-in res [:pages-index page-id :options :values :test])))))
@ -49,7 +49,7 @@
:page-id page-id
:option :test
:value nil}
res (cp/process-changes data [chg])]
res (ch/process-changes data [chg])]
(t/is (empty? (keys (get-in res [:pages-index page-id :options]))))))
(t/testing "Remove option nested 1"
@ -65,7 +65,7 @@
:page-id page-id
:option [:values :test]
:value nil}]
res (cp/process-changes data chgs)]
res (ch/process-changes data chgs)]
(t/is (empty? (keys (get-in res [:pages-index page-id :options]))))))
(t/testing "Remove option nested 2"
@ -81,7 +81,7 @@
:page-id page-id
:option [:values :test2]
:value nil}]
res (cp/process-changes data chgs)]
res (ch/process-changes data chgs)]
(t/is (= [:test1] (keys (get-in res [:pages-index page-id :options :values]))))))
))
@ -105,7 +105,7 @@
:id id-a
:type :rect
:name "rect"})}
res (cp/process-changes data [chg])]
res (ch/process-changes data [chg])]
(let [objects (get-in res [:pages-index page-id :objects])]
(t/is (= 2 (count objects)))
@ -126,7 +126,7 @@
:frame-id uuid/zero
:type :rect
:name (str id)})})
res (cp/process-changes data [(chg id-a 0)
res (ch/process-changes data [(chg id-a 0)
(chg id-b 0)
(chg id-c 1)])]
@ -152,7 +152,7 @@
:operations [{:type :set
:attr :name
:val "foobar"}]}
res (cp/process-changes data [chg])]
res (ch/process-changes data [chg])]
(let [objects (get-in res [:pages-index page-id :objects])]
(t/is (= "foobar" (get-in objects [uuid/zero :name]))))))
@ -163,7 +163,7 @@
:operations [{:type :set
:attr :name
:val "foobar"}]}
res (cp/process-changes data [chg])]
res (ch/process-changes data [chg])]
(t/is (= res data))))
))
@ -185,7 +185,7 @@
;; (let [chg {:type :del-obj
;; :page-id page-id
;; :id id}
;; res (cp/process-changes data [chg])]
;; res (ch/process-changes data [chg])]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; (t/is (= 1 (count objects)))
@ -195,8 +195,8 @@
;; (let [chg {:type :del-obj
;; :page-id page-id
;; :id id}
;; res1 (cp/process-changes data [chg])
;; res2 (cp/process-changes res1 [chg])]
;; res1 (ch/process-changes data [chg])
;; res2 (ch/process-changes res1 [chg])]
;; (t/is (= res1 res2))
;; (let [objects (get-in res1 [:pages-index page-id :objects])]
@ -304,7 +304,7 @@
;; :page-id page-id
;; :parent-id new-group-id
;; :shapes [rect-b-id rect-c-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (clojure.pprint/pprint data)
;; ;; (println "===============")
@ -324,7 +324,7 @@
;; :parent-id group-b-id
;; :index 0
;; :shapes [rect-a-id rect-c-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; (t/is (= [group-a-id group-b-id rect-e-id]
@ -340,7 +340,7 @@
;; :parent-id group-b-id
;; :index 0
;; :shapes [rect-a-id rect-e-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; (t/is (= [group-a-id group-b-id]
@ -356,7 +356,7 @@
;; :parent-id group-b-id
;; :index 0
;; :shapes [rect-a-id rect-e-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; (t/is (= [group-a-id group-b-id]
@ -371,7 +371,7 @@
;; :page-id page-id
;; :parent-id group-a-id
;; :shapes [rect-d-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; (t/is (= [group-a-id group-b-id rect-e-id]
@ -383,7 +383,7 @@
;; :page-id page-id
;; :parent-id frame-b-id
;; :shapes [group-a-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (pprint (get-in data [:pages-index page-id :objects]))
;; ;; (println "==========")
@ -403,7 +403,7 @@
;; :parent-id uuid/zero
;; :shapes [group-a-id]
;; :index 0}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; ;; (pprint (get-in data [:objects uuid/zero]))
@ -418,7 +418,7 @@
;; :page-id page-id
;; :parent-id group-a-id
;; :shapes [group-a-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (t/is (= data res))))
;; ))
@ -462,7 +462,7 @@
;; :name "Shape 3"}}
;; ]
;; data (make-file-data file-id page-id)
;; data (cp/process-changes data changes)]
;; data (ch/process-changes data changes)]
;; (t/testing "preserve order on multiple shape mov 1"
;; (let [changes [{:type :mov-objects
@ -470,7 +470,7 @@
;; :shapes [shape-2-id shape-3-id]
;; :parent-id uuid/zero
;; :index 0}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (println "==> BEFORE")
;; ;; (pprint (get-in data [:objects]))
@ -488,7 +488,7 @@
;; :shapes [shape-3-id shape-2-id]
;; :parent-id uuid/zero
;; :index 0}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (println "==> BEFORE")
;; ;; (pprint (get-in data [:objects]))
@ -509,7 +509,7 @@
;; :page-id page-id
;; :shapes [shape-2-id]
;; :parent-id uuid/zero}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (t/is (= (get-in res [:pages-index page-id :objects shape-1-id :frame-id])
;; (get-in data [:pages-index page-id :objects shape-1-id :frame-id])))
@ -569,7 +569,7 @@
;; :shapes [shape-1-id shape-2-id]}]
;; data (make-file-data file-id page-id)
;; data (cp/process-changes data changes)]
;; data (ch/process-changes data changes)]
;; (t/testing "case 1"
;; (let [changes [{:type :mov-objects
@ -577,7 +577,7 @@
;; :parent-id uuid/zero
;; :index 2
;; :shapes [shape-3-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; Before
@ -599,7 +599,7 @@
;; :parent-id group-1-id
;; :index 2
;; :shapes [shape-3-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; Before
@ -627,7 +627,7 @@
;; :parent-id group-1-id
;; :index 1
;; :shapes [shape-3-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; Before
@ -655,7 +655,7 @@
;; :parent-id group-1-id
;; :index 0
;; :shapes [shape-3-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; Before
@ -683,7 +683,7 @@
;; :parent-id uuid/zero
;; :index 0
;; :shapes [shape-2-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (pprint (get-in data [:pages-index page-id :objects uuid/zero]))
;; ;; (pprint (get-in res [:pages-index page-id :objects uuid/zero]))
@ -715,7 +715,7 @@
;; :parent-id uuid/zero
;; :index 0
;; :shapes [shape-2-id shape-1-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (pprint (get-in data [:pages-index page-id :objects uuid/zero]))
;; ;; (pprint (get-in res [:pages-index page-id :objects uuid/zero]))