penpot/common/test/common_tests/path_names_test.cljc
Andrés Moya 0e4be21320
🐛 Ensure component name always matches root instance name (#12794)
* 🐛 Remove svg extension when creating a component from a svg file

* 🐛 Normalize root names to always match the component name

* ✨ Remove any extension ignoring case, not only .svg

* 🔧 Add some fixes and checks

* 🔧 Improve rename detection
2026-11-13 13:53:28 +01:00

51 lines
2.0 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 common-tests.path-names-test
(:require
[app.common.path-names :as cpn]
[clojure.test :as t]))
(t/deftest remove-extension
(t/is (= "photo" (cpn/remove-extension "photo.svg")))
(t/is (= "icon" (cpn/remove-extension "icon.SVG")))
(t/is (= "my.svg.icon" (cpn/remove-extension "my.svg.icon.svg")))
(t/is (= "archive.tar" (cpn/remove-extension "archive.tar.gz")))
(t/is (= "design" (cpn/remove-extension "design")))
(t/is (= "" (cpn/remove-extension ".svg"))))
(t/deftest split-group-name
(t/is (= ["foo" "bar"] (cpn/split-group-name "foo/bar")))
(t/is (= ["" "foo"] (cpn/split-group-name "foo")))
(t/is (= ["" "foo"] (cpn/split-group-name "/foo")))
(t/is (= ["" ""] (cpn/split-group-name "")))
(t/is (= ["" ""] (cpn/split-group-name nil))))
(t/deftest split-and-join-path
(let [name "group/subgroup/name"
path (cpn/split-path name :separator "/")
name' (cpn/join-path path :separator "/" :with-spaces? false)]
(t/is (= (first path) "group"))
(t/is (= (second path) "subgroup"))
(t/is (= (nth path 2) "name"))
(t/is (= name' name))))
(t/deftest split-and-join-path-with-spaces
(let [name "group / subgroup / name"
path (cpn/split-path name :separator "/")]
(t/is (= (first path) "group"))
(t/is (= (second path) "subgroup"))
(t/is (= (nth path 2) "name"))))
(t/deftest normalize-path-name
(t/is (= "Button" (cpn/normalize-path-name " Button ")))
(t/is (= "Group / Button" (cpn/normalize-path-name "Group / Button")))
(t/is (nil? (cpn/normalize-path-name nil)))
(t/is (nil? (cpn/normalize-path-name "")))
(t/is (nil? (cpn/normalize-path-name " ")))
(t/is (nil? (cpn/normalize-path-name "Button/")))
(t/is (nil? (cpn/normalize-path-name "Group / "))))