From 3413d4b42f8dc3c054545cd90d7ffed9fcf4ca91 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 19 Aug 2024 09:09:09 +0200 Subject: [PATCH] Add tests --- .../main/ui/workspace/tokens/token_set.cljs | 17 --------- frontend/test/token_tests/token_set_test.cljs | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 frontend/test/token_tests/token_set_test.cljs diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index e44c3da6a..7d7a432b8 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -59,23 +59,6 @@ (or temp-theme-id-set #{}) new-themes))) -(comment - (let [state {:workspace-data {:token-themes-index {1 {:id 1}}}}] - (toggle-active-theme-id 1 state)) - - (let [state {:workspace-data {:token-active-themes #{1} - :token-themes-index {1 {:id 1}}}}] - (toggle-active-theme-id 1 state)) - - (let [state {:workspace-data {:token-active-themes #{2 3 4} - :token-themes-index {1 {:id 1} - 2 {:id 2} - 3 {:id 3} - 4 {:id 4 :group :different}}}}] - (toggle-active-theme-id 1 state)) - nil) - - (defn update-theme-id [state] (let [active-themes (get-active-theme-ids state) diff --git a/frontend/test/token_tests/token_set_test.cljs b/frontend/test/token_tests/token_set_test.cljs new file mode 100644 index 000000000..d199e221c --- /dev/null +++ b/frontend/test/token_tests/token_set_test.cljs @@ -0,0 +1,37 @@ +(ns token-tests.token-set-test + (:require + [app.main.ui.workspace.tokens.token-set :as wtts] + [cljs.test :as t])) + +(t/deftest toggle-active-theme-id-test + (t/testing "toggles active theme id" + (let [state {:workspace-data {:token-themes-index {1 {:id 1}}}}] + (t/testing "activates theme with id") + (t/is (= (wtts/toggle-active-theme-id 1 state) #{1}))) + + (let [state {:workspace-data {:token-active-themes #{1} + :token-themes-index {1 {:id 1}}}}] + (t/testing "missing temp theme returns empty set" + (t/is (= #{} (wtts/toggle-active-theme-id 1 state))))) + + (let [state {:workspace-data {:token-theme-temporary-id :temp + :token-active-themes #{1} + :token-themes-index {1 {:id 1}}}}] + (t/testing "empty set returns temp theme" + (t/is (= #{:temp} (wtts/toggle-active-theme-id 1 state))))) + + (let [state {:workspace-data {:token-active-themes #{2 3 4} + :token-themes-index {1 {:id 1} + 2 {:id 2} + 3 {:id 3} + 4 {:id 4 :group :different}}}}] + (t/testing "removes same group themes and keeps different group themes" + (t/is (= #{1 4} (wtts/toggle-active-theme-id 1 state))))) + + (let [state {:workspace-data {:token-active-themes #{1 2 3 4}} + :token-themes-index {1 {:id 1} + 2 {:id 2} + 3 {:id 3} + 4 {:id 4 :group :different}}}] + (t/testing "removes theme when active" + (t/is (= #{4 3 2} (wtts/toggle-active-theme-id 1 state)))))))