🔧 Tighten the token helper tests after review (#13242)

Follow-up to #13210, from its review. The warning and error message
tests now echo the translation arguments, so they fail when the value
goes missing from the message. The generic shape attributes also check
sizing, opacity and rotation, and the group renaming cases talk about
group membership rather than the group's name in the path.

The token tests now share one `tr` stub instead of three copies.

Signed-off-by: Florian Schroedl <flo.schroedl@gmail.com>
Co-authored-by: Eva Marco <eva.marco@kaleidos.net>
This commit is contained in:
Florian Schrödl 2026-11-24 10:24:56 +01:00 committed by GitHub
parent a7726b279d
commit 8490d2a18a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 45 additions and 31 deletions

View File

@ -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)))

View File

@ -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")))))))

View File

@ -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)) ")")))

View File

@ -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"

View File

@ -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]

View File

@ -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"]