mirror of
https://github.com/penpot/penpot.git
synced 2026-11-01 23:50:38 +00:00
* 🐛 Fix token tree collapsing repeated path segments Tokens whose path contains the same segment name twice in a row (e.g. test.pointer.pointer) collapsed to a single level in the token tree. build-tree-node marked a node as a leaf when the current segment name matched the first segment of every remaining path. Because group-by-first-segment rewrites nested paths into the segment name, a still-nested remaining path was indistinguishable from a token ending at the current node, so test.pointer.pointer merged into one leaf. Mark rewritten segments with an internal ::remaining? marker and strip it when the rest-path is fully consumed; is-leaf? only accepts unmarked remaining segments as leaves. Closes #11588 AI-assisted-by: glm-5.3-flash Signed-off-by: Junsoo Choi <junsoo1172@gmail.com> * 🐛 Preserve ancestor tokens in path trees Keep a node's token and descendants independently when imported paths contain both an ancestor and a child. Render both in the token tree and include the ancestor token in existing path-based group operations. Cover accepted same-set imports, leaf IDs, repeated segments, and internal marker removal without changing import or collision validation. AI-assisted-by: GPT-6 Signed-off-by: makesomethingshit <junsoo1172@gmail.com> * ♻️ Rework token tree path building Carry the segments left to descend as a ::remaining-path vector on each segment and advance it by subvec, instead of rewriting the segment :name and re-splitting it later. With that, build-tree-node finds the leaf token with a predicate over ::remaining-path and takes children from the segments that still have one, so the pre-grouping children-first sort no longer changes the result. Drop sort-children-first and its segment-has-children? helper, and document inside-path?. AI-assisted-by: deepseek-v4.1-flash * 🐛 Fix and relocate the token tree tests The ancestor-and-descendant test called a function that does not exist in app.common.types.tokens-lib, so the namespace failed to load and the whole common suite errored. Use make-tokens-status-from-lib and the two-argument get-tokens-in-active-sets instead. Move the build-tree-root tests to path-names-tree-test so path-names-test stays a pure split/join unit test. AI-assisted-by: deepseek-v4.1-flash * ♻️ Refactor the token tree rendering and share path helpers Extract the token pill into a leaf-node* component and treat a node as a leaf only when it holds a token and has no children, so a node can carry both a token and its children. Make token-separator public and reuse it from the token tree and the management panel instead of local copies. Both management path filters inlined the same ancestor-or-descendant rule; extract it as token-in-path? and cover it with a unit test. AI-assisted-by: deepseek-v4.1-flash --------- Signed-off-by: Junsoo Choi <junsoo1172@gmail.com> Signed-off-by: makesomethingshit <junsoo1172@gmail.com> Co-authored-by: luisddm <luis.dedios@kaieldos.net>
40 lines
1.6 KiB
Clojure
40 lines
1.6 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-path-test
|
|
(:require
|
|
[app.main.ui.workspace.tokens.management :as wtm]
|
|
[cljs.test :as t :include-macros true]))
|
|
|
|
;; https://github.com/penpot/penpot/issues/11588
|
|
;; A token whose name equals a tree node path must stay in the operations of
|
|
;; that node, alongside the tokens nested below it.
|
|
|
|
(t/deftest token-in-path-matches-the-path-itself
|
|
(t/testing "an ancestor token is in its own path"
|
|
(t/is (true? (wtm/token-in-path? "a.a" "a.a")))
|
|
(t/is (true? (wtm/token-in-path? "a" "a")))))
|
|
|
|
(t/deftest token-in-path-matches-nested-tokens
|
|
(t/testing "a token nested below the path is in the path"
|
|
(t/is (true? (wtm/token-in-path? "a.a" "a.a.a")))
|
|
(t/is (true? (wtm/token-in-path? "a" "a.b.c")))
|
|
(t/is (true? (wtm/token-in-path? "a.a" "a.a.b.c")))))
|
|
|
|
(t/deftest token-in-path-rejects-non-descendants
|
|
(t/testing "a sibling is not in the path"
|
|
(t/is (false? (wtm/token-in-path? "a.a" "a.b"))))
|
|
|
|
(t/testing "a deeper path does not match a shorter token"
|
|
(t/is (false? (wtm/token-in-path? "a.a.a" "a.a"))))
|
|
|
|
(t/testing "a name sharing the prefix without a separator boundary is not in the path"
|
|
(t/is (false? (wtm/token-in-path? "a.a" "a.ab")))
|
|
(t/is (false? (wtm/token-in-path? "a" "ab"))))
|
|
|
|
(t/testing "an unrelated path is not in the path"
|
|
(t/is (false? (wtm/token-in-path? "x.y" "z")))))
|