mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 17:50:38 +00:00
Create default cells in newly inherited grid tracks before assigning added copy children. A cell override previously made sync append an extra track; a later full sync shrank the tracks beneath the retained cells. Keep existing authored cells and skip positions covered by existing spans. Add common and real frontend row/column growth histories, including an opposite copy direction, retained overrides, exact undo/redo and stable full sync. The original common test failed 12 of 100 assertions and the frontend test failed 4 of 100. Keep those assertions and add checks that each child has exactly one cell. Sync benchmark lower quantiles (ms), baseline -> now (ratio): deepest three levels: 35.215 -> 18.770 (0.53) chain of dependents: 68.931 -> 37.764 (0.55) library update: 83.083 -> 49.418 (0.59) main among many shapes: 4.837 -> 3.008 (0.62) main into 10 copies: 1.790 -> 0.968 (0.54) main into 100 copies: 15.415 -> 9.474 (0.61) main into 1000 copies: 153.086 -> 97.063 (0.63) variant switch: 32.052 -> 22.157 (0.69) All worlds pass the recorded 10% regression limit. The baseline used another machine/JVM, so ratios are rough comparisons. Validation: common JVM 2,016 tests / 33,356 assertions; common JS 1,952 / 32,015; frontend 1,752 / 14,088; backend 1,793 / 9,007; exporter 16 / 40. Six properties pass 40 programs at seed 712 in both common runtimes. Lint and format checks pass for all four modules. Golden-master data is unchanged. AI-assisted-by: gpt-6
64 lines
3.4 KiB
Clojure
64 lines
3.4 KiB
Clojure
(ns frontend-tests.composable-tests.grid-layout-test
|
|
(:require
|
|
[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.undo-check :as uc]
|
|
[app.common.test-helpers.composable.core :as tm]
|
|
[app.common.test-helpers.compositions :as tho]
|
|
[app.common.test-helpers.files :as thf]
|
|
[app.common.test-helpers.ids-map :as thi]
|
|
[app.common.test-helpers.shapes :as ths]
|
|
[app.common.uuid :as uuid]
|
|
[app.main.data.workspace.libraries :as dwl]
|
|
[app.main.data.workspace.shape-layout :as dwsl]
|
|
[app.main.data.workspace.undo :as dwu]
|
|
[app.main.repo :as rp]
|
|
[beicon.v2.core :as rx]
|
|
[cljs.test :as t :include-macros true]
|
|
[frontend-tests.composable-tests.interpreter :as ftm]
|
|
[frontend-tests.helpers.mock :as mock]
|
|
[potok.v2.core :as ptk]))
|
|
|
|
(t/use-fixtures :each ftm/fixture)
|
|
|
|
(t/deftest ^:async grid-growth-keeps-overrides-within-inherited-tracks
|
|
(await
|
|
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
|
(doseq [direction [:row :column]
|
|
turn-copy? [false true]]
|
|
(await (install-grid))
|
|
(let [initial (tm/make-situation (ftm/current-file))
|
|
_ (ftm/uninstall!)
|
|
ops (concat (when (= direction :column) [(n/edit-grid :main :direction :column)])
|
|
[(n/edit-grid :copy :cell {:row 1 :column 1 :props {:align-self :end}})]
|
|
(when turn-copy? [(n/edit-grid :copy :direction (if (= direction :row) :column :row))])
|
|
[(n/add-child :main :extra-a :width 20 :height 20)
|
|
(n/add-child :main :extra-b :width 20 :height 20)])
|
|
grown (loop [live (ftm/start-generated initial) ops ops]
|
|
(if-let [op (first ops)]
|
|
(let [next (await (ftm/run-generated-step live op))]
|
|
(t/is (some? next))
|
|
(t/is (empty? (uc/failures next)))
|
|
(recur next (rest ops)))
|
|
live))
|
|
dims (if (= direction :row) [2 3] [3 2])
|
|
coords (set (for [row (range 1 (inc (first dims)))
|
|
column (range 1 (inc (second dims)))] [row column]))
|
|
members (set (:shapes (get-shape :main)))]
|
|
(doseq [label [:main :copy :other]]
|
|
(t/is (= dims (mapv #(count (get (get-shape label) %)) [:layout-grid-rows :layout-grid-columns])))
|
|
(t/is (= coords (set (map (juxt :row :column) (get-cells label)))))
|
|
(t/is (= members (set (mapcat :shapes (get-cells label)))))
|
|
(t/is (= (frequencies members) (frequencies (mapcat :shapes (get-cells label))))))
|
|
(t/is (= :end (:align-self (first (get-cells :copy)))))
|
|
(t/is (= (cond-> #{:layout-grid-cells} turn-copy? (conj :layout-grid-dir))
|
|
(:touched (get-shape :copy))))
|
|
(t/is (empty? (:touched (get-shape :other))))
|
|
(let [before (ftm/snapshot)
|
|
file-id (:id (ftm/current-file))]
|
|
(t/is (= :settled (await (ftm/await-step [(dwl/sync-file file-id file-id :components (thi/id :component))]))))
|
|
(t/is (uc/same-state? before (ftm/snapshot))))
|
|
(t/is (empty? (uc/failures (await (ftm/finish-generated (ftm/refresh-generated grown))))))
|
|
(ftm/uninstall!))))))
|