mirror of
https://github.com/penpot/penpot.git
synced 2026-07-28 17:06:21 +00:00
✨ Align event names column in format-last-events output
The third column (event name) in error report "last events" now starts at a consistent position regardless of the delta value, by right-padding the delta string to 10 characters. The first event always shows (+0ms). Adds tests for empty, single, multi-event, and column alignment cases. AI-assisted-by: deepseek-v4-flash
This commit is contained in:
parent
af120feb1f
commit
63e0c536f0
@ -107,8 +107,8 @@
|
||||
(defn format-last-events
|
||||
"Render the `last-events` buffer as a multi-line string with the
|
||||
wall-clock time of each event and the delta (ms) since the previous
|
||||
entry. The first entry has no delta. Useful for embedding in error
|
||||
reports."
|
||||
entry. The delta column is right-padded to 10 chars so the event
|
||||
names align. Useful for embedding in error reports."
|
||||
([] (format-last-events @last-events))
|
||||
([events]
|
||||
(let [lines
|
||||
@ -117,13 +117,14 @@
|
||||
out (transient [])]
|
||||
(if xs
|
||||
(let [{:keys [name t]} (first xs)
|
||||
iso (ct/format-inst t :iso)
|
||||
tail (if prev-t
|
||||
(str " (+" (ct/diff-ms prev-t t) "ms)")
|
||||
"")]
|
||||
iso (ct/format-inst t :iso)
|
||||
delta (if prev-t
|
||||
(str "(+" (ct/diff-ms prev-t t) "ms)")
|
||||
"(+0ms)")
|
||||
delta-pad (str/pad delta {:length 10 :type :right})]
|
||||
(recur t
|
||||
(next xs)
|
||||
(conj! out (str iso tail " " name))))
|
||||
(conj! out (str iso " " delta-pad " " name))))
|
||||
(persistent! out)))]
|
||||
(str/join "\n" lines))))
|
||||
|
||||
|
||||
49
frontend/test/frontend_tests/data/store_test.cljs
Normal file
49
frontend/test/frontend_tests/data/store_test.cljs
Normal file
@ -0,0 +1,49 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC Sucursal en España SL
|
||||
|
||||
(ns frontend-tests.data.store-test
|
||||
"Unit tests for app.main.store.
|
||||
Tests cover:
|
||||
- format-last-events – empty, single, multi, column alignment"
|
||||
(:require
|
||||
[app.main.store :as st]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(t/deftest format-last-events-empty
|
||||
(t/testing "empty events produce empty string"
|
||||
(t/is (= "" (st/format-last-events [])))))
|
||||
|
||||
(t/deftest format-last-events-single
|
||||
(t/testing "a single event shows (+0ms) and its name"
|
||||
(let [result (st/format-last-events [{:name ":test/event" :t (js/Date. 1000)}])]
|
||||
(t/is (str/includes? result "(+0ms)"))
|
||||
(t/is (str/includes? result ":test/event"))
|
||||
(t/is (= 1 (count (str/split result "\n")))))))
|
||||
|
||||
(t/deftest format-last-events-multi
|
||||
(t/testing "multiple events show correct deltas and event names"
|
||||
(let [events [{:name ":event/a" :t (js/Date. 0)}
|
||||
{:name ":event/b" :t (js/Date. 500)}
|
||||
{:name ":event/c" :t (js/Date. 2500)}]
|
||||
lines (str/split (st/format-last-events events) "\n")]
|
||||
(t/is (= 3 (count lines)))
|
||||
(t/is (some #(str/includes? % ":event/a") lines))
|
||||
(t/is (some #(str/includes? % ":event/b") lines))
|
||||
(t/is (some #(str/includes? % ":event/c") lines))
|
||||
(t/is (str/includes? (nth lines 0) "(+0ms)"))
|
||||
(t/is (str/includes? (nth lines 1) "(+500ms)"))
|
||||
(t/is (str/includes? (nth lines 2) "(+2000ms)")))))
|
||||
|
||||
(t/deftest format-last-events-alignment
|
||||
(t/testing "event names start at the same column across all lines"
|
||||
(let [events [{:name ":evt-a" :t (js/Date. 0)}
|
||||
{:name ":evt-b" :t (js/Date. 500)}]
|
||||
lines (str/split (st/format-last-events events) "\n")
|
||||
col-a (.indexOf (nth lines 0) ":evt-a")
|
||||
col-b (.indexOf (nth lines 1) ":evt-b")]
|
||||
(t/is (pos? col-a))
|
||||
(t/is (= col-a col-b)))))
|
||||
@ -9,6 +9,7 @@
|
||||
[frontend-tests.copy-as-svg-test]
|
||||
[frontend-tests.data.nitrate-test]
|
||||
[frontend-tests.data.repo-test]
|
||||
[frontend-tests.data.store-test]
|
||||
[frontend-tests.data.uploads-test]
|
||||
[frontend-tests.data.viewer-test]
|
||||
[frontend-tests.data.workspace-colors-test]
|
||||
@ -86,6 +87,7 @@
|
||||
'frontend-tests.copy-as-svg-test
|
||||
'frontend-tests.data.nitrate-test
|
||||
'frontend-tests.data.repo-test
|
||||
'frontend-tests.data.store-test
|
||||
'frontend-tests.errors-test
|
||||
'frontend-tests.main-errors-test
|
||||
'frontend-tests.data.uploads-test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user