diff --git a/common/src/app/common/schema/test.cljc b/common/src/app/common/schema/test.cljc index 4947e36c1c..35b29df105 100644 --- a/common/src/app/common/schema/test.cljc +++ b/common/src/app/common/schema/test.cljc @@ -105,12 +105,13 @@ (defn check! "Check a property with reproducible size and seed. PENPOT_GEN_NUM and - PENPOT_GEN_SEED override the defaults; explicit options take precedence." + PENPOT_GEN_SEED override the defaults, `:default-num` (20) among them; + explicit options take precedence." [p & {:as options}] - (let [num (or (:num options) (environment-number "PENPOT_GEN_NUM") 20) + (let [num (or (:num options) (environment-number "PENPOT_GEN_NUM") (:default-num options) 20) seed (or (:seed options) (environment-number "PENPOT_GEN_SEED")) options (cond-> (merge {:max-size 50 :reporter-fn default-reporter-fn} - (dissoc options :num)) + (dissoc options :num :default-num)) seed (assoc :seed seed)) result (tc/quick-check num p options) pass? (:pass? result) diff --git a/common/src/app/common/test_helpers/composable/comp/nodes.cljc b/common/src/app/common/test_helpers/composable/comp/nodes.cljc index 2fd6686531..5b9f4dba6f 100644 --- a/common/src/app/common/test_helpers/composable/comp/nodes.cljc +++ b/common/src/app/common/test_helpers/composable/comp/nodes.cljc @@ -165,6 +165,15 @@ (-> (reduce with-layout-reflow changes layout-ids) (assoc ::layout-reflow? true))))) +(defn- with-swap-layouts-reflow + "Reflow the layouts a swap of `new-shape` changes: the `parent-ids` it + returns and those of the new subtree, as the frontend's `component-swap` + does." + [changes new-shape parent-ids] + (let [objects (pcb/get-objects changes) + ids (concat parent-ids (cfh/get-children-ids-with-self objects (:id new-shape)))] + (reduce with-layout-reflow changes (filter #(:layout (get objects %)) ids)))) + (defn layout-reflow? "Whether a property operation requires layout after its component sync." [changes] @@ -1338,13 +1347,15 @@ (let [the-file (tm/file situation) page (thf/current-page the-file) shape (get (:objects page) (tm/target-shape-id situation target)) - [_ changes _] (clv/generate-component-swap-in-place (pcb/empty-changes nil (:id page)) - page - (libraries situation) - (:data (get (libraries situation) (swap-target-file-id situation to))) - shape - (swap-target-id situation to) - (boolean keep-touched?)) + [new-shape changes parent-ids] + (clv/generate-component-swap-in-place (pcb/empty-changes nil (:id page)) + page + (libraries situation) + (:data (get (libraries situation) (swap-target-file-id situation to))) + shape + (swap-target-id situation to) + (boolean keep-touched?)) + changes (with-swap-layouts-reflow changes new-shape parent-ids) file' (thf/apply-changes the-file changes :validate? false)] (-> situation (tm/with-file file') @@ -1608,9 +1619,10 @@ :else (let [ldata (get-in libraries [(:component-file shape) :data]) - [_ changes _] (clv/generate-component-swap-in-place - (pcb/empty-changes nil (:id page)) - page libraries ldata shape (:id component) true) + [new-shape changes parent-ids] (clv/generate-component-swap-in-place + (pcb/empty-changes nil (:id page)) + page libraries ldata shape (:id component) true) + changes (with-swap-layouts-reflow changes new-shape parent-ids) file' (thf/apply-changes the-file changes :validate? false)] (-> situation (tm/with-file file') diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 60bdf17dc2..1ba3e40a7d 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1594,13 +1594,17 @@ (t/is (thrown? #?(:clj Exception :cljs js/Error) (cg/run {:world [2 0] :ops [[:restore 0]]})))) +;; programs each random composition test draws, enough for every kind to reach its coverage share +(def ^:private coverage-programs 50) + (t/deftest random-compositions (let [coverage (atom {}) failure (atom nil)] (smt/check! (smt/for [program cg/program-gen] (cg/check-program program coverage failure)) - :max-size 30) + :max-size 30 + :default-num coverage-programs) (println "Component operation coverage:" (pr-str @coverage)) (t/is (empty? (cg/coverage-errors @coverage [:edit :reset :update-main :detach :sync :undo :redo])) (pr-str (cg/coverage-errors @coverage [:edit :reset :update-main :detach :sync :undo :redo]))))) @@ -1611,7 +1615,8 @@ (smt/check! (smt/for [program cg/structure-program-gen] (cg/check-program program coverage failure)) - :max-size 30) + :max-size 30 + :default-num coverage-programs) (println "Structure operation coverage:" (pr-str @coverage)) (t/is (empty? (cg/coverage-errors @coverage cg/structure-kinds)) (pr-str (cg/coverage-errors @coverage cg/structure-kinds))))) @@ -1660,7 +1665,8 @@ (smt/check! (smt/for [program cg/swap-program-gen] (cg/check-program program coverage failure)) - :max-size 30) + :max-size 30 + :default-num coverage-programs) (println "Swap operation coverage:" (pr-str @coverage)) (t/is (empty? (cg/coverage-errors @coverage cg/swap-kinds)) (pr-str (cg/coverage-errors @coverage cg/swap-kinds))))) @@ -2103,6 +2109,12 @@ [:add-variant] [:add-variant] [:add-variant] [:switch 4] [:transform 0 0 0 7] [:update-main 22]]})))) +(t/deftest moving-a-flex-copy-child-after-a-switch-resized-its-sibling-authors-no-geometry + (t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:nest 8] [:switch 17] [:duplicate 8] [:transform 9 0 0 3]]})))) + (t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false :layout-item-margins false :grid-square false :rich-variants true @@ -2135,7 +2147,8 @@ (smt/check! (smt/for [program cg/variant-program-gen] (cg/check-program program coverage failure)) - :max-size 30) + :max-size 30 + :default-num coverage-programs) (println "Variant operation coverage:" (pr-str @coverage)) (t/is (empty? (cg/coverage-errors @coverage cg/variant-coverage-kinds)) (pr-str (cg/coverage-errors @coverage cg/variant-coverage-kinds))))) @@ -2196,7 +2209,8 @@ (smt/check! (smt/for [program cg/library-program-gen] (cg/check-program program coverage failure)) - :max-size 30) + :max-size 30 + :default-num coverage-programs) (println "Library operation coverage:" (pr-str @coverage)) (t/is (empty? (cg/coverage-errors @coverage cg/library-kinds)) (pr-str (cg/coverage-errors @coverage cg/library-kinds))))) @@ -2207,7 +2221,8 @@ (smt/check! (smt/for [program cg/stale-library-program-gen] (cg/check-program program coverage failure)) - :max-size 30) + :max-size 30 + :default-num coverage-programs) (println "Stale library operation coverage:" (pr-str @coverage)) (t/is (empty? (cg/coverage-errors @coverage cg/stale-library-coverage-kinds #{:sync})) (pr-str (cg/coverage-errors @coverage cg/stale-library-coverage-kinds #{:sync}))))) @@ -2218,7 +2233,8 @@ (smt/check! (smt/for [program cg/dependency-program-gen] (cg/check-program program coverage failure)) - :max-size 30) + :max-size 30 + :default-num coverage-programs) (println "Library dependency operation coverage:" (pr-str @coverage)) (t/is (empty? (cg/coverage-errors @coverage cg/dependency-kinds #{:sync})) (pr-str (cg/coverage-errors @coverage cg/dependency-kinds #{:sync}))))) diff --git a/common/test/common_tests/logic/golden_master.edn b/common/test/common_tests/logic/golden_master.edn index 96ef2efc16..95f128f664 100644 --- a/common/test/common_tests/logic/golden_master.edn +++ b/common/test/common_tests/logic/golden_master.edn @@ -14,7 +14,7 @@ [{:transcript "create-component {:component \"main\", :id sync-main-component}\n create-component {:component \"s1\", :id sync-s1-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n swap-shape {:target #fn, :to \"s1\", :keep-touched? false}\n detach {:target #fn, :detached sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["a3cb16fb335bc929" "e10b1283627fbeb6" "9be2dfab826240b0" "1fc0e554196dfd2b"]} {:transcript "create-component {:component \"main\", :id sync-main-component}\n create-component {:component \"s1\", :id sync-s1-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n swap-shape {:target #fn, :to \"s1\", :keep-touched? false}\n duplicate {:target #fn, :new-head 5}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["a3cb16fb335bc929" "d291c9ca9a187b1b" "99bb6214c05d575b" "0694d4feab3cb633"]}] :af - [{:transcript "swap-shape {:target :copy-child, :to :other, :keep-touched? false}\n move-to-cell {:board :main-root, :child :main-child, :row 1, :column 3}", :states ["0ad5feb2c5e1a843" "9d4bf4912c552f43" "317588029f30f1ef"]} + [{:transcript "swap-shape {:target :copy-child, :to :other, :keep-touched? false}\n move-to-cell {:board :main-root, :child :main-child, :row 1, :column 3}", :states ["c53dfdd17c491952" "9d4bf4912c552f43" "317588029f30f1ef"]} {:transcript "one-of -> skip\n move-to-cell {:board :main-root, :child :main-child, :row 1, :column 3}", :states ["92614cf6d7575ad8" "00312b9131f4fec6"]}] :ag [{:transcript "move-child {:target :sub1, :parent :row-root, :to-index 3}", :states ["b8a611163a069cb1" "7b199a2abaca4eeb"]}] @@ -23,7 +23,7 @@ {:transcript "one-of -> recorded-choice\n remove-child {:target :copy-sub3}", :states ["e2e4320b1a62202d" "44788f4405295d27"]} {:transcript "one-of -> skip", :states ["4f8193bba8dbfb0d"]}] :ak - [{:transcript "swap-shape {:target :copy-child, :to :other, :keep-touched? false}\n move-to-cell {:board :copy-root, :child :copy-child, :row 1, :column 3}\n update-main {:target :copy-root, :updated grid-copy}", :states ["0ad5feb2c5e1a843" "7e8833e5c26e234c" "2508613c0f17bc78" "f3d331b4689dd5b9"]} + [{:transcript "swap-shape {:target :copy-child, :to :other, :keep-touched? false}\n move-to-cell {:board :copy-root, :child :copy-child, :row 1, :column 3}\n update-main {:target :copy-root, :updated grid-copy}", :states ["c53dfdd17c491952" "c2b95eac774d215f" "270882861b7b147e" "5bf41603d2d1f53d"]} {:transcript "one-of -> skip\n move-to-cell {:board :copy-root, :child :copy-child, :row 1, :column 3}\n update-main {:target :copy-root, :updated grid-copy}", :states ["8aad596633c254fd" "7f1f0be7424c543f" "7c9214e430ebb4e8"]}] :al [{:transcript "change-property {:target :copy-root, :property :name, :value \"Renamed\"}\n change-property {:target :copy-instance, :property :name, :value \"Renamed child\"}\n update-main {:target :copy-root, :updated copy-root}", :states ["0166c98332ed23a7" "6c0c864aa286702f" "af3a00259b74b965" "6598d0729b91c5b3"]} diff --git a/common/test/common_tests/schema_check_test.cljc b/common/test/common_tests/schema_check_test.cljc index 59ad2a741f..cfe33b1fbf 100644 --- a/common/test/common_tests/schema_check_test.cljc +++ b/common/test/common_tests/schema_check_test.cljc @@ -39,3 +39,12 @@ :reporter-fn #(when (= :complete (:type %)) (reset! seed (:seed %)))) (when (some? expected) (t/is (= expected @seed))))) + +(t/deftest check-runs-the-default-num-unless-the-environment-sets-one + (let [runs (atom 0) + environment-num #?(:clj (System/getenv "PENPOT_GEN_NUM") + :cljs (some-> js/globalThis .-process .-env .-PENPOT_GEN_NUM))] + (when-not environment-num + (smt/check! (smt/for [_ gen/nat] (swap! runs inc) true) + :default-num 3) + (t/is (= 3 @runs)))))