diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index c8f536ab10..b9b86045c3 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1,6 +1,7 @@ (ns common-tests.logic.composable-gen-test (:require [app.common.schema.test :as smt] + [app.common.test-helpers.composable.comp.nodes :as n] [app.common.test-helpers.composable.comp.runner :as r] [app.common.test-helpers.composable.comp.setups :as setup] [app.common.test-helpers.composable.core :as tm] @@ -44,3 +45,183 @@ (t/is (= 2 (count (r/pending-components (:situation state))))) (t/is (= 1 (count (r/pending-components (:situation partial))))) (t/is (empty? (r/pending-components (:situation settled)))))) + +(t/deftest generated-library-world-has-remote-mains-and-local-copies + (let [situation (cg/world [2 1 {:library true}]) + file (tm/file situation) + libraries (tm/aux-files situation) + remote (filter #(contains? libraries (:component-file (:shape %))) (cg/tree situation))] + (t/is (= 1 (count libraries))) + (t/is (seq remote)) + (t/is (every? :shape-ref (map :shape remote))) + (t/is (not (contains? libraries (:id file)))))) + +(t/deftest generated-library-update-main-checks-remote-and-local-inverses + (let [program {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:sync 1]]} + result (cg/run program)] + (t/is (= 1 (get-in result [:executed :update-main]))) + (t/is (= 1 (get-in result [:executed :library-sync]))) + (t/is (= 1 (count (tm/aux-files (:situation result))))))) + +(t/deftest random-library-compositions + (let [coverage (atom {}) + failure (atom nil)] + (smt/check! + (smt/for [program cg/library-program-gen] + (cg/check-program program coverage failure)) + :max-size 30) + (println "Executed library operations:" (pr-str @coverage)) + (doseq [kind [:edit :update-main :library-sync :undo :redo]] + (t/is (pos? (get @coverage kind 0)) (str "No executed " kind))))) + +(t/deftest update-main-moves-an-authored-swap-to-the-replaced-main-shape + (let [result (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 2 0 0 0] [:update-main 0 0 0 0]]})] + (t/is (some #(contains? % :swap-group) (vals (:model result)))))) + +(t/deftest update-main-after-deleting-a-swapped-main-keeps-the-model-in-step + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 1 0 0 0] [:delete 2 0 0 0] [:update-main 0 0 0 0]]})))) + +(t/deftest switch-keeps-root-geometry-inherited-through-a-near-main + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:rotate 0 0 0 0] [:switch 1 0 0 0]]})))) + +(t/deftest a-main-detach-removes-an-indirect-copys-invalid-swap + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 1 0 0 0] [:detach 0 0 0 0] [:delete 0 0 0 0]]})))) + +(t/deftest detached-swapped-head-follows-its-own-component-without-position-overrides + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:duplicate 1 0 0 0] [:swap 13 0 0 0] [:detach 16 0 0 0]]})))) + +(t/deftest detaching-an-outer-copy-keeps-its-surviving-inner-swap + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 3 0 0 0] [:detach 3 0 0 0]]})))) + +(t/deftest updating-main-then-swapping-a-child-restores-parent-state + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 5 0 0 0] [:update-main 0 0 0 0] [:swap 13 0 0 0]]})))) + +(t/deftest pushed-variant-subtree-restores-its-main-parent-order + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:resize 0 0 0 0] [:duplicate 0 0 0 0] + [:switch 2 0 0 0] [:update-main 2 0 0 0]]})))) + +(t/deftest updating-a-duplicated-switched-copy-restores-the-main-order + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 1 0 0 0] [:duplicate 0 0 0 0] + [:update-main 0 0 0 0] [:redo 0 0 0 0]]})))) + +(t/deftest switching-a-detached-rotated-copy-keeps-its-resize + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:rotate 1 0 0 0] [:detach 1 0 0 0] + [:detach 2 0 0 0] [:resize 2 0 0 0] [:switch 2 0 0 0]]})))) + +(t/deftest switching-a-copy-of-a-swap-keeps-position-overrides-inherited + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 13 0 0 0] [:rotate 0 0 0 0] [:switch 2 0 0 0]]})))) + +(t/deftest generated-library-pushed-swap-authors-content-against-its-new-position + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 2 0 0 0] [:edit 8 0 0 0] [:switch 0 0 0 0] + [:update-main 7 0 0 0]]})))) + +(t/deftest generated-library-swap-back-syncs-the-near-positions-overrides + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 15 0 0 0] [:duplicate 16 0 0 0] [:edit 8 0 0 0] + [:switch 4 0 0 0] [:update-main 0 0 0 0]]})))) + +(t/deftest generated-library-move-restores-existing-component-nesting-on-undo + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 5 0 0 0] [:nest 8 0 0 0] [:nest 5 0 0 0] + [:restore 0 0 0 0]]})))) + +(t/deftest generated-library-authored-child-follows-its-parents-synced-turn + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:resize 0 0 0 0] [:switch 2 0 0 0] [:rotate 1 0 0 0] + [:remove-child 0 0 0 0]]})))) + +(t/deftest pushing-a-swap-keeps-the-orientation-inherited-from-its-position + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:rotate 0 0 0 0] [:swap 13 0 0 0] [:update-main 1 0 0 0]]})))) + +(t/deftest pushing-a-switched-child-uses-its-parents-pushed-frame + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 5 0 0 0] [:rotate 1 0 0 0] [:update-main 0 0 0 0]]})))) + +(t/deftest generated-library-switch-keeps-overrides-from-a-deleted-near-main + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:delete 0 0 0 0] [:delete 3 0 0 0] [:resize 0 0 0 0] + [:delete 9 0 0 0] [:switch 0 0 0 0]]})))) + +(t/deftest generated-library-duplicate-refuses-an-expanding-component-branch + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 5] [:nest 8] [:duplicate 1]]})))) + +(t/deftest generated-library-parent-turn-settles-swapped-placement + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 2 0 0 0] [:resize 0 0 0 0] [:rotate 2 0 0 0]]})))) + +(t/deftest generated-library-restored-variant-syncs-its-converted-name + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:delete 3 0 0 0] [:delete 1 0 0 0] [:restore 7 0 0 0] + [:delete 1 0 0 0] [:restore 0 0 0 0]]})))) + +(t/deftest generated-library-switch-inherits-a-swapped-near-mains-authored-fill + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:edit 12 0 0 0] [:nest 10 0 0 0] + [:switch 7 0 0 0] [:switch 2 0 0 0]]})))) + +(t/deftest generated-library-reset-places-new-children-after-clearing-rotation + (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 1 0 0 0] [:rotate 1 0 0 0] [:duplicate 0 0 0 0] + [:reset 2 0 0 0] [:redo 0 0 0 0]]})))) diff --git a/common/test/common_tests/logic/composable_runner_test.cljc b/common/test/common_tests/logic/composable_runner_test.cljc index ae60b01f81..35a5604ed3 100644 --- a/common/test/common_tests/logic/composable_runner_test.cljc +++ b/common/test/common_tests/logic/composable_runner_test.cljc @@ -8,6 +8,7 @@ (:require [app.common.files.changes-builder :as pcb] [app.common.logic.shapes :as cls] + [app.common.test-helpers.components :as thc] [app.common.test-helpers.composable.comp.nodes :as n] [app.common.test-helpers.composable.comp.runner :as r] [app.common.test-helpers.composable.comp.setups :as setup] @@ -585,6 +586,22 @@ (reset! counted @made)))) (t/is (= 2 @counted)))) +(t/deftest library-update-main-routes-both-files-and-undoes-the-cascade + (let [initial (setup/cross-file-component-with-copy setup/labeled-fill) + library (first (vals (tm/aux-files initial))) + initial (tm/with-file initial + (thc/instantiate-component (tm/file initial) :component1 :copy2-root + :library library :children-labels [:copy2-child])) + edited (-> initial (r/step (n/change-property :copy-child :fills "#ff0000")) r/settle) + updated (-> edited (r/step (n/update-main :copy-root)) r/settle) + remote (get (tm/aux-files updated) (:id library)) + snapshot (fn [s] (uc/snapshot-files (assoc (tm/aux-files s) (:id (tm/file s)) (tm/file s))))] + (t/is (= "#ff0000" (get-in (thf/current-page remote) [:objects (thi/id :main-child) :fills 0 :fill-color]))) + (t/is (= "#ff0000" (:fill-color (first (:fills (tm/resolve-shape updated :copy2-child)))))) + (t/is (nil? (:touched (tm/resolve-shape updated :copy-child)))) + (t/is (= (snapshot edited) (snapshot (r/step updated (n/undo))))) + (t/is (= (snapshot updated) (snapshot (-> updated (r/step (n/undo)) (r/step (n/redo)))))))) + (t/deftest adding-a-grid-child-records-cell-order-before-reflow (let [initial (setup/grid-component-with-copy) changed (-> initial (r/step (n/add-child :grid-root :new-grid-child)) r/settle) diff --git a/frontend/test/frontend_tests/composable_tests/generated_test.cljs b/frontend/test/frontend_tests/composable_tests/generated_test.cljs index a64bca9ee6..852a9a2cc5 100644 --- a/frontend/test/frontend_tests/composable_tests/generated_test.cljs +++ b/frontend/test/frontend_tests/composable_tests/generated_test.cljs @@ -11,9 +11,12 @@ [app.common.test-helpers.composable.gen :as cg] [app.common.test-helpers.composable.oracle :as oracle] [app.common.test-helpers.normalize :as thn] + [app.main.repo :as rp] + [beicon.v2.core :as rx] [cljs.test :as t :include-macros true] [clojure.test.check.generators :as gen] - [frontend-tests.composable-tests.interpreter :as ftm])) + [frontend-tests.composable-tests.interpreter :as ftm] + [frontend-tests.helpers.mock :as mock])) (t/use-fixtures :each ftm/fixture) @@ -89,3 +92,134 @@ (t/deftest ^:async nesting-restores-default-constraints-on-undo (await (replay {:world [2 0] :ops [[:nest 0]]}))) + +(t/deftest ^:async library-programs-replay-through-the-frontend + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:sync 1]]})) + (await (replay (gen/generate cg/library-program-gen 5 712)))) + +(t/deftest ^:async inherited-rotation-switch-shrunk-regression + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:rotate 0 0 0 0] [:switch 1 0 0 0]]}))) + +(t/deftest ^:async swapped-subtree-update-main-shrunk-regression + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:resize 0 0 0 0] [:duplicate 0 0 0 0] + [:switch 2 0 0 0] [:update-main 2 0 0 0]]}))) + +(t/deftest ^:async main-head-detach-shrunk-regression + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 1 0 0 0] [:detach 0 0 0 0] [:delete 0 0 0 0]]}))) + +(t/deftest ^:async updating-main-then-swapping-a-child-restores-parent-state + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 5 0 0 0] [:update-main 0 0 0 0] [:swap 13 0 0 0]]}))) + +(t/deftest ^:async updating-a-duplicated-switched-copy-restores-the-main-order + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 1 0 0 0] [:duplicate 0 0 0 0] + [:update-main 0 0 0 0] [:redo 0 0 0 0]]}))) + +(t/deftest ^:async switching-a-detached-rotated-copy-keeps-its-resize + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:rotate 1 0 0 0] [:detach 1 0 0 0] + [:detach 2 0 0 0] [:resize 2 0 0 0] [:switch 2 0 0 0]]}))) + +(t/deftest ^:async switching-a-copy-of-a-swap-keeps-position-overrides-inherited + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 13 0 0 0] [:rotate 0 0 0 0] [:switch 2 0 0 0]]}))) + +(t/deftest ^:async pushing-a-swap-keeps-the-orientation-inherited-from-its-position + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:rotate 0 0 0 0] [:swap 13 0 0 0] [:update-main 1 0 0 0]]}))) + +(t/deftest ^:async pushing-a-switched-child-uses-its-parents-pushed-frame + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 5 0 0 0] [:rotate 1 0 0 0] [:update-main 0 0 0 0]]}))) + +(t/deftest ^:async generated-library-pushed-swap-authors-content-against-its-new-position + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 2 0 0 0] [:edit 8 0 0 0] [:switch 0 0 0 0] + [:update-main 7 0 0 0]]}))) + +(t/deftest ^:async generated-library-swap-back-syncs-the-near-positions-overrides + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 15 0 0 0] [:duplicate 16 0 0 0] [:edit 8 0 0 0] + [:switch 4 0 0 0] [:update-main 0 0 0 0]]}))) + +(t/deftest ^:async generated-library-move-restores-existing-component-nesting-on-undo + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 5 0 0 0] [:nest 8 0 0 0] [:nest 5 0 0 0] + [:restore 0 0 0 0]]}))) + +(t/deftest ^:async generated-library-authored-child-follows-its-parents-synced-turn + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:resize 0 0 0 0] [:switch 2 0 0 0] [:rotate 1 0 0 0] + [:remove-child 0 0 0 0]]}))) + +(t/deftest ^:async generated-library-switch-keeps-overrides-from-a-deleted-near-main + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:delete 0 0 0 0] [:delete 3 0 0 0] [:resize 0 0 0 0] + [:delete 9 0 0 0] [:switch 0 0 0 0]]}))) + +(t/deftest ^:async generated-library-duplicate-refuses-an-expanding-component-branch + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 5] [:nest 8] [:duplicate 1]]}))) + +(t/deftest ^:async generated-library-parent-turn-settles-swapped-placement + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 2 0 0 0] [:resize 0 0 0 0] [:rotate 2 0 0 0]]}))) + +(t/deftest ^:async generated-library-restored-variant-syncs-its-converted-name + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:delete 3 0 0 0] [:delete 1 0 0 0] [:restore 7 0 0 0] + [:delete 1 0 0 0] [:restore 0 0 0 0]]}))) + +(t/deftest ^:async generated-library-switch-inherits-a-swapped-near-mains-authored-fill + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:edit 12 0 0 0] [:nest 10 0 0 0] + [:switch 7 0 0 0] [:switch 2 0 0 0]]}))) + +(t/deftest ^:async generated-library-reset-places-new-children-after-clearing-rotation + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync] + [:undo] [:redo] [:reset 0] [:sync 1] + [:switch 1 0 0 0] [:rotate 1 0 0 0] [:duplicate 0 0 0 0] + [:reset 2 0 0 0] [:redo 0 0 0 0]]}))) diff --git a/plugins/apps/composable-test-suite/src/composable-tests/operations/OpSwap.ts b/plugins/apps/composable-test-suite/src/composable-tests/operations/OpSwap.ts index e98d4cecb2..b17414d854 100644 --- a/plugins/apps/composable-test-suite/src/composable-tests/operations/OpSwap.ts +++ b/plugins/apps/composable-test-suite/src/composable-tests/operations/OpSwap.ts @@ -9,8 +9,9 @@ import { PenpotSync } from "../util/PenpotSync"; * component, via the Plugin API's `swapComponent()`. The new head keeps the * old head's id, so a target that found the old head finds the new one. * - * Unlike the swap in the workspace UI, the API keeps the head's overrides - * (it swaps with keep-touched, F33 in the stabilization plan). + * The API follows the workspace rules: ordinary swaps clear content + * overrides and retain orientation. A switch between variants of one set + * carries matching overrides. */ export class OpSwap extends Operation { /**