mirror of
https://github.com/penpot/penpot.git
synced 2025-02-15 19:48:22 -05:00
🔧 Make themes a two-level only tree
This commit is contained in:
parent
3a4ec32f8e
commit
5f703d6a79
4 changed files with 122 additions and 119 deletions
|
@ -67,7 +67,7 @@
|
||||||
(oassoc o k (oassoc-in (get o k) ks v))
|
(oassoc o k (oassoc-in (get o k) ks v))
|
||||||
(oassoc o k v)))
|
(oassoc o k v)))
|
||||||
|
|
||||||
#_(defn oupdate-in
|
(defn oupdate-in
|
||||||
[m ks f & args]
|
[m ks f & args]
|
||||||
(let [up (fn up [m ks f args]
|
(let [up (fn up [m ks f args]
|
||||||
(let [[k & ks] ks]
|
(let [[k & ks] ks]
|
||||||
|
|
|
@ -849,13 +849,13 @@
|
||||||
(ctotl/assoc-active-token-themes data theme-ids))
|
(ctotl/assoc-active-token-themes data theme-ids))
|
||||||
|
|
||||||
(defmethod process-change :delete-temporary-token-theme
|
(defmethod process-change :delete-temporary-token-theme
|
||||||
[data {:keys [id name]}]
|
[data {:keys [id group name]}]
|
||||||
(-> data
|
(-> data
|
||||||
(ctotl/delete-temporary-token-theme id)
|
(ctotl/delete-temporary-token-theme id)
|
||||||
(update :tokens-lib
|
(update :tokens-lib
|
||||||
#(-> %
|
#(-> %
|
||||||
(ctob/ensure-tokens-lib)
|
(ctob/ensure-tokens-lib)
|
||||||
(ctob/delete-theme name)))))
|
(ctob/delete-theme group name)))))
|
||||||
|
|
||||||
(defmethod process-change :add-token-theme
|
(defmethod process-change :add-token-theme
|
||||||
[data {:keys [token-theme]}]
|
[data {:keys [token-theme]}]
|
||||||
|
@ -869,25 +869,26 @@
|
||||||
(ctob/make-token-theme)))))))
|
(ctob/make-token-theme)))))))
|
||||||
|
|
||||||
(defmethod process-change :mod-token-theme
|
(defmethod process-change :mod-token-theme
|
||||||
[data {:keys [id name token-theme]}]
|
[data {:keys [id name group token-theme]}]
|
||||||
(-> data
|
(-> data
|
||||||
(ctotl/update-token-theme id merge token-theme)
|
(ctotl/update-token-theme id merge token-theme)
|
||||||
(update :tokens-lib
|
(update :tokens-lib
|
||||||
#(-> %
|
#(-> %
|
||||||
(ctob/ensure-tokens-lib)
|
(ctob/ensure-tokens-lib)
|
||||||
(ctob/update-theme name (fn [prev-theme]
|
(ctob/update-theme name group
|
||||||
(merge prev-theme
|
(fn [prev-theme]
|
||||||
(-> token-theme
|
(merge prev-theme
|
||||||
(update :sets (partial set-ids->names data))))))))))
|
(-> token-theme
|
||||||
|
(update :sets (partial set-ids->names data))))))))))
|
||||||
|
|
||||||
(defmethod process-change :del-token-theme
|
(defmethod process-change :del-token-theme
|
||||||
[data {:keys [id name]}]
|
[data {:keys [id group name]}]
|
||||||
(-> data
|
(-> data
|
||||||
(ctotl/delete-token-theme id)
|
(ctotl/delete-token-theme id)
|
||||||
(update :tokens-lib
|
(update :tokens-lib
|
||||||
#(-> %
|
#(-> %
|
||||||
(ctob/ensure-tokens-lib)
|
(ctob/ensure-tokens-lib)
|
||||||
(ctob/delete-theme name)))))
|
(ctob/delete-theme group name)))))
|
||||||
|
|
||||||
(defmethod process-change :add-token-set
|
(defmethod process-change :add-token-set
|
||||||
[data {:keys [token-set]}]
|
[data {:keys [token-set]}]
|
||||||
|
|
|
@ -258,10 +258,11 @@
|
||||||
(defprotocol ITokenTheme
|
(defprotocol ITokenTheme
|
||||||
(toggle-set [_ set-name] "togle a set used / not used in the theme"))
|
(toggle-set [_ set-name] "togle a set used / not used in the theme"))
|
||||||
|
|
||||||
(defrecord TokenTheme [name description is-source modified-at sets]
|
(defrecord TokenTheme [name group description is-source modified-at sets]
|
||||||
ITokenTheme
|
ITokenTheme
|
||||||
(toggle-set [_ set-name]
|
(toggle-set [_ set-name]
|
||||||
(TokenTheme. name
|
(TokenTheme. name
|
||||||
|
group
|
||||||
description
|
description
|
||||||
is-source
|
is-source
|
||||||
(dt/now)
|
(dt/now)
|
||||||
|
@ -272,6 +273,7 @@
|
||||||
(def schema:token-theme
|
(def schema:token-theme
|
||||||
[:and [:map {:title "TokenTheme"}
|
[:and [:map {:title "TokenTheme"}
|
||||||
[:name :string]
|
[:name :string]
|
||||||
|
[:group :string]
|
||||||
[:description [:maybe :string]]
|
[:description [:maybe :string]]
|
||||||
[:is-source :boolean]
|
[:is-source :boolean]
|
||||||
[:modified-at ::sm/inst]
|
[:modified-at ::sm/inst]
|
||||||
|
@ -291,7 +293,7 @@
|
||||||
[& {:keys [] :as params}]
|
[& {:keys [] :as params}]
|
||||||
(let [params (-> params
|
(let [params (-> params
|
||||||
(dissoc :id)
|
(dissoc :id)
|
||||||
(dissoc :group)
|
(update :group #(or % ""))
|
||||||
(update :is-source #(or % false))
|
(update :is-source #(or % false))
|
||||||
(update :modified-at #(or % (dt/now)))
|
(update :modified-at #(or % (dt/now)))
|
||||||
(update :sets #(into (d/ordered-set) %)))
|
(update :sets #(into (d/ordered-set) %)))
|
||||||
|
@ -307,17 +309,18 @@
|
||||||
|
|
||||||
(defprotocol ITokenThemes
|
(defprotocol ITokenThemes
|
||||||
(add-theme [_ token-theme] "add a theme to the library, at the end")
|
(add-theme [_ token-theme] "add a theme to the library, at the end")
|
||||||
(update-theme [_ theme-name f] "modify a theme in the ilbrary")
|
(update-theme [_ group name f] "modify a theme in the ilbrary")
|
||||||
(delete-theme [_ theme-name] "delete a theme in the library")
|
(delete-theme [_ group name] "delete a theme in the library")
|
||||||
(theme-count [_] "get the total number if themes in the library")
|
(theme-count [_] "get the total number if themes in the library")
|
||||||
(get-theme-tree [_] "get a nested tree of all themes in the library")
|
(get-theme-tree [_] "get a nested tree of all themes in the library")
|
||||||
(get-themes [_] "get an ordered sequence of all themes in the library")
|
(get-themes [_] "get an ordered sequence of all themes in the library")
|
||||||
(get-theme [_ theme-name] "get one theme looking for name"))
|
(get-theme [_ group name] "get one theme looking for name"))
|
||||||
|
|
||||||
(def schema:token-themes
|
(def schema:token-themes
|
||||||
[:and
|
[:and
|
||||||
[:map-of {:title "TokenThemes"}
|
[:map-of {:title "TokenThemes"}
|
||||||
:string ::token-theme]
|
:string [:and [:map-of :string ::token-theme]
|
||||||
|
[:fn d/ordered-map?]]]
|
||||||
[:fn d/ordered-map?]])
|
[:fn d/ordered-map?]])
|
||||||
|
|
||||||
(sm/register! ::token-themes schema:token-themes)
|
(sm/register! ::token-themes schema:token-themes)
|
||||||
|
@ -335,7 +338,7 @@
|
||||||
(add-token-in-set [_ set-name token] "add token to a set")
|
(add-token-in-set [_ set-name token] "add token to a set")
|
||||||
(update-token-in-set [_ set-name token-name f] "update a token in a set")
|
(update-token-in-set [_ set-name token-name f] "update a token in a set")
|
||||||
(delete-token-from-set [_ set-name token-name] "delete a token from a set")
|
(delete-token-from-set [_ set-name token-name] "delete a token from a set")
|
||||||
(toggle-set-in-theme [_ theme-name set-name] "toggle a set used / not used in a theme")
|
(toggle-set-in-theme [_ group-name theme-name set-name] "toggle a set used / not used in a theme")
|
||||||
(validate [_]))
|
(validate [_]))
|
||||||
|
|
||||||
(deftype TokensLib [sets set-groups themes]
|
(deftype TokensLib [sets set-groups themes]
|
||||||
|
@ -405,33 +408,31 @@
|
||||||
ITokenThemes
|
ITokenThemes
|
||||||
(add-theme [_ token-theme]
|
(add-theme [_ token-theme]
|
||||||
(dm/assert! "expected valid token theme" (check-token-theme! token-theme))
|
(dm/assert! "expected valid token theme" (check-token-theme! token-theme))
|
||||||
(let [path (get-path token-theme "/")]
|
(TokensLib. sets
|
||||||
(TokensLib. sets
|
set-groups
|
||||||
set-groups
|
(update themes (:group token-theme) d/oassoc (:name token-theme) token-theme)))
|
||||||
(d/oassoc-in themes path token-theme))))
|
|
||||||
|
|
||||||
(update-theme [this theme-name f]
|
(update-theme [this group name f]
|
||||||
(let [path (split-path theme-name "/")
|
(let [theme (dm/get-in themes [group name])]
|
||||||
theme (get-in themes path)]
|
|
||||||
(if theme
|
(if theme
|
||||||
(let [theme' (-> (make-token-theme (f theme))
|
(let [theme' (-> (make-token-theme (f theme))
|
||||||
(assoc :modified-at (dt/now)))
|
(assoc :modified-at (dt/now)))
|
||||||
path' (get-path theme' "/")]
|
group' (:group theme')
|
||||||
|
name' (:name theme')]
|
||||||
(check-token-theme! theme')
|
(check-token-theme! theme')
|
||||||
(TokensLib. sets
|
(TokensLib. sets
|
||||||
set-groups
|
set-groups
|
||||||
(if (= (:name theme) (:name theme'))
|
(if (and (= group group') (= name name'))
|
||||||
(d/oassoc-in themes path theme')
|
(update themes group' assoc name' theme')
|
||||||
(-> themes
|
(-> themes
|
||||||
(d/oassoc-in-before path path' theme')
|
(d/oassoc-in-before [group name] [group' name'] theme')
|
||||||
(d/dissoc-in path)))))
|
(d/dissoc-in [group name])))))
|
||||||
this)))
|
this)))
|
||||||
|
|
||||||
(delete-theme [_ theme-name]
|
(delete-theme [_ group name]
|
||||||
(let [path (split-path theme-name "/")]
|
(TokensLib. sets
|
||||||
(TokensLib. sets
|
set-groups
|
||||||
set-groups
|
(d/dissoc-in themes [group name])))
|
||||||
(d/dissoc-in themes path))))
|
|
||||||
|
|
||||||
(get-theme-tree [_]
|
(get-theme-tree [_]
|
||||||
themes)
|
themes)
|
||||||
|
@ -443,9 +444,8 @@
|
||||||
(theme-count [this]
|
(theme-count [this]
|
||||||
(count (get-themes this)))
|
(count (get-themes this)))
|
||||||
|
|
||||||
(get-theme [_ theme-name]
|
(get-theme [_ group name]
|
||||||
(let [path (split-path theme-name "/")]
|
(dm/get-in themes [group name]))
|
||||||
(get-in themes path)))
|
|
||||||
|
|
||||||
ITokensLib
|
ITokensLib
|
||||||
(add-token-in-set [this set-name token]
|
(add-token-in-set [this set-name token]
|
||||||
|
@ -472,12 +472,12 @@
|
||||||
themes)
|
themes)
|
||||||
this))
|
this))
|
||||||
|
|
||||||
(toggle-set-in-theme [this theme-name set-name]
|
(toggle-set-in-theme [this theme-group theme-name set-name]
|
||||||
(if (contains? themes theme-name)
|
(if-let [_theme (get-in themes theme-group theme-name)]
|
||||||
(TokensLib. sets
|
(TokensLib. sets
|
||||||
set-groups
|
set-groups
|
||||||
(update themes theme-name
|
(d/oupdate-in themes [theme-group theme-name]
|
||||||
#(toggle-set % set-name)))
|
#(toggle-set % set-name)))
|
||||||
this))
|
this))
|
||||||
|
|
||||||
(validate [_]
|
(validate [_]
|
||||||
|
|
|
@ -78,18 +78,21 @@
|
||||||
(let [now (dt/now)
|
(let [now (dt/now)
|
||||||
token-theme1 (ctob/make-token-theme :name "test-token-theme-1")
|
token-theme1 (ctob/make-token-theme :name "test-token-theme-1")
|
||||||
token-theme2 (ctob/make-token-theme :name "test-token-theme-2"
|
token-theme2 (ctob/make-token-theme :name "test-token-theme-2"
|
||||||
|
:group "group-1"
|
||||||
:description "test description"
|
:description "test description"
|
||||||
:is-source true
|
:is-source true
|
||||||
:modified-at now
|
:modified-at now
|
||||||
:sets #{})]
|
:sets #{})]
|
||||||
|
|
||||||
(t/is (= (:name token-theme1) "test-token-theme-1"))
|
(t/is (= (:name token-theme1) "test-token-theme-1"))
|
||||||
|
(t/is (= (:group token-theme1) ""))
|
||||||
(t/is (nil? (:description token-theme1)))
|
(t/is (nil? (:description token-theme1)))
|
||||||
(t/is (false? (:is-source token-theme1)))
|
(t/is (false? (:is-source token-theme1)))
|
||||||
(t/is (some? (:modified-at token-theme1)))
|
(t/is (some? (:modified-at token-theme1)))
|
||||||
(t/is (empty? (:sets token-theme1)))
|
(t/is (empty? (:sets token-theme1)))
|
||||||
|
|
||||||
(t/is (= (:name token-theme2) "test-token-theme-2"))
|
(t/is (= (:name token-theme2) "test-token-theme-2"))
|
||||||
|
(t/is (= (:group token-theme2) "group-1"))
|
||||||
(t/is (= (:description token-theme2) "test description"))
|
(t/is (= (:description token-theme2) "test description"))
|
||||||
(t/is (true? (:is-source token-theme2)))
|
(t/is (true? (:is-source token-theme2)))
|
||||||
(t/is (= (:modified-at token-theme2) now))
|
(t/is (= (:modified-at token-theme2) now))
|
||||||
|
@ -97,6 +100,7 @@
|
||||||
|
|
||||||
(t/deftest invalid-token-theme
|
(t/deftest invalid-token-theme
|
||||||
(let [args {:name 777
|
(let [args {:name 777
|
||||||
|
:group nil
|
||||||
:description 999
|
:description 999
|
||||||
:is-source 42}]
|
:is-source 42}]
|
||||||
(t/is (thrown-with-msg? Exception #"expected valid token theme"
|
(t/is (thrown-with-msg? Exception #"expected valid token theme"
|
||||||
|
@ -313,9 +317,8 @@
|
||||||
tokens-lib' (ctob/add-theme tokens-lib token-theme)
|
tokens-lib' (ctob/add-theme tokens-lib token-theme)
|
||||||
|
|
||||||
token-themes' (ctob/get-themes tokens-lib')
|
token-themes' (ctob/get-themes tokens-lib')
|
||||||
token-theme' (ctob/get-theme tokens-lib' "test-token-theme")]
|
token-theme' (ctob/get-theme tokens-lib' "" "test-token-theme")]
|
||||||
|
|
||||||
(prn "lib" tokens-lib')
|
|
||||||
(t/is (= (ctob/theme-count tokens-lib') 1))
|
(t/is (= (ctob/theme-count tokens-lib') 1))
|
||||||
(t/is (= (first token-themes') token-theme))
|
(t/is (= (first token-themes') token-theme))
|
||||||
(t/is (= token-theme' token-theme))))
|
(t/is (= token-theme' token-theme))))
|
||||||
|
@ -325,17 +328,17 @@
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme")))
|
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme")))
|
||||||
|
|
||||||
tokens-lib' (-> tokens-lib
|
tokens-lib' (-> tokens-lib
|
||||||
(ctob/update-theme "test-token-theme"
|
(ctob/update-theme "" "test-token-theme"
|
||||||
(fn [token-theme]
|
(fn [token-theme]
|
||||||
(assoc token-theme
|
(assoc token-theme
|
||||||
:description "some description")))
|
:description "some description")))
|
||||||
(ctob/update-theme "not-existing-theme"
|
(ctob/update-theme "" "not-existing-theme"
|
||||||
(fn [token-theme]
|
(fn [token-theme]
|
||||||
(assoc token-theme
|
(assoc token-theme
|
||||||
:description "no-effect"))))
|
:description "no-effect"))))
|
||||||
|
|
||||||
token-theme (ctob/get-theme tokens-lib "test-token-theme")
|
token-theme (ctob/get-theme tokens-lib "" "test-token-theme")
|
||||||
token-theme' (ctob/get-theme tokens-lib' "test-token-theme")]
|
token-theme' (ctob/get-theme tokens-lib' "" "test-token-theme")]
|
||||||
|
|
||||||
(t/is (= (ctob/theme-count tokens-lib') 1))
|
(t/is (= (ctob/theme-count tokens-lib') 1))
|
||||||
(t/is (= (:name token-theme') "test-token-theme"))
|
(t/is (= (:name token-theme') "test-token-theme"))
|
||||||
|
@ -347,13 +350,13 @@
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme")))
|
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme")))
|
||||||
|
|
||||||
tokens-lib' (-> tokens-lib
|
tokens-lib' (-> tokens-lib
|
||||||
(ctob/update-theme "test-token-theme"
|
(ctob/update-theme "" "test-token-theme"
|
||||||
(fn [token-theme]
|
(fn [token-theme]
|
||||||
(assoc token-theme
|
(assoc token-theme
|
||||||
:name "updated-name"))))
|
:name "updated-name"))))
|
||||||
|
|
||||||
token-theme (ctob/get-theme tokens-lib "test-token-theme")
|
token-theme (ctob/get-theme tokens-lib "" "test-token-theme")
|
||||||
token-theme' (ctob/get-theme tokens-lib' "updated-name")]
|
token-theme' (ctob/get-theme tokens-lib' "" "updated-name")]
|
||||||
|
|
||||||
(t/is (= (ctob/theme-count tokens-lib') 1))
|
(t/is (= (ctob/theme-count tokens-lib') 1))
|
||||||
(t/is (= (:name token-theme') "updated-name"))
|
(t/is (= (:name token-theme') "updated-name"))
|
||||||
|
@ -364,10 +367,10 @@
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme")))
|
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme")))
|
||||||
|
|
||||||
tokens-lib' (-> tokens-lib
|
tokens-lib' (-> tokens-lib
|
||||||
(ctob/delete-theme "test-token-theme")
|
(ctob/delete-theme "" "test-token-theme")
|
||||||
(ctob/delete-theme "not-existing-theme"))
|
(ctob/delete-theme "" "not-existing-theme"))
|
||||||
|
|
||||||
token-theme' (ctob/get-theme tokens-lib' "updated-name")]
|
token-theme' (ctob/get-theme tokens-lib' "" "updated-name")]
|
||||||
|
|
||||||
(t/is (= (ctob/theme-count tokens-lib') 0))
|
(t/is (= (ctob/theme-count tokens-lib') 0))
|
||||||
(t/is (nil? token-theme'))))
|
(t/is (nil? token-theme'))))
|
||||||
|
@ -379,12 +382,12 @@
|
||||||
(ctob/add-set (ctob/make-token-set :name "token-set-3"))
|
(ctob/add-set (ctob/make-token-set :name "token-set-3"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme")))
|
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme")))
|
||||||
tokens-lib' (-> tokens-lib
|
tokens-lib' (-> tokens-lib
|
||||||
(ctob/toggle-set-in-theme "test-token-theme" "token-set-1")
|
(ctob/toggle-set-in-theme "" "test-token-theme" "token-set-1")
|
||||||
(ctob/toggle-set-in-theme "test-token-theme" "token-set-2")
|
(ctob/toggle-set-in-theme "" "test-token-theme" "token-set-2")
|
||||||
(ctob/toggle-set-in-theme "test-token-theme" "token-set-2"))
|
(ctob/toggle-set-in-theme "" "test-token-theme" "token-set-2"))
|
||||||
|
|
||||||
token-theme (ctob/get-theme tokens-lib "test-token-theme")
|
token-theme (ctob/get-theme tokens-lib "" "test-token-theme")
|
||||||
token-theme' (ctob/get-theme tokens-lib' "test-token-theme")]
|
token-theme' (ctob/get-theme tokens-lib' "" "test-token-theme")]
|
||||||
|
|
||||||
(t/is (dt/is-after? (:modified-at token-theme') (:modified-at token-theme))))))
|
(t/is (dt/is-after? (:modified-at token-theme') (:modified-at token-theme))))))
|
||||||
|
|
||||||
|
@ -397,7 +400,7 @@
|
||||||
:type :boolean
|
:type :boolean
|
||||||
:value true))
|
:value true))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
|
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
|
||||||
(ctob/toggle-set-in-theme "test-token-theme" "test-token-set"))
|
(ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set"))
|
||||||
encoded-str (tr/encode-str tokens-lib)
|
encoded-str (tr/encode-str tokens-lib)
|
||||||
tokens-lib' (tr/decode-str encoded-str)]
|
tokens-lib' (tr/decode-str encoded-str)]
|
||||||
|
|
||||||
|
@ -412,7 +415,7 @@
|
||||||
:type :boolean
|
:type :boolean
|
||||||
:value true))
|
:value true))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
|
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
|
||||||
(ctob/toggle-set-in-theme "test-token-theme" "test-token-set"))
|
(ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set"))
|
||||||
encoded-blob (fres/encode tokens-lib)
|
encoded-blob (fres/encode tokens-lib)
|
||||||
tokens-lib' (fres/decode encoded-blob)]
|
tokens-lib' (fres/decode encoded-blob)]
|
||||||
|
|
||||||
|
@ -840,34 +843,40 @@
|
||||||
(t/testing "grouped themes"
|
(t/testing "grouped themes"
|
||||||
(t/deftest grouped-themes
|
(t/deftest grouped-themes
|
||||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "token-theme-1"))
|
(ctob/add-theme (ctob/make-token-theme :group "" :name "token-theme-1"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/token-theme-2"))
|
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-2"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/token-theme-3"))
|
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-3"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/subgroup11/token-theme-4"))
|
(ctob/add-theme (ctob/make-token-theme :group "group2" :name "token-theme-4")))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group2/token-theme-5")))
|
|
||||||
|
|
||||||
themes-list (ctob/get-themes tokens-lib)
|
themes-list (ctob/get-themes tokens-lib)
|
||||||
|
|
||||||
themes-tree (ctob/get-theme-tree tokens-lib)
|
themes-tree (ctob/get-theme-tree tokens-lib)
|
||||||
|
|
||||||
[node-theme1 node-group1 node-group2]
|
[node-group0 node-group1 node-group2]
|
||||||
(ctob/get-children themes-tree)
|
(ctob/get-children themes-tree)
|
||||||
|
|
||||||
[node-theme2 node-theme3 node-subgroup11]
|
[node-theme1]
|
||||||
|
(ctob/get-children (second node-group0))
|
||||||
|
|
||||||
|
[node-theme2 node-theme3]
|
||||||
(ctob/get-children (second node-group1))
|
(ctob/get-children (second node-group1))
|
||||||
|
|
||||||
[node-theme4]
|
[node-theme4]
|
||||||
(ctob/get-children (second node-subgroup11))
|
|
||||||
|
|
||||||
[node-theme5]
|
|
||||||
(ctob/get-children (second node-group2))]
|
(ctob/get-children (second node-group2))]
|
||||||
|
|
||||||
(t/is (= (count themes-list) 5))
|
(t/is (= (count themes-list) 4))
|
||||||
(t/is (= (:name (nth themes-list 0)) "token-theme-1"))
|
(t/is (= (:name (nth themes-list 0)) "token-theme-1"))
|
||||||
(t/is (= (:name (nth themes-list 1)) "group1/token-theme-2"))
|
(t/is (= (:name (nth themes-list 1)) "token-theme-2"))
|
||||||
(t/is (= (:name (nth themes-list 2)) "group1/token-theme-3"))
|
(t/is (= (:name (nth themes-list 2)) "token-theme-3"))
|
||||||
(t/is (= (:name (nth themes-list 3)) "group1/subgroup11/token-theme-4"))
|
(t/is (= (:name (nth themes-list 3)) "token-theme-4"))
|
||||||
(t/is (= (:name (nth themes-list 4)) "group2/token-theme-5"))
|
(t/is (= (:group (nth themes-list 0)) ""))
|
||||||
|
(t/is (= (:group (nth themes-list 1)) "group1"))
|
||||||
|
(t/is (= (:group (nth themes-list 2)) "group1"))
|
||||||
|
(t/is (= (:group (nth themes-list 3)) "group2"))
|
||||||
|
|
||||||
|
(t/is (= (first node-group0) ""))
|
||||||
|
(t/is (= (ctob/group? (second node-group0)) true))
|
||||||
|
(t/is (= (count (second node-group0)) 1))
|
||||||
|
|
||||||
(t/is (= (first node-theme1) "token-theme-1"))
|
(t/is (= (first node-theme1) "token-theme-1"))
|
||||||
(t/is (= (ctob/group? (second node-theme1)) false))
|
(t/is (= (ctob/group? (second node-theme1)) false))
|
||||||
|
@ -875,38 +884,29 @@
|
||||||
|
|
||||||
(t/is (= (first node-group1) "group1"))
|
(t/is (= (first node-group1) "group1"))
|
||||||
(t/is (= (ctob/group? (second node-group1)) true))
|
(t/is (= (ctob/group? (second node-group1)) true))
|
||||||
(t/is (= (count (second node-group1)) 3))
|
(t/is (= (count (second node-group1)) 2))
|
||||||
|
|
||||||
(t/is (= (first node-theme2) "token-theme-2"))
|
(t/is (= (first node-theme2) "token-theme-2"))
|
||||||
(t/is (= (ctob/group? (second node-theme2)) false))
|
(t/is (= (ctob/group? (second node-theme2)) false))
|
||||||
(t/is (= (:name (second node-theme2)) "group1/token-theme-2"))
|
(t/is (= (:name (second node-theme2)) "token-theme-2"))
|
||||||
|
|
||||||
(t/is (= (first node-theme3) "token-theme-3"))
|
(t/is (= (first node-theme3) "token-theme-3"))
|
||||||
(t/is (= (ctob/group? (second node-theme3)) false))
|
(t/is (= (ctob/group? (second node-theme3)) false))
|
||||||
(t/is (= (:name (second node-theme3)) "group1/token-theme-3"))
|
(t/is (= (:name (second node-theme3)) "token-theme-3"))
|
||||||
|
|
||||||
(t/is (= (first node-subgroup11) "subgroup11"))
|
|
||||||
(t/is (= (ctob/group? (second node-subgroup11)) true))
|
|
||||||
(t/is (= (count (second node-subgroup11)) 1))
|
|
||||||
|
|
||||||
(t/is (= (first node-theme4) "token-theme-4"))
|
(t/is (= (first node-theme4) "token-theme-4"))
|
||||||
(t/is (= (ctob/group? (second node-theme4)) false))
|
(t/is (= (ctob/group? (second node-theme4)) false))
|
||||||
(t/is (= (:name (second node-theme4)) "group1/subgroup11/token-theme-4"))
|
(t/is (= (:name (second node-theme4)) "token-theme-4"))))
|
||||||
|
|
||||||
(t/is (= (first node-theme5) "token-theme-5"))
|
|
||||||
(t/is (= (ctob/group? (second node-theme5)) false))
|
|
||||||
(t/is (= (:name (second node-theme5)) "group2/token-theme-5"))))
|
|
||||||
|
|
||||||
(t/deftest update-theme-in-groups
|
(t/deftest update-theme-in-groups
|
||||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "token-theme-1"))
|
(ctob/add-theme (ctob/make-token-theme :group "" :name "token-theme-1"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/token-theme-2"))
|
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-2"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/token-theme-3"))
|
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-3"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/subgroup11/token-theme-4"))
|
(ctob/add-theme (ctob/make-token-theme :group "group2" :name "token-theme-4")))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group2/token-theme-5")))
|
|
||||||
|
|
||||||
tokens-lib' (-> tokens-lib
|
tokens-lib' (-> tokens-lib
|
||||||
(ctob/update-theme "group1/token-theme-2"
|
(ctob/update-theme "group1" "token-theme-2"
|
||||||
(fn [token-theme]
|
(fn [token-theme]
|
||||||
(assoc token-theme :description "some description"))))
|
(assoc token-theme :description "some description"))))
|
||||||
|
|
||||||
|
@ -916,26 +916,26 @@
|
||||||
token-theme (get-in themes-tree ["group1" "token-theme-2"])
|
token-theme (get-in themes-tree ["group1" "token-theme-2"])
|
||||||
token-theme' (get-in themes-tree' ["group1" "token-theme-2"])]
|
token-theme' (get-in themes-tree' ["group1" "token-theme-2"])]
|
||||||
|
|
||||||
(t/is (= (ctob/theme-count tokens-lib') 5))
|
(t/is (= (ctob/theme-count tokens-lib') 4))
|
||||||
(t/is (= (count group1') 3))
|
(t/is (= (count group1') 2))
|
||||||
(t/is (= (d/index-of (keys group1') "token-theme-2") 0))
|
(t/is (= (d/index-of (keys group1') "token-theme-2") 0))
|
||||||
(t/is (= (:name token-theme') "group1/token-theme-2"))
|
(t/is (= (:name token-theme') "token-theme-2"))
|
||||||
|
(t/is (= (:group token-theme') "group1"))
|
||||||
(t/is (= (:description token-theme') "some description"))
|
(t/is (= (:description token-theme') "some description"))
|
||||||
(t/is (dt/is-after? (:modified-at token-theme') (:modified-at token-theme)))))
|
(t/is (dt/is-after? (:modified-at token-theme') (:modified-at token-theme)))))
|
||||||
|
|
||||||
(t/deftest rename-theme-in-groups
|
(t/deftest rename-theme-in-groups
|
||||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "token-theme-1"))
|
(ctob/add-theme (ctob/make-token-theme :group "" :name "token-theme-1"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/token-theme-2"))
|
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-2"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/token-theme-3"))
|
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-3"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/subgroup11/token-theme-4"))
|
(ctob/add-theme (ctob/make-token-theme :group "group2" :name "token-theme-4")))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group2/token-theme-5")))
|
|
||||||
|
|
||||||
tokens-lib' (-> tokens-lib
|
tokens-lib' (-> tokens-lib
|
||||||
(ctob/update-theme "group1/token-theme-2"
|
(ctob/update-theme "group1" "token-theme-2"
|
||||||
(fn [token-theme]
|
(fn [token-theme]
|
||||||
(assoc token-theme
|
(assoc token-theme
|
||||||
:name "group1/updated-name"))))
|
:name "updated-name"))))
|
||||||
|
|
||||||
themes-tree (ctob/get-theme-tree tokens-lib)
|
themes-tree (ctob/get-theme-tree tokens-lib)
|
||||||
themes-tree' (ctob/get-theme-tree tokens-lib')
|
themes-tree' (ctob/get-theme-tree tokens-lib')
|
||||||
|
@ -943,26 +943,27 @@
|
||||||
token-theme (get-in themes-tree ["group1" "token-theme-2"])
|
token-theme (get-in themes-tree ["group1" "token-theme-2"])
|
||||||
token-theme' (get-in themes-tree' ["group1" "updated-name"])]
|
token-theme' (get-in themes-tree' ["group1" "updated-name"])]
|
||||||
|
|
||||||
(t/is (= (ctob/theme-count tokens-lib') 5))
|
(t/is (= (ctob/theme-count tokens-lib') 4))
|
||||||
(t/is (= (count group1') 3))
|
(t/is (= (count group1') 2))
|
||||||
(t/is (= (d/index-of (keys group1') "updated-name") 0))
|
(t/is (= (d/index-of (keys group1') "updated-name") 0))
|
||||||
(t/is (= (:name token-theme') "group1/updated-name"))
|
(t/is (= (:name token-theme') "updated-name"))
|
||||||
|
(t/is (= (:group token-theme') "group1"))
|
||||||
(t/is (= (:description token-theme') nil))
|
(t/is (= (:description token-theme') nil))
|
||||||
(t/is (dt/is-after? (:modified-at token-theme') (:modified-at token-theme)))))
|
(t/is (dt/is-after? (:modified-at token-theme') (:modified-at token-theme)))))
|
||||||
|
|
||||||
(t/deftest move-theme-of-group
|
(t/deftest move-theme-of-group
|
||||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "token-theme-1"))
|
(ctob/add-theme (ctob/make-token-theme :group "" :name "token-theme-1"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/token-theme-2"))
|
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-2"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/token-theme-3"))
|
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-3"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/subgroup11/token-theme-4"))
|
#_(ctob/add-theme (ctob/make-token-theme :group "group2" :name "token-theme-4")))
|
||||||
#_(ctob/add-theme (ctob/make-token-theme :name "group2/token-theme-5")))
|
|
||||||
|
|
||||||
tokens-lib' (-> tokens-lib
|
tokens-lib' (-> tokens-lib
|
||||||
(ctob/update-theme "group1/token-theme-2"
|
(ctob/update-theme "group1" "token-theme-2"
|
||||||
(fn [token-theme]
|
(fn [token-theme]
|
||||||
(assoc token-theme
|
(assoc token-theme
|
||||||
:name "group2/updated-name"))))
|
:name "updated-name"
|
||||||
|
:group "group2"))))
|
||||||
|
|
||||||
themes-tree (ctob/get-theme-tree tokens-lib)
|
themes-tree (ctob/get-theme-tree tokens-lib)
|
||||||
themes-tree' (ctob/get-theme-tree tokens-lib')
|
themes-tree' (ctob/get-theme-tree tokens-lib')
|
||||||
|
@ -971,21 +972,22 @@
|
||||||
token-theme (get-in themes-tree ["group1" "token-theme-2"])
|
token-theme (get-in themes-tree ["group1" "token-theme-2"])
|
||||||
token-theme' (get-in themes-tree' ["group2" "updated-name"])]
|
token-theme' (get-in themes-tree' ["group2" "updated-name"])]
|
||||||
|
|
||||||
(t/is (= (ctob/theme-count tokens-lib') 4))
|
(t/is (= (ctob/theme-count tokens-lib') 3))
|
||||||
(t/is (= (count group1') 2))
|
(t/is (= (count group1') 1))
|
||||||
(t/is (= (count group2') 1))
|
(t/is (= (count group2') 1))
|
||||||
(t/is (= (d/index-of (keys group2') "updated-name") 0))
|
(t/is (= (d/index-of (keys group2') "updated-name") 0))
|
||||||
(t/is (= (:name token-theme') "group2/updated-name"))
|
(t/is (= (:name token-theme') "updated-name"))
|
||||||
|
(t/is (= (:group token-theme') "group2"))
|
||||||
(t/is (= (:description token-theme') nil))
|
(t/is (= (:description token-theme') nil))
|
||||||
(t/is (dt/is-after? (:modified-at token-theme') (:modified-at token-theme)))))
|
(t/is (dt/is-after? (:modified-at token-theme') (:modified-at token-theme)))))
|
||||||
|
|
||||||
(t/deftest delete-theme-in-group
|
(t/deftest delete-theme-in-group
|
||||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "token-theme-1"))
|
(ctob/add-theme (ctob/make-token-theme :group "" :name "token-theme-1"))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "group1/token-theme-2")))
|
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-2")))
|
||||||
|
|
||||||
tokens-lib' (-> tokens-lib
|
tokens-lib' (-> tokens-lib
|
||||||
(ctob/delete-theme "group1/token-theme-2"))
|
(ctob/delete-theme "group1" "token-theme-2"))
|
||||||
|
|
||||||
themes-tree' (ctob/get-theme-tree tokens-lib')
|
themes-tree' (ctob/get-theme-tree tokens-lib')
|
||||||
token-theme' (get-in themes-tree' ["group1" "token-theme-2"])]
|
token-theme' (get-in themes-tree' ["group1" "token-theme-2"])]
|
||||||
|
|
Loading…
Add table
Reference in a new issue