2024-06-28 13:34:54 +02:00
|
|
|
;; 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
|
|
|
|
|
2024-06-28 13:51:32 +02:00
|
|
|
(ns token-tests.token-test
|
2024-06-28 13:34:54 +02:00
|
|
|
(:require
|
2024-06-28 13:51:32 +02:00
|
|
|
[app.main.ui.workspace.tokens.token :as wtt]
|
2024-06-28 13:34:54 +02:00
|
|
|
[cljs.test :as t :include-macros true]))
|
|
|
|
|
2024-07-01 14:05:06 +02:00
|
|
|
(t/deftest token-applied-test
|
|
|
|
(t/testing "matches passed token with `:token-attributes`"
|
|
|
|
(t/is (true? (wtt/token-applied? {:id :a} {:applied-tokens {:x :a}} #{:x}))))
|
|
|
|
(t/testing "doesn't match empty token"
|
|
|
|
(t/is (nil? (wtt/token-applied? {} {:applied-tokens {:x :a}} #{:x}))))
|
|
|
|
(t/testing "does't match passed token `:id`"
|
|
|
|
(t/is (nil? (wtt/token-applied? {:id :b} {:applied-tokens {:x :a}} #{:x}))))
|
|
|
|
(t/testing "doesn't match passed `:token-attributes`"
|
|
|
|
(t/is (nil? (wtt/token-applied? {:id :a} {:applied-tokens {:x :a}} #{:y})))))
|
|
|
|
|
|
|
|
(t/deftest tokens-applied-test
|
|
|
|
(t/testing "is true when single shape matches the token and attributes"
|
2024-07-02 08:22:27 +02:00
|
|
|
(t/is (true? (wtt/shapes-token-applied? {:id :a} [{:applied-tokens {:x :a}}
|
2024-07-02 15:03:04 +02:00
|
|
|
{:applied-tokens {:x :b}}]
|
2024-07-01 14:05:06 +02:00
|
|
|
#{:x}))))
|
|
|
|
(t/testing "is false when no shape matches the token or attributes"
|
2024-07-02 08:22:27 +02:00
|
|
|
(t/is (nil? (wtt/shapes-token-applied? {:id :a} [{:applied-tokens {:x :b}}
|
2024-07-02 15:03:04 +02:00
|
|
|
{:applied-tokens {:x :b}}]
|
2024-07-01 14:05:06 +02:00
|
|
|
#{:x})))
|
2024-07-02 08:22:27 +02:00
|
|
|
(t/is (nil? (wtt/shapes-token-applied? {:id :a} [{:applied-tokens {:x :a}}
|
2024-07-02 15:03:04 +02:00
|
|
|
{:applied-tokens {:x :a}}]
|
2024-07-01 14:05:06 +02:00
|
|
|
#{:y})))))
|
|
|
|
|
2024-06-28 13:34:54 +02:00
|
|
|
(t/deftest name->path-test
|
2024-06-28 13:51:32 +02:00
|
|
|
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo.bar.baz")))
|
|
|
|
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo..bar.baz")))
|
|
|
|
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo..bar.baz...."))))
|
2024-06-28 13:43:41 +02:00
|
|
|
|
2024-07-01 14:14:36 +02:00
|
|
|
(t/deftest tokens-name-map-test
|
|
|
|
(t/testing "creates a a names map from tokens"
|
|
|
|
(t/is (= {"border-radius.sm" {:name "border-radius.sm", :value "10"}
|
|
|
|
"border-radius.md" {:name "border-radius.md", :value "20"}}
|
|
|
|
(wtt/token-names-map [{:name "border-radius.sm" :value "10"}
|
|
|
|
{:name "border-radius.md" :value "20"}])))))
|
|
|
|
|
2024-06-28 14:39:36 +02:00
|
|
|
(t/deftest tokens-name-tree-test
|
2024-06-28 13:43:41 +02:00
|
|
|
(t/is (= {"foo"
|
|
|
|
{"bar"
|
|
|
|
{"baz" {:name "foo.bar.baz", :value "a"},
|
|
|
|
"bam" {:name "foo.bar.bam", :value "b"}}},
|
|
|
|
"baz" {"bar" {"foo" {:name "baz.bar.foo", :value "{foo.bar.baz}"}}}}
|
2024-06-28 13:51:32 +02:00
|
|
|
(wtt/token-names-tree {:a {:name "foo.bar.baz"
|
2024-06-28 13:43:41 +02:00
|
|
|
:value "a"}
|
|
|
|
:b {:name "foo.bar.bam"
|
|
|
|
:value "b"}
|
|
|
|
:c {:name "baz.bar.foo"
|
|
|
|
:value "{foo.bar.baz}"}}))))
|
2024-06-28 14:39:36 +02:00
|
|
|
|
|
|
|
(t/deftest token-name-path-exists?-test
|
2024-07-01 10:16:15 +02:00
|
|
|
(t/is (true? (wtt/token-name-path-exists? "border-radius" {"border-radius" {"sm" {:name "sm"}}})))
|
2024-06-28 14:39:36 +02:00
|
|
|
(t/is (true? (wtt/token-name-path-exists? "border-radius" {"border-radius" {:name "sm"}})))
|
|
|
|
(t/is (true? (wtt/token-name-path-exists? "border-radius.sm" {"border-radius" {:name "sm"}})))
|
|
|
|
(t/is (true? (wtt/token-name-path-exists? "border-radius.sm.x" {"border-radius" {:name "sm"}})))
|
|
|
|
(t/is (false? (wtt/token-name-path-exists? "other" {"border-radius" {:name "sm"}})))
|
|
|
|
(t/is (false? (wtt/token-name-path-exists? "dark.border-radius.md" {"dark" {"border-radius" {"sm" {:name "sm"}}}}))))
|