diff --git a/frontend/src/app/main/data/event.cljs b/frontend/src/app/main/data/event.cljs index c381583e12..64070e1e85 100644 --- a/frontend/src/app/main/data/event.cljs +++ b/frontend/src/app/main/data/event.cljs @@ -8,7 +8,6 @@ (:require ["@penpot/ua-parser" :as ua] [app.common.data :as d] - [app.common.data.macros :as dm] [app.common.json :as json] [app.common.logging :as l] [app.common.math :as math] @@ -316,14 +315,14 @@ 0))) (add-libraries-counters [state files] - (reduce (fn [state library-id] - (let [data (dm/get-in files [library-id :data])] - (-> state - (update :total-components + (count (:components data))) - (update :total-colors + (count (:colors data))) - (update :total-typographies + (count (:typographies data)))))) - state - (refs/select-libraries files file-id)))] + (reduce-kv (fn [state _ library] + (let [data (:data library)] + (-> state + (update :total-components + (count (:components data))) + (update :total-colors + (count (:colors data))) + (update :total-typographies + (count (:typographies data)))))) + state + (refs/select-libraries files file-id)))] (ptk/reify ::snapshot-performance-info ptk/UpdateEvent diff --git a/frontend/test/frontend_tests/data/event_test.cljs b/frontend/test/frontend_tests/data/event_test.cljs index 9add050dd4..04a184e94f 100644 --- a/frontend/test/frontend_tests/data/event_test.cljs +++ b/frontend/test/frontend_tests/data/event_test.cljs @@ -6,12 +6,14 @@ (ns frontend-tests.data.event-test (:require + [app.common.uuid :as uuid] [app.main.data.event :as ev] [app.main.repo :as rp] [beicon.v2.core :as rx] [cljs.test :as t :include-macros true] [frontend-tests.helpers.async :as async] - [frontend-tests.helpers.mock :as mock])) + [frontend-tests.helpers.mock :as mock] + [potok.v2.core :as ptk])) (t/deftest events-enabled?-truth-table (t/testing "enabled when audit-log is present" @@ -41,3 +43,39 @@ {rp/cmd! (mock/stub (fn [_cmd] (rx/throw (ex-info "boom" {}))))} (await (async/->promise (ev/fetch-environment-data)))))] (t/is (= {:flags #{:telemetry}} data)))) + +(t/deftest snapshot-performance-info-counts-libraries + (let [file-id (uuid/next) + lib-id (uuid/next) + other-id (uuid/next) + unlinked (uuid/next) + sized (fn [n] (zipmap (repeatedly n uuid/next) (repeat {}))) + data (fn [components colors typographies] + {:components (sized components) + :colors (sized colors) + :typographies (sized typographies)}) + state {:files + {file-id {:id file-id + :data (-> (data 1 1 1) + (assoc :pages-index (zipmap (repeatedly 2 uuid/next) + [{:objects (sized 4)} + {:objects (sized 2)}])))} + lib-id {:id lib-id + :library-of file-id + :data (data 2 3 1)} + other-id {:id other-id + :library-of file-id + :data (data 1 2 2)} + unlinked {:id unlinked + :library-of (uuid/next) + :data (data 3 3 3)}}} + state' (ptk/update (#'ev/snapshot-performance-info {:file-id file-id}) state) + counters (get-in state' [:performance-info :counters])] + + (t/testing "counts shapes of the current file" + (t/is (= 6 (:total-shapes counters)))) + + (t/testing "sums the data of the file and its libraries, not other files" + (t/is (= 4 (:total-components counters))) + (t/is (= 6 (:total-colors counters))) + (t/is (= 4 (:total-typographies counters))))))