diff --git a/common/test/common_tests/types/token_test.cljc b/common/test/common_tests/types/token_test.cljc index 70632607ba..64ae2bee36 100644 --- a/common/test/common_tests/types/token_test.cljc +++ b/common/test/common_tests/types/token_test.cljc @@ -73,6 +73,9 @@ (t/testing "circles, paths, booleans and svgs share the generic attributes" (let [attrs (cto/shape-type->attributes :circle false)] + (t/is (set/subset? cto/sizing-keys attrs)) + (t/is (set/subset? cto/opacity-keys attrs)) + (t/is (set/subset? cto/rotation-keys attrs)) (t/is (set/subset? cto/stroke-width-keys attrs)) (t/is (set/subset? cto/shadow-keys attrs)) (t/is (empty? (set/intersection cto/border-radius-keys attrs))) diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 41761083ee..5e2458cad8 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -2176,12 +2176,12 @@ (map first result))) (t/is (= (map first result) (map (comp :name second) result))))) - (t/testing "tokens without the group's name in their path stay as they are" + (t/testing "tokens outside the renamed group stay as they are" (let [result (into {} (ctob/update-tokens-group active-tokens "color.brand" "brand" "accent"))] (t/is (= (get active-tokens "color.neutral.gray") (get result "color.neutral.gray"))) (t/is (= (get active-tokens "spacing.sm") (get result "spacing.sm"))))) - (t/testing "renaming a top level group renames it in the tokens that have its name" + (t/testing "renaming a top level group renames it in all of its tokens" (t/is (= ["palette.brand.primary" "palette.brand.secondary" "palette.neutral.gray" "spacing.sm"] (map first (ctob/update-tokens-group active-tokens "color" "color" "palette"))))))) diff --git a/frontend/test/frontend_tests/helpers/i18n.cljs b/frontend/test/frontend_tests/helpers/i18n.cljs new file mode 100644 index 0000000000..68f85627ee --- /dev/null +++ b/frontend/test/frontend_tests/helpers/i18n.cljs @@ -0,0 +1,20 @@ +;; 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.helpers.i18n + (:require + [app.util.i18n :as i18n] + [clojure.string :as str])) + +;; Both arities, like `tr`: a call site compiled for one of them looks up +;; that arity on the replacement. +(defn tr-stub + "Stands in for `tr` in tests about the values in a message. The test run + loads no translations, so `tr` returns the bare key and drops the values; + this echoes the key with them." + ([key] key) + ([key & args] + (str key "(" (str/join ", " (map #(if (i18n/c? %) @% %) args)) ")"))) diff --git a/frontend/test/frontend_tests/tokens/import_export_test.cljs b/frontend/test/frontend_tests/tokens/import_export_test.cljs index a38110d19f..62851a7220 100644 --- a/frontend/test/frontend_tests/tokens/import_export_test.cljs +++ b/frontend/test/frontend_tests/tokens/import_export_test.cljs @@ -12,18 +12,11 @@ [app.util.i18n :as i18n] [beicon.v2.core :as rx] [cljs.test :as t :include-macros true] - [clojure.string :as str])) + [clojure.string :as str] + [frontend-tests.helpers.i18n :refer [tr-stub]])) (def ^:private import-warnings-notification @#'dwti/import-warnings-notification) -;; Echoes the key and its arguments, so the test sees what went into each -;; string. Both arities, like `tr`: a call site compiled for one of them -;; looks up that arity on the replacement. -(defn- tr-stub - ([key] key) - ([key & args] - (str key "(" (str/join ", " (map #(if (i18n/c? %) @% %) args)) ")"))) - (t/deftest import-warnings-notification-test (with-redefs [i18n/tr tr-stub] (let [unknown-types {"core.motion.fast" "duration" diff --git a/frontend/test/frontend_tests/tokens/token_errors_test.cljs b/frontend/test/frontend_tests/tokens/token_errors_test.cljs index 5089324913..08df0f3096 100644 --- a/frontend/test/frontend_tests/tokens/token_errors_test.cljs +++ b/frontend/test/frontend_tests/tokens/token_errors_test.cljs @@ -9,14 +9,7 @@ [app.main.data.workspace.tokens.errors :as wte] [app.util.i18n :as i18n :refer [tr]] [cljs.test :as t :include-macros true] - [clojure.string :as str])) - -;; The test run loads no translations, so `tr` returns the bare key and -;; drops its arguments. Tests about the values in a message echo them with -;; this stub. Both arities, like `tr`. -(defn- tr-stub - ([key] key) - ([key & args] (str key "(" (str/join ", " args) ")"))) + [frontend-tests.helpers.i18n :refer [tr-stub]])) ;; --------------------------------------------------------------------------- ;; resolve-error-message @@ -40,8 +33,9 @@ (t/deftest resolve-error-message-known-error (t/testing "a known error code shows its translated message" - (t/is (= (tr "errors.tokens.invalid-color" "#zzz") - (wte/resolve-error-message (wte/error-with-value :error.token/invalid-color "#zzz")))))) + (with-redefs [i18n/tr tr-stub] + (t/is (= (tr "errors.tokens.invalid-color" "#zzz") + (wte/resolve-error-message (wte/error-with-value :error.token/invalid-color "#zzz"))))))) (t/deftest resolve-error-message-without-error (t/testing "without an error the message is the unknown error" @@ -81,10 +75,11 @@ (t/deftest humanize-errors (t/testing "known error codes show their translated message" - (t/is (= [(tr "errors.tokens.empty-input") - (tr "errors.tokens.invalid-color" "#zzz")] - (wte/humanize-errors [(wte/error-with-value :error.token/empty-input nil) - (wte/error-with-value :error.token/invalid-color "#zzz")])))) + (with-redefs [i18n/tr tr-stub] + (t/is (= [(tr "errors.tokens.empty-input") + (tr "errors.tokens.invalid-color" "#zzz")] + (wte/humanize-errors [(wte/error-with-value :error.token/empty-input nil) + (wte/error-with-value :error.token/invalid-color "#zzz")]))))) (t/testing "incompatible units are listed in one message" (with-redefs [i18n/tr tr-stub] diff --git a/frontend/test/frontend_tests/tokens/token_warnings_test.cljs b/frontend/test/frontend_tests/tokens/token_warnings_test.cljs index 9f1cf24778..4b0f44c6c6 100644 --- a/frontend/test/frontend_tests/tokens/token_warnings_test.cljs +++ b/frontend/test/frontend_tests/tokens/token_warnings_test.cljs @@ -7,17 +7,20 @@ (ns frontend-tests.tokens.token-warnings-test (:require [app.main.data.workspace.tokens.warnings :as wtw] - [app.util.i18n :refer [tr]] - [cljs.test :as t :include-macros true])) + [app.util.i18n :as i18n :refer [tr]] + [cljs.test :as t :include-macros true] + [frontend-tests.helpers.i18n :refer [tr-stub]])) (t/deftest humanize-warnings (t/testing "an out of range opacity shows the resolved value and the allowed range" - (t/is (= [(str (tr "workspace.tokens.resolved-value" 1.5) ".\n" (tr "errors.tokens.opacity-range"))] - (wtw/humanize-warnings [(wtw/warning-with-value :warning.style-dictionary/invalid-referenced-token-value-opacity 1.5)])))) + (with-redefs [i18n/tr tr-stub] + (t/is (= [(str (tr "workspace.tokens.resolved-value" 1.5) ".\n" (tr "errors.tokens.opacity-range"))] + (wtw/humanize-warnings [(wtw/warning-with-value :warning.style-dictionary/invalid-referenced-token-value-opacity 1.5)]))))) (t/testing "an out of range stroke width shows the resolved value and the allowed range" - (t/is (= [(str (tr "workspace.tokens.resolved-value" -2) ".\n" (tr "errors.tokens.stroke-width-range"))] - (wtw/humanize-warnings [(wtw/warning-with-value :warning.style-dictionary/invalid-referenced-token-value-stroke-width -2)])))) + (with-redefs [i18n/tr tr-stub] + (t/is (= [(str (tr "workspace.tokens.resolved-value" -2) ".\n" (tr "errors.tokens.stroke-width-range"))] + (wtw/humanize-warnings [(wtw/warning-with-value :warning.style-dictionary/invalid-referenced-token-value-stroke-width -2)]))))) (t/testing "an unknown warning code shows the unknown warning message" (t/is (= ["Unknown warning"]