penpot/frontend/test/frontend_tests/tokens/token_tree_test.cljs
Florian Schrödl 4b2061f399
✨ Add unit tests for the token forms and token tree (#12781)
* ✨ Add unit tests for the token form and combobox helpers

Several helpers of the token forms and the token value combobox were
already pure but had no tests. Cover the reference under the cursor,
the order of the token tree, moving through the combobox options, the
shadow and typography form values and their validation, which value a
form tab validates, and that a token import needs a json file.

Signed-off-by: Florian Schroedl <flo.schroedl@gmail.com>

* ✨ Test the shadow and typography form rules

Add tests for the shadow and typography form schemas: a negative blur
is rejected, a negative spread and a blank blur or spread are accepted,
every shadow needs its offsets and color, a line height needs a font
size, and a token can't reference itself. A typography token submitted
without any field is rejected.

They replace the tests of the validator wrappers, the combobox focus
order and the import file check.

Signed-off-by: Florian Schroedl <flo.schroedl@gmail.com>

---------

Signed-off-by: Florian Schroedl <flo.schroedl@gmail.com>
2026-11-04 12:04:52 +01:00

38 lines
1.2 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.tokens.token-tree-test
(:require
[app.common.path-names :as cpn]
[app.common.types.tokens-lib :as ctob]
[app.main.ui.workspace.tokens.management.token-tree :as wtt]
[cljs.test :as t :include-macros true]))
(def ^:private sort-nodes @#'wtt/sort-nodes)
(defn- tree
[& names]
(cpn/build-tree-root
(map #(ctob/make-token :name % :type :spacing :value "4") names)
ctob/token-separator))
(defn- sorted-names
[nodes]
(map :name (sort-nodes nodes)))
(t/deftest sort-nodes-test
(t/testing "tokens come before groups"
(t/is (= ["zeta" "alpha" "beta"]
(sorted-names (tree "alpha.sm" "zeta" "beta.md")))))
(t/testing "numbers in names sort by value"
(t/is (= ["size2" "size10" "group2" "group10"]
(sorted-names (tree "size10" "group10.sm" "size2" "group2.sm")))))
(t/testing "a token that also has tokens below it sorts with the groups"
(t/is (= ["md" "space"]
(sorted-names (tree "space.sm" "md" "space"))))))