mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 17:50:38 +00:00
* 🐛 Fix compile warnings in the frontend test tree The frontend test build printed 25 analyzer warnings, all of them in test namespaces: 7 :fn-arity and 18 :infer-warning. The arity ones were latent bugs. Both builds use the :esm target, where a call that crosses a namespace boundary becomes a plain JS call, so CLJS arity dispatch never runs and the missing argument arrives as undefined instead of throwing: the warning was the only signal. One `wait-for` call had no message, and five `interaction-proxy` calls still passed five arguments after the six-argument signature landed in #11621. The rest were JS property reads whose target type could not be inferred (proxies, atoms, awaited promises). A `^js` hint on the target fixes them, the convention already used under src/. Inside `set!` a form-level hint does not reach the target, so the two per-side stroke widths bind the stroke first. Test behavior is unchanged: the same 27 tests in shape-bugfixes-test keep their 63 assertions, and the full frontend suite passes (1901 tests, 7686 assertions). The memories record why `:fn-arity` cannot be ignored in this build and how to force a clean recompile before checking for warnings. AI-assisted-by: deepseek-v4.1-flash * ♻️ Split the tokens plugin tests into one test per case `tokens_test.cljs` drove five tests from `doseq` tables, one of them a nested loop over three catalogs and seventeen mutations. A failure only named the case through its `t/testing` label, and the nested one shared a single store across all fifty-one combinations. Each row is now a test of its own: twelve stroke property edits, four `tokensSource` rejections, seventeen catalog mutations (each asserting the local, source and other connected catalog), five activation changes and three token application paths, taking the namespace from 67 to 104 tests. Fixtures (`stroke-tokens-fixture`, `external-tokens-fixture`, ...) keep the arrangement in one place, and every test builds a fresh store. Two helpers return JS objects with `^js` on their names, so the test bodies stay free of interop hints. Assertions drop from 430 to 345 because the cross product no longer repeats `isEditableTokens` and `tokens-unchanged?` once per catalog and mutation; every write is still asserted against the three catalogs. `mem:testing` now says tables are for short identical bodies only; `frontend/testing` records the `defn ^js` return-tag trick. Verified: namespace 104 tests / 345 assertions, full frontend suite 1938 tests / 7601 assertions, 0 failures; test build 0 warnings; cljfmt and clj-kondo clean. AI-assisted-by: deepseek-v4.1-flash * 📎 Apply suggestion from @elenatorro Co-authored-by: Elena Torró <elenatorro@gmail.com> Signed-off-by: Andrey Antukh <niwi@niwi.nz> --------- Signed-off-by: Andrey Antukh <niwi@niwi.nz> Co-authored-by: Elena Torró <elenatorro@gmail.com>
134 lines
5.1 KiB
Clojure
134 lines
5.1 KiB
Clojure
;; 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 SUBSIDIARY SL
|
|
|
|
(ns frontend-tests.plugins.file-test
|
|
(:require
|
|
[app.common.time :as ct]
|
|
[app.common.uuid :as uuid]
|
|
[app.main.repo :as rp]
|
|
[app.plugins.file :as file]
|
|
[app.plugins.register :as r]
|
|
[beicon.v2.core :as rx]
|
|
[cljs.test :as t :include-macros true]
|
|
[frontend-tests.helpers.mock :as mock]))
|
|
|
|
(t/deftest file-version-created-at-returns-stored-date
|
|
(let [created-at (js/Date.)
|
|
version (file/file-version-proxy
|
|
"00000000-0000-0000-0000-000000000000"
|
|
(random-uuid)
|
|
{}
|
|
{:id (random-uuid)
|
|
:label "Version"
|
|
:created-at created-at})]
|
|
(t/is (identical? created-at (.-createdAt version)))))
|
|
|
|
(defn- make-version
|
|
[file-id data]
|
|
(file/file-version-proxy (str (uuid/next)) file-id {} data))
|
|
|
|
(defn- record-cmd!
|
|
"Mock for `rp/cmd!` that records the calls and answers an observable with
|
|
the shape each command expects: a list of team users, and `true` for the
|
|
snapshot update (`update-file-snapshot` answers a boolean)."
|
|
[calls]
|
|
(fn [cmd params]
|
|
(swap! calls conj [cmd params])
|
|
(rx/of (if (= :get-team-users cmd) [] true))))
|
|
|
|
;; The snapshot RPC commands require the `file-id` (they use it to prune the
|
|
;; partitions of `file_change`); the plugin proxy is the other door to them and
|
|
;; sends it on rename, remove and pin.
|
|
|
|
(t/deftest ^:async renaming-a-version-sends-the-current-file-id
|
|
(let [file-id (uuid/next)
|
|
version-id (uuid/next)
|
|
calls (atom [])]
|
|
|
|
(await
|
|
(mock/with-mocks*
|
|
{r/check-permission (constantly true)
|
|
rp/cmd! (mock/stub (record-cmd! calls))}
|
|
|
|
(let [version (make-version file-id
|
|
{:id version-id
|
|
:label "Version"
|
|
:created-at (ct/now)
|
|
:created-by "user"})]
|
|
(aset version "label" "renamed")
|
|
(let [[cmd params] (last @calls)]
|
|
(t/is (= :update-file-snapshot cmd))
|
|
(t/is (= version-id (:id params)))
|
|
(t/is (= file-id (:file-id params)))
|
|
(t/is (= "renamed" (:label params)))))))))
|
|
|
|
(t/deftest ^:async removing-a-version-sends-the-current-file-id
|
|
(let [file-id (uuid/next)
|
|
version-id (uuid/next)
|
|
calls (atom [])]
|
|
|
|
(await
|
|
(mock/with-mocks*
|
|
{r/check-permission (constantly true)
|
|
rp/cmd! (mock/stub (record-cmd! calls))}
|
|
|
|
(let [version (make-version file-id
|
|
{:id version-id
|
|
:label "Version"
|
|
:created-at (ct/now)
|
|
:created-by "user"})]
|
|
(await (.remove version))
|
|
(let [[cmd params] (last @calls)]
|
|
(t/is (= :delete-file-snapshot cmd))
|
|
(t/is (= version-id (:id params)))
|
|
(t/is (= file-id (:file-id params)))))))))
|
|
|
|
(t/deftest ^:async pinning-a-version-sends-the-current-file-id
|
|
(let [file-id (uuid/next)
|
|
version-id (uuid/next)
|
|
calls (atom [])]
|
|
|
|
(await
|
|
(mock/with-mocks*
|
|
{r/check-permission (constantly true)
|
|
rp/cmd! (mock/stub (record-cmd! calls))}
|
|
|
|
(let [version (make-version file-id
|
|
{:id version-id
|
|
:label "Version"
|
|
:created-at (ct/now)
|
|
:created-by "system"})]
|
|
(await (.pin version))
|
|
(t/is (= [[:get-team-users file-id]
|
|
[:update-file-snapshot file-id]]
|
|
(mapv (fn [[cmd params]] [cmd (:file-id params)]) @calls))))))))
|
|
|
|
(t/deftest ^:async file-version-proxy-pin-resolves-the-pinned-version
|
|
;; `pin` answers with a proxy, not with the boolean the snapshot command
|
|
;; returns: the autosave becomes a user version with a new label.
|
|
(let [file-id (uuid/next)
|
|
version-id (uuid/next)
|
|
created-at (ct/now)
|
|
calls (atom [])]
|
|
(await
|
|
(mock/with-mocks*
|
|
{r/check-permission (constantly true)
|
|
rp/cmd! (mock/stub (record-cmd! calls))}
|
|
(let [version (make-version file-id
|
|
{:id version-id
|
|
:label "Version"
|
|
:created-at created-at
|
|
:created-by "system"})
|
|
^js pinned (await (.pin version))]
|
|
(t/is (file/file-version-proxy? pinned))
|
|
(t/is (= [[:get-team-users file-id]
|
|
[:update-file-snapshot file-id]]
|
|
(mapv (fn [[cmd params]] [cmd (:file-id params)]) @calls)))
|
|
(t/is (= (ct/format-inst created-at :localized-date)
|
|
(.-label pinned)))
|
|
(t/is (false? (.-isAutosave pinned)))
|
|
(t/is (identical? created-at (.-createdAt pinned))))))))
|