diff --git a/frontend/src/app/worker/index.cljs b/frontend/src/app/worker/index.cljs index 1117440563..cf28759971 100644 --- a/frontend/src/app/worker/index.cljs +++ b/frontend/src/app/worker/index.cljs @@ -40,6 +40,9 @@ (let [tpoint (ct/tpoint-ms)] (try (let [old-page (dm/get-in @state [:pages-index page-id]) + ;; The index only holds pages, without the file id nor its + ;; components, so shape validation can't run here + changes (remove #(= :validate-shapes (:type %)) changes) new-page (-> state (swap! ch/process-changes changes false) (dm/get-in [:pages-index page-id])) diff --git a/frontend/test/frontend_tests/runner.cljs b/frontend/test/frontend_tests/runner.cljs index 97295805d5..7442211027 100644 --- a/frontend/test/frontend_tests/runner.cljs +++ b/frontend/test/frontend_tests/runner.cljs @@ -157,6 +157,7 @@ [frontend-tests.util-zip-test] [frontend-tests.util.code-gen-markup-svg-wasm-test] [frontend-tests.util.dom.dnd-test] + [frontend-tests.worker-index-test] [frontend-tests.worker-snap-test] [frontend-tests.worker.exports-test] [goog.object :as gobj])) @@ -327,6 +328,7 @@ 'frontend-tests.util.code-gen-markup-svg-wasm-test 'frontend-tests.util.dom.dnd-test 'frontend-tests.util-zip-test + 'frontend-tests.worker-index-test 'frontend-tests.worker-snap-test]) (assert (every? find-ns-obj test-namespaces) diff --git a/frontend/test/frontend_tests/worker_index_test.cljs b/frontend/test/frontend_tests/worker_index_test.cljs new file mode 100644 index 0000000000..d0d74ee2f7 --- /dev/null +++ b/frontend/test/frontend_tests/worker_index_test.cljs @@ -0,0 +1,46 @@ +;; 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 SUBSIDIARY SL + +(ns frontend-tests.worker-index-test + (:require + [app.common.files.changes-builder :as pcb] + [app.common.test-helpers.compositions :as ctho] + [app.common.test-helpers.files :as cthf] + [app.common.test-helpers.ids-map :as cthi] + [app.common.test-helpers.shapes :as cths] + [app.common.types.shape :as cts] + [app.common.uuid :as uuid] + [app.worker.impl :as impl] + [app.worker.index :as index] + [cljs.test :as t :include-macros true])) + +(t/use-fixtures :each + {:before cthi/reset-idmap!}) + +(t/deftest update-index-with-validate-shapes-changes + ;; The index only holds pages, without the file id nor its components, so + ;; a :validate-shapes change must not stop it from applying the others + (let [;; ==== Setup + file (-> (cthf/sample-file :file1) + (ctho/add-simple-component :c01 :m01 :r01)) + page (cthf/current-page file) + main (cths/get-shape file :m01) + rect (cts/setup-shape {:id (uuid/next) :type :rect :name "Rect" + :x 0 :y 0 :width 10 :height 10}) + + changes (-> (pcb/empty-changes nil (:id page)) + (pcb/with-objects (:objects page)) + (pcb/add-object rect) + (pcb/validate-shapes (:id page) [(:id main)] "test")) + + ;; ==== Action + _ (impl/handler {:cmd :index/initialize :page page}) + _ (impl/handler {:cmd :index/update + :page-id (:id page) + :changes (:redo-changes changes)})] + + ;; ==== Check + (t/is (some? (get-in @index/state [:pages-index (:id page) :objects (:id rect)])))))