diff --git a/common/src/app/common/test_helpers/composable/gen.cljc b/common/src/app/common/test_helpers/composable/gen.cljc index 6586642b36..2101c0b4d4 100644 --- a/common/src/app/common/test_helpers/composable/gen.cljc +++ b/common/src/app/common/test_helpers/composable/gen.cljc @@ -296,7 +296,8 @@ (cond-> (and (zero? index) (pos? depth) (:layout opts) (:layout-copies opts) (:layout-children opts)) (with-settled-layout name)) - (as-> s (reduce #(tm/apply-to %2 %1) s [(n/instantiate-copy name) (n/instantiate-copy name)]))))) + (as-> s (reduce #(tm/apply-to %2 %1) s + (repeatedly (:copies opts 2) #(n/instantiate-copy name))))))) (let [s (setup/empty-situation) s (if (:variants opts) (let [s (reduce #(tm/apply-to %2 %1) s @@ -332,7 +333,8 @@ (:layout opts) (r/settle-layout) (:library opts) (with-library opts) (:stale-libraries opts) (cf/freeze-libraries) - (:rich-variants opts) (as-> s (assoc s :shape-budget (+ 80 (count (tree s))))))) + (:rich-variants opts) (as-> s (assoc s :shape-budget (+ 80 (count (tree s))))) + (:scale opts) (as-> s (assoc s :shape-budget (+ 120 (count (tree s))))))) (defn candidates [situation model kind scope] @@ -1398,6 +1400,28 @@ :grid-square (= grid :square) :grid-empty (= grid :empty)}] :ops ops})) +(def scale-coverage-kinds + "The kinds the scale programs must cover: the steps that walk every copy + and every nesting level." + [:edit :reset :update-main :sync :swap :switch :undo :redo]) + +(def scale-program-gen + "Worlds deeper and wider than the other properties draw: up to four + components nested three or four levels, with up to six copies each." + (gen/let [components (gen/choose 3 4) + depth (gen/choose 3 4) + copies (gen/choose 3 6) + differ? gen/boolean + layout (gen/elements [nil :flex :grid]) + layout-children gen/boolean + grid (gen/elements [nil :square :empty]) + ops (operation-gen variant-kinds)] + {:world [components depth {:scale true :copies copies :variants true :variant-diff differ? + :rich-variants true :text true :text-styles true :layout layout + :layout-copies true :layout-children layout-children + :grid-square (= grid :square) :grid-empty (= grid :empty)}] + :ops ops})) + (def library-kinds (into structure-kinds [:swap :switch :library-sync])) diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index 808060d7be..a564889c31 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -573,25 +573,35 @@ model model)) (defn sync-scaled-heads - "A copy parent that a sync resizes sizes its untouched swapped heads - through their constraints. A head it gives another size authors that - size, placed in the parent." + "A copy shape that a sync resizes sizes its subtree through constraints. + An untouched swapped head in it that the resize gives another size + authors that size, placed in its parent. The resize starts at the + topmost resized ancestor of the head: a sync resizes only a copy shape + without authored geometry." [model before after] (let [sized-alike? #(and (mth/close? (:width %1) (:width %2)) - (mth/close? (:height %1) (:height %2)))] + (mth/close? (:height %1) (:height %2))) + ;; whether `id` keeps its parent and has another size in `after` + resized? (fn [id] + (let [old (get before id) shape (get after id)] + (and old shape (= (:parent-id old) (:parent-id shape)) + (not (sized-alike? old shape)))))] (reduce-kv (fn [result id groups] - (let [old (get before id) - shape (get after id) - old-parent (get before (:parent-id old)) - parent (get after (:parent-id shape))] + (let [shape (get after id) + parent (get after (:parent-id shape)) + origin (when (and parent (resized? (:id parent))) + (loop [current parent] + (let [above (get after (:parent-id current))] + (if (and above (not= (:id above) (:id current)) (resized? (:id above))) + (recur above) + current))))] (if (and (contains? groups :swap-group) (not (contains? groups :geometry-group)) - old shape old-parent parent - (= (:parent-id old) (:parent-id shape)) - (:shape-ref parent) - (not (sized-alike? old-parent parent)) - (not (sized-alike? old shape))) + (resized? id) + (some? origin) + (:shape-ref origin) + (not (contains? (get model (:id origin)) :geometry-group))) (assoc-in result [id :geometry-group] (author-geometry shape parent)) result))) model model))) @@ -891,9 +901,8 @@ retained-orientation? (or (not (mth/close? (mod (or (:rotation old-root) 0) 360) rotation 0.01)) (not= (boolean (:flip-x old-root)) (flip :flip-x)) (not= (boolean (:flip-y old-root)) (flip :flip-y))) - ;; a switch keeps the old head's layout item values, and their overrides - layout-items (when keep? - (into {} (filter #(.startsWith (name (key %)) "layout-item-")) (get model root-id))) + ;; a swap keeps the old head's layout item values, and their overrides + layout-items (into {} (filter #(.startsWith (name (key %)) "layout-item-")) (get model root-id)) ;; a swap in a copy keeps an authored place its position does not give, ;; unless a layout places the head kept-place? (and (:shape-ref parent) position diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 9245da8789..d1d0c40693 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2289,6 +2289,19 @@ :ops [[:add-variant 15] [:duplicate 10] [:make-variant 8] [:switch 15] [:style 21 9 1] [:update-main] [:duplicate 16] [:resize 16]]})))) +(t/deftest resizing-a-copy-parent-leaves-unauthored-the-size-it-gives-a-swapped-head + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout nil :variant-diff false + :layout-item-margins false :grid-square false :rich-variants false + :layout-children false :grid-empty false :layout-copies false :text false}] + :ops [[:make-variant 17] [:style 16 9 1] [:switch 7] [:detach 15] [:resize 15]]})))) + +(t/deftest swapping-a-copy-head-keeps-the-margin-it-authors + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :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 [[:combine 10] [:make-variant 12] [:make-variant 4] [:make-variant 1] [:swap 8] + [:style 0 10] [:swap 25]]})))) + (t/deftest pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false :layout-item-margins false :grid-square true :rich-variants false @@ -2340,6 +2353,19 @@ (t/is (empty? (cg/coverage-errors @coverage cg/variant-coverage-kinds)) (pr-str (cg/coverage-errors @coverage cg/variant-coverage-kinds))))) +(t/deftest random-scale-compositions + ;; scale programs run several times longer than the others; the gates draw more + (let [coverage (atom {}) + failure (atom nil)] + (smt/check! + (smt/for [program cg/scale-program-gen] + (cg/check-program program coverage failure)) + :max-size 30 + :default-num 12) + (println "Scale operation coverage:" (pr-str @coverage)) + (t/is (empty? (cg/coverage-errors @coverage cg/scale-coverage-kinds)) + (pr-str (cg/coverage-errors @coverage cg/scale-coverage-kinds))))) + (t/deftest random-renames-leave-variant-management-to-its-own-operations (let [situation (cg/world [2 2 {:variants true}]) file (tm/file situation)] diff --git a/frontend/test/frontend_tests/data/workspace_variants_test.cljs b/frontend/test/frontend_tests/data/workspace_variants_test.cljs index 5cf893cfee..60fc820841 100644 --- a/frontend/test/frontend_tests/data/workspace_variants_test.cljs +++ b/frontend/test/frontend_tests/data/workspace_variants_test.cljs @@ -204,11 +204,11 @@ [] (-> (cthf/sample-file :file1) (ctho/add-simple-component :c01 :m01 :r01 - :root-params {:name "Tag" :x 0 :y 0 :width 100 :height 80}) + :root-params {:name "Tag" :x 0 :y 0 :width 100 :height 80}) (ctho/add-simple-component :c02 :m02 :r02 - :root-params {:name "Tag" :x 150 :y 0 :width 100 :height 80}) + :root-params {:name "Tag" :x 150 :y 0 :width 100 :height 80}) (ctho/add-simple-component :c03 :m03 :r03 - :root-params {:name "Tag" :x 300 :y 0 :width 100 :height 80}))) + :root-params {:name "Tag" :x 300 :y 0 :width 100 :height 80}))) (defn- path-named-main-file []